Java 类org.apache.camel.spi.RuntimeEndpointRegistry 实例源码

项目:Camel    文件:ManagedRuntimeEndpointRegistry.java   
@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);
    }
}
项目:Camel    文件:RuntimeEndpointRegistryTest.java   
public void testRuntimeEndpointRegistry() throws Exception {
    RuntimeEndpointRegistry registry = context.getRuntimeEndpointRegistry();
    assertEquals(0, registry.getAllEndpoints(false).size());
    // we have 2 at the start as we have all endpoints for the route consumers
    assertEquals(2, registry.getAllEndpoints(true).size());

    MockEndpoint mock = getMockEndpoint("mock:foo2");
    mock.expectedMessageCount(1);
    template.sendBodyAndHeader("seda:foo", "Hello World", "slip", "mock:foo2");
    mock.assertIsSatisfied();

    assertEquals(4, registry.getAllEndpoints(true).size());
    assertEquals(3, registry.getEndpointsPerRoute("foo", true).size());
    assertEquals(1, registry.getEndpointsPerRoute("bar", true).size());

    mock = getMockEndpoint("mock:bar2");
    mock.expectedMessageCount(1);
    template.sendBodyAndHeader("seda:bar", "Bye World", "slip", "mock:bar2");
    mock.assertIsSatisfied();

    assertEquals(6, registry.getAllEndpoints(true).size());
    assertEquals(3, registry.getEndpointsPerRoute("foo", true).size());
    assertEquals(3, registry.getEndpointsPerRoute("bar", true).size());

    // lets check the json
    String json = context.createRouteStaticEndpointJson(null);
    assertNotNull(json);
    log.info(json);

    assertTrue("Should have outputs", json.contains(" { \"uri\": \"mock://foo\" }"));
    assertTrue("Should have outputs", json.contains(" { \"uri\": \"mock://foo2\" }"));
    assertTrue("Should have outputs", json.contains(" { \"uri\": \"mock://bar\" }"));
    assertTrue("Should have outputs", json.contains(" { \"uri\": \"mock://bar2\" }"));
}
项目:Camel    文件:AbstractLocalCamelController.java   
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;
}
项目:Camel    文件:ManagedRuntimeEndpointRegistry.java   
public ManagedRuntimeEndpointRegistry(CamelContext context, RuntimeEndpointRegistry registry) {
    super(context, registry);
    this.registry = registry;
}
项目:Camel    文件:DefaultCamelContext.java   
public RuntimeEndpointRegistry getRuntimeEndpointRegistry() {
    return runtimeEndpointRegistry;
}
项目:Camel    文件:DefaultCamelContext.java   
public void setRuntimeEndpointRegistry(RuntimeEndpointRegistry runtimeEndpointRegistry) {
    this.runtimeEndpointRegistry = runtimeEndpointRegistry;
}
项目:microservice-bundle    文件:ManagedCamelContext.java   
@Override
public RuntimeEndpointRegistry getRuntimeEndpointRegistry() {
  return context.getRuntimeEndpointRegistry();
}
项目:microservice-bundle    文件:ManagedCamelContext.java   
@Override
public void setRuntimeEndpointRegistry(RuntimeEndpointRegistry runtimeEndpointRegistry) {
  context.setRuntimeEndpointRegistry(runtimeEndpointRegistry);
}
项目:dropwizard-camel    文件:ManagedCamelContext.java   
@Override
public RuntimeEndpointRegistry getRuntimeEndpointRegistry() {
    return context.getRuntimeEndpointRegistry();
}
项目:dropwizard-camel    文件:ManagedCamelContext.java   
@Override
public void setRuntimeEndpointRegistry(RuntimeEndpointRegistry runtimeEndpointRegistry) {
    context.setRuntimeEndpointRegistry(runtimeEndpointRegistry);
}
项目:Camel    文件:CamelContext.java   
/**
 * Gets the {@link org.apache.camel.spi.RuntimeEndpointRegistry} to use, or <tt>null</tt> if none is in use.
 */
RuntimeEndpointRegistry getRuntimeEndpointRegistry();
项目:Camel    文件:CamelContext.java   
/**
 * Sets a custom {@link org.apache.camel.spi.RuntimeEndpointRegistry} to use.
 */
void setRuntimeEndpointRegistry(RuntimeEndpointRegistry runtimeEndpointRegistry);