forked from nathanmarz/storm
/
BatchSpoutExecutor.java
75 lines (59 loc) · 1.89 KB
/
BatchSpoutExecutor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package storm.trident.spout;
import backtype.storm.task.TopologyContext;
import storm.trident.topology.TransactionAttempt;
import backtype.storm.tuple.Fields;
import java.util.Map;
import storm.trident.operation.TridentCollector;
public class BatchSpoutExecutor implements ITridentSpout {
public static class EmptyCoordinator implements BatchCoordinator {
@Override
public Object initializeTransaction(long txid, Object prevMetadata, Object currMetadata) {
return null;
}
@Override
public void close() {
}
@Override
public void success(long txid) {
}
@Override
public boolean isReady(long txid) {
return true;
}
}
public class BatchSpoutEmitter implements Emitter {
@Override
public void emitBatch(TransactionAttempt tx, Object coordinatorMeta, TridentCollector collector) {
_spout.emitBatch(tx.getTransactionId(), collector);
}
@Override
public void success(TransactionAttempt tx) {
_spout.ack(tx.getTransactionId());
}
@Override
public void close() {
_spout.close();
}
}
IBatchSpout _spout;
public BatchSpoutExecutor(IBatchSpout spout) {
_spout = spout;
}
@Override
public BatchCoordinator getCoordinator(String txStateId, Map conf, TopologyContext context) {
return new EmptyCoordinator();
}
@Override
public Emitter getEmitter(String txStateId, Map conf, TopologyContext context) {
_spout.open(conf, context);
return new BatchSpoutEmitter();
}
@Override
public Map getComponentConfiguration() {
return _spout.getComponentConfiguration();
}
@Override
public Fields getOutputFields() {
return _spout.getOutputFields();
}
}