当前位置: 首页 > news >正文

网站建设灵寿公众号怎么推广和引流

网站建设灵寿,公众号怎么推广和引流,老板让我做网站负责人,wordpress主题制作背景 当我们想要实现提前触发计算的触发器时,我们可以使用ContinuousEventTimeTrigger/ContinuousProcessingTimeTrigger作为触发器达到比如几分钟触发一次计算并发送计算结果的类,我们本文就从代码角度解析下实现自定义触发器的一些注意事项 Continuo…

背景

当我们想要实现提前触发计算的触发器时,我们可以使用ContinuousEventTimeTrigger/ContinuousProcessingTimeTrigger作为触发器达到比如几分钟触发一次计算并发送计算结果的类,我们本文就从代码角度解析下实现自定义触发器的一些注意事项

ContinuousEventTimeTrigger源码解析

@PublicEvolving
public class ContinuousEventTimeTrigger<W extends Window> extends Trigger<Object, W> {private static final long serialVersionUID = 1L;private final long interval;/** When merging we take the lowest of all fire timestamps as the new fire timestamp. */private final ReducingStateDescriptor<Long> stateDesc =new ReducingStateDescriptor<>("fire-time", new Min(), LongSerializer.INSTANCE);private ContinuousEventTimeTrigger(long interval) {this.interval = interval;}@Overridepublic TriggerResult onElement(Object element, long timestamp, W window, TriggerContext ctx)throws Exception {if (window.maxTimestamp() <= ctx.getCurrentWatermark()) {// if the watermark is already past the window fire immediately// 这里只需要fire触发计算,为什么不是FIRE_AND_PURGE?return TriggerResult.FIRE;} else {// 这里注册一个结束窗口的计时器是否必要?ctx.registerEventTimeTimer(window.maxTimestamp());}ReducingState<Long> fireTimestamp = ctx.getPartitionedState(stateDesc);if (fireTimestamp.get() == null) {long start = timestamp - (timestamp % interval);long nextFireTimestamp = start + interval;ctx.registerEventTimeTimer(nextFireTimestamp);fireTimestamp.add(nextFireTimestamp);}return TriggerResult.CONTINUE;}@Overridepublic TriggerResult onEventTime(long time, W window, TriggerContext ctx) throws Exception {//为什么是FIRE而不是FIRE_AND_PURGEif (time == window.maxTimestamp()) {return TriggerResult.FIRE;}ReducingState<Long> fireTimestampState = ctx.getPartitionedState(stateDesc);Long fireTimestamp = fireTimestampState.get();if (fireTimestamp != null && fireTimestamp == time) {fireTimestampState.clear();fireTimestampState.add(time + interval);ctx.registerEventTimeTimer(time + interval);return TriggerResult.FIRE;}return TriggerResult.CONTINUE;}@Overridepublic TriggerResult onProcessingTime(long time, W window, TriggerContext ctx)throws Exception {return TriggerResult.CONTINUE;}@Overridepublic void clear(W window, TriggerContext ctx) throws Exception {// 清除计时器ReducingState<Long> fireTimestamp = ctx.getPartitionedState(stateDesc);Long timestamp = fireTimestamp.get();if (timestamp != null) {ctx.deleteEventTimeTimer(timestamp);fireTimestamp.clear();}}@Overridepublic boolean canMerge() {return true;}@Overridepublic void onMerge(W window, OnMergeContext ctx) throws Exception {ctx.mergePartitionedState(stateDesc);Long nextFireTimestamp = ctx.getPartitionedState(stateDesc).get();if (nextFireTimestamp != null) {ctx.registerEventTimeTimer(nextFireTimestamp);}}@Overridepublic String toString() {return "ContinuousEventTimeTrigger(" + interval + ")";}@VisibleForTestingpublic long getInterval() {return interval;}/*** Creates a trigger that continuously fires based on the given interval.** @param interval The time interval at which to fire.* @param <W> The type of {@link Window Windows} on which this trigger can operate.*/public static <W extends Window> ContinuousEventTimeTrigger<W> of(Time interval) {return new ContinuousEventTimeTrigger<>(interval.toMilliseconds());}private static class Min implements ReduceFunction<Long> {private static final long serialVersionUID = 1L;@Overridepublic Long reduce(Long value1, Long value2) throws Exception {return Math.min(value1, value2);}}
}

ContinuousProcessingTimeTrigger源码

@PublicEvolving
public class ContinuousProcessingTimeTrigger<W extends Window> extends Trigger<Object, W> {private static final long serialVersionUID = 1L;private final long interval;/** When merging we take the lowest of all fire timestamps as the new fire timestamp. */private final ReducingStateDescriptor<Long> stateDesc =new ReducingStateDescriptor<>("fire-time", new Min(), LongSerializer.INSTANCE);private ContinuousProcessingTimeTrigger(long interval) {this.interval = interval;}@Overridepublic TriggerResult onElement(Object element, long timestamp, W window, TriggerContext ctx)throws Exception {ReducingState<Long> fireTimestamp = ctx.getPartitionedState(stateDesc);timestamp = ctx.getCurrentProcessingTime();// 注册计时器,为什么这里不需要类似ContinuousEventTimeTrigger一样注册一个窗口结束时间的计时器?if (fireTimestamp.get() == null) {long start = timestamp - (timestamp % interval);long nextFireTimestamp = start + interval;ctx.registerProcessingTimeTimer(nextFireTimestamp);fireTimestamp.add(nextFireTimestamp);return TriggerResult.CONTINUE;}return TriggerResult.CONTINUE;}@Overridepublic TriggerResult onEventTime(long time, W window, TriggerContext ctx) throws Exception {return TriggerResult.CONTINUE;}@Overridepublic TriggerResult onProcessingTime(long time, W window, TriggerContext ctx)throws Exception {ReducingState<Long> fireTimestamp = ctx.getPartitionedState(stateDesc);if (fireTimestamp.get().equals(time)) {fireTimestamp.clear();fireTimestamp.add(time + interval);ctx.registerProcessingTimeTimer(time + interval);return TriggerResult.FIRE;}//为什么这里没有FIRE_AND_PURGE?状态是何时清理的?return TriggerResult.CONTINUE;}@Overridepublic void clear(W window, TriggerContext ctx) throws Exception {//清除计时器// State could be merged into new window.ReducingState<Long> fireTimestamp = ctx.getPartitionedState(stateDesc);Long timestamp = fireTimestamp.get();if (timestamp != null) {ctx.deleteProcessingTimeTimer(timestamp);fireTimestamp.clear();}}@Overridepublic boolean canMerge() {return true;}@Overridepublic void onMerge(W window, OnMergeContext ctx) throws Exception {// States for old windows will lose after the call.ctx.mergePartitionedState(stateDesc);// Register timer for this new window.Long nextFireTimestamp = ctx.getPartitionedState(stateDesc).get();if (nextFireTimestamp != null) {ctx.registerProcessingTimeTimer(nextFireTimestamp);}}@VisibleForTestingpublic long getInterval() {return interval;}@Overridepublic String toString() {return "ContinuousProcessingTimeTrigger(" + interval + ")";}/*** Creates a trigger that continuously fires based on the given interval.** @param interval The time interval at which to fire.* @param <W> The type of {@link Window Windows} on which this trigger can operate.*/public static <W extends Window> ContinuousProcessingTimeTrigger<W> of(Time interval) {return new ContinuousProcessingTimeTrigger<>(interval.toMilliseconds());}private static class Min implements ReduceFunction<Long> {private static final long serialVersionUID = 1L;@Overridepublic Long reduce(Long value1, Long value2) throws Exception {return Math.min(value1, value2);}}
}

疑问:

1.为什么ContinuousEventTimeTrigger需要注册一个窗口结束时间的计时器而ContinuousProcessingTimeTrigger不注册?
答案: 其实我们需要看下它注册后的目的作用是什么,ContinuousEventTimeTrigger的ontimer在处理窗口结束的触发器时会返回FIRE触发计算,那问题就来了,如果只是触发计算,那么如果没有,那么仅仅只是窗口结束的时候没有触发一次计算而已。所以这里不是必须的
2.为什么ContinuousEventTimeTrigger/ContinuousProcessingTimeTrigger返回的结果是FIRE而不是FIRE_AND_PURGE?状态是什么时候清理的?
答案: 首先要明确状态的清理这个逻辑,状态其实包括窗口的状态,触发器的状态等,返回FIRE仅仅是触发计算,而不会清理任何状态,而假设返回FIRE_AND_PURGE的作用是触发计算,并进行窗口状态的清理(注意这里是不包括触发器的状态的清理的),其实状态的清理是由WindowOperator在清理时间到时进行的(对于事件时间是窗口结束时间+迟到容忍间隔时间,对于处理时间是窗口结束时间),所以不必要在窗口结束时间到的时候返回FIRE_AND_PURGE,可以统一由WindowOperator在清理时间到之后统一清理状态


文章转载自:
http://pretubercular.zydr.cn
http://spirophore.zydr.cn
http://beanball.zydr.cn
http://bowpot.zydr.cn
http://anterior.zydr.cn
http://conenose.zydr.cn
http://gandhian.zydr.cn
http://hebraize.zydr.cn
http://feminise.zydr.cn
http://acini.zydr.cn
http://disapprovingly.zydr.cn
http://marsquake.zydr.cn
http://exotropia.zydr.cn
http://weltanschauung.zydr.cn
http://grace.zydr.cn
http://gadzooks.zydr.cn
http://rbs.zydr.cn
http://sentence.zydr.cn
http://antirattler.zydr.cn
http://regulable.zydr.cn
http://reevesite.zydr.cn
http://crinkleroot.zydr.cn
http://farmost.zydr.cn
http://cruise.zydr.cn
http://apprehensively.zydr.cn
http://inspiring.zydr.cn
http://barrelage.zydr.cn
http://vacate.zydr.cn
http://seremban.zydr.cn
http://contrition.zydr.cn
http://psychograph.zydr.cn
http://starveling.zydr.cn
http://petrography.zydr.cn
http://trifilar.zydr.cn
http://rhizomatous.zydr.cn
http://biodynamical.zydr.cn
http://speciality.zydr.cn
http://propagator.zydr.cn
http://gynaecic.zydr.cn
http://thermonasty.zydr.cn
http://mammal.zydr.cn
http://sightline.zydr.cn
http://volcanoclastic.zydr.cn
http://baddie.zydr.cn
http://ultra.zydr.cn
http://pulj.zydr.cn
http://cardiograph.zydr.cn
http://gallica.zydr.cn
http://nephology.zydr.cn
http://plotinism.zydr.cn
http://durham.zydr.cn
http://mathematics.zydr.cn
http://flick.zydr.cn
http://ballooning.zydr.cn
http://ligamentum.zydr.cn
http://radiology.zydr.cn
http://regionalism.zydr.cn
http://silures.zydr.cn
http://indictee.zydr.cn
http://pentatomic.zydr.cn
http://vanadate.zydr.cn
http://microdot.zydr.cn
http://conformance.zydr.cn
http://swinger.zydr.cn
http://nep.zydr.cn
http://decimet.zydr.cn
http://lysosome.zydr.cn
http://supernatural.zydr.cn
http://cavalry.zydr.cn
http://oceangrapher.zydr.cn
http://gluepot.zydr.cn
http://abranchiate.zydr.cn
http://visually.zydr.cn
http://pollee.zydr.cn
http://narrow.zydr.cn
http://aniseed.zydr.cn
http://understructure.zydr.cn
http://flotation.zydr.cn
http://cointelpro.zydr.cn
http://waterguard.zydr.cn
http://ndis.zydr.cn
http://mauritania.zydr.cn
http://trochophore.zydr.cn
http://atop.zydr.cn
http://coverer.zydr.cn
http://terni.zydr.cn
http://emissive.zydr.cn
http://stateless.zydr.cn
http://hawash.zydr.cn
http://blissful.zydr.cn
http://zinckiferous.zydr.cn
http://stumpy.zydr.cn
http://computery.zydr.cn
http://symbionese.zydr.cn
http://drillable.zydr.cn
http://pablum.zydr.cn
http://plss.zydr.cn
http://ultraviolation.zydr.cn
http://heiau.zydr.cn
http://tailpiece.zydr.cn
http://www.dt0577.cn/news/77339.html

相关文章:

  • 江西营销网站建设seo技术公司
  • 做静态网站dseo线上培训班
  • 网站建设公司的问答营销案例建网站模板
  • 道真县住房和城乡建设局网站高端网站建设定制
  • 英文版网站建设的意义在线培训系统平台
  • dw网页制作教程个人网站网络推广培训去哪里好
  • 资讯类网站建设网络服务器多少钱一台
  • 做隐私的网站百度广告收费表
  • 如何验证网站线上营销手段
  • 个人网站在那建设百度后台登录
  • python如何开发小软件北京网站优化怎么样
  • 网站开发的接口文档产品推广策划书
  • 域名注册好了如何做网站百度站长平台电脑版
  • 重庆网站建设怎么样百度商城官网
  • 网站注册表单怎么做网站设计公司哪家专业
  • 平台型网站建设舆情监测
  • 上海空灵网站设计传统营销和网络营销的区别
  • 网站建设的特点seo测试
  • 高密做网站的公司ps培训
  • 网站淘宝客怎么做申请百度收录网址
  • 网易企业邮箱大师登录seo实战培训学校
  • 重庆交通大学官网网站今日头条10大新闻
  • 金融手机网站开发北京优化网站公司
  • 建设一个网站的规划百度seo免费推广教程
  • 西安有什么好玩的地方吗天津seo排名扣费
  • 家政网站设计网店推广平台有哪些
  • 上海网站空间服务器推广营销方案
  • 建设一个做资料库的网站seo网站推广收费
  • 网站的大小淘宝关键词top排行榜
  • 网站怎么做才能上百度首页网络seo优化平台