Inheritance: AbstractMessage, IEvent
Esempio n. 1
0
        public override void Complete()
        {
            if (IsCompleted())
            {
                // complete() was called more than once
                IMessage @event = new DefaultEvent("CAT", "BadInstrument")
                {
                    Status = "TransactionAlreadyCompleted"
                };

                @event.Complete();
                AddChild(@event);
            }
            else
            {
                _mDurationInMicro = MilliSecondTimer.CurrentTimeMicros() - TimestampInMicros;

                SetCompleted(true);

                if (_messageManager != null)
                {
                    _messageManager.End(this);
                }
            }
        }
Esempio n. 2
0
        public void Bind(string tag, string childMessageId, string title = null)
        {
            IEvent @event = new DefaultEvent(PureCatConstants.TYPE_REMOTE_CALL, "Tagged");

            @event.AddData(childMessageId, title ?? $"{Type}:{Name}");
            @event.Timestamp = Timestamp;
            @event.Status    = PureCatConstants.SUCCESS;
            @event.Complete();

            AddChild(@event);
        }
            private void TruncateAndFlush(DefaultMessageManager manager, long timestamp)
            {
                IMessageTree tree = _mTree;
                Stack<ITransaction> stack = _mStack;
                IMessage message = tree.Message;

                if (message is DefaultTransaction)
                {
                    if (tree.MessageId == null)
                    {
                        tree.MessageId = manager.NextMessageId();
                    }

                    string rootId = tree.RootMessageId;
                    string childId = manager.NextMessageId();

                    DefaultTransaction source = message as DefaultTransaction;
                    DefaultTransaction target = new DefaultTransaction(source.Type, source.Name, manager);
                    target.Timestamp = source.Timestamp;
                    target.DurationInMicros = source.DurationInMicros;
                    target.AddData(source.Data);
                    target.Status = PureCatConstants.SUCCESS;

                    MigrateMessage(manager, stack, source, target, 1);

                    var list = stack.ToList();

                    for (int i = list.Count - 1; i >= 0; i--)
                    {
                        DefaultTransaction tran = list[i] as DefaultTransaction;
                        tran.Timestamp = timestamp;
                        tran.DurationInMicros = -1;
                    }

                    IEvent next = new DefaultEvent(PureCatConstants.TYPE_REMOTE_CALL, "Next");
                    next.AddData(childId);
                    next.Status = PureCatConstants.SUCCESS;
                    target.AddChild(next);

                    IMessageTree t = tree.Copy();

                    t.Message = target;

                    _mTree.MessageId = childId;
                    _mTree.ParentMessageId = tree.MessageId;
                    _mTree.RootMessageId = rootId ?? tree.MessageId;

                    manager.Flush(t);
                }
            }
 private void MarkAsNotCompleted(DefaultTransaction transaction)
 {
     IEvent notCompleteEvent = new DefaultEvent("CAT", "BadInstrument") { Status = "TransactionNotCompleted" };
     notCompleteEvent.Complete();
     transaction.AddChild(notCompleteEvent);
     transaction.Complete();
 }
            internal void LinkAsRunAway(DefaultMessageManager manager, IForkedTransaction transaction)
            {
                IEvent @event = new DefaultEvent(PureCatConstants.TYPE_REMOTE_CALL, "RunAway");

                @event.AddData(transaction.ForkedMessageId, $"{transaction.Type}:{transaction.Name}");
                @event.Timestamp = transaction.Timestamp;
                @event.Status = PureCatConstants.SUCCESS;
                @event.Complete();

                transaction.Standalone = true;

                manager.Add(@event);
            }
        protected internal IMessage DecodeLine(ChannelBuffer buf, ITransaction parent,
                                               Stack<ITransaction> stack, IMessageTree tree)
        {
            BufferHelper helper = _mBufferHelper;
            char identifier = (char)buf.ReadByte();
            string timestamp = helper.Read(buf, TAB);
            string type = helper.Read(buf, TAB);
            string name = helper.Read(buf, TAB);
            switch (identifier)
            {
                case 't':
                    IMessage transaction = new DefaultTransaction(type, name, null);

                    helper.Read(buf, LF); // get rid of line feed
                    transaction.Timestamp = _mDateHelper.Parse(timestamp);

                    if (parent != null)
                    {
                        parent.AddChild(transaction);
                    }

                    stack.Push(parent);
                    return transaction;
                case 'A':
                    DefaultTransaction tran = new DefaultTransaction(type, name, null);
                    string status = helper.Read(buf, TAB);
                    string duration = helper.Read(buf, TAB);
                    string data = helper.ReadRaw(buf, TAB);

                    helper.Read(buf, LF); // get rid of line feed
                    tran.Timestamp = _mDateHelper.Parse(timestamp);
                    tran.Status = status;
                    tran.AddData(data);

                    long d = long.Parse(duration.Substring(0, duration.Length - 2), NumberStyles.Integer);

                    tran.DurationInMicros = d;

                    if (parent != null)
                    {
                        parent.AddChild(tran);
                        return parent;
                    }
                    return tran;
                case 'T':
                    string transactionStatus = helper.Read(buf, TAB);
                    string transactionDuration = helper.Read(buf, TAB);
                    string transactionData = helper.ReadRaw(buf, TAB);

                    helper.Read(buf, LF); // get rid of line feed
                    parent.Status = transactionStatus;
                    parent.AddData(transactionData);

                    long transactionD = long.Parse(transactionDuration.Substring(0, transactionDuration.Length - 2), NumberStyles.Integer);

                    parent.DurationInMicros = transactionD;

                    return stack.Pop();
                case 'E':
                    DefaultEvent evt = new DefaultEvent(type, name);
                    string eventStatus = helper.Read(buf, TAB);
                    string eventData = helper.ReadRaw(buf, TAB);

                    helper.Read(buf, LF); // get rid of line feed
                    evt.Timestamp = _mDateHelper.Parse(timestamp);
                    evt.Status = eventStatus;
                    evt.AddData(eventData);

                    if (parent != null)
                    {
                        parent.AddChild(evt);
                        return parent;
                    }
                    return evt;
                case 'M':
                    DefaultMetric metric = new DefaultMetric(type, name);
                    string metricStatus = helper.Read(buf, TAB);
                    string metricData = helper.ReadRaw(buf, TAB);

                    helper.Read(buf, LF);
                    metric.Timestamp = _mDateHelper.Parse(timestamp);
                    metric.Status = metricStatus;
                    metric.AddData(metricData);

                    if (parent != null)
                    {
                        parent.AddChild(metric);
                        return parent;
                    }
                    return metric;
                case 'L':
                    DefaultTrace trace = new DefaultTrace(type, name);
                    string traceStatus = helper.Read(buf, TAB);
                    string traceData = helper.Read(buf, TAB);

                    helper.Read(buf, LF); // get rid of line feed
                    trace.Timestamp = _mDateHelper.Parse(timestamp);
                    trace.Status = traceStatus;
                    trace.AddData(traceData);

                    if (parent != null)
                    {
                        parent.AddChild(trace);
                        return parent;
                    }
                    return trace;
                case 'H':
                    DefaultHeartbeat heartbeat = new DefaultHeartbeat(type, name);
                    string heartbeatStatus = helper.Read(buf, TAB);
                    string heartbeatData = helper.ReadRaw(buf, TAB);

                    helper.Read(buf, LF); // get rid of line feed
                    heartbeat.Timestamp = _mDateHelper.Parse(timestamp);
                    heartbeat.Status = heartbeatStatus;
                    heartbeat.AddData(heartbeatData);

                    if (parent != null)
                    {
                        parent.AddChild(heartbeat);
                        return parent;
                    }
                    return heartbeat;
            }

            Logger.Error("Unknown identifier(" + identifier + ") of message: " + buf);
            //throw new Exception("Unknown identifier int name"); //java版的抛出异常

            // unknown message, ignore it
            return parent;
        }
        public void Bind(string tag, string childMessageId, string title = null)
        {
            IEvent @event = new DefaultEvent(PureCatConstants.TYPE_REMOTE_CALL, "Tagged");

            @event.AddData(childMessageId, title ?? $"{Type}:{Name}");
            @event.Timestamp = Timestamp;
            @event.Status = PureCatConstants.SUCCESS;
            @event.Complete();

            AddChild(@event);
        }
        public virtual IEvent NewEvent(string type, string name)
        {
            if (!_manager.HasContext())
            {
                _manager.Setup();
            }

            if (_manager.CatEnabled)
            {
                IEvent @event = new DefaultEvent(type, name);

                _manager.Add(@event);
                return @event;
            }
            return NullMessage.EVENT;
        }
Esempio n. 9
0
        public override void Complete()
        {
            if (IsCompleted())
            {
                // complete() was called more than once
                IMessage @event = new DefaultEvent("CAT", "BadInstrument") { Status = "TransactionAlreadyCompleted" };

                @event.Complete();
                AddChild(@event);
            }
            else
            {
                _mDurationInMicro = MilliSecondTimer.CurrentTimeMicros - TimestampInMicros;

                SetCompleted(true);

                if (_messageManager != null)
                {
                    _messageManager.End(this);
                }
            }
        }