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

项目:Camel    文件:TwoManagedCamelContextAutoAssignedNameClashTest.java   
public void testTwoManagedCamelContextClash() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }

    camel1 = createCamelContext();
    camel1.start();
    assertTrue("Should be started", camel1.getStatus().isStarted());

    MBeanServer mbeanServer = camel1.getManagementStrategy().getManagementAgent().getMBeanServer();
    ObjectName on = ObjectName.getInstance("org.apache.camel:context=" + camel1.getManagementName() + ",type=context,name=\"camel-1\"");
    assertTrue("Should be registered", mbeanServer.isRegistered(on));

    // now cheat and reset the counter so we can test for a clash
    DefaultCamelContextNameStrategy.setCounter(0);

    camel2 = createCamelContext();
    camel2.start();
    ObjectName on2 = ObjectName.getInstance("org.apache.camel:context=" + camel2.getManagementName() + ",type=context,name=\"camel-1\"");
    assertTrue("Should be registered", mbeanServer.isRegistered(on2));

    assertTrue("Should still be registered after name clash", mbeanServer.isRegistered(on));
    assertTrue("Should still be registered after name clash", mbeanServer.isRegistered(on2));
}
项目:Camel    文件:CamelContextOsgiProducer.java   
@Override
public T produce(CreationalContext<T> ctx) {
    T context = super.produce(ctx);

    // Register the context in the OSGi registry
    BundleContext bundle = BundleContextUtils.getBundleContext(getClass());
    context.getManagementStrategy().addEventNotifier(new OsgiCamelContextPublisher(bundle));

    if (!(context instanceof DefaultCamelContext)) {
        // Fail fast for the time being to avoid side effects by some methods get declared on the CamelContext interface
        throw new InjectionException("Camel CDI requires Camel context [" + context.getName() + "] to be a subtype of DefaultCamelContext");
    }

    DefaultCamelContext adapted = context.adapt(DefaultCamelContext.class);
    adapted.setRegistry(OsgiCamelContextHelper.wrapRegistry(context, context.getRegistry(), bundle));
    CamelContextNameStrategy strategy = context.getNameStrategy();
    OsgiCamelContextHelper.osgiUpdate(adapted, bundle);
    // FIXME: the above call should not override explicit strategies provided by the end user or should decorate them instead of overriding them completely
    if (!(strategy instanceof DefaultCamelContextNameStrategy)) {
        context.setNameStrategy(strategy);
    }

    return context;
}
项目:camel-cdi    文件:CamelContextOsgiProducer.java   
@Override
public T produce(CreationalContext<T> cc) {
    T context = super.produce(cc);

    // Register the context in the OSGi registry
    BundleContext bundle = BundleContextUtils.getBundleContext(getClass());
    context.getManagementStrategy().addEventNotifier(new OsgiCamelContextPublisher(bundle));

    if (!(context instanceof DefaultCamelContext))
        // Fail fast for the time being to avoid side effects by some methods get declared on the CamelContext interface
        throw new DeploymentException("Camel CDI requires Camel context [" + context.getName() + "] to be a subtype of DefaultCamelContext");

    DefaultCamelContext adapted = context.adapt(DefaultCamelContext.class);
    adapted.setRegistry(OsgiCamelContextHelper.wrapRegistry(context, context.getRegistry(), bundle));
    CamelContextNameStrategy strategy = context.getNameStrategy();
    OsgiCamelContextHelper.osgiUpdate(adapted, bundle);
    // FIXME: the above call should not override explicit strategies provided by the end user or should decorate them instead of overriding them completely
    if (!(strategy instanceof DefaultCamelContextNameStrategy))
        context.setNameStrategy(strategy);

    return context;
}
项目:Camel    文件:CamelContextProducer.java   
@Override
public T produce(CreationalContext<T> ctx) {
    T context = super.produce(ctx);

    // Do not override the name if it's been already set (in the bean constructor for example)
    if (context.getNameStrategy() instanceof DefaultCamelContextNameStrategy) {
        context.setNameStrategy(nameStrategy(annotated));
    }

    // Add bean registry and Camel injector
    if (context instanceof DefaultCamelContext) {
        DefaultCamelContext adapted = context.adapt(DefaultCamelContext.class);
        adapted.setRegistry(new CdiCamelRegistry(manager));
        adapted.setInjector(new CdiCamelInjector(context.getInjector(), manager));
    } else {
        // Fail fast for the time being to avoid side effects by the time these two methods get declared on the CamelContext interface
        throw new InjectionException("Camel CDI requires Camel context [" + context.getName() + "] to be a subtype of DefaultCamelContext");
    }

    // Add event notifier if at least one observer is present
    Set<Annotation> qualifiers = annotated.getAnnotations().stream()
        .filter(isAnnotationType(Named.class).negate()
            .and(q -> manager.isQualifier(q.annotationType())))
        .collect(toSet());
    qualifiers.add(ANY);
    if (qualifiers.size() == 1) {
        qualifiers.add(DEFAULT);
    }
    qualifiers.retainAll(extension.getObserverEvents());
    if (!qualifiers.isEmpty()) {
        context.getManagementStrategy().addEventNotifier(new CdiEventNotifier(manager, qualifiers));
    }

    return context;
}
项目:camel-cdi    文件:CamelContextProducer.java   
@Override
public T produce(CreationalContext<T> cc) {
    T context = super.produce(cc);

    // Do not override the name if it's been already set (in the bean constructor for example)
    if (context.getNameStrategy() instanceof DefaultCamelContextNameStrategy)
        context.setNameStrategy(nameStrategy(annotated));

    // Add bean registry and Camel injector
    if (context instanceof DefaultCamelContext) {
        DefaultCamelContext adapted = context.adapt(DefaultCamelContext.class);
        adapted.setRegistry(new CdiCamelRegistry(manager));
        adapted.setInjector(new CdiCamelInjector(context.getInjector(), manager));
    } else {
        // Fail fast for the time being to avoid side effects by the time these two methods get declared on the CamelContext interface
        throw new DeploymentException("Camel CDI requires Camel context [" + context.getName() + "] to be a subtype of DefaultCamelContext");
    }

    // Add event notifier if at least one observer is present
    Set<Annotation> qualifiers = annotated.getAnnotations().stream()
        .filter(isAnnotationType(Named.class).negate()
            .and(q -> manager.isQualifier(q.annotationType())))
        .collect(toSet());
    qualifiers.add(Any.Literal.INSTANCE);
    if (qualifiers.size() == 1)
        qualifiers.add(Default.Literal.INSTANCE);
    qualifiers.retainAll(manager.getExtension(CdiCamelExtension.class).getObserverEvents());
    if (!qualifiers.isEmpty())
        context.getManagementStrategy().addEventNotifier(new CdiEventNotifier(manager, qualifiers));

    return context;
}
项目:careconnect-reference-implementation    文件:CamelConfig.java   
@Override
protected void setupCamelContext(CamelContext camelContext) throws Exception {

    camelContext.setNameStrategy(new DefaultCamelContextNameStrategy("Gateway"));

}
项目:careconnect-reference-implementation    文件:CamelConfig.java   
@Override
protected void setupCamelContext(CamelContext camelContext) throws Exception {

    camelContext.setNameStrategy(new DefaultCamelContextNameStrategy("Gateway"));

}