Analysis of Fixedbatchspout in Trident

Source: Internet
Author: User
Tags ack

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&LT;OBJECT&GT, ... 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.