parallelised service endpoint discovery and ensured that old threads are destroyed...
[jalview.git] / src / jalview / ws / jws2 / JabaWsServerQuery.java
1 /**
2  * 
3  */
4 package jalview.ws.jws2;
5
6 import jalview.bin.Cache;
7
8 import compbio.data.msa.MsaWS;
9 import compbio.ws.client.Jws2Client;
10 import compbio.ws.client.Services;
11
12 /**
13  * @author JimP
14  *
15  */
16 public class JabaWsServerQuery implements Runnable
17 {
18
19   Jws2Discoverer jws2Discoverer=null;
20   String jwsservers=null;
21   boolean quit=false,
22   running=false;
23   /**
24    * @return the running
25    */
26   public  boolean isRunning()
27   {
28     return running;
29   }
30
31   /**
32    * @param quit the quit to set
33    */
34   public void setQuit(boolean quit)
35   {
36     this.quit = quit;
37   }
38
39   public JabaWsServerQuery(Jws2Discoverer jws2Discoverer, String jwsservers)
40   {
41     this.jws2Discoverer = jws2Discoverer;
42     this.jwsservers=jwsservers;
43   }
44
45   /* (non-Javadoc)
46    * @see java.lang.Runnable#run()
47    */
48   @Override
49   public void run()
50   {
51     running=true;
52         try
53     {
54       if (Jws2Client.validURL(jwsservers))
55       {
56         // look for services
57         for (Services srv : Services.values())
58         {
59           if (quit)
60           {
61             running=false;
62             return;
63           }
64           MsaWS service = null;
65           try
66           {
67             service = Jws2Client.connect(jwsservers, srv);
68           } catch (Exception e)
69           {
70             System.err.println("Jws2 Discoverer: Problem on "
71                     + jwsservers + " with service " + srv + ":\n"
72                     + e.getMessage());
73             if (!(e instanceof javax.xml.ws.WebServiceException))
74             {
75               e.printStackTrace();
76             }
77           }
78           ;
79           if (service != null)
80           {
81             jws2Discoverer.addService(jwsservers, srv, service);
82           }
83         }
84
85       }
86       else
87       {
88         Cache.log.info("Ignoring invalid Jws2 service url " + jwsservers);
89       }
90     } catch (Exception e)
91     {
92       e.printStackTrace();
93       Cache.log.warn("Exception when discovering Jws2 services.", e);
94     } catch (Error e)
95     {
96       Cache.log.error("Exception when discovering Jws2 services.", e);
97     }
98     running=false;
99   }
100
101 }