private void MarkAsNotCompleted(DefaultTransaction transaction) { IEvent notCompleteEvent = new DefaultEvent("CAT", "BadInstrument") { Status = "TransactionNotCompleted" }; notCompleteEvent.Complete(); transaction.AddChild(notCompleteEvent); transaction.Complete(); }
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 IMessageTree MergeTree() { var max = PureCatConstants.MAX_CHILD_NUMBER; var tran = new DefaultTransaction("_CatMergeTree", "_CatMergeTree"); IMessageTree first = null; if (!_atomicTress.TryDequeue(out first)) { return null; } tran.Status = PureCatConstants.SUCCESS; tran.Complete(); tran.AddChild(first.Message); tran.Timestamp = first.Message.Timestamp; long lastTimestamp = 0; long lastDuration = 0; while (max-- >= 0) { IMessageTree tree = null; if (!_atomicTress.TryDequeue(out tree)) { tran.DurationInMillis = (lastTimestamp - tran.Timestamp + lastDuration); break; } lastTimestamp = tree.Message.Timestamp; if (tree.Message is DefaultTransaction) { lastDuration = ((DefaultTransaction)tree.Message).DurationInMillis; } else { lastDuration = 0; } tran.AddChild(tree.Message); } first.Message = tran; return first; }