DumpAnalyzer.java
2.88 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package com.dianping.cat.consumer.dump;
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.unidal.helper.Threads;
import org.unidal.lookup.annotation.Inject;
import com.dianping.cat.Cat;
import com.dianping.cat.analysis.AbstractMessageAnalyzer;
import com.dianping.cat.helper.TimeHelper;
import com.dianping.cat.message.internal.MessageId;
import com.dianping.cat.message.spi.MessageTree;
import com.dianping.cat.message.storage.MessageBucketManager;
import com.dianping.cat.report.ReportManager;
import com.dianping.cat.statistic.ServerStatisticManager;
public class DumpAnalyzer extends AbstractMessageAnalyzer<Object> implements LogEnabled {
public static final String ID = "dump";
@Inject(type = MessageBucketManager.class, value = LocalMessageBucketManager.ID)
private LocalMessageBucketManager m_bucketManager;
@Inject
private ServerStatisticManager m_serverStateManager;
private Logger m_logger;
private void checkpointAsyc(final long startTime) {
Threads.forGroup("cat").start(new Threads.Task() {
@Override
public String getName() {
return "DumpAnalyzer-Checkpoint";
}
@Override
public void run() {
try {
m_bucketManager.archive(startTime);
m_logger.info("Dump analyzer checkpoint is completed!");
} catch (Exception e) {
Cat.logError(e);
}
}
@Override
public void shutdown() {
}
});
}
@Override
public synchronized void doCheckpoint(boolean atEnd) {
try {
long startTime = getStartTime();
checkpointAsyc(startTime);
} catch (Exception e) {
m_logger.error(e.getMessage(), e);
}
}
@Override
public void enableLogging(Logger logger) {
m_logger = logger;
}
@Override
public Object getReport(String domain) {
throw new UnsupportedOperationException("This should not be called!");
}
@Override
public ReportManager<?> getReportManager() {
return null;
}
@Override
protected void loadReports() {
// do nothing
}
@Override
public void process(MessageTree tree) {
String domain = tree.getDomain();
if ("PhoenixAgent".equals(domain)) {
return;
} else {
MessageId messageId = MessageId.parse(tree.getMessageId());
if (messageId.getVersion() == 2) {
long time = tree.getMessage().getTimestamp();
long fixedTime = time - time % (TimeHelper.ONE_HOUR);
long idTime = messageId.getTimestamp();
long duration = fixedTime - idTime;
if (duration == 0 || duration == ONE_HOUR || duration == -ONE_HOUR) {
m_bucketManager.storeMessage(tree, messageId);
} else {
m_serverStateManager.addPigeonTimeError(1);
}
}
}
}
public void setBucketManager(LocalMessageBucketManager bucketManager) {
m_bucketManager = bucketManager;
}
public void setServerStateManager(ServerStatisticManager serverStateManager) {
m_serverStateManager = serverStateManager;
}
@Override
public int getAnanlyzerCount() {
return 2;
}
}