TimeLine可以跟踪调用链路点,记录经过的各个环节点,从而知道这条消息经过了哪几个组件;
使用:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29public final class SingleUserPushTask implements PushTask, ChannelFutureListener {
//初始化
private final TimeLine timeLine = new TimeLine();
public SingleUserPushTask(MPushServer mPushServer, IPushMessage message, FlowControl flowControl) {
.....
//标记开始
this.timeLine.begin("push-center-begin");
}
....
mPushServer.getPushCenter().getPushListener().onTimeout(message, timeLine.timeoutEnd().getTimePoints());
mPushServer.getPushCenter().getPushListener().onSuccess(message, timeLine.successEnd().getTimePoints());
mPushServer.getPushCenter().getPushListener().onFailure(message, timeLine.failureEnd().getTimePoints());
mPushServer.getPushCenter().getPushListener().onRedirect(message, timeLine.end("redirect-end").getTimePoints());
mPushServer.getPushCenter().getPushListener().onOffline(message, timeLine.end("offline-end").getTimePoints());
/**
* 添加ACK任务到队列, 等待客户端响应
* @param messageId 下发到客户端待ack的消息的sessionId
*/
private void addAckTask(int messageId) {
timeLine.addTimePoint("waiting-ack");
//因为要进队列,可以提前释放一些比较占用内存的字段,便于垃圾回收
message.finalized();
AckTask task = AckTask
.from(messageId)
.setCallback(new PushAckCallback(message, timeLine, mPushServer.getPushCenter()));
mPushServer.getPushCenter().getAckTaskQueue().add(task, message.getTimeoutMills() - (int) (System.currentTimeMillis() - start));
}
}
1 | public final class TimeLine { |
功能组件文章目录: