6233 |
17 May 21 |
nicklas |
1 |
package net.sf.basedb.varsearch.query; |
6233 |
17 May 21 |
nicklas |
2 |
|
6233 |
17 May 21 |
nicklas |
3 |
import java.io.IOException; |
6233 |
17 May 21 |
nicklas |
4 |
import java.util.Collection; |
6233 |
17 May 21 |
nicklas |
5 |
|
6233 |
17 May 21 |
nicklas |
6 |
import org.apache.lucene.search.CollectorManager; |
6241 |
21 May 21 |
nicklas |
7 |
import org.slf4j.LoggerFactory; |
6233 |
17 May 21 |
nicklas |
8 |
|
7074 |
24 Mar 23 |
nicklas |
9 |
import net.sf.basedb.util.extensions.logging.ExtensionsLog; |
7074 |
24 Mar 23 |
nicklas |
10 |
import net.sf.basedb.util.extensions.logging.ExtensionsLogger; |
7074 |
24 Mar 23 |
nicklas |
11 |
|
6233 |
17 May 21 |
nicklas |
12 |
/** |
6233 |
17 May 21 |
nicklas |
Collector manager for multi-threaded searching. The index searcher |
6233 |
17 May 21 |
nicklas |
create {@link RawBioAssayIdCollector} instances as needed. The |
6233 |
17 May 21 |
nicklas |
results are then merged in by the reduce() method. |
6233 |
17 May 21 |
nicklas |
16 |
*/ |
6233 |
17 May 21 |
nicklas |
17 |
public class RawBioAssayIdCollectorManager |
6241 |
21 May 21 |
nicklas |
18 |
implements CollectorManager<RawBioAssayIdCollector, QueryResult> |
6233 |
17 May 21 |
nicklas |
19 |
{ |
6241 |
21 May 21 |
nicklas |
20 |
|
7074 |
24 Mar 23 |
nicklas |
21 |
private static final ExtensionsLogger logger = |
7074 |
24 Mar 23 |
nicklas |
22 |
ExtensionsLog.getLogger(LuceneQueryFactory.ID, true).wrap(LoggerFactory.getLogger(RawBioAssayIdCollectorManager.class)); |
6233 |
17 May 21 |
nicklas |
23 |
|
6233 |
17 May 21 |
nicklas |
24 |
private final String idField; |
6241 |
21 May 21 |
nicklas |
25 |
private final int timeOutInSeconds; |
6241 |
21 May 21 |
nicklas |
26 |
private final long timeLimit; |
6241 |
21 May 21 |
nicklas |
27 |
|
6241 |
21 May 21 |
nicklas |
28 |
private int numCollectors; |
6233 |
17 May 21 |
nicklas |
29 |
|
6553 |
27 Jan 22 |
nicklas |
30 |
public RawBioAssayIdCollectorManager(String idField, int timeOutInSeconds) |
6233 |
17 May 21 |
nicklas |
31 |
{ |
6233 |
17 May 21 |
nicklas |
32 |
this.idField = idField; |
6241 |
21 May 21 |
nicklas |
33 |
this.timeOutInSeconds = timeOutInSeconds; |
6241 |
21 May 21 |
nicklas |
34 |
this.timeLimit = timeOutInSeconds <= 0 ? Long.MAX_VALUE : System.currentTimeMillis()+1000*timeOutInSeconds; |
6233 |
17 May 21 |
nicklas |
35 |
} |
6233 |
17 May 21 |
nicklas |
36 |
|
6233 |
17 May 21 |
nicklas |
37 |
@Override |
6233 |
17 May 21 |
nicklas |
38 |
public RawBioAssayIdCollector newCollector() |
6233 |
17 May 21 |
nicklas |
39 |
throws IOException |
6233 |
17 May 21 |
nicklas |
40 |
{ |
6241 |
21 May 21 |
nicklas |
41 |
numCollectors++; |
6246 |
24 May 21 |
nicklas |
42 |
logger.trace("newCollector: " + numCollectors); |
6553 |
27 Jan 22 |
nicklas |
43 |
return new RawBioAssayIdCollector(idField, timeLimit); |
6233 |
17 May 21 |
nicklas |
44 |
} |
6233 |
17 May 21 |
nicklas |
45 |
|
6233 |
17 May 21 |
nicklas |
46 |
@Override |
6241 |
21 May 21 |
nicklas |
47 |
public QueryResult reduce(Collection<RawBioAssayIdCollector> collectors) |
6233 |
17 May 21 |
nicklas |
48 |
throws IOException |
6233 |
17 May 21 |
nicklas |
49 |
{ |
6241 |
21 May 21 |
nicklas |
50 |
QueryResult result = new QueryResult(timeOutInSeconds); |
6233 |
17 May 21 |
nicklas |
51 |
for (RawBioAssayIdCollector c : collectors) |
6233 |
17 May 21 |
nicklas |
52 |
{ |
6246 |
24 May 21 |
nicklas |
53 |
if (logger.isTraceEnabled()) |
6241 |
21 May 21 |
nicklas |
54 |
{ |
6246 |
24 May 21 |
nicklas |
55 |
logger.trace("mergeResults: rba="+c.getRbaIds().size()+"; variants=" + c.getNumTotalCollect()+"; after timeout="+c.getNumCollectAfterTimeout()); |
6241 |
21 May 21 |
nicklas |
56 |
} |
6241 |
21 May 21 |
nicklas |
57 |
result.mergeResults(c); |
6233 |
17 May 21 |
nicklas |
58 |
} |
6241 |
21 May 21 |
nicklas |
59 |
return result; |
6233 |
17 May 21 |
nicklas |
60 |
} |
6233 |
17 May 21 |
nicklas |
61 |
|
6233 |
17 May 21 |
nicklas |
62 |
} |