Skip to content

Commit 3bf77ab

Browse files
lixiaojieeralf0131
authored andcommitted
Add monitor module javadoc (apache#3121)
1 parent 6aad8da commit 3bf77ab

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/AbstractMonitorFactory.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,21 @@
4444
public abstract class AbstractMonitorFactory implements MonitorFactory {
4545
private static final Logger logger = LoggerFactory.getLogger(AbstractMonitorFactory.class);
4646

47-
// lock for getting monitor center
47+
/**
48+
* The lock for getting monitor center
49+
*/
4850
private static final ReentrantLock LOCK = new ReentrantLock();
4951

50-
// monitor centers Map<RegistryAddress, Registry>
52+
/**
53+
* The monitor centers Map<RegistryAddress, Registry>
54+
*/
5155
private static final Map<String, Monitor> MONITORS = new ConcurrentHashMap<String, Monitor>();
5256

5357
private static final Map<String, CompletableFuture<Monitor>> FUTURES = new ConcurrentHashMap<String, CompletableFuture<Monitor>>();
5458

59+
/**
60+
* The monitor create executor
61+
*/
5562
private static final ExecutorService executor = new ThreadPoolExecutor(0, 10, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new NamedThreadFactory("DubboMonitorCreator", true));
5663

5764
public static Collection<Monitor> getMonitors() {

dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/MonitorFilter.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,28 @@ public class MonitorFilter implements Filter {
4545

4646
private static final Logger logger = LoggerFactory.getLogger(MonitorFilter.class);
4747

48+
/**
49+
* The Concurrent counter
50+
*/
4851
private final ConcurrentMap<String, AtomicInteger> concurrents = new ConcurrentHashMap<String, AtomicInteger>();
4952

53+
/**
54+
* The MonitorFactory
55+
*/
5056
private MonitorFactory monitorFactory;
5157

5258
public void setMonitorFactory(MonitorFactory monitorFactory) {
5359
this.monitorFactory = monitorFactory;
5460
}
5561

56-
// intercepting invocation
62+
/**
63+
* The invocation interceptor,it will collect the invoke data about this invocation and send it to monitor center
64+
*
65+
* @param invoker service
66+
* @param invocation invocation.
67+
* @return {@link Result} the invoke result
68+
* @throws RpcException
69+
*/
5770
@Override
5871
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
5972
if (invoker.getUrl().hasParameter(Constants.MONITOR_KEY)) {
@@ -76,7 +89,16 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcExcept
7689
}
7790
}
7891

79-
// collect info
92+
/**
93+
* The collector logic, it will be handled by the default monitor
94+
*
95+
* @param invoker
96+
* @param invocation
97+
* @param result the invoke result
98+
* @param remoteHost the remote host address
99+
* @param start the timestamp the invoke begin
100+
* @param error if there is an error on the invoke
101+
*/
80102
private void collect(Invoker<?> invoker, Invocation invocation, Result result, String remoteHost, long start, boolean error) {
81103
try {
82104
URL monitorUrl = invoker.getUrl().getUrlParameter(Constants.MONITOR_KEY);
@@ -91,6 +113,17 @@ private void collect(Invoker<?> invoker, Invocation invocation, Result result, S
91113
}
92114
}
93115

116+
/**
117+
* Create statistics url
118+
*
119+
* @param invoker
120+
* @param invocation
121+
* @param result
122+
* @param remoteHost
123+
* @param start
124+
* @param error
125+
* @return
126+
*/
94127
private URL createStatisticsUrl(Invoker<?> invoker, Invocation invocation, Result result, String remoteHost, long start, boolean error) {
95128
// ---- service statistics ----
96129
long elapsed = System.currentTimeMillis() - start; // invocation cost
@@ -114,7 +147,6 @@ private URL createStatisticsUrl(Invoker<?> invoker, Invocation invocation, Resul
114147
remoteKey = MonitorService.CONSUMER;
115148
remoteValue = remoteHost;
116149
}
117-
118150
String input = "", output = "";
119151
if (invocation.getAttachment(Constants.INPUT_KEY) != null) {
120152
input = invocation.getAttachment(Constants.INPUT_KEY);

dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/DubboMonitor.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,28 @@ public class DubboMonitor implements Monitor {
4242

4343
private static final Logger logger = LoggerFactory.getLogger(DubboMonitor.class);
4444

45+
/**
46+
* The length of the array which is a container of the statistics
47+
*/
4548
private static final int LENGTH = 10;
4649

4750
/**
48-
* The timer sends the statistics data to monitor center
51+
* The timer for sending statistics
4952
*/
5053
private final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(3, new NamedThreadFactory("DubboMonitorSendTimer", true));
5154

55+
/**
56+
* The future that can cancel the <b>scheduledExecutorService</b>
57+
*/
5258
private final ScheduledFuture<?> sendFuture;
5359

5460
private final Invoker<MonitorService> monitorInvoker;
5561

5662
private final MonitorService monitorService;
5763

64+
/**
65+
* The time interval for timer <b>scheduledExecutorService</b> to send data
66+
*/
5867
private final long monitorInterval;
5968

6069
private final ConcurrentMap<Statistics, AtomicReference<long[]>> statisticsMap = new ConcurrentHashMap<Statistics, AtomicReference<long[]>>();

0 commit comments

Comments
 (0)