Java 类org.apache.camel.impl.ExplicitCamelContextNameStrategy 实例源码

项目:Camel    文件:ContextListCommandTest.java   
@Test
public void testContextList() throws Exception {
    CamelContext context = new DefaultCamelContext();
    context.setNameStrategy(new ExplicitCamelContextNameStrategy("foobar"));
    context.start();

    CamelController controller = new DummyCamelController(context);

    OutputStream os = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(os);

    ContextListCommand command = new ContextListCommand();
    command.execute(controller, ps, null);

    String out = os.toString();
    assertNotNull(out);
    LOG.info("\n\n{}\n", out);

    // should contain a table with the context
    assertTrue(out.contains("foobar"));
    assertTrue(out.contains("Started"));

    context.stop();
}
项目:Camel    文件:CatalogCommandTest.java   
@Test
public void testListComponents() throws Exception {
    CamelContext context = new DefaultCamelContext();
    context.setNameStrategy(new ExplicitCamelContextNameStrategy("foobar"));
    context.start();

    CamelController controller = new DummyCamelController(context);

    OutputStream os = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(os);

    CatalogComponentListCommand command = new CatalogComponentListCommand(false, null);
    command.execute(controller, ps, null);

    String out = os.toString();
    assertNotNull(out);
    LOG.info("\n\n{}\n", out);

    context.stop();
}
项目:Camel    文件:CatalogCommandTest.java   
@Test
public void testComponentInfo() throws Exception {
    CamelContext context = new DefaultCamelContext();
    context.setNameStrategy(new ExplicitCamelContextNameStrategy("foobar"));
    context.start();

    CamelController controller = new DummyCamelController(context);

    OutputStream os = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(os);

    CatalogComponentInfoCommand command = new CatalogComponentInfoCommand("hdfs", true, "consumer");
    command.execute(controller, ps, null);

    String out = os.toString();
    assertNotNull(out);
    LOG.info("\n\n{}\n", out);

    context.stop();
}
项目:Camel    文件:AbstractCamelRunner.java   
protected void setupCamelContext(final BundleContext bundleContext, final String camelContextId) throws Exception {
    // Set up CamelContext
    if (camelContextId != null) {
        context.setNameStrategy(new ExplicitCamelContextNameStrategy(camelContextId));
    }
    // TODO: allow to configure these options and not hardcode
    context.setUseMDCLogging(true);
    context.setUseBreadcrumb(true);

    // Add routes
    for (RoutesBuilder route : getRouteBuilders()) {
        context.addRoutes(configure(context, route, log));
    }

    // ensure we publish this CamelContext to the OSGi service registry
    context.getManagementStrategy().addEventNotifier(new OsgiCamelContextPublisher(bundleContext));
}
项目:Camel    文件:CamelContextProducer.java   
private static CamelContextNameStrategy nameStrategy(Annotated annotated) {
    if (annotated.isAnnotationPresent(ContextName.class)) {
        return new ExplicitCamelContextNameStrategy(annotated.getAnnotation(ContextName.class).value());
    } else if (annotated.isAnnotationPresent(Named.class)) {
        // TODO: support stereotype with empty @Named annotation
        String name = annotated.getAnnotation(Named.class).value();
        if (name.isEmpty()) {
            if (annotated instanceof AnnotatedField) {
                name = ((AnnotatedField) annotated).getJavaMember().getName();
            } else if (annotated instanceof AnnotatedMethod) {
                name = ((AnnotatedMethod) annotated).getJavaMember().getName();
                if (name.startsWith("get")) {
                    name = decapitalize(name.substring(3));
                }
            } else {
                name = decapitalize(getRawType(annotated.getBaseType()).getSimpleName());
            }
        }
        return new ExplicitCamelContextNameStrategy(name);
    } else {
        // Use a specific naming strategy for Camel CDI as the default one increments the suffix for each CDI proxy created
        return new CdiCamelContextNameStrategy();
    }
}
项目:camel-cdi    文件:CamelContextProducer.java   
private static CamelContextNameStrategy nameStrategy(Annotated annotated) {
    if (annotated.isAnnotationPresent(ContextName.class)) {
        return new ExplicitCamelContextNameStrategy(annotated.getAnnotation(ContextName.class).value());
    } else if (annotated.isAnnotationPresent(Named.class)) {
        // TODO: support stereotype with empty @Named annotation
        String name = annotated.getAnnotation(Named.class).value();
        if (name.isEmpty()) {
            if (annotated instanceof AnnotatedField) {
                name = ((AnnotatedField) annotated).getJavaMember().getName();
            } else if (annotated instanceof AnnotatedMethod) {
                name = ((AnnotatedMethod) annotated).getJavaMember().getName();
                if (name.startsWith("get"))
                    name = decapitalize(name.substring(3));
            } else {
                name = decapitalize(getRawType(annotated.getBaseType()).getSimpleName());
            }
        }
        return new ExplicitCamelContextNameStrategy(name);
    } else {
        // Use a specific naming strategy for Camel CDI as the default one increments the suffix for each CDI proxy created
        return new CdiCamelContextNameStrategy();
    }
}
项目:camel-cookbook-examples    文件:JmxNamingContextCamelApplication.java   
public void setup() throws Exception {
    context = new DefaultCamelContext();

    context.setNameStrategy(new ExplicitCamelContextNameStrategy("myCamelContextName"));

    // Add a simple test route
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
                    .routeId("first-route")
                .log(LoggingLevel.INFO, "First Route", "${body}")
                .to("mock:result");

            from("direct:startOther")
                    .routeId("other-route")
                .log(LoggingLevel.INFO, "Other Route", "${body}")
                .to("mock:resultOther");
        }
    });
}
项目:syndesis    文件:Application.java   
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
@Bean(name = "verifier-context", initMethod = "start", destroyMethod = "stop")
public static CamelContext verifierContext() {
    CamelContext context = new DefaultCamelContext();
    context.setNameStrategy(new ExplicitCamelContextNameStrategy("verifier-context"));
    context.disableJMX();

    return context;
}
项目:Camel    文件:ContextListCommandTest.java   
@Test
public void testEndpointStats() throws Exception {
    CamelContext context = new DefaultCamelContext();
    context.setNameStrategy(new ExplicitCamelContextNameStrategy("foobar"));
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").to("mock:result");
        }
    });
    context.start();

    context.createProducerTemplate().sendBody("direct:start", "Hello World");

    CamelController controller = new DummyCamelController(context);

    OutputStream os = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(os);

    EndpointStatisticCommand command = new EndpointStatisticCommand("foobar", false, null);
    command.execute(controller, ps, null);

    String out = os.toString();
    assertNotNull(out);
    LOG.info("\n\n{}\n", out);

    assertTrue(out.contains("direct://start"));
    assertTrue(out.contains("mock://result"));

    context.stop();
}
项目:omakase    文件:CamelLifecycle.java   
public void startup() {
    try {
        camelContext.setTracing(false);
        camelContext.setNameStrategy(new ExplicitCamelContextNameStrategy("omakase-camel-context"));
        registerInterceptorStrategy();
        registerExecutorService();
        camelQueueEndpoint.register(camelContext);
        registerRoutes();
        camelContext.start();
    } catch (Exception e) {
        LOGGER.error("Failed to start Omakase's Camel Context", e);
    }
}
项目:camel-cookbook-examples    文件:JmxNamingPatternCamelApplication.java   
public void setup() throws Exception {
    context = new DefaultCamelContext();

    context.setNameStrategy(new ExplicitCamelContextNameStrategy("myCamelContextName"));

    final ManagementStrategy managementStrategy = context.getManagementStrategy();

    final ManagementAgent managementAgent = managementStrategy.getManagementAgent();
    managementAgent.setMBeanServerDefaultDomain("org.apache.camel");

    final ManagementNameStrategy managementNameStrategy = context.getManagementNameStrategy();
    managementNameStrategy.setNamePattern("CustomName-#name#");

    // Add a simple test route
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
                    .routeId("first-route")
                .log(LoggingLevel.INFO, "First Route", "${body}")
                .to("mock:result");

            from("direct:startOther")
                    .routeId("other-route")
                .log(LoggingLevel.INFO, "Other Route", "${body}")
                .to("mock:resultOther");
        }
    });
}
项目:wildfly-camel    文件:MyRouteConfiguration.java   
@Override
public RouteBuilder route() {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            getContext().setNameStrategy(new ExplicitCamelContextNameStrategy("javaConfigContext"));
            from("direct:start").transform(body().prepend("Hello "));
        }
    };
}
项目:wildfly-camel    文件:SecureRouteBuilder.java   
@Override
public void configure() throws Exception {
    getContext().setNameStrategy(new ExplicitCamelContextNameStrategy("secured-context"));
    from("direct:start")
    .policy(new DomainAuthorizationPolicy().roles("Role2"))
    .transform(body().prepend("Hello "));
}
项目:wildfly-camel    文件:CDIRouteBuilder.java   
@Override
public void configure() throws Exception {
    getContext().setNameStrategy(new ExplicitCamelContextNameStrategy("camel-sql-cdi-context"));
    from("sql:select name from information_schema.users?dataSource=wildFlyExampleDS")
    .to("seda:end");
}
项目:wildfly-camel    文件:SimpleRouteBuilder.java   
@Override
public void configure() throws Exception {
    getContext().setNameStrategy(new ExplicitCamelContextNameStrategy("simple-camel-context"));
    from("direct:start").bean("helloBean");
}