Search in sources :

Example 1 with Registry

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

the class EjbComponent method createEndpoint.

@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    EjbEndpoint answer = new EjbEndpoint(uri, this);
    answer.setBeanName(remaining);
    // plugin registry to lookup in jndi for the EJBs
    Registry registry = new JndiRegistry(getContext());
    // and register the bean as a holder on the endpoint
    BeanHolder holder = new EjbRegistryBean(registry, getCamelContext(), answer.getBeanName());
    answer.setBeanHolder(holder);
    return answer;
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) BeanHolder(org.apache.camel.component.bean.BeanHolder) Registry(org.apache.camel.spi.Registry) JndiRegistry(org.apache.camel.impl.JndiRegistry)

Example 2 with Registry

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

the class CamelContextFactoryBean method initCustomRegistry.

@Override
protected void initCustomRegistry(BlueprintCamelContext context) {
    Registry registry = getBeanForType(Registry.class);
    if (registry != null) {
        LOG.info("Using custom Registry: " + registry);
        context.setRegistry(registry);
    }
}
Also used : Registry(org.apache.camel.spi.Registry)

Example 3 with Registry

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

the class BeanInfo method createParameterMappingStrategy.

public static ParameterMappingStrategy createParameterMappingStrategy(CamelContext camelContext) {
    // lookup in registry first if there is a user define strategy
    Registry registry = camelContext.getRegistry();
    ParameterMappingStrategy answer = registry.lookupByNameAndType(BeanConstants.BEAN_PARAMETER_MAPPING_STRATEGY, ParameterMappingStrategy.class);
    if (answer == null) {
        // no then use the default one
        answer = new DefaultParameterMappingStrategy();
    }
    return answer;
}
Also used : Registry(org.apache.camel.spi.Registry)

Example 4 with Registry

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

the class BindyAbstractDataFormat method tryToGetFactoryRegistry.

private FactoryRegistry tryToGetFactoryRegistry() {
    Function<CamelContext, Registry> f = CamelContext::getRegistry;
    Function<Registry, Set<FactoryRegistry>> g = r -> r.findByType(FactoryRegistry.class);
    Function<Set<FactoryRegistry>, FactoryRegistry> h = factoryRegistries -> {
        if (factoryRegistries.size() > 1) {
            LOGGER.warn("Number of registered {}: {}", FactoryRegistry.class.getCanonicalName(), factoryRegistries.size());
        }
        if (factoryRegistries.iterator().hasNext()) {
            return factoryRegistries.iterator().next();
        } else {
            return new DefaultFactoryRegistry();
        }
    };
    return Optional.ofNullable(camelContext).map(f).map(g).map(h).orElse(new DefaultFactoryRegistry());
}
Also used : CamelContext(org.apache.camel.CamelContext) CamelContext(org.apache.camel.CamelContext) CamelContextAware(org.apache.camel.CamelContextAware) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Registry(org.apache.camel.spi.Registry) DefaultFactoryRegistry(org.apache.camel.dataformat.bindy.format.factories.DefaultFactoryRegistry) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) HashMap(java.util.HashMap) Field(java.lang.reflect.Field) Function(java.util.function.Function) ArrayList(java.util.ArrayList) FactoryRegistry(org.apache.camel.dataformat.bindy.format.factories.FactoryRegistry) DataFormatName(org.apache.camel.spi.DataFormatName) Link(org.apache.camel.dataformat.bindy.annotation.Link) DataFormat(org.apache.camel.spi.DataFormat) List(java.util.List) Map(java.util.Map) Optional(java.util.Optional) ServiceSupport(org.apache.camel.support.ServiceSupport) FormatFactoryInterface(org.apache.camel.dataformat.bindy.format.factories.FormatFactoryInterface) FormatFactories(org.apache.camel.dataformat.bindy.annotation.FormatFactories) Collections(java.util.Collections) DefaultFactoryRegistry(org.apache.camel.dataformat.bindy.format.factories.DefaultFactoryRegistry) Set(java.util.Set) DefaultFactoryRegistry(org.apache.camel.dataformat.bindy.format.factories.DefaultFactoryRegistry) FactoryRegistry(org.apache.camel.dataformat.bindy.format.factories.FactoryRegistry) Registry(org.apache.camel.spi.Registry) DefaultFactoryRegistry(org.apache.camel.dataformat.bindy.format.factories.DefaultFactoryRegistry) FactoryRegistry(org.apache.camel.dataformat.bindy.format.factories.FactoryRegistry)

Example 5 with Registry

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

the class CompositeRegistry method lookupByNameAndType.

public <T> T lookupByNameAndType(String name, Class<T> type) {
    T answer = null;
    RuntimeCamelException ex = null;
    for (Registry registry : registryList) {
        try {
            answer = registry.lookupByNameAndType(name, type);
        } catch (Throwable e) {
            // do not double wrap the exception
            if (e instanceof NoSuchBeanException) {
                ex = (NoSuchBeanException) e;
            } else {
                ex = new NoSuchBeanException(name, "Cannot lookup: " + name + " from registry: " + registry + " with expected type: " + type + " due: " + e.getMessage(), e);
            }
        }
        if (answer != null) {
            return answer;
        }
    }
    if (ex != null) {
        throw ex;
    } else {
        return answer;
    }
}
Also used : NoSuchBeanException(org.apache.camel.NoSuchBeanException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) Registry(org.apache.camel.spi.Registry)

Aggregations

Registry (org.apache.camel.spi.Registry)10 MetricRegistry (com.codahale.metrics.MetricRegistry)3 MetricsModule (com.codahale.metrics.json.MetricsModule)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 MBeanServer (javax.management.MBeanServer)2 CamelContext (org.apache.camel.CamelContext)2 Endpoint (org.apache.camel.Endpoint)2 ManagementAgent (org.apache.camel.spi.ManagementAgent)2 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Function (java.util.function.Function)1 CamelContextAware (org.apache.camel.CamelContextAware)1 NoSuchBeanException (org.apache.camel.NoSuchBeanException)1