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
}\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
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
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
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
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
((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
\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
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
\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
}\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