Skip to content

Commit b048a07

Browse files
authored
move decoder pool to its own class (#1389)
1 parent 5344492 commit b048a07

2 files changed

Lines changed: 50 additions & 19 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.jlab.detector.decode;
2+
3+
import java.util.concurrent.ConcurrentLinkedQueue;
4+
5+
/**
6+
*
7+
* @author baltzell
8+
*/
9+
public class CLASDecoderPool {
10+
11+
ConcurrentLinkedQueue<CLASDecoder> pool;
12+
13+
int sharedConstantsManagers = 64;
14+
15+
public CLASDecoderPool(int size, String variation, String timestamp) {
16+
17+
pool = new ConcurrentLinkedQueue<>();
18+
19+
CLASDecoder d0 = null;
20+
21+
for (int i=0; i<size; i++) {
22+
23+
CLASDecoder d;
24+
25+
if (i % sharedConstantsManagers == 0) {
26+
d0 = new CLASDecoder();
27+
if (variation != null) d0.setVariation(variation);
28+
if (timestamp != null) d0.setTimestamp(timestamp);
29+
d = d0;
30+
}
31+
else d = new CLASDecoder(d0);
32+
33+
pool.add(d);
34+
}
35+
}
36+
37+
public CLASDecoder take() throws InterruptedException {
38+
return pool.poll();
39+
}
40+
41+
public void put(CLASDecoder decoder) throws InterruptedException {
42+
pool.offer(decoder);
43+
}
44+
45+
}

‎common-tools/clas-reco/src/main/java/org/jlab/clas/reco/DecoderEngine.java‎

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
import java.util.HashSet;
55
import java.nio.ByteBuffer;
66
import java.nio.ByteOrder;
7-
import java.util.concurrent.ArrayBlockingQueue;
8-
import java.util.concurrent.BlockingQueue;
97
import org.jlab.clara.base.ClaraUtil;
108
import org.jlab.clara.engine.Engine;
119
import org.jlab.clara.engine.EngineData;
1210
import org.jlab.clara.engine.EngineDataType;
1311
import org.jlab.clara.engine.EngineStatus;
1412
import org.jlab.detector.decode.CLASDecoder;
13+
import org.jlab.detector.decode.CLASDecoderPool;
1514
import org.jlab.io.evio.EvioDataEvent;
1615
import org.jlab.io.hipo.HipoDataEvent;
1716
import org.jlab.jnp.hipo4.data.SchemaFactory;
@@ -28,8 +27,7 @@ public class DecoderEngine implements Engine {
2827
Clas12Types.EVIO,Clas12Types.HIPO,EngineDataType.JSON,EngineDataType.STRING);
2928

3029
SchemaFactory schema;
31-
BlockingQueue<CLASDecoder> pool;
32-
int constantsShared = 64;
30+
CLASDecoderPool pool;
3331

3432
public DecoderEngine() {
3533
schema = new SchemaFactory();
@@ -58,21 +56,9 @@ public void destroy() {}
5856
@Override
5957
public EngineData configure(EngineData ed) {
6058
JSONObject json = new JSONObject(ed.getData());
61-
pool = new ArrayBlockingQueue<>(POOL_SIZE);
62-
CLASDecoder d0 = null;
63-
for (int i=0; i<POOL_SIZE; i++) {
64-
CLASDecoder d;
65-
if (i % constantsShared == 0) {
66-
d0 = new CLASDecoder();
67-
if (json.has("variation")) d0.setVariation(json.getString("variation"));
68-
if (json.has("timestamp")) d0.setVariation(json.getString("timestamp"));
69-
d = d0;
70-
}
71-
else {
72-
d = new CLASDecoder(d0);
73-
}
74-
pool.add(d);
75-
}
59+
pool = new CLASDecoderPool(POOL_SIZE,
60+
json.optString("variation","default"),
61+
json.optString("timestamp",null));
7662
return ed;
7763
}
7864

0 commit comments

Comments
 (0)