object count bolt
来源:互联网 发布:淘宝上怎么退货 编辑:程序博客网 时间:2024/05/29 03:36
import backtype.storm.tuple.Fields;import backtype.storm.tuple.Tuple;import backtype.storm.tuple.Values;import com.newegg.storm.util.TimeUtils;import com.newegg.storm.util.TupleHelpers;/** * receive tuple [time,obj,...] * emit tuple [emitTime, obj, count, ...] * @author bw67 * */public abstract class ObjectCountWithTimeBolt extends ObjectCountBolt {private long startTime;private boolean isFirst = true;private long emitTime;private long tickTimesSinceLastEmit;/** * count the latest windowLength campaign * and emit the result every emitFrequencyInSeconds * @param outputFields: must match to values returned from method getValuesToEmit * @param windowLengthInSeconds * @param emitFrequencyInSeconds */public ObjectCountWithTimeBolt(Fields outputFields, int windowLengthInSeconds, int emitFrequencyInSeconds){super(outputFields,windowLengthInSeconds,emitFrequencyInSeconds);}public void execute(Tuple input) {if (TupleHelpers.isTickTuple(input)) {tickTimesSinceLastEmit += 1;//if after 2 ticks, emit the last resultif(tickTimesSinceLastEmit >=2){emitCurrentWindowCounts();emitTime += getEmitFrequencyInSeconds() * 1000;tickTimesSinceLastEmit = 0;}}else{long time = getObjectTime(input);//initialize the emitTime by time of the first tuple if(isFirst){emitTime = TimeUtils.floor(time, "mm");tickTimesSinceLastEmit = 0;isFirst = false;}//System.out.println("time=" + TimeUtils.stringOf(time) + ", emitTime=" + TimeUtils.stringOf(emitTime)); //if time of the tuple is over the emit time, then emit the last results and update emit time long d = time -emitTime;if(d >= 0){long n = d / (getEmitFrequencyInSeconds() * 1000);for(int i = 0; i <= n; i++){emitCurrentWindowCounts();emitTime += getEmitFrequencyInSeconds() * 1000;} tickTimesSinceLastEmit = 0;} countObjAndAck(input);} }@Overridepublic void doWhenEmit() {}@Overridepublic Values getValuesToEmit(Object obj, Long count) {return new Values(emitTime,obj,count);}public abstract long getObjectTime(Tuple tuple);}
0 0
- object count bolt
- Count in String and Object
- Bolt概述
- 迅雷bolt界面引擎
- storm bolt多重聚合
- 迅雷Bolt界面引擎
- Storm bolt/spout生命周期
- Bolt的生命周期
- bolt BaseBasicBolt BaseRichBolt
- Csimsoft.Bolt+Trelis.Pro
- golang bolt库操作手册
- PHP Tip: Getting the property count for an object
- Ruby Count Array objects if object includes value
- Object 获取对象的引用计数(retain count)
- [__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from object
- [__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from object
- Count
- COUNT
- Code Style
- seajs配合spm应用之四弹出框
- 强连通分量+缩点uva12167
- LVS技术浅析
- Freeswitch常用配置
- object count bolt
- ASP.NET MVC 系列之 (MVC中使用Ninject)
- ACM中国国家集训队论文集目录(1999-2009)
- classpath 小解
- 2011年清华大学计算机研究生机试真题之四
- java 去掉空格
- Spring中使用注解的方式注入方式1
- 最长递增子序列
- 关于Django model 与json序列的转换