From 3bf77abd86e7d51c74df307c4608b0294d89ca57 Mon Sep 17 00:00:00 2001 From: XiaoJie Li Date: Thu, 3 Jan 2019 16:21:55 +0800 Subject: [PATCH] Add monitor module javadoc (#3121) --- .../support/AbstractMonitorFactory.java | 11 +++++- .../dubbo/monitor/support/MonitorFilter.java | 38 +++++++++++++++++-- .../dubbo/monitor/dubbo/DubboMonitor.java | 11 +++++- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/AbstractMonitorFactory.java b/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/AbstractMonitorFactory.java index c49cb1be3c0..74a129b99b5 100644 --- a/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/AbstractMonitorFactory.java +++ b/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/AbstractMonitorFactory.java @@ -44,14 +44,21 @@ public abstract class AbstractMonitorFactory implements MonitorFactory { private static final Logger logger = LoggerFactory.getLogger(AbstractMonitorFactory.class); - // lock for getting monitor center + /** + * The lock for getting monitor center + */ private static final ReentrantLock LOCK = new ReentrantLock(); - // monitor centers Map + /** + * The monitor centers Map + */ private static final Map MONITORS = new ConcurrentHashMap(); private static final Map> FUTURES = new ConcurrentHashMap>(); + /** + * The monitor create executor + */ private static final ExecutorService executor = new ThreadPoolExecutor(0, 10, 60L, TimeUnit.SECONDS, new SynchronousQueue(), new NamedThreadFactory("DubboMonitorCreator", true)); public static Collection getMonitors() { diff --git a/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/MonitorFilter.java b/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/MonitorFilter.java index d9d4b796b36..10eb31e42fc 100644 --- a/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/MonitorFilter.java +++ b/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/MonitorFilter.java @@ -45,15 +45,28 @@ public class MonitorFilter implements Filter { private static final Logger logger = LoggerFactory.getLogger(MonitorFilter.class); + /** + * The Concurrent counter + */ private final ConcurrentMap concurrents = new ConcurrentHashMap(); + /** + * The MonitorFactory + */ private MonitorFactory monitorFactory; public void setMonitorFactory(MonitorFactory monitorFactory) { this.monitorFactory = monitorFactory; } - // intercepting invocation + /** + * The invocation interceptor,it will collect the invoke data about this invocation and send it to monitor center + * + * @param invoker service + * @param invocation invocation. + * @return {@link Result} the invoke result + * @throws RpcException + */ @Override public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { if (invoker.getUrl().hasParameter(Constants.MONITOR_KEY)) { @@ -76,7 +89,16 @@ public Result invoke(Invoker invoker, Invocation invocation) throws RpcExcept } } - // collect info + /** + * The collector logic, it will be handled by the default monitor + * + * @param invoker + * @param invocation + * @param result the invoke result + * @param remoteHost the remote host address + * @param start the timestamp the invoke begin + * @param error if there is an error on the invoke + */ private void collect(Invoker invoker, Invocation invocation, Result result, String remoteHost, long start, boolean error) { try { URL monitorUrl = invoker.getUrl().getUrlParameter(Constants.MONITOR_KEY); @@ -91,6 +113,17 @@ private void collect(Invoker invoker, Invocation invocation, Result result, S } } + /** + * Create statistics url + * + * @param invoker + * @param invocation + * @param result + * @param remoteHost + * @param start + * @param error + * @return + */ private URL createStatisticsUrl(Invoker invoker, Invocation invocation, Result result, String remoteHost, long start, boolean error) { // ---- service statistics ---- long elapsed = System.currentTimeMillis() - start; // invocation cost @@ -114,7 +147,6 @@ private URL createStatisticsUrl(Invoker invoker, Invocation invocation, Resul remoteKey = MonitorService.CONSUMER; remoteValue = remoteHost; } - String input = "", output = ""; if (invocation.getAttachment(Constants.INPUT_KEY) != null) { input = invocation.getAttachment(Constants.INPUT_KEY); diff --git a/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/DubboMonitor.java b/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/DubboMonitor.java index 1e441e5c226..04df72df97f 100644 --- a/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/DubboMonitor.java +++ b/dubbo-monitor/dubbo-monitor-default/src/main/java/org/apache/dubbo/monitor/dubbo/DubboMonitor.java @@ -42,19 +42,28 @@ public class DubboMonitor implements Monitor { private static final Logger logger = LoggerFactory.getLogger(DubboMonitor.class); + /** + * The length of the array which is a container of the statistics + */ private static final int LENGTH = 10; /** - * The timer sends the statistics data to monitor center + * The timer for sending statistics */ private final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(3, new NamedThreadFactory("DubboMonitorSendTimer", true)); + /** + * The future that can cancel the scheduledExecutorService + */ private final ScheduledFuture sendFuture; private final Invoker monitorInvoker; private final MonitorService monitorService; + /** + * The time interval for timer scheduledExecutorService to send data + */ private final long monitorInterval; private final ConcurrentMap> statisticsMap = new ConcurrentHashMap>();