public void Launch() { Context.Logger.Info("[Bolt] Launch ..."); ApacheStorm.ctx = new BoltContext(); IPlugin iPlugin = this._createDelegate(ApacheStorm.ctx); if (!(iPlugin is IBolt)) { Context.Logger.Error("[Bolt] newPlugin must return IBolt!"); } this._bolt = (IBolt)iPlugin; try { //call Prepare method. this._bolt.Prepare(Context.Config, Context.TopologyContext); while (true) { StormTuple tuple = ApacheStorm.ReadTuple(); if (tuple.IsHeartBeatTuple()) { ApacheStorm.Sync(); } else { this._bolt.Execute(tuple); } } } catch (Exception ex) { Context.Logger.Error(ex.ToString()); } }
public void Execute(StormTuple tuple) { Context.Logger.Info("SimpleDRPC Execute enter"); string sentence = tuple.GetString(0) + "!"; this.ctx.Emit("default", new List<StormTuple> { tuple }, new List<object> { sentence, tuple.GetValue(1) }); Context.Logger.Info("SimpleDRPC Execute exit"); ApacheStorm.Ack(tuple); }
/// <summary> /// The Execute() function will be called, when a new tuple is available. /// </summary> /// <param name="tuple"></param> public void Execute(StormTuple tuple) { Context.Logger.Info("Execute enter"); string sentence = tuple.GetString(0); foreach (string word in sentence.Split(' ')) { Context.Logger.Info("Splitter Emit: {0}", word); this.ctx.Emit("default", new List<StormTuple> { tuple }, new List<object> { word, word[0] }); } Context.Logger.Info("Splitter Execute exit"); }
/// <summary> /// The Execute() function will be called, when a new tuple is available. /// </summary> /// <param name="tuple"></param> public void Execute(StormTuple tuple) { Context.Logger.Info("Execute enter"); string word = tuple.GetString(0); int count = counts.ContainsKey(word) ? counts[word] : 0; count++; counts[word] = count; Context.Logger.Info("Counter Emit: {0}, count: {1}", word, count); this.ctx.Emit("default", new List<StormTuple> { tuple }, new List<object> { word, count }); Context.Logger.Info("Counter Execute exit"); }
public abstract void Fail(StormTuple tuple);
public abstract void Ack(StormTuple tuple);
public override void Fail(StormTuple tuple) { Context.Logger.Error("[SpoutContext] Bolt can not call this function!"); }
public static void Fail(StormTuple tuple) { SendMsgToParent("{\"command\": \"fail\", \"id\": \"" + tuple.GetTupleId() + "\"}"); }
public override void Fail(StormTuple tuple) { ApacheStorm.Fail(tuple); }
public override void Ack(StormTuple tuple) { ApacheStorm.Ack(tuple); }