CAT的Client端发送消息

本文详细介绍了CAT客户端如何发送消息,包括初始化上下文、消息管理、时间区间判断、消息队列选择、采样设置、状态更新及异常处理等过程。在消息处理过程中,着重讨论了线程局部存储、消息树结构以及栈管理,确保消息正确发送和流程的顺利执行。
摘要由CSDN通过智能技术生成

1. 生产消息newTransaction,检查上下文ThreadLocal<Context>是否已经初始化,没有则通过m_manager.setup()初始化。初始化消息DefaultTransaction,转交给默认消息管理开始消息处理,m_manager.start(transaction, false);如果是该线程的第一个消息则保存在MessageTree

public void start(Transaction transaction, boolean forked) {
			if (!m_stack.isEmpty()) {
				// Do NOT make strong reference from parent transaction to forked transaction.
				// Instead, we create a "soft" reference to forked transaction later, via linkAsRunAway()
				// By doing so, there is no need for synchronization between parent and child threads.
				// Both threads can complete() anytime despite the other thread.
				Transaction parent = m_stack.peek();
				addTransactionChild(transaction, parent);
			} else {
				m_tree.setMessage(transaction);
			}

			if (!forked) {
				m_stack.push(transaction);
			}
		}

否则就和Stack中的栈顶消息比较生成时间,超过本时段结束时间10s即到达下一时段或者子消息的数量超过配置的最大值,这时深度复制最初的消息以及它的子消息,添加事件消息消息DefaultEvent,最后设置ctx.m_totalDurationInMicros为对应的生成时间,也就表示该值大于0。

public void truncateAndFlush(Context ctx, long timestamp) {
			MessageTree tree = ctx.m_tree;
			Stack<Transaction> stack = ctx.m_stack;
			Message message = tree.getMessage();

			if (message instanceof DefaultTransaction) {
				String id = tree.getMessageId();

				if (id == null) {
					id = nextMessageId();
					tree.setMessageId(id);
				}

				Stri
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值