1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.ws.jws2; |
22 |
|
|
23 |
|
import java.awt.Color; |
24 |
|
import java.awt.event.ActionEvent; |
25 |
|
import java.awt.event.ActionListener; |
26 |
|
import java.beans.PropertyChangeEvent; |
27 |
|
import java.beans.PropertyChangeListener; |
28 |
|
import java.beans.PropertyChangeSupport; |
29 |
|
import java.net.MalformedURLException; |
30 |
|
import java.net.URL; |
31 |
|
import java.util.ArrayList; |
32 |
|
import java.util.Arrays; |
33 |
|
import java.util.HashMap; |
34 |
|
import java.util.HashSet; |
35 |
|
import java.util.Hashtable; |
36 |
|
import java.util.List; |
37 |
|
import java.util.Map; |
38 |
|
import java.util.Set; |
39 |
|
import java.util.StringTokenizer; |
40 |
|
import java.util.Vector; |
41 |
|
|
42 |
|
import javax.swing.JMenu; |
43 |
|
import javax.swing.JMenuItem; |
44 |
|
|
45 |
|
import compbio.ws.client.Services; |
46 |
|
import jalview.bin.Cache; |
47 |
|
import jalview.bin.Console; |
48 |
|
import jalview.gui.AlignFrame; |
49 |
|
import jalview.gui.Desktop; |
50 |
|
import jalview.gui.JvSwingUtils; |
51 |
|
import jalview.util.MessageManager; |
52 |
|
import jalview.ws.WSMenuEntryProviderI; |
53 |
|
import jalview.ws.jws2.jabaws2.Jws2Instance; |
54 |
|
import jalview.ws.params.ParamDatastoreI; |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
@author |
61 |
|
|
62 |
|
|
|
|
| 54.7% |
Uncovered Elements: 229 (505) |
Complexity: 141 |
Complexity Density: 0.44 |
|
63 |
|
public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI |
64 |
|
{ |
65 |
|
public static final String COMPBIO_JABAWS = "http://www.compbio.dundee.ac.uk/jabaws"; |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
private final static String JWS2HOSTURLS = "JWS2HOSTURLS"; |
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
private static Jws2Discoverer discoverer; |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
private static List<String> testUrls = null; |
81 |
|
|
82 |
|
|
83 |
|
private String preferredUrl; |
84 |
|
|
85 |
|
private PropertyChangeSupport changeSupport = new PropertyChangeSupport( |
86 |
|
this); |
87 |
|
|
88 |
|
private Vector<String> invalidServiceUrls = null; |
89 |
|
|
90 |
|
private Vector<String> urlsWithoutServices = null; |
91 |
|
|
92 |
|
private Vector<String> validServiceUrls = null; |
93 |
|
|
94 |
|
private volatile boolean running = false; |
95 |
|
|
96 |
|
private volatile boolean aborted = false; |
97 |
|
|
98 |
|
private Thread oldthread = null; |
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
protected Vector<Jws2Instance> services; |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
108 |
1 |
private Jws2Discoverer()... |
109 |
|
{ |
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
@param |
116 |
|
|
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
118 |
41 |
public void addPropertyChangeListener(... |
119 |
|
java.beans.PropertyChangeListener listener) |
120 |
|
{ |
121 |
41 |
changeSupport.addPropertyChangeListener(listener); |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
@param |
128 |
|
|
129 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
130 |
0 |
public void removePropertyChangeListener(... |
131 |
|
java.beans.PropertyChangeListener listener) |
132 |
|
{ |
133 |
0 |
changeSupport.removePropertyChangeListener(listener); |
134 |
|
} |
135 |
|
|
136 |
|
|
137 |
|
@return |
138 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
139 |
768 |
public boolean isAborted()... |
140 |
|
{ |
141 |
768 |
return aborted; |
142 |
|
} |
143 |
|
|
144 |
|
|
145 |
|
@param |
146 |
|
|
147 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
148 |
18 |
public void setAborted(boolean aborted)... |
149 |
|
{ |
150 |
18 |
this.aborted = aborted; |
151 |
|
} |
152 |
|
|
|
|
| 86.6% |
Uncovered Elements: 13 (97) |
Complexity: 23 |
Complexity Density: 0.34 |
|
153 |
41 |
@Override... |
154 |
|
public void run() |
155 |
|
{ |
156 |
|
|
157 |
41 |
if (running && oldthread != null && oldthread.isAlive()) |
158 |
|
{ |
159 |
17 |
if (!aborted) |
160 |
|
{ |
161 |
0 |
return; |
162 |
|
} |
163 |
34 |
while (running) |
164 |
|
{ |
165 |
17 |
try |
166 |
|
{ |
167 |
17 |
Console.debug( |
168 |
|
"Waiting around for old discovery thread to finish."); |
169 |
|
|
170 |
17 |
Thread.sleep(100); |
171 |
|
} catch (Exception e) |
172 |
|
{ |
173 |
|
} |
174 |
|
} |
175 |
17 |
aborted = false; |
176 |
17 |
Console.debug("Old discovery thread has finished."); |
177 |
|
} |
178 |
41 |
running = true; |
179 |
|
|
180 |
|
|
181 |
41 |
final Set<String> ignoredServices = new HashSet<>(); |
182 |
41 |
for (String ignored : Cache |
183 |
|
.getDefault("IGNORED_JABAWS_SERVICETYPES", "").split("\\|")) |
184 |
|
{ |
185 |
41 |
ignoredServices.add(ignored); |
186 |
|
} |
187 |
|
|
188 |
41 |
changeSupport.firePropertyChange("services", services, |
189 |
|
new Vector<Jws2Instance>()); |
190 |
41 |
oldthread = Thread.currentThread(); |
191 |
41 |
try |
192 |
|
{ |
193 |
41 |
Class foo = getClass().getClassLoader() |
194 |
|
.loadClass("compbio.ws.client.Jws2Client"); |
195 |
|
} catch (ClassNotFoundException e) |
196 |
|
{ |
197 |
0 |
jalview.bin.Console.errPrintln( |
198 |
|
"Not enabling JABA Webservices : client jar is not available." |
199 |
|
+ "\nPlease check that your webstart JNLP file is up to date!"); |
200 |
0 |
running = false; |
201 |
0 |
return; |
202 |
|
} |
203 |
|
|
204 |
41 |
if (services != null) |
205 |
|
{ |
206 |
40 |
services.removeAllElements(); |
207 |
|
} |
208 |
41 |
if (urlsWithoutServices != null) |
209 |
|
{ |
210 |
0 |
urlsWithoutServices.removeAllElements(); |
211 |
|
} |
212 |
41 |
if (invalidServiceUrls != null) |
213 |
|
{ |
214 |
0 |
invalidServiceUrls.removeAllElements(); |
215 |
|
} |
216 |
41 |
if (validServiceUrls != null) |
217 |
|
{ |
218 |
40 |
validServiceUrls.removeAllElements(); |
219 |
|
} |
220 |
41 |
ArrayList<String> svctypes = new ArrayList<>(); |
221 |
|
|
222 |
41 |
List<JabaWsServerQuery> qrys = new ArrayList<>(); |
223 |
41 |
for (final String jwsserver : getServiceUrls()) |
224 |
|
{ |
225 |
41 |
JabaWsServerQuery squery = new JabaWsServerQuery(this, jwsserver); |
226 |
41 |
if (svctypes.size() == 0) |
227 |
|
{ |
228 |
|
|
229 |
|
|
230 |
41 |
for (Services sv : squery.JABAWS2SERVERS) |
231 |
|
{ |
232 |
451 |
if (!ignoredServices.contains(sv.toString())) |
233 |
|
{ |
234 |
451 |
svctypes.add(sv.toString()); |
235 |
|
} |
236 |
|
} |
237 |
|
|
238 |
|
} |
239 |
41 |
qrys.add(squery); |
240 |
41 |
new Thread(squery).start(); |
241 |
|
} |
242 |
41 |
boolean finished = true; |
243 |
41 |
do |
244 |
|
{ |
245 |
165 |
finished = true; |
246 |
165 |
try |
247 |
|
{ |
248 |
165 |
Thread.sleep(100); |
249 |
|
} catch (Exception e) |
250 |
|
{ |
251 |
|
} |
252 |
165 |
for (JabaWsServerQuery squery : qrys) |
253 |
|
{ |
254 |
165 |
if (squery.isRunning()) |
255 |
|
{ |
256 |
144 |
finished = false; |
257 |
|
} |
258 |
|
} |
259 |
165 |
if (aborted) |
260 |
|
{ |
261 |
23 |
Console.debug( |
262 |
|
"Aborting " + qrys.size() + " JABAWS discovery threads."); |
263 |
23 |
for (JabaWsServerQuery squery : qrys) |
264 |
|
{ |
265 |
23 |
squery.setQuit(true); |
266 |
|
} |
267 |
|
} |
268 |
165 |
} while (!aborted && !finished); |
269 |
41 |
if (!aborted) |
270 |
|
{ |
271 |
|
|
272 |
|
|
273 |
|
|
274 |
18 |
if (services != null && services.size() > 0) |
275 |
|
{ |
276 |
18 |
Jws2Instance[] svcs = new Jws2Instance[services.size()]; |
277 |
18 |
int[] spos = new int[services.size()]; |
278 |
18 |
int ipos = 0; |
279 |
18 |
List<String> svcUrls = getServiceUrls(); |
280 |
18 |
for (Jws2Instance svc : services) |
281 |
|
{ |
282 |
252 |
svcs[ipos] = svc; |
283 |
252 |
spos[ipos++] = 1000 * svcUrls.indexOf(svc.getHost()) + 1 |
284 |
|
+ svctypes.indexOf(svc.serviceType); |
285 |
|
} |
286 |
18 |
jalview.util.QuickSort.sort(spos, svcs); |
287 |
18 |
services = new Vector<>(); |
288 |
18 |
for (Jws2Instance svc : svcs) |
289 |
|
{ |
290 |
252 |
if (!ignoredServices.contains(svc.serviceType)) |
291 |
|
{ |
292 |
252 |
services.add(svc); |
293 |
|
} |
294 |
|
} |
295 |
|
} |
296 |
|
} |
297 |
41 |
oldthread = null; |
298 |
41 |
running = false; |
299 |
41 |
changeSupport.firePropertyChange("services", new Vector<Jws2Instance>(), |
300 |
|
services); |
301 |
|
} |
302 |
|
|
303 |
|
|
304 |
|
|
305 |
|
|
306 |
|
@param |
307 |
|
@param |
308 |
|
@param |
309 |
|
|
|
|
| 94.1% |
Uncovered Elements: 1 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
310 |
382 |
synchronized void addService(String jwsservers, Jws2Instance service)... |
311 |
|
{ |
312 |
382 |
if (services == null) |
313 |
|
{ |
314 |
1 |
services = new Vector<>(); |
315 |
|
} |
316 |
382 |
jalview.bin.Console.info( |
317 |
|
"Discovered service: " + jwsservers + " " + service.toString()); |
318 |
|
|
319 |
|
|
320 |
|
|
321 |
382 |
services.add(service); |
322 |
|
|
323 |
382 |
ParamDatastoreI pds = service.getParamStore(); |
324 |
382 |
if (pds != null) |
325 |
|
{ |
326 |
382 |
pds.getPresets(); |
327 |
|
} |
328 |
382 |
service.hasParameters(); |
329 |
382 |
if (validServiceUrls == null) |
330 |
|
{ |
331 |
1 |
validServiceUrls = new Vector<>(); |
332 |
|
} |
333 |
382 |
validServiceUrls.add(jwsservers); |
334 |
|
} |
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
340 |
781 |
@Override... |
341 |
|
public void attachWSMenuEntry(JMenu wsmenu, final AlignFrame alignFrame) |
342 |
|
{ |
343 |
|
|
344 |
781 |
populateWSMenuEntry(wsmenu, alignFrame, null); |
345 |
|
} |
346 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
347 |
8031 |
private boolean isRecalculable(String action)... |
348 |
|
{ |
349 |
8031 |
return (action != null && action.equalsIgnoreCase("conservation")); |
350 |
|
} |
351 |
|
|
|
|
| 60% |
Uncovered Elements: 22 (55) |
Complexity: 11 |
Complexity Density: 0.28 |
|
352 |
781 |
private void populateWSMenuEntry(JMenu jws2al,... |
353 |
|
final AlignFrame alignFrame, String typeFilter) |
354 |
|
{ |
355 |
781 |
if (running || services == null || services.size() == 0) |
356 |
|
{ |
357 |
0 |
return; |
358 |
|
} |
359 |
|
|
360 |
|
|
361 |
|
|
362 |
|
|
363 |
|
|
364 |
781 |
JMenu atpoint; |
365 |
781 |
List<Jws2Instance> enumerableServices = new ArrayList<>(); |
366 |
|
|
367 |
781 |
Map<String, Jws2Instance> preferredHosts = new HashMap<>(); |
368 |
781 |
Map<String, List<Jws2Instance>> alternates = new HashMap<>(); |
369 |
781 |
for (Jws2Instance service : services.toArray(new Jws2Instance[0])) |
370 |
|
{ |
371 |
8031 |
if (!isRecalculable(service.action)) |
372 |
|
{ |
373 |
|
|
374 |
|
|
375 |
7526 |
enumerableServices.add(service); |
376 |
|
} |
377 |
|
else |
378 |
|
{ |
379 |
505 |
if (!preferredHosts.containsKey(service.serviceType)) |
380 |
|
{ |
381 |
505 |
Jws2Instance preferredInstance = getPreferredServiceFor( |
382 |
|
alignFrame, service.serviceType); |
383 |
505 |
if (preferredInstance != null) |
384 |
|
{ |
385 |
505 |
preferredHosts.put(service.serviceType, preferredInstance); |
386 |
|
} |
387 |
|
else |
388 |
|
{ |
389 |
0 |
preferredHosts.put(service.serviceType, service); |
390 |
|
} |
391 |
|
} |
392 |
505 |
List<Jws2Instance> ph = alternates.get(service.serviceType); |
393 |
505 |
if (preferredHosts.get(service.serviceType) != service) |
394 |
|
{ |
395 |
0 |
if (ph == null) |
396 |
|
{ |
397 |
0 |
ph = new ArrayList<>(); |
398 |
|
} |
399 |
0 |
ph.add(service); |
400 |
0 |
alternates.put(service.serviceType, ph); |
401 |
|
} |
402 |
|
} |
403 |
|
|
404 |
|
} |
405 |
|
|
406 |
|
|
407 |
781 |
addEnumeratedServices(jws2al, alignFrame, enumerableServices); |
408 |
|
|
409 |
772 |
for (final Jws2Instance service : preferredHosts.values()) |
410 |
|
{ |
411 |
496 |
atpoint = JvSwingUtils.findOrCreateMenu(jws2al, service.action); |
412 |
496 |
JMenuItem hitm; |
413 |
496 |
if (atpoint.getItemCount() > 1) |
414 |
|
{ |
415 |
|
|
416 |
0 |
atpoint.addSeparator(); |
417 |
|
} |
418 |
496 |
atpoint.add(hitm = new JMenuItem(service.getHost())); |
419 |
496 |
hitm.setForeground(Color.blue); |
420 |
496 |
hitm.addActionListener(new ActionListener() |
421 |
|
{ |
422 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
423 |
0 |
@Override... |
424 |
|
public void actionPerformed(ActionEvent e) |
425 |
|
{ |
426 |
0 |
Desktop.showUrl(service.getHost()); |
427 |
|
} |
428 |
|
}); |
429 |
496 |
hitm.setToolTipText(JvSwingUtils.wrapTooltip(false, |
430 |
|
MessageManager.getString("label.open_jabaws_web_page"))); |
431 |
|
|
432 |
496 |
service.attachWSMenuEntry(atpoint, alignFrame); |
433 |
493 |
if (alternates.containsKey(service.serviceType)) |
434 |
|
{ |
435 |
0 |
atpoint.add(hitm = new JMenu( |
436 |
|
MessageManager.getString("label.switch_server"))); |
437 |
0 |
hitm.setToolTipText(JvSwingUtils.wrapTooltip(false, |
438 |
|
MessageManager.getString("label.choose_jabaws_server"))); |
439 |
0 |
for (final Jws2Instance sv : alternates.get(service.serviceType)) |
440 |
|
{ |
441 |
0 |
JMenuItem itm; |
442 |
0 |
hitm.add(itm = new JMenuItem(sv.getHost())); |
443 |
0 |
itm.setForeground(Color.blue); |
444 |
0 |
itm.addActionListener(new ActionListener() |
445 |
|
{ |
446 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
447 |
0 |
@Override... |
448 |
|
public void actionPerformed(ActionEvent arg0) |
449 |
|
{ |
450 |
0 |
new Thread(new Runnable() |
451 |
|
{ |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
452 |
0 |
@Override... |
453 |
|
public void run() |
454 |
|
{ |
455 |
0 |
setPreferredServiceFor(alignFrame, sv.serviceType, |
456 |
|
sv.action, sv); |
457 |
0 |
changeSupport.firePropertyChange("services", |
458 |
|
new Vector<Jws2Instance>(), services); |
459 |
|
} |
460 |
|
}).start(); |
461 |
|
|
462 |
|
} |
463 |
|
}); |
464 |
|
} |
465 |
|
} |
466 |
|
} |
467 |
|
} |
468 |
|
|
469 |
|
|
470 |
|
|
471 |
|
|
472 |
|
|
|
|
| 78.3% |
Uncovered Elements: 13 (60) |
Complexity: 12 |
Complexity Density: 0.29 |
|
473 |
781 |
private void addEnumeratedServices(final JMenu jws2al,... |
474 |
|
final AlignFrame alignFrame, |
475 |
|
List<Jws2Instance> enumerableServices) |
476 |
|
{ |
477 |
781 |
boolean byhost = Cache.getDefault("WSMENU_BYHOST", false), |
478 |
|
bytype = Cache.getDefault("WSMENU_BYTYPE", false); |
479 |
|
|
480 |
|
|
481 |
|
|
482 |
|
|
483 |
781 |
JMenu atpoint; |
484 |
|
|
485 |
781 |
List<String> hostLabels = new ArrayList<>(); |
486 |
781 |
Hashtable<String, String> lasthostFor = new Hashtable<>(); |
487 |
781 |
Hashtable<String, ArrayList<Jws2Instance>> hosts = new Hashtable<>(); |
488 |
781 |
ArrayList<String> hostlist = new ArrayList<>(); |
489 |
781 |
for (Jws2Instance service : enumerableServices) |
490 |
|
{ |
491 |
7526 |
ArrayList<Jws2Instance> hostservices = hosts.get(service.getHost()); |
492 |
7526 |
if (hostservices == null) |
493 |
|
{ |
494 |
781 |
hosts.put(service.getHost(), hostservices = new ArrayList<>()); |
495 |
781 |
hostlist.add(service.getHost()); |
496 |
|
} |
497 |
7526 |
hostservices.add(service); |
498 |
|
} |
499 |
|
|
500 |
781 |
for (String host : hostlist) |
501 |
|
{ |
502 |
781 |
Jws2Instance orderedsvcs[] = hosts.get(host) |
503 |
|
.toArray(new Jws2Instance[1]); |
504 |
781 |
String sortbytype[] = new String[orderedsvcs.length]; |
505 |
8307 |
for (int i = 0; i < sortbytype.length; i++) |
506 |
|
{ |
507 |
7526 |
sortbytype[i] = orderedsvcs[i].serviceType; |
508 |
|
} |
509 |
781 |
jalview.util.QuickSort.sort(sortbytype, orderedsvcs); |
510 |
781 |
for (final Jws2Instance service : orderedsvcs) |
511 |
|
{ |
512 |
7427 |
atpoint = JvSwingUtils.findOrCreateMenu(jws2al, service.action); |
513 |
7427 |
String type = service.serviceType; |
514 |
7427 |
if (byhost) |
515 |
|
{ |
516 |
0 |
atpoint = JvSwingUtils.findOrCreateMenu(atpoint, host); |
517 |
0 |
if (atpoint.getToolTipText() == null) |
518 |
|
{ |
519 |
0 |
atpoint.setToolTipText(MessageManager |
520 |
|
.formatMessage("label.services_at", new String[] |
521 |
|
{ host })); |
522 |
|
} |
523 |
|
} |
524 |
7427 |
if (bytype) |
525 |
|
{ |
526 |
0 |
atpoint = JvSwingUtils.findOrCreateMenu(atpoint, type); |
527 |
0 |
if (atpoint.getToolTipText() == null) |
528 |
|
{ |
529 |
0 |
atpoint.setToolTipText(service.getActionText()); |
530 |
|
} |
531 |
|
} |
532 |
7427 |
if (!byhost && !hostLabels.contains( |
533 |
|
host + service.serviceType + service.getActionText())) |
534 |
|
|
535 |
|
|
536 |
|
{ |
537 |
|
|
538 |
|
|
539 |
|
|
540 |
|
|
541 |
7427 |
JMenuItem hitm; |
542 |
7427 |
if (hostLabels.contains(host)) |
543 |
|
{ |
544 |
6646 |
atpoint.addSeparator(); |
545 |
|
} |
546 |
|
else |
547 |
|
{ |
548 |
781 |
hostLabels.add(host); |
549 |
|
} |
550 |
7427 |
if (lasthostFor.get(service.action) == null |
551 |
|
|| !lasthostFor.get(service.action).equals(host)) |
552 |
|
{ |
553 |
1909 |
atpoint.add(hitm = new JMenuItem(host)); |
554 |
1909 |
hitm.setForeground(Color.blue); |
555 |
1909 |
hitm.addActionListener(new ActionListener() |
556 |
|
{ |
557 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
558 |
0 |
@Override... |
559 |
|
public void actionPerformed(ActionEvent e) |
560 |
|
{ |
561 |
0 |
Desktop.showUrl(service.getHost()); |
562 |
|
} |
563 |
|
}); |
564 |
1909 |
hitm.setToolTipText( |
565 |
|
JvSwingUtils.wrapTooltip(true, MessageManager |
566 |
|
.getString("label.open_jabaws_web_page"))); |
567 |
1909 |
lasthostFor.put(service.action, host); |
568 |
|
} |
569 |
7427 |
hostLabels.add( |
570 |
|
host + service.serviceType + service.getActionText()); |
571 |
|
} |
572 |
|
|
573 |
7427 |
service.attachWSMenuEntry(atpoint, alignFrame); |
574 |
|
} |
575 |
|
} |
576 |
|
} |
577 |
|
|
578 |
|
|
579 |
|
|
580 |
|
@param |
581 |
|
|
582 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 5 |
Complexity Density: 0.5 |
|
583 |
0 |
public static void main(String[] args)... |
584 |
|
{ |
585 |
0 |
if (args.length > 0) |
586 |
|
{ |
587 |
0 |
testUrls = new ArrayList<>(); |
588 |
0 |
for (String url : args) |
589 |
|
{ |
590 |
0 |
testUrls.add(url); |
591 |
|
} |
592 |
|
} |
593 |
0 |
Thread runner = getDiscoverer() |
594 |
|
.startDiscoverer(new PropertyChangeListener() |
595 |
|
{ |
596 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
597 |
0 |
@Override... |
598 |
|
public void propertyChange(PropertyChangeEvent evt) |
599 |
|
{ |
600 |
0 |
if (getDiscoverer().services != null) |
601 |
|
{ |
602 |
0 |
jalview.bin.Console |
603 |
|
.outPrintln("Changesupport: There are now " |
604 |
|
+ getDiscoverer().services.size() |
605 |
|
+ " services"); |
606 |
0 |
int i = 1; |
607 |
0 |
for (Jws2Instance instance : getDiscoverer().services) |
608 |
|
{ |
609 |
0 |
jalview.bin.Console.outPrintln("Service " + i++ + " " |
610 |
|
+ instance.getClass() + "@" + instance.getHost() |
611 |
|
+ ": " + instance.getActionText()); |
612 |
|
} |
613 |
|
|
614 |
|
} |
615 |
|
} |
616 |
|
}); |
617 |
0 |
while (runner.isAlive()) |
618 |
|
{ |
619 |
0 |
try |
620 |
|
{ |
621 |
0 |
Thread.sleep(50); |
622 |
|
} catch (InterruptedException e) |
623 |
|
{ |
624 |
|
} |
625 |
|
} |
626 |
0 |
try |
627 |
|
{ |
628 |
0 |
Thread.sleep(50); |
629 |
|
} catch (InterruptedException x) |
630 |
|
{ |
631 |
|
} |
632 |
|
} |
633 |
|
|
634 |
|
|
635 |
|
|
636 |
|
|
637 |
|
@return |
638 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
639 |
3664 |
public static Jws2Discoverer getDiscoverer()... |
640 |
|
{ |
641 |
3664 |
if (discoverer == null) |
642 |
|
{ |
643 |
1 |
discoverer = new Jws2Discoverer(); |
644 |
|
} |
645 |
3664 |
return discoverer; |
646 |
|
} |
647 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
648 |
2064 |
public boolean hasServices()... |
649 |
|
{ |
650 |
2064 |
return !running && services != null && services.size() > 0; |
651 |
|
} |
652 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
653 |
3652 |
public boolean isRunning()... |
654 |
|
{ |
655 |
3652 |
return running; |
656 |
|
} |
657 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.33 |
|
658 |
0 |
public void setServiceUrls(List<String> wsUrls)... |
659 |
|
{ |
660 |
0 |
if (wsUrls != null && !wsUrls.isEmpty()) |
661 |
|
{ |
662 |
0 |
StringBuilder urls = new StringBuilder(128); |
663 |
0 |
String sep = ""; |
664 |
0 |
for (String url : wsUrls) |
665 |
|
{ |
666 |
0 |
urls.append(sep); |
667 |
0 |
urls.append(url); |
668 |
0 |
sep = ","; |
669 |
|
} |
670 |
0 |
Cache.setProperty(JWS2HOSTURLS, urls.toString()); |
671 |
|
} |
672 |
|
else |
673 |
|
{ |
674 |
0 |
Cache.removeProperty(JWS2HOSTURLS); |
675 |
|
} |
676 |
|
} |
677 |
|
|
678 |
|
|
679 |
|
|
680 |
|
|
681 |
|
|
682 |
|
@return |
683 |
|
|
|
|
| 61.3% |
Uncovered Elements: 12 (31) |
Complexity: 8 |
Complexity Density: 0.38 |
|
684 |
59 |
public List<String> getServiceUrls()... |
685 |
|
{ |
686 |
59 |
if (testUrls != null) |
687 |
|
{ |
688 |
|
|
689 |
0 |
return testUrls; |
690 |
|
} |
691 |
59 |
List<String> urls = new ArrayList<>(); |
692 |
|
|
693 |
59 |
if (this.preferredUrl != null) |
694 |
|
{ |
695 |
0 |
urls.add(preferredUrl); |
696 |
|
} |
697 |
|
|
698 |
59 |
String surls = Cache.getDefault(JWS2HOSTURLS, COMPBIO_JABAWS); |
699 |
59 |
try |
700 |
|
{ |
701 |
59 |
StringTokenizer st = new StringTokenizer(surls, ","); |
702 |
118 |
while (st.hasMoreElements()) |
703 |
|
{ |
704 |
59 |
String url = null; |
705 |
59 |
try |
706 |
|
{ |
707 |
59 |
url = st.nextToken(); |
708 |
59 |
new URL(url); |
709 |
59 |
if (!urls.contains(url)) |
710 |
|
{ |
711 |
59 |
urls.add(url); |
712 |
|
} |
713 |
|
else |
714 |
|
{ |
715 |
0 |
Console.warn("Ignoring duplicate url " + url + " in " |
716 |
|
+ JWS2HOSTURLS + " list"); |
717 |
|
} |
718 |
|
} catch (MalformedURLException ex) |
719 |
|
{ |
720 |
0 |
Console.warn("Problem whilst trying to make a URL from '" |
721 |
0 |
+ ((url != null) ? url : "<null>") + "'"); |
722 |
0 |
Console.warn( |
723 |
|
"This was probably due to a malformed comma separated list" |
724 |
|
+ " in the " + JWS2HOSTURLS |
725 |
|
+ " entry of $(HOME)/.jalview_properties)"); |
726 |
0 |
Console.debug("Exception was ", ex); |
727 |
|
} |
728 |
|
} |
729 |
|
} catch (Exception ex) |
730 |
|
{ |
731 |
0 |
Console.warn("Error parsing comma separated list of urls in " |
732 |
|
+ JWS2HOSTURLS + " preference.", ex); |
733 |
|
} |
734 |
59 |
return urls; |
735 |
|
} |
736 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
737 |
769 |
public Vector<Jws2Instance> getServices()... |
738 |
|
{ |
739 |
769 |
return (services == null) ? new Vector<>() : new Vector<>(services); |
740 |
|
} |
741 |
|
|
742 |
|
|
743 |
|
|
744 |
|
|
745 |
|
@param |
746 |
|
@return |
747 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 4 |
Complexity Density: 0.44 |
|
748 |
0 |
public static boolean testServiceUrl(URL foo)... |
749 |
|
{ |
750 |
0 |
try |
751 |
|
{ |
752 |
0 |
compbio.ws.client.WSTester |
753 |
|
.main(new String[] |
754 |
|
{ "-h=" + foo.toString() }); |
755 |
|
} catch (Exception e) |
756 |
|
{ |
757 |
0 |
e.printStackTrace(); |
758 |
0 |
return false; |
759 |
|
} catch (OutOfMemoryError e) |
760 |
|
{ |
761 |
0 |
e.printStackTrace(); |
762 |
0 |
return false; |
763 |
|
} catch (Error e) |
764 |
|
{ |
765 |
0 |
e.printStackTrace(); |
766 |
0 |
return false; |
767 |
|
} |
768 |
|
|
769 |
0 |
return true; |
770 |
|
} |
771 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
772 |
0 |
public boolean restart()... |
773 |
|
{ |
774 |
0 |
synchronized (this) |
775 |
|
{ |
776 |
0 |
if (running) |
777 |
|
{ |
778 |
0 |
aborted = true; |
779 |
|
} |
780 |
|
else |
781 |
|
{ |
782 |
0 |
running = true; |
783 |
|
} |
784 |
0 |
return aborted; |
785 |
|
} |
786 |
|
} |
787 |
|
|
788 |
|
|
789 |
|
|
790 |
|
|
791 |
|
|
792 |
|
|
793 |
|
@param |
794 |
|
@return |
795 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
796 |
41 |
public Thread startDiscoverer(PropertyChangeListener changeSupport2)... |
797 |
|
{ |
798 |
|
|
799 |
|
|
800 |
|
|
801 |
|
|
802 |
|
|
803 |
|
|
804 |
|
|
805 |
|
|
806 |
|
|
807 |
|
|
808 |
41 |
if (isRunning()) |
809 |
|
{ |
810 |
18 |
setAborted(true); |
811 |
|
} |
812 |
41 |
addPropertyChangeListener(changeSupport2); |
813 |
41 |
Thread thr = new Thread(this); |
814 |
41 |
thr.start(); |
815 |
41 |
return thr; |
816 |
|
} |
817 |
|
|
818 |
|
|
819 |
|
@return |
820 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
821 |
314 |
public Vector<String> getInvalidServiceUrls()... |
822 |
|
{ |
823 |
314 |
return invalidServiceUrls; |
824 |
|
} |
825 |
|
|
826 |
|
|
827 |
|
@return |
828 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
829 |
314 |
public Vector<String> getUrlsWithoutServices()... |
830 |
|
{ |
831 |
314 |
return urlsWithoutServices; |
832 |
|
} |
833 |
|
|
834 |
|
|
835 |
|
|
836 |
|
|
837 |
|
|
838 |
|
@param |
839 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 5 |
Complexity Density: 1.25 |
|
840 |
0 |
public synchronized void addUrlwithnoservices(String jwsservers)... |
841 |
|
{ |
842 |
0 |
if (urlsWithoutServices == null) |
843 |
|
{ |
844 |
0 |
urlsWithoutServices = new Vector<>(); |
845 |
|
} |
846 |
|
|
847 |
0 |
if ((invalidServiceUrls == null |
848 |
|
|| !invalidServiceUrls.contains(jwsservers)) |
849 |
|
&& !urlsWithoutServices.contains(jwsservers)) |
850 |
|
{ |
851 |
0 |
urlsWithoutServices.add(jwsservers); |
852 |
|
} |
853 |
|
} |
854 |
|
|
855 |
|
|
856 |
|
|
857 |
|
|
858 |
|
@param |
859 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
860 |
0 |
public synchronized void addInvalidServiceUrl(String jwsservers)... |
861 |
|
{ |
862 |
0 |
if (invalidServiceUrls == null) |
863 |
|
{ |
864 |
0 |
invalidServiceUrls = new Vector<>(); |
865 |
|
} |
866 |
0 |
if (!invalidServiceUrls.contains(jwsservers)) |
867 |
|
{ |
868 |
0 |
invalidServiceUrls.add(jwsservers); |
869 |
|
} |
870 |
|
} |
871 |
|
|
872 |
|
|
873 |
|
|
874 |
|
@return |
875 |
|
|
876 |
|
|
|
|
| 37.1% |
Uncovered Elements: 22 (35) |
Complexity: 10 |
Complexity Density: 0.43 |
|
877 |
1559 |
public String getErrorMessages()... |
878 |
|
{ |
879 |
1559 |
if (!isRunning() && !isAborted()) |
880 |
|
{ |
881 |
314 |
StringBuffer ermsg = new StringBuffer(); |
882 |
314 |
boolean list = false; |
883 |
314 |
if (getInvalidServiceUrls() != null |
884 |
|
&& getInvalidServiceUrls().size() > 0) |
885 |
|
{ |
886 |
0 |
ermsg.append(MessageManager.getString("warn.urls_not_contacted") |
887 |
|
+ ": \n"); |
888 |
0 |
for (String svcurl : getInvalidServiceUrls()) |
889 |
|
{ |
890 |
0 |
if (list) |
891 |
|
{ |
892 |
0 |
ermsg.append(", "); |
893 |
|
} |
894 |
0 |
list = true; |
895 |
0 |
ermsg.append(svcurl); |
896 |
|
} |
897 |
0 |
ermsg.append("\n\n"); |
898 |
|
} |
899 |
314 |
list = false; |
900 |
314 |
if (getUrlsWithoutServices() != null |
901 |
|
&& getUrlsWithoutServices().size() > 0) |
902 |
|
{ |
903 |
0 |
ermsg.append( |
904 |
|
MessageManager.getString("warn.urls_no_jaba") + ": \n"); |
905 |
0 |
for (String svcurl : getUrlsWithoutServices()) |
906 |
|
{ |
907 |
0 |
if (list) |
908 |
|
{ |
909 |
0 |
ermsg.append(", "); |
910 |
|
} |
911 |
0 |
list = true; |
912 |
0 |
ermsg.append(svcurl); |
913 |
|
} |
914 |
0 |
ermsg.append("\n"); |
915 |
|
} |
916 |
314 |
if (ermsg.length() > 1) |
917 |
|
{ |
918 |
0 |
return ermsg.toString(); |
919 |
|
} |
920 |
|
|
921 |
|
} |
922 |
1559 |
return null; |
923 |
|
} |
924 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 7 |
Complexity Density: 1 |
|
925 |
0 |
public int getServerStatusFor(String url)... |
926 |
|
{ |
927 |
0 |
if (validServiceUrls != null && validServiceUrls.contains(url)) |
928 |
|
{ |
929 |
0 |
return 1; |
930 |
|
} |
931 |
0 |
if (urlsWithoutServices != null && urlsWithoutServices.contains(url)) |
932 |
|
{ |
933 |
0 |
return 0; |
934 |
|
} |
935 |
0 |
if (invalidServiceUrls != null && invalidServiceUrls.contains(url)) |
936 |
|
{ |
937 |
0 |
return -1; |
938 |
|
} |
939 |
0 |
return -2; |
940 |
|
} |
941 |
|
|
942 |
|
|
943 |
|
|
944 |
|
|
945 |
|
|
946 |
|
|
947 |
|
@param |
948 |
|
@return |
949 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 5 |
Complexity Density: 0.45 |
|
950 |
0 |
public Jws2Instance getPreferredServiceFor(String[] serviceURLs)... |
951 |
|
{ |
952 |
0 |
HashSet<String> urls = new HashSet<>(); |
953 |
0 |
urls.addAll(Arrays.asList(serviceURLs)); |
954 |
0 |
Jws2Instance match = null; |
955 |
0 |
if (services != null) |
956 |
|
{ |
957 |
0 |
for (Jws2Instance svc : services) |
958 |
|
{ |
959 |
0 |
if (urls.contains(svc.getServiceTypeURI())) |
960 |
|
{ |
961 |
0 |
if (match == null) |
962 |
|
{ |
963 |
|
|
964 |
|
|
965 |
0 |
match = svc; |
966 |
|
} |
967 |
0 |
if (urls.contains(svc.getUri())) |
968 |
|
{ |
969 |
|
|
970 |
|
|
971 |
0 |
return svc; |
972 |
|
} |
973 |
|
} |
974 |
|
} |
975 |
|
} |
976 |
0 |
return match; |
977 |
|
} |
978 |
|
|
979 |
|
Map<String, Map<String, String>> preferredServiceMap = new HashMap<>(); |
980 |
|
|
981 |
|
|
982 |
|
|
983 |
|
|
984 |
|
@param |
985 |
|
|
986 |
|
@param |
987 |
|
|
988 |
|
@return |
989 |
|
|
990 |
|
|
|
|
| 80% |
Uncovered Elements: 5 (25) |
Complexity: 8 |
Complexity Density: 0.53 |
|
991 |
505 |
public Jws2Instance getPreferredServiceFor(AlignFrame af,... |
992 |
|
String serviceType) |
993 |
|
{ |
994 |
505 |
String serviceurl = null; |
995 |
505 |
synchronized (preferredServiceMap) |
996 |
|
{ |
997 |
505 |
String afid = (af == null) ? "" : af.getViewport().getSequenceSetId(); |
998 |
505 |
Map<String, String> prefmap = preferredServiceMap.get(afid); |
999 |
505 |
if (afid.length() > 0 && prefmap == null) |
1000 |
|
{ |
1001 |
|
|
1002 |
505 |
prefmap = preferredServiceMap.get(""); |
1003 |
|
} |
1004 |
505 |
if (prefmap != null) |
1005 |
|
{ |
1006 |
0 |
serviceurl = prefmap.get(serviceType); |
1007 |
|
} |
1008 |
|
|
1009 |
|
} |
1010 |
505 |
Jws2Instance response = null; |
1011 |
505 |
for (Jws2Instance svc : services) |
1012 |
|
{ |
1013 |
4545 |
if (svc.serviceType.equals(serviceType)) |
1014 |
|
{ |
1015 |
505 |
if (serviceurl == null || serviceurl.equals(svc.getHost())) |
1016 |
|
{ |
1017 |
505 |
response = svc; |
1018 |
505 |
break; |
1019 |
|
} |
1020 |
|
} |
1021 |
|
} |
1022 |
505 |
return response; |
1023 |
|
} |
1024 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
1025 |
0 |
public void setPreferredServiceFor(AlignFrame af, String serviceType,... |
1026 |
|
String serviceAction, Jws2Instance selectedServer) |
1027 |
|
{ |
1028 |
0 |
String afid = (af == null) ? "" : af.getViewport().getSequenceSetId(); |
1029 |
0 |
if (preferredServiceMap == null) |
1030 |
|
{ |
1031 |
0 |
preferredServiceMap = new HashMap<>(); |
1032 |
|
} |
1033 |
0 |
Map<String, String> prefmap = preferredServiceMap.get(afid); |
1034 |
0 |
if (prefmap == null) |
1035 |
|
{ |
1036 |
0 |
prefmap = new HashMap<>(); |
1037 |
0 |
preferredServiceMap.put(afid, prefmap); |
1038 |
|
} |
1039 |
0 |
prefmap.put(serviceType, selectedServer.getHost()); |
1040 |
0 |
prefmap.put(serviceAction, selectedServer.getHost()); |
1041 |
|
} |
1042 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1043 |
0 |
public void setPreferredServiceFor(String serviceType,... |
1044 |
|
String serviceAction, Jws2Instance selectedServer) |
1045 |
|
{ |
1046 |
0 |
setPreferredServiceFor(null, serviceType, serviceAction, |
1047 |
|
selectedServer); |
1048 |
|
} |
1049 |
|
|
1050 |
|
|
1051 |
|
|
1052 |
|
|
1053 |
|
|
1054 |
|
|
1055 |
|
@param |
1056 |
|
@throws |
1057 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
1058 |
0 |
public void setPreferredUrl(String value) throws MalformedURLException... |
1059 |
|
{ |
1060 |
0 |
if (value != null && value.trim().length() > 0) |
1061 |
|
{ |
1062 |
0 |
new URL(value); |
1063 |
0 |
preferredUrl = value; |
1064 |
|
} |
1065 |
|
} |
1066 |
|
} |