Search in sources :

Example 1 with ProducerCache

use of org.apache.camel.impl.ProducerCache in project camel by apache.

the class Enricher method doStart.

protected void doStart() throws Exception {
    if (aggregationStrategy == null) {
        aggregationStrategy = defaultAggregationStrategy();
    }
    if (producerCache == null) {
        if (cacheSize < 0) {
            producerCache = new EmptyProducerCache(this, camelContext);
            LOG.debug("Enricher {} is not using ProducerCache", this);
        } else if (cacheSize == 0) {
            producerCache = new ProducerCache(this, camelContext);
            LOG.debug("Enricher {} using ProducerCache with default cache size", this);
        } else {
            producerCache = new ProducerCache(this, camelContext, cacheSize);
            LOG.debug("Enricher {} using ProducerCache with cacheSize={}", this, cacheSize);
        }
    }
    ServiceHelper.startServices(producerCache, aggregationStrategy);
}
Also used : EmptyProducerCache(org.apache.camel.impl.EmptyProducerCache) ProducerCache(org.apache.camel.impl.ProducerCache) EmptyProducerCache(org.apache.camel.impl.EmptyProducerCache)

Example 2 with ProducerCache

use of org.apache.camel.impl.ProducerCache in project camel by apache.

the class RecipientList method doStart.

protected void doStart() throws Exception {
    if (producerCache == null) {
        if (cacheSize < 0) {
            producerCache = new EmptyProducerCache(this, camelContext);
            LOG.debug("RecipientList {} is not using ProducerCache", this);
        } else if (cacheSize == 0) {
            producerCache = new ProducerCache(this, camelContext);
            LOG.debug("RecipientList {} using ProducerCache with default cache size", this);
        } else {
            producerCache = new ProducerCache(this, camelContext, cacheSize);
            LOG.debug("RecipientList {} using ProducerCache with cacheSize={}", this, cacheSize);
        }
    }
    ServiceHelper.startServices(aggregationStrategy, producerCache);
}
Also used : EmptyProducerCache(org.apache.camel.impl.EmptyProducerCache) ProducerCache(org.apache.camel.impl.ProducerCache) EmptyProducerCache(org.apache.camel.impl.EmptyProducerCache)

Example 3 with ProducerCache

use of org.apache.camel.impl.ProducerCache in project camel by apache.

the class SendProcessor method doStart.

protected void doStart() throws Exception {
    if (producerCache == null) {
        // use a single producer cache as we need to only hold reference for one destination
        // and use a regular HashMap as we do not want a soft reference store that may get re-claimed when low on memory
        // as we want to ensure the producer is kept around, to ensure its lifecycle is fully managed,
        // eg stopping the producer when we stop etc.
        producerCache = new ProducerCache(this, camelContext, new HashMap<String, Producer>(1));
    // do not add as service as we do not want to manage the producer cache
    }
    ServiceHelper.startService(producerCache);
    // the destination could since have been intercepted by a interceptSendToEndpoint so we got to
    // lookup this before we can use the destination
    Endpoint lookup = camelContext.hasEndpoint(destination.getEndpointKey());
    if (lookup instanceof InterceptSendToEndpoint) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Intercepted sending to {} -> {}", URISupport.sanitizeUri(destination.getEndpointUri()), URISupport.sanitizeUri(lookup.getEndpointUri()));
        }
        destination = lookup;
    }
    // warm up the producer by starting it so we can fail fast if there was a problem
    // however must start endpoint first
    ServiceHelper.startService(destination);
    // this SendProcessor is used a lot in Camel (eg every .to in the route DSL) and therefore we
    // want to optimize for regular producers, by using the producer directly instead of the ProducerCache
    // Only for pooled and non singleton producers we have to use the ProducerCache as it supports these
    // kind of producer better (though these kind of producer should be rare)
    Producer producer = producerCache.acquireProducer(destination);
    if (producer instanceof ServicePoolAware || !producer.isSingleton()) {
        // no we cannot optimize it - so release the producer back to the producer cache
        // and use the producer cache for sending
        producerCache.releaseProducer(destination, producer);
    } else {
        // yes we can optimize and use the producer directly for sending
        this.producer = AsyncProcessorConverterHelper.convert(producer);
    }
}
Also used : InterceptSendToEndpoint(org.apache.camel.impl.InterceptSendToEndpoint) Endpoint(org.apache.camel.Endpoint) InterceptSendToEndpoint(org.apache.camel.impl.InterceptSendToEndpoint) Producer(org.apache.camel.Producer) HashMap(java.util.HashMap) ServicePoolAware(org.apache.camel.ServicePoolAware) ProducerCache(org.apache.camel.impl.ProducerCache)

Example 4 with ProducerCache

use of org.apache.camel.impl.ProducerCache in project fabric8 by jboss-fuse.

the class FabricComponent method doStart.

// Implementation methods
// -------------------------------------------------------------------------
@Override
protected void doStart() throws Exception {
    super.doStart();
    if (producerCache == null) {
        producerCache = new ProducerCache(this, getCamelContext(), cacheSize);
    }
    ServiceHelper.startService(producerCache);
}
Also used : ProducerCache(org.apache.camel.impl.ProducerCache)

Example 5 with ProducerCache

use of org.apache.camel.impl.ProducerCache in project fabric8 by jboss-fuse.

the class FabricLocatorEndpoint method getProcessor.

public Processor getProcessor(String uri) throws URISyntaxException {
    uri = ZooKeeperUtils.getSubstitutedData(component.getCurator(), uri);
    LOG.info("Creating endpoint for " + uri);
    final Endpoint endpoint = getCamelContext().getEndpoint(uri);
    return new Processor() {

        public void process(Exchange exchange) throws Exception {
            ProducerCache producerCache = component.getProducerCache();
            Producer producer = producerCache.acquireProducer(endpoint);
            try {
                producer.process(exchange);
            } finally {
                producerCache.releaseProducer(endpoint, producer);
            }
        }

        @Override
        public String toString() {
            return "Producer for " + endpoint;
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) DefaultEndpoint(org.apache.camel.impl.DefaultEndpoint) Endpoint(org.apache.camel.Endpoint) DefaultProducer(org.apache.camel.impl.DefaultProducer) Producer(org.apache.camel.Producer) ProducerCache(org.apache.camel.impl.ProducerCache)

Aggregations

ProducerCache (org.apache.camel.impl.ProducerCache)10 EmptyProducerCache (org.apache.camel.impl.EmptyProducerCache)4 Processor (org.apache.camel.Processor)3 Producer (org.apache.camel.Producer)3 Endpoint (org.apache.camel.Endpoint)2 Exchange (org.apache.camel.Exchange)2 HashMap (java.util.HashMap)1 Channel (org.apache.camel.Channel)1 Consumer (org.apache.camel.Consumer)1 NonManagedService (org.apache.camel.NonManagedService)1 ServicePoolAware (org.apache.camel.ServicePoolAware)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 RuntimeCamelCatalog (org.apache.camel.catalog.RuntimeCamelCatalog)1 ConsumerCache (org.apache.camel.impl.ConsumerCache)1 DefaultEndpoint (org.apache.camel.impl.DefaultEndpoint)1 DefaultEndpointRegistry (org.apache.camel.impl.DefaultEndpointRegistry)1 DefaultProducer (org.apache.camel.impl.DefaultProducer)1 DefaultTransformerRegistry (org.apache.camel.impl.DefaultTransformerRegistry)1 DefaultValidatorRegistry (org.apache.camel.impl.DefaultValidatorRegistry)1 InterceptSendToEndpoint (org.apache.camel.impl.InterceptSendToEndpoint)1