Fixedbatchspout inherited from Ibatchspout
Ibatchspout method
Public interface Ibatchspout extends Serializable { void open (Map conf, topologycontext context); void Emitbatch (Long BatchId, tridentcollector collector); void ack (long BatchId); void Close (); Map getcomponentconfiguration (); Fields Getoutputfields ();}
Fixedbatchspout Code Package Storm.trident.testing;import Backtype.storm.config;import Backtype.storm.task.topologycontext;import Backtype.storm.tuple.fields;import Java.util.List;import Java.util.Map ; Import Storm.trident.operation.tridentcollector;import Storm.trident.spout.ibatchspout;public class Fixedbatchspout implements ibatchspout {fields; List<object>[] outputs; int maxbatchsize; Public fixedbatchspout (fields, int maxbatchsize, LIST<OBJECT>, ... outputs) {this.fields = fields;//Output Out field this.outputs = outputs; Save to local, each object is a list<object> this.maxbatchsize = maxbatchsize; The maximum number of times the batch was emitted, but not the only determinant of the element} int index = 0; Boolean cycle = false; public void Setcycle (Boolean cycle) {this.cycle = cycle; } @Override public void Open (Map conf, Topologycontext context) {index = 0; } @Override public void Emitbatch (long BatchId, tridentcollector collector) {//utiLs.sleep (2000); if (index>=outputs.length && cycle) {index = 0; After subscript, let Index zero, continue to loop send}//In the case of no more than outputs size, each time the launch of a list<object> for (int i=0; index < out Puts.length && i < maxbatchsize; index++, i++) {collector.emit (Outputs[index]); }} @Override public void ack (long BatchId) {} @Override public void Close () {} @Overrid E public Map getcomponentconfiguration () {Config conf = new Config (); Conf.setmaxtaskparallelism (1); The maximum degree of parallelism, by default, is 1. It seems that there is no interface to modify, very strange. return conf; } @Override public Fields Getoutputfields () {return fields; Output field}}
External use
fixedbatchspout spout = new Fixedbatchspout (new fields ("sentence"), 1,
The new Values ("AB-ab AB-AB")); This is set to 1, which means that only one list<value> is sent per batch, but the setting is larger and does not go wrong, see the code comment above, which satisfies no more than the array size, so it does not cross the line.
Spout.setcycle (TRUE); The setting indicates that it will always be sent and can be commented out if it has not been fired.
The other is Trident internal invocation.
If the analysis is wrong, please point out, thank you.
Analysis of Fixedbatchspout in Trident