1 29 package net.sourceforge.groboutils.autodoc.v1.testserver; 30 31 32 import java.util.Hashtable ; 33 34 import org.apache.log4j.Logger; 35 36 37 45 public class DefaultMonitor implements Monitor 46 { 47 private static final Logger LOG = Logger.getLogger( DefaultMonitor.class ); 48 49 private Hashtable testData = new Hashtable (); 50 private TestDataFactory dataFactory; 51 private Server server; 52 53 54 67 public DefaultMonitor( Server s, TestDataFactory f ) 68 { 69 if (s == null || f == null) 70 { 71 throw new IllegalArgumentException ("no null arguments"); 72 } 73 this.server = s; 74 this.dataFactory = f; 75 } 76 77 78 89 public void addTestData( TestInfo info ) 90 { 91 assertNotNull( info ); 92 synchronized (this.testData) 93 { 94 if (this.testData.containsKey( info )) 95 { 96 throw new IllegalStateException ( "Test "+info+ 97 " has already been registered." ); 98 } 99 LOG.debug("**** Monitor "+this+" adding test "+info); 100 TestData td = createTestData( info ); 101 this.testData.put( info, td ); 102 } 103 } 104 105 106 116 public TestData getTestData( TestInfo info ) 117 { 118 assertNotNull( info ); 119 synchronized (this.testData) 120 { 121 TestData td = (TestData)this.testData.get( info ); 122 assertNotNull( td ); 123 return td; 124 } 125 } 126 127 128 138 public void sendTestData( TestInfo info ) 139 { 140 assertNotNull( info ); 141 TestData td; 142 synchronized (this.testData) 143 { 144 td = (TestData)this.testData.remove( info ); 145 } 146 LOG.debug("**** Monitor "+this+" removing test "+info); 147 sendTestDataToServer( td ); 148 } 149 150 151 158 protected TestData createTestData( TestInfo info ) 159 { 160 TestData td = this.dataFactory.createTestData( info ); 161 if (td == null) 162 { 163 throw new IllegalStateException ("factory returned null"); 164 } 165 return td; 166 } 167 168 169 175 protected TestData retrieveTestData( TestInfo info ) 176 { 177 TestData td = (TestData)this.testData.get( info ); 178 return td; 179 } 180 181 182 185 protected void sendTestDataToServer( TestData td ) 186 { 187 assertNotNull( td ); 188 this.server.addTestData( td ); 189 } 190 191 192 195 protected void assertNotNull( TestInfo info ) 196 { 197 if (info == null) 198 { 199 throw new IllegalArgumentException ( "TestInfo was null" ); 200 } 201 } 202 203 204 207 protected void assertNotNull( TestData td ) 208 { 209 if (td == null) 210 { 211 throw new IllegalStateException ( "Test is not registered." ); 212 } 213 } 214 } 215 216 | Popular Tags |