15 |
15 |
import eu.dnetlib.enabling.resultset.rmi.ResultSetService;
|
16 |
16 |
|
17 |
17 |
public class ProcessCountingResultSetListener implements ResultSetListener, ResultSetAware {
|
|
18 |
|
18 |
19 |
private int count;
|
19 |
|
|
|
20 |
|
20 |
21 |
private GraphProcess process;
|
21 |
22 |
private ResultSetService inputService;
|
22 |
23 |
private String inputRsId;
|
... | ... | |
24 |
25 |
private int inputSize;
|
25 |
26 |
private boolean inaccurate = false;
|
26 |
27 |
|
|
28 |
private final static String RS_CLOSED = "closed";
|
27 |
29 |
/**
|
28 |
30 |
* Logger.
|
29 |
31 |
*/
|
... | ... | |
39 |
41 |
}
|
40 |
42 |
|
41 |
43 |
@Override
|
42 |
|
public List<String> getResult(int from, int to) {
|
|
44 |
public List<String> getResult(final int from, final int to) {
|
43 |
45 |
if (process.isCanceled()) {
|
44 |
46 |
this.outputResulset.close();
|
45 |
47 |
return Lists.newArrayList();
|
46 |
48 |
}
|
47 |
49 |
try {
|
48 |
|
this.count = to;
|
|
50 |
this.count = to;
|
49 |
51 |
if (count >= this.inputSize) {
|
50 |
|
outputResulset.close();
|
|
52 |
closeRSIfNeeded();
|
51 |
53 |
}
|
52 |
54 |
return inputService.getResult(inputRsId, from, to, "WAITING");
|
53 |
55 |
} catch (ResultSetException e) {
|
... | ... | |
61 |
63 |
if (process.isCanceled()) {
|
62 |
64 |
this.outputResulset.close();
|
63 |
65 |
return count;
|
64 |
|
}
|
|
66 |
}
|
65 |
67 |
try {
|
66 |
68 |
int size = inputService.getNumberOfElements(inputRsId);
|
67 |
69 |
if (this.inputSize != size) {
|
68 |
70 |
this.inputSize = size;
|
69 |
|
this.inaccurate = true;
|
|
71 |
this.inaccurate = true;
|
70 |
72 |
}
|
71 |
73 |
this.inputSize = size;
|
72 |
74 |
if (count >= this.inputSize) {
|
73 |
|
outputResulset.close();
|
74 |
|
this.inaccurate = false;
|
|
75 |
closeRSIfNeeded();
|
|
76 |
this.inaccurate = false;
|
75 |
77 |
}
|
76 |
78 |
return this.inputSize;
|
77 |
79 |
} catch (ResultSetException e) {
|
... | ... | |
81 |
83 |
|
82 |
84 |
}
|
83 |
85 |
|
|
86 |
private void closeRSIfNeeded() throws ResultSetException {
|
|
87 |
if (inputService.getProperty(inputRsId, "classSimpleName").equalsIgnoreCase("TransientPushResultSetImpl")) {
|
|
88 |
log.info("Not closing the counting resultset unless the underlying push result is already closed ");
|
|
89 |
if (inputService.getRSStatus(inputRsId).equals(RS_CLOSED)) {
|
|
90 |
outputResulset.close();
|
|
91 |
}
|
|
92 |
} else {
|
|
93 |
outputResulset.close();
|
|
94 |
}
|
|
95 |
}
|
|
96 |
|
84 |
97 |
@Override
|
85 |
|
public void setResultSet(ResultSet outputResulset) {
|
|
98 |
public void setResultSet(final ResultSet outputResulset) {
|
86 |
99 |
this.outputResulset = outputResulset;
|
87 |
100 |
}
|
88 |
101 |
|
... | ... | |
90 |
103 |
return count;
|
91 |
104 |
}
|
92 |
105 |
|
93 |
|
public void setCount(int count) {
|
|
106 |
public void setCount(final int count) {
|
94 |
107 |
this.count = count;
|
95 |
108 |
}
|
96 |
109 |
|
ResultSetService exposes a new ResultSet property that is used by the Counting RS Listener to not close the result set if the underlying result set is an open Push Result set.