Command line options are described and added to the client. Registry is modified...
[jabaws.git] / webservices / compbio / ws / server / RegistryWS.java
index dda265e..0ff4294 100644 (file)
@@ -35,8 +35,16 @@ public class RegistryWS implements compbio.data.msa.RegistryWS, JABAService {
 \r
        private static Logger log = Logger.getLogger(RegistryWS.class);\r
 \r
+       /**\r
+        * Stores tested and passed (the test) services and their testing time\r
+        */\r
        private final static Map<Services, Date> operating = new ConcurrentHashMap<Services, Date>();\r
 \r
+       /**\r
+        * Indicate whether the services were tested at all\r
+        */\r
+       private static boolean allTested = false;\r
+\r
        @Override\r
        public Set<Services> getSupportedServices() {\r
                init();\r
@@ -44,16 +52,44 @@ public class RegistryWS implements compbio.data.msa.RegistryWS, JABAService {
        }\r
 \r
        private void init() {\r
-               // This should not be run concurrently\r
-               if (operating.isEmpty()) {\r
+               // Do not allow tests to run concurrently\r
+               if (timeToTest()) {\r
                        synchronized (operating) {\r
-                               if (operating.isEmpty()) {\r
+                               if (timeToTest()) {\r
                                        testAllServices();\r
+                                       allTested = true;\r
                                }\r
                        }\r
                }\r
        }\r
 \r
+       private boolean timeToTest() {\r
+               if (!allTested) {\r
+                       return true;\r
+               }\r
+               // 24 h\r
+               if (getLongestUntestedServiceTime() > 3600 * 24) {\r
+                       return true;\r
+               }\r
+               return false;\r
+       }\r
+\r
+       /**\r
+        * Return time in seconds for the test for the oldest unchecked service\r
+        * \r
+        * @return\r
+        */\r
+       private int getLongestUntestedServiceTime() {\r
+               int timePassed = 0;\r
+               for (Services serv : operating.keySet()) {\r
+                       int lasttimepassed = getLastTested(serv);\r
+                       if (timePassed < lasttimepassed) {\r
+                               timePassed = lasttimepassed;\r
+                       }\r
+               }\r
+               return timePassed;\r
+       }\r
+\r
        @Override\r
        public int getLastTested(Services service) {\r
                Date testedOn = getLastTestedOn(service);\r