X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=webservices%2Fcompbio%2Fws%2Fserver%2FRegistryWS.java;h=3898b884ff4c0aafebf46091dba76faba3f3a945;hb=140e024c6b00451dd933a9c25feac2d170d5f9f6;hp=dda265e20e447ac64620195d28923f3ecdef482e;hpb=804613aebb1aba7ef76a4766c0b16698c35e6795;p=jabaws.git diff --git a/webservices/compbio/ws/server/RegistryWS.java b/webservices/compbio/ws/server/RegistryWS.java index dda265e..3898b88 100644 --- a/webservices/compbio/ws/server/RegistryWS.java +++ b/webservices/compbio/ws/server/RegistryWS.java @@ -1,3 +1,20 @@ +/* Copyright (c) 2011 Peter Troshin + * + * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0 + * + * This library is free software; you can redistribute it and/or modify it under the terms of the + * Apache License version 2 as published by the Apache Software Foundation + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache + * License for more details. + * + * A copy of the license is in apache_license.txt. It is also available here: + * @see: http://www.apache.org/licenses/LICENSE-2.0.txt + * + * Any republication or derived work distributed in source code form + * must include this copyright and license notice. + */ package compbio.ws.server; import java.io.PrintWriter; @@ -26,7 +43,7 @@ import compbio.ws.client.WSTester; * @author pvtroshin * */ -@WebService(endpointInterface = "compbio.data.msa.RegistryWS", targetNamespace = "http://msa.data.compbio/01/12/2010/", serviceName = "RegistryWS") +@WebService(endpointInterface = "compbio.data.msa.RegistryWS", targetNamespace = JABAService.V2_SERVICE_NAMESPACE, serviceName = "RegistryWS") public class RegistryWS implements compbio.data.msa.RegistryWS, JABAService { // Ask for resource injection @@ -35,8 +52,16 @@ public class RegistryWS implements compbio.data.msa.RegistryWS, JABAService { private static Logger log = Logger.getLogger(RegistryWS.class); + /** + * Stores tested and passed (the test) services and their testing time + */ private final static Map operating = new ConcurrentHashMap(); + /** + * Indicate whether the services were tested at all + */ + private static boolean allTested = false; + @Override public Set getSupportedServices() { init(); @@ -44,16 +69,44 @@ public class RegistryWS implements compbio.data.msa.RegistryWS, JABAService { } private void init() { - // This should not be run concurrently - if (operating.isEmpty()) { + // Do not allow tests to run concurrently + if (timeToTest()) { synchronized (operating) { - if (operating.isEmpty()) { + if (timeToTest()) { testAllServices(); + allTested = true; } } } } + private boolean timeToTest() { + if (!allTested) { + return true; + } + // 24 h + if (getLongestUntestedServiceTime() > 3600 * 24) { + return true; + } + return false; + } + + /** + * Return time in seconds for the test for the oldest unchecked service + * + * @return + */ + private int getLongestUntestedServiceTime() { + int timePassed = 0; + for (Services serv : operating.keySet()) { + int lasttimepassed = getLastTested(serv); + if (timePassed < lasttimepassed) { + timePassed = lasttimepassed; + } + } + return timePassed; + } + @Override public int getLastTested(Services service) { Date testedOn = getLastTestedOn(service); @@ -87,8 +140,16 @@ public class RegistryWS implements compbio.data.msa.RegistryWS, JABAService { // the server synchronized (operating) { for (Services service : Services.values()) { - if (tester.checkService(service)) { - operating.put(service, new Date()); + try { + if (tester.checkService(service)) { + operating.put(service, new Date()); + } + } catch (Exception e) { + log.info(e, e.getCause()); + writer.println("Fails to connect to a web service: " + + service + " With " + e.getLocalizedMessage() + + "\nDetails: "); + e.printStackTrace(writer); } } } @@ -120,16 +181,30 @@ public class RegistryWS implements compbio.data.msa.RegistryWS, JABAService { operating.put(service, new Date()); } } + } catch (Exception e) { + log.info(e, e.getCause()); + writer.println("Fails to connect to a web service: " + service + + " With " + e.getLocalizedMessage() + "\nDetails: "); + e.printStackTrace(writer); } finally { writer.close(); } return testlog.toString(); } - @Override public boolean isOperating(Services service) { init(); return operating.containsKey(service); } + @Override + public String getServiceDescription(Services service) { + return service.getServiceInfo(); + } + + @Override + public Set getServiceCategories() { + return Category.getCategories(); + } + }