Search in sources :

Example 1 with EndpointRegistry

use of org.apache.camel.spi.EndpointRegistry in project camel by apache.

the class AbstractLocalCamelController method getEndpointRuntimeStatistics.

public List<Map<String, String>> getEndpointRuntimeStatistics(String camelContextName) throws Exception {
    List<Map<String, String>> answer = new ArrayList<Map<String, String>>();
    if (camelContextName != null) {
        CamelContext context = this.getLocalCamelContext(camelContextName);
        if (context != null) {
            EndpointRegistry staticRegistry = context.getEndpointRegistry();
            for (RuntimeEndpointRegistry.Statistic stat : context.getRuntimeEndpointRegistry().getEndpointStatistics()) {
                String url = stat.getUri();
                String routeId = stat.getRouteId();
                String direction = stat.getDirection();
                Boolean isStatic = staticRegistry.isStatic(url);
                Boolean isDynamic = staticRegistry.isDynamic(url);
                long hits = stat.getHits();
                Map<String, String> row = new LinkedHashMap<String, String>();
                row.put("camelContextName", context.getName());
                row.put("uri", url);
                row.put("routeId", routeId);
                row.put("direction", direction);
                row.put("static", isStatic.toString());
                row.put("dynamic", isDynamic.toString());
                row.put("hits", "" + hits);
                answer.add(row);
            }
        }
        // sort the list
        Collections.sort(answer, new Comparator<Map<String, String>>() {

            @Override
            public int compare(Map<String, String> endpoint1, Map<String, String> endpoint2) {
                // sort by route id
                String route1 = endpoint1.get("routeId");
                String route2 = endpoint2.get("routeId");
                int num = route1.compareTo(route2);
                if (num == 0) {
                    // we want in before out
                    String dir1 = endpoint1.get("direction");
                    String dir2 = endpoint2.get("direction");
                    num = dir1.compareTo(dir2);
                }
                return num;
            }
        });
    }
    return answer;
}
Also used : CamelContext(org.apache.camel.CamelContext) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) RuntimeEndpointRegistry(org.apache.camel.spi.RuntimeEndpointRegistry) EndpointRegistry(org.apache.camel.spi.EndpointRegistry) RuntimeEndpointRegistry(org.apache.camel.spi.RuntimeEndpointRegistry) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with EndpointRegistry

use of org.apache.camel.spi.EndpointRegistry in project camel by apache.

the class ManagedRuntimeEndpointRegistry method endpointStatistics.

@Override
public TabularData endpointStatistics() {
    try {
        TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.listRuntimeEndpointsTabularType());
        EndpointRegistry staticRegistry = getContext().getEndpointRegistry();
        int index = 0;
        for (RuntimeEndpointRegistry.Statistic stat : registry.getEndpointStatistics()) {
            CompositeType ct = CamelOpenMBeanTypes.listRuntimeEndpointsCompositeType();
            String url = stat.getUri();
            Boolean isStatic = staticRegistry.isStatic(url);
            Boolean isDynamic = staticRegistry.isDynamic(url);
            if (sanitize) {
                url = URISupport.sanitizeUri(url);
            }
            String routeId = stat.getRouteId();
            String direction = stat.getDirection();
            long hits = stat.getHits();
            CompositeData data = new CompositeDataSupport(ct, new String[] { "index", "url", "routeId", "direction", "static", "dynamic", "hits" }, new Object[] { index, url, routeId, direction, isStatic, isDynamic, hits });
            answer.put(data);
            // use a counter as the single index in the TabularData as we do not want a multi-value index
            index++;
        }
        return answer;
    } catch (Exception e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
}
Also used : CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) TabularData(javax.management.openmbean.TabularData) TabularDataSupport(javax.management.openmbean.TabularDataSupport) RuntimeEndpointRegistry(org.apache.camel.spi.RuntimeEndpointRegistry) EndpointRegistry(org.apache.camel.spi.EndpointRegistry) RuntimeEndpointRegistry(org.apache.camel.spi.RuntimeEndpointRegistry) CompositeType(javax.management.openmbean.CompositeType)

Aggregations

EndpointRegistry (org.apache.camel.spi.EndpointRegistry)2 RuntimeEndpointRegistry (org.apache.camel.spi.RuntimeEndpointRegistry)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 CompositeData (javax.management.openmbean.CompositeData)1 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)1 CompositeType (javax.management.openmbean.CompositeType)1 TabularData (javax.management.openmbean.TabularData)1 TabularDataSupport (javax.management.openmbean.TabularDataSupport)1 CamelContext (org.apache.camel.CamelContext)1