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);
}
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);
}
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);
}
}
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);
}
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;
}
};
}
Aggregations