Search in sources :

Example 6 with Registry

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

the class MetricsMessageHistoryService method doStart.

@Override
protected void doStart() throws Exception {
    if (metricsRegistry == null) {
        Registry camelRegistry = getCamelContext().getRegistry();
        metricsRegistry = camelRegistry.lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
        // create a new metricsRegistry by default
        if (metricsRegistry == null) {
            metricsRegistry = new MetricRegistry();
        }
    }
    if (useJmx) {
        ManagementAgent agent = getCamelContext().getManagementStrategy().getManagementAgent();
        if (agent != null) {
            MBeanServer server = agent.getMBeanServer();
            if (server != null) {
                reporter = JmxReporter.forRegistry(metricsRegistry).registerWith(server).inDomain(jmxDomain).build();
                reporter.start();
            }
        } else {
            throw new IllegalStateException("CamelContext has not enabled JMX");
        }
    }
    // json mapper
    this.mapper = new ObjectMapper().registerModule(new MetricsModule(getRateUnit(), getDurationUnit(), false));
    if (getRateUnit() == TimeUnit.SECONDS && getDurationUnit() == TimeUnit.SECONDS) {
        // they both use same units so reuse
        this.secondsMapper = this.mapper;
    } else {
        this.secondsMapper = new ObjectMapper().registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false));
    }
}
Also used : ManagementAgent(org.apache.camel.spi.ManagementAgent) MetricRegistry(com.codahale.metrics.MetricRegistry) MetricsModule(com.codahale.metrics.json.MetricsModule) MetricRegistry(com.codahale.metrics.MetricRegistry) Registry(org.apache.camel.spi.Registry) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MBeanServer(javax.management.MBeanServer)

Example 7 with Registry

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

the class SpringLdapComponent method createEndpoint.

/**
     * creates a Spring LDAP endpoint
     * @param remaining name of the Spring LDAP template bean to be used for the LDAP operation
     * @param parameters key-value pairs to be set on @see org.apache.camel.component.springldap.SpringLdapEndpoint.
     * Currently supported keys are operation and scope.
     * 'operation' is defined in org.apache.camel.component.springldap.LdapOperation.
     * 'scope' must be one of "object", "onelevel", or "subtree".
     */
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    CamelContext camelContext = getCamelContext();
    Registry registry = camelContext.getRegistry();
    LdapTemplate ldapTemplate = registry.lookupByNameAndType(remaining, LdapTemplate.class);
    Endpoint endpoint = new SpringLdapEndpoint(remaining, ldapTemplate);
    setProperties(endpoint, parameters);
    return endpoint;
}
Also used : CamelContext(org.apache.camel.CamelContext) Endpoint(org.apache.camel.Endpoint) Registry(org.apache.camel.spi.Registry) LdapTemplate(org.springframework.ldap.core.LdapTemplate)

Example 8 with Registry

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

the class CamelContextFactoryBean method initCustomRegistry.

protected void initCustomRegistry(SpringCamelContext 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 9 with Registry

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

the class MetricsComponent method createEndpoint.

@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    if (metricRegistry == null) {
        Registry camelRegistry = getCamelContext().getRegistry();
        metricRegistry = getOrCreateMetricRegistry(camelRegistry, METRIC_REGISTRY_NAME);
    }
    String metricsName = getMetricsName(remaining);
    MetricsType metricsType = getMetricsType(remaining);
    LOG.debug("Metrics type: {}; name: {}", metricsType, metricsName);
    Endpoint endpoint = new MetricsEndpoint(uri, this, metricRegistry, metricsType, metricsName);
    setProperties(endpoint, parameters);
    return endpoint;
}
Also used : Endpoint(org.apache.camel.Endpoint) MetricRegistry(com.codahale.metrics.MetricRegistry) Registry(org.apache.camel.spi.Registry)

Example 10 with Registry

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

the class MetricsRegistryService method doStart.

@Override
protected void doStart() throws Exception {
    if (metricsRegistry == null) {
        Registry camelRegistry = getCamelContext().getRegistry();
        metricsRegistry = camelRegistry.lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
        // create a new metricsRegistry by default
        if (metricsRegistry == null) {
            metricsRegistry = new MetricRegistry();
        }
    }
    if (useJmx) {
        ManagementAgent agent = getCamelContext().getManagementStrategy().getManagementAgent();
        if (agent != null) {
            MBeanServer server = agent.getMBeanServer();
            if (server != null) {
                reporter = JmxReporter.forRegistry(metricsRegistry).registerWith(server).inDomain(jmxDomain).build();
                reporter.start();
            }
        } else {
            throw new IllegalStateException("CamelContext has not enabled JMX");
        }
    }
    // json mapper
    this.mapper = new ObjectMapper().registerModule(new MetricsModule(getRateUnit(), getDurationUnit(), false));
    if (getRateUnit() == TimeUnit.SECONDS && getDurationUnit() == TimeUnit.SECONDS) {
        // they both use same units so reuse
        this.secondsMapper = this.mapper;
    } else {
        this.secondsMapper = new ObjectMapper().registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false));
    }
}
Also used : ManagementAgent(org.apache.camel.spi.ManagementAgent) MetricRegistry(com.codahale.metrics.MetricRegistry) MetricsModule(com.codahale.metrics.json.MetricsModule) MetricRegistry(com.codahale.metrics.MetricRegistry) Registry(org.apache.camel.spi.Registry) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MBeanServer(javax.management.MBeanServer)

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