1
|
package org.bgbm.utis.controller;
|
2
|
|
3
|
import org.cybertaxonomy.utis.checklist.BaseChecklistClient;
|
4
|
import org.cybertaxonomy.utis.checklist.DRFChecklistException;
|
5
|
import org.cybertaxonomy.utis.checklist.UnsupportedIdentifierException;
|
6
|
import org.cybertaxonomy.utis.tnr.msg.TnrMsg;
|
7
|
import org.cybertaxonomy.utis.utils.TnrMsgUtils;
|
8
|
import org.slf4j.Logger;
|
9
|
import org.slf4j.LoggerFactory;
|
10
|
|
11
|
public class ChecklistClientRunner extends Thread{
|
12
|
|
13
|
protected Logger logger = LoggerFactory.getLogger(ChecklistClientRunner.class);
|
14
|
|
15
|
private final BaseChecklistClient client;
|
16
|
|
17
|
private final TnrMsg tnrMsg;
|
18
|
|
19
|
private long duration;
|
20
|
|
21
|
private boolean unsupportedMode = false;
|
22
|
|
23
|
private boolean unsupportedIdentifier = false;
|
24
|
|
25
|
public BaseChecklistClient getClient() {
|
26
|
return client;
|
27
|
}
|
28
|
|
29
|
public ChecklistClientRunner(BaseChecklistClient client, TnrMsg tnrMsg){
|
30
|
this.client = client;
|
31
|
this.tnrMsg = tnrMsg;
|
32
|
TnrMsgUtils.assertSearchModeSet(tnrMsg, true);
|
33
|
unsupportedMode = !client.getSearchModes().contains(TnrMsgUtils.getSearchMode(tnrMsg));
|
34
|
}
|
35
|
|
36
|
@Override
|
37
|
public void run() {
|
38
|
|
39
|
if(tnrMsg == null){
|
40
|
logger.error("TnrMsg object must not be NULL");
|
41
|
}
|
42
|
|
43
|
if(isUnsupportedMode()){
|
44
|
// skip
|
45
|
return;
|
46
|
}
|
47
|
|
48
|
long start = System.currentTimeMillis();
|
49
|
try {
|
50
|
client.queryChecklist(tnrMsg);
|
51
|
if(logger.isDebugEnabled()){
|
52
|
logger.debug("query to " + client.getServiceProviderInfo().getId() + " completed");
|
53
|
}
|
54
|
} catch (DRFChecklistException e) {
|
55
|
if(e instanceof UnsupportedIdentifierException){
|
56
|
setUnsupportedIdentifier(true);
|
57
|
// skip
|
58
|
return;
|
59
|
}
|
60
|
logger.error("Error during request to " + client.getServiceProviderInfo().getId(), e);
|
61
|
|
62
|
}
|
63
|
duration = System.currentTimeMillis() - start;
|
64
|
}
|
65
|
|
66
|
/**
|
67
|
* @return the duration of the last run
|
68
|
*/
|
69
|
public long getDuration() {
|
70
|
return duration;
|
71
|
}
|
72
|
|
73
|
/**
|
74
|
* @return the unsupportedMode
|
75
|
*/
|
76
|
public boolean isUnsupportedMode() {
|
77
|
return unsupportedMode;
|
78
|
}
|
79
|
|
80
|
/**
|
81
|
* @param unsupportedMode the unsupportedMode to set
|
82
|
*/
|
83
|
public void setUnsupportedMode(boolean unsupportedMode) {
|
84
|
this.unsupportedMode = unsupportedMode;
|
85
|
}
|
86
|
|
87
|
/**
|
88
|
* @return the unsupportedIdentifier
|
89
|
*/
|
90
|
public boolean isUnsupportedIdentifier() {
|
91
|
return unsupportedIdentifier;
|
92
|
}
|
93
|
|
94
|
/**
|
95
|
* @param unsupportedIdentifier the unsupportedIdentifier to set
|
96
|
*/
|
97
|
public void setUnsupportedIdentifier(boolean unsupportedIdentifier) {
|
98
|
this.unsupportedIdentifier = unsupportedIdentifier;
|
99
|
}
|
100
|
|
101
|
}
|