Repository: camel Updated Branches: refs/heads/master a87299217 -> 1ceb5c70d
CAMEL-9014: More endpoint usage statitics on the runtime endpoint mbean Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/29cef6f2 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/29cef6f2 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/29cef6f2 Branch: refs/heads/master Commit: 29cef6f2a37254e02916cb6c7968b74d24e5bdfd Parents: a872992 Author: Claus Ibsen <davscl...@apache.org> Authored: Sun Jul 26 20:33:15 2015 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sun Jul 26 20:33:15 2015 +0200 ---------------------------------------------------------------------- .../management/mbean/CamelOpenMBeanTypes.java | 6 +-- .../ManagedRuntimeEndpointRegistryMBean.java | 23 +++++----- .../impl/DefaultRuntimeEndpointRegistry.java | 44 ++++++++------------ .../mbean/ManagedRuntimeEndpointRegistry.java | 24 +++++------ .../camel/spi/RuntimeEndpointRegistry.java | 23 +++++----- 5 files changed, 51 insertions(+), 69 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/29cef6f2/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java b/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java index c72d382..32de297 100644 --- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java +++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java @@ -72,9 +72,9 @@ public final class CamelOpenMBeanTypes { } public static CompositeType listRuntimeEndpointsCompositeType() throws OpenDataException { - return new CompositeType("endpoints", "Endpoints", new String[]{"url", "routeId", "input", "output", "static", "dynamic"}, - new String[]{"Url", "Route Id", "Input", "Output", "Static", "Dynamic"}, - new OpenType[]{SimpleType.STRING, SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN, SimpleType.BOOLEAN, SimpleType.BOOLEAN}); + return new CompositeType("endpoints", "Endpoints", new String[]{"url", "routeId", "direction", "static", "dynamic"}, + new String[]{"Url", "Route Id", "Direction", "Static", "Dynamic"}, + new OpenType[]{SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN}); } public static TabularType explainComponentTabularType() throws OpenDataException { http://git-wip-us.apache.org/repos/asf/camel/blob/29cef6f2/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRuntimeEndpointRegistryMBean.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRuntimeEndpointRegistryMBean.java b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRuntimeEndpointRegistryMBean.java index 2199c7d..3e00a6e 100644 --- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRuntimeEndpointRegistryMBean.java +++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRuntimeEndpointRegistryMBean.java @@ -17,7 +17,6 @@ package org.apache.camel.api.management.mbean; import java.util.List; - import javax.management.openmbean.TabularData; import org.apache.camel.api.management.ManagedAttribute; @@ -25,28 +24,28 @@ import org.apache.camel.api.management.ManagedOperation; public interface ManagedRuntimeEndpointRegistryMBean extends ManagedServiceMBean { - @ManagedOperation(description = "Resets the usage gathered") - void reset(); + @ManagedOperation(description = "Clears the registry") + void clear(); - @ManagedAttribute(description = "Whether gathering runtime usage is enabled or not.") + @ManagedAttribute(description = "Whether gathering runtime usage is enabled or not") boolean isEnabled(); - @ManagedAttribute(description = "Whether gathering runtime usage is enabled or not.") + @ManagedAttribute(description = "Whether gathering runtime usage is enabled or not") void setEnabled(boolean enabled); - @ManagedAttribute(description = "Maximum number of endpoints to keep in the cache per route.") + @ManagedAttribute(description = "Maximum number of endpoints to keep in the cache per route") int getLimit(); - @ManagedAttribute(description = "Number of endpoints currently in the cache.") - int size(); + @ManagedAttribute(description = "Number of endpoints currently in the registry") + int getSize(); - @ManagedOperation(description = " Gets all the endpoint uris captured during runtime that are in-use.") + @ManagedOperation(description = " Gets all the endpoint urls captured during runtime that are in-use") List<String> getAllEndpoints(boolean includeInputs); - @ManagedOperation(description = " Gets all the endpoint uris captured during runtime that are in-use for the given route.") + @ManagedOperation(description = " Gets all the endpoint urls captured during runtime that are in-use for the given route") List<String> getEndpointsPerRoute(String routeId, boolean includeInputs); - @ManagedOperation(description = "Lists all the endpoints in the registry (url)") - TabularData listEndpoints(); + @ManagedOperation(description = "Lists statistics about all the endpoints in the registry") + TabularData endpointStatistics(); } http://git-wip-us.apache.org/repos/asf/camel/blob/29cef6f2/camel-core/src/main/java/org/apache/camel/impl/DefaultRuntimeEndpointRegistry.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultRuntimeEndpointRegistry.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultRuntimeEndpointRegistry.java index 8faf4b8..bf8a276 100644 --- a/camel-core/src/main/java/org/apache/camel/impl/DefaultRuntimeEndpointRegistry.java +++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultRuntimeEndpointRegistry.java @@ -21,7 +21,6 @@ import java.util.Collections; import java.util.EventObject; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -84,14 +83,14 @@ public class DefaultRuntimeEndpointRegistry extends EventNotifierSupport impleme } @Override - public Map<String, Statistic> getStatistics() { - Map<String, Statistic> answer = new LinkedHashMap<String, Statistic>(); + public List<Statistic> getEndpointStatistics() { + List<Statistic> answer = new ArrayList<Statistic>(); // inputs for (Map.Entry<String, Set<String>> entry : inputs.entrySet()) { String routeId = entry.getKey(); for (String uri : entry.getValue()) { - answer.put(uri, new EndpointRuntimeStatistics(routeId, true, false, 0)); + answer.add(new EndpointRuntimeStatistics(uri, routeId, "in", 0)); } } @@ -99,12 +98,7 @@ public class DefaultRuntimeEndpointRegistry extends EventNotifierSupport impleme for (Map.Entry<String, Map<String, String>> entry : outputs.entrySet()) { String routeId = entry.getKey(); for (String uri : entry.getValue().keySet()) { - if (answer.containsKey(uri)) { - // both input and output - answer.put(uri, new EndpointRuntimeStatistics(routeId, true, true, 0)); - } else { - answer.put(uri, new EndpointRuntimeStatistics(routeId, false, true, 0)); - } + answer.add(new EndpointRuntimeStatistics(uri, routeId, "out", 0)); } } @@ -122,7 +116,7 @@ public class DefaultRuntimeEndpointRegistry extends EventNotifierSupport impleme } @Override - public void reset() { + public void clear() { inputs.clear(); outputs.clear(); } @@ -146,7 +140,7 @@ public class DefaultRuntimeEndpointRegistry extends EventNotifierSupport impleme @Override protected void doStop() throws Exception { - reset(); + clear(); } @Override @@ -204,34 +198,30 @@ public class DefaultRuntimeEndpointRegistry extends EventNotifierSupport impleme private static class EndpointRuntimeStatistics implements Statistic { + private final String uri; private final String routeId; - private final boolean input; - private final boolean output; + private final String direction; private final long hits; - private EndpointRuntimeStatistics(String routeId, boolean input, boolean output, long hits) { + private EndpointRuntimeStatistics(String uri, String routeId, String direction, long hits) { + this.uri = uri; this.routeId = routeId; - this.input = input; - this.output = output; + this.direction = direction; this.hits = hits; } - @Override - public String getRouteId() { - return routeId; + public String getUri() { + return uri; } - @Override - public boolean isInput() { - return input; + public String getRouteId() { + return routeId; } - @Override - public boolean isOutput() { - return output; + public String getDirection() { + return direction; } - @Override public long getHits() { return hits; } http://git-wip-us.apache.org/repos/asf/camel/blob/29cef6f2/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRuntimeEndpointRegistry.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRuntimeEndpointRegistry.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRuntimeEndpointRegistry.java index c93d2c6..daafe91 100644 --- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRuntimeEndpointRegistry.java +++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRuntimeEndpointRegistry.java @@ -17,7 +17,6 @@ package org.apache.camel.management.mbean; import java.util.List; -import java.util.Map; import javax.management.openmbean.CompositeData; import javax.management.openmbean.CompositeDataSupport; import javax.management.openmbean.CompositeType; @@ -51,8 +50,8 @@ public class ManagedRuntimeEndpointRegistry extends ManagedService implements Ma } @Override - public void reset() { - registry.reset(); + public void clear() { + registry.clear(); } @Override @@ -71,7 +70,7 @@ public class ManagedRuntimeEndpointRegistry extends ManagedService implements Ma } @Override - public int size() { + public int getSize() { return registry.size(); } @@ -86,29 +85,26 @@ public class ManagedRuntimeEndpointRegistry extends ManagedService implements Ma } @Override - public TabularData listEndpoints() { + public TabularData endpointStatistics() { try { TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.listRuntimeEndpointsTabularType()); EndpointRegistry staticRegistry = getContext().getEndpointRegistry(); - Map<String, RuntimeEndpointRegistry.Statistic> stats = registry.getStatistics(); - for (Map.Entry<String, RuntimeEndpointRegistry.Statistic> entry : stats.entrySet()) { + for (RuntimeEndpointRegistry.Statistic stat : registry.getEndpointStatistics()) { CompositeType ct = CamelOpenMBeanTypes.listRuntimeEndpointsCompositeType(); - String url = entry.getKey(); - + String url = stat.getUri(); Boolean isStatic = staticRegistry.isStatic(url); Boolean isDynamic = staticRegistry.isDynamic(url); if (sanitize) { url = URISupport.sanitizeUri(url); } - String routeId = entry.getValue().getRouteId(); - Boolean input = entry.getValue().isInput(); - Boolean output = entry.getValue().isOutput(); + String routeId = stat.getRouteId(); + String direction = stat.getDirection(); - CompositeData data = new CompositeDataSupport(ct, new String[]{"url", "routeId", "input", "output", "static", "dynamic"}, - new Object[]{url, routeId, input, output, isStatic, isDynamic}); + CompositeData data = new CompositeDataSupport(ct, new String[]{"url", "routeId", "direction", "static", "dynamic"}, + new Object[]{url, routeId, direction, isStatic, isDynamic}); answer.put(data); } return answer; http://git-wip-us.apache.org/repos/asf/camel/blob/29cef6f2/camel-core/src/main/java/org/apache/camel/spi/RuntimeEndpointRegistry.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/spi/RuntimeEndpointRegistry.java b/camel-core/src/main/java/org/apache/camel/spi/RuntimeEndpointRegistry.java index a56cc04..d09b5e5 100644 --- a/camel-core/src/main/java/org/apache/camel/spi/RuntimeEndpointRegistry.java +++ b/camel-core/src/main/java/org/apache/camel/spi/RuntimeEndpointRegistry.java @@ -17,7 +17,6 @@ package org.apache.camel.spi; import java.util.List; -import java.util.Map; import org.apache.camel.StaticService; @@ -32,23 +31,21 @@ public interface RuntimeEndpointRegistry extends StaticService { public interface Statistic { /** - * The route id (if the endpoint is associated with a route) + * The endpoint uri */ - String getRouteId(); + String getUri(); /** - * Whether the endpoint is used as input - * <p/> - * Notice an endpoint can be used as both input and output, such as when its linking two routes + * The route id (if the endpoint is associated with a route) */ - boolean isInput(); + String getRouteId(); /** - * Whether the endpoint is used as output + * Whether the endpoint is used as input our output * <p/> - * Notice an endpoint can be used as both input and output, such as when its linking two routes + * The returned value can either be <tt>in</tt> or <tt>out</tt> */ - boolean isOutput(); + String getDirection(); /** * Usage of the endpoint, such as how many messages it has received / sent to @@ -82,9 +79,9 @@ public interface RuntimeEndpointRegistry extends StaticService { void setLimit(int limit); /** - * Clears the runtime usage gathered + * Clears the registry */ - void reset(); + void clear(); /** * Number of endpoints currently in the cache. @@ -109,6 +106,6 @@ public interface RuntimeEndpointRegistry extends StaticService { /** * Gets details about all the endpoint captured from the given route during runtime routing that are in-use of the routes. */ - Map<String, Statistic> getStatistics(); + List<Statistic> getEndpointStatistics(); }