Command line options are described and added to the client. Registry is modified...
authorpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Mon, 13 Jun 2011 15:01:09 +0000 (15:01 +0000)
committerpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Mon, 13 Jun 2011 15:01:09 +0000 (15:01 +0000)
git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@4261 e3abac25-378b-4346-85de-24260fe3988d

testsrc/testdata/aaconprm.txt [new file with mode: 0644]
webservices/compbio/ws/client/CmdHelper.java
webservices/compbio/ws/client/Jws2Client.java
webservices/compbio/ws/client/Services.java
webservices/compbio/ws/server/RegistryWS.java

diff --git a/testsrc/testdata/aaconprm.txt b/testsrc/testdata/aaconprm.txt
new file mode 100644 (file)
index 0000000..fa4f64a
--- /dev/null
@@ -0,0 +1,2 @@
+-m=LANDGRAF\r
+-n\r
index 1faf3dc..5b33aba 100644 (file)
@@ -1,11 +1,13 @@
 package compbio.ws.client;\r
 import static compbio.ws.client.Constraints.hostkey;\r
 import static compbio.ws.client.Constraints.limitList;\r
+import static compbio.ws.client.Constraints.listServices;\r
 import static compbio.ws.client.Constraints.paramList;\r
 import static compbio.ws.client.Constraints.presetList;\r
 import static compbio.ws.client.Constraints.presetkey;\r
 import static compbio.ws.client.Constraints.pseparator;\r
 import static compbio.ws.client.Constraints.servicekey;\r
+import static compbio.ws.client.Constraints.testKey;\r
 \r
 class CmdHelper {\r
 \r
@@ -32,6 +34,26 @@ class CmdHelper {
        }\r
 \r
        /**\r
+        * list available services\r
+        * \r
+        * @param cmd\r
+        * @return\r
+        */\r
+       static boolean listServices(String[] cmd) {\r
+               return keyFound(cmd, listServices);\r
+       }\r
+\r
+       /**\r
+        * tests service\r
+        * \r
+        * @param cmd\r
+        * @return\r
+        */\r
+       static boolean testService(String[] cmd) {\r
+               return keyFound(cmd, testKey);\r
+       }\r
+\r
+       /**\r
         * Checks whether the key is in the command line\r
         * \r
         * @param cmd\r
index 48d107d..c18f100 100644 (file)
@@ -32,6 +32,7 @@ import java.net.MalformedURLException;
 import java.net.URL;\r
 import java.util.Arrays;\r
 import java.util.List;\r
+import java.util.Set;\r
 import java.util.logging.Level;\r
 import java.util.logging.Logger;\r
 \r
@@ -42,6 +43,7 @@ import javax.xml.ws.WebServiceException;
 import compbio.data.msa.JABAService;\r
 import compbio.data.msa.Metadata;\r
 import compbio.data.msa.MsaWS;\r
+import compbio.data.msa.RegistryWS;\r
 import compbio.data.msa.SequenceAnnotation;\r
 import compbio.data.sequence.Alignment;\r
 import compbio.data.sequence.FastaSequence;\r
@@ -115,6 +117,13 @@ public class Jws2Client {
                        System.err.println("Host name is not valid!");\r
                        printUsage(1);\r
                }\r
+               // Just list available services and quit\r
+               boolean listServices = CmdHelper.listServices(cmd);\r
+               if (listServices) {\r
+                       listServices(hostname);\r
+                       System.exit(0);\r
+               }\r
+\r
                String serviceName = CmdHelper.getServiceName(cmd);\r
                if (serviceName == null) {\r
                        System.err.println("Service name is no provided!");\r
@@ -123,10 +132,17 @@ public class Jws2Client {
                Services service = Services.getService(serviceName);\r
                if (service == null) {\r
                        System.err.println("Service " + serviceName\r
-                                       + " is no supported! Valid values are: "\r
+                                       + " is no recognized! Valid values are: "\r
                                        + Arrays.toString(Services.values()));\r
                        printUsage(1);\r
                }\r
+               // Test service and quit\r
+               boolean testService = CmdHelper.testService(cmd);\r
+               if (testService) {\r
+                       testService(hostname, service);\r
+                       System.exit(0);\r
+               }\r
+\r
                File inputFile = IOHelper.getFile(cmd, inputkey, true);\r
                File outFile = IOHelper.getFile(cmd, outputkey, false);\r
                File parametersFile = IOHelper.getFile(cmd, paramFile, true);\r
@@ -182,6 +198,30 @@ public class Jws2Client {
                ((Closeable) msaws).close();\r
                log.fine("Disconnected successfully!");\r
        }\r
+\r
+       private void testService(String hostname, Services service)\r
+                       throws IOException {\r
+               RegistryWS registry = connectToRegistry(hostname);\r
+               if (registry != null) {\r
+                       String message = registry.testService(service);\r
+                       System.out.println("Service " + service + " testing results: ");\r
+                       System.out.println(message);\r
+                       ((Closeable) registry).close();\r
+               }\r
+       }\r
+\r
+       private void listServices(String hostname) throws IOException {\r
+               RegistryWS registry = connectToRegistry(hostname);\r
+               if (registry != null) {\r
+                       Set<Services> services = registry.getSupportedServices();\r
+                       System.out.println("Supported services are: "\r
+                                       + Services.toString(services));\r
+                       ((Closeable) registry).close();\r
+               } else {\r
+                       System.out.println("Failed to connect to the registry! ");\r
+               }\r
+       }\r
+\r
        /**\r
         * Calculate conservation for sequences loaded from the file\r
         * \r
index 01b4827..3c55c18 100644 (file)
@@ -20,6 +20,7 @@ package compbio.ws.client;
 \r
 import java.io.File;\r
 import java.net.URL;\r
+import java.util.Set;\r
 \r
 import javax.xml.namespace.QName;\r
 import javax.xml.ws.Service;\r
@@ -132,6 +133,19 @@ public enum Services {
                return Service.create(url, qname);\r
        }\r
 \r
+       public static String toString(Set<Services> services) {\r
+               if (services == null || services.isEmpty()) {\r
+                       return "";\r
+               }\r
+               String value = "";\r
+               String delim = ", ";\r
+               for (Services serv : services) {\r
+                       value += serv.toString() + delim;\r
+               }\r
+               value = value.substring(0, value.length() - delim.length());\r
+               return value;\r
+       }\r
+\r
        Class<? extends JABAService> getServiceType() {\r
                switch (this) {\r
                        // deliberate leaking\r
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