Пример #1
0
        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());
            }
        }
Пример #2
0
        public override void Emit(string streamId, List <StormTuple> anchors, List <object> values, string taskId = null)
        {
            List <string> tupleIds = new List <string>();

            if (anchors != null && anchors.Count > 0)
            {
                foreach (var anchor in anchors)
                {
                    tupleIds.Add(anchor.GetTupleId());
                }
            }

            base.CheckOutputSchema(streamId, values == null ? 0 : values.Count);

            if (string.IsNullOrEmpty(taskId))
            {
                string msg = @"""command"": ""emit"", ""anchors"": {0}, ""stream"": ""{1}"", ""tuple"": {2}";
                ApacheStorm.SendMsgToParent("{" + string.Format(msg, JsonConvert.SerializeObject(tupleIds), streamId, JsonConvert.SerializeObject(values)) + "}");
                ApacheStorm.ReadTaskId();
            }
            else
            {
                string msg = @"""command"": ""emit"", ""anchors"": {0}, ""stream"": ""{1}"", ""task"": {2}, ""tuple"": {3}";
                ApacheStorm.SendMsgToParent("{" + string.Format(msg, JsonConvert.SerializeObject(tupleIds), streamId, taskId, JsonConvert.SerializeObject(values)) + "}");
            }
        }
Пример #3
0
        private void SendLog(string Message, int level = 2)
        {
            LoggerMsg message = new LoggerMsg();

            message.command = "log";
            message.msg     = classMsg + Message;
            message.level   = level;

            ApacheStorm.SendMsgToParent(JsonConvert.SerializeObject(message));
        }
Пример #4
0
        public void Launch()
        {
            Context.Logger.Info("[Spout] Launch ...");
            ApacheStorm.ctx = new SpoutContext();
            IPlugin iPlugin = this._createDelegate(ApacheStorm.ctx);

            if (!(iPlugin is ISpout))
            {
                Context.Logger.Error("[Spout] newPlugin must return ISpout!");
            }
            this._spout = (ISpout)iPlugin;
            //call Open method.
            this._spout.Open(Context.Config, Context.TopologyContext);

            Stopwatch stopwatch = new Stopwatch();

            while (true)
            {
                try
                {
                    stopwatch.Start();
                    Command command = ApacheStorm.ReadCommand();
                    if (command.command == "next")
                    {
                        this._spout.NextTuple();
                    }
                    else if (command.command == "ack")
                    {
                        long seqId = long.Parse(command.id);
                        this._spout.Ack(seqId);
                    }
                    else if (command.command == "fail")
                    {
                        long seqId = long.Parse(command.id);
                        this._spout.Fail(seqId);
                    }
                    else
                    {
                        Context.Logger.Error("[Spout] unexpected message.");
                    }
                    ApacheStorm.Sync();
                    stopwatch.Stop();
                }
                catch (Exception ex)
                {
                    Context.Logger.Error(ex.ToString());
                }
            }
        }
Пример #5
0
        public override void Emit(string streamId, List <object> values, long seqId, string taskId = null)
        {
            base.CheckOutputSchema(streamId, values == null ? 0 : values.Count);

            if (string.IsNullOrEmpty(taskId))
            {
                string msg = @"""command"": ""emit"", ""id"": ""{0}"", ""stream"": ""{1}"", ""tuple"": {2}";
                ApacheStorm.SendMsgToParent("{" + string.Format(msg, seqId.ToString(), streamId, JsonConvert.SerializeObject(values)) + "}");
                ApacheStorm.ReadTaskId();
            }
            else
            {
                string msg = @"""command"": ""emit"", ""id"": ""{0}"", ""stream"": ""{1}"", ""task"": {2}, ""tuple"": {3}";
                ApacheStorm.SendMsgToParent("{" + string.Format(msg, seqId.ToString(), streamId, taskId, JsonConvert.SerializeObject(values)) + "}");
            }
        }
Пример #6
0
 public override void Fail(StormTuple tuple)
 {
     ApacheStorm.Fail(tuple);
 }
Пример #7
0
 public override void Ack(StormTuple tuple)
 {
     ApacheStorm.Ack(tuple);
 }