use of org.apache.camel.PollingConsumer in project camel by apache.
the class CamelPostProcessorHelper method createInjectionPollingConsumer.
/**
* Factory method to create a started
* {@link org.apache.camel.PollingConsumer} to be injected into a POJO
*/
protected PollingConsumer createInjectionPollingConsumer(Endpoint endpoint, Object bean, String beanName) {
try {
PollingConsumer consumer = endpoint.createPollingConsumer();
startService(consumer, endpoint.getCamelContext(), bean, beanName);
return consumer;
} catch (Exception e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
}
use of org.apache.camel.PollingConsumer in project camel by apache.
the class ConsumerCache method receiveNoWait.
public Exchange receiveNoWait(Endpoint endpoint) {
LOG.debug("<<<< {}", endpoint);
PollingConsumer consumer = null;
try {
consumer = doGetPollingConsumer(endpoint, true);
return consumer.receiveNoWait();
} finally {
if (consumer != null) {
releasePollingConsumer(endpoint, consumer);
}
}
}
use of org.apache.camel.PollingConsumer in project camel by apache.
the class ConsumerCache method doStop.
protected void doStop() throws Exception {
// when stopping we intend to shutdown
ServiceHelper.stopAndShutdownServices(statistics, pool);
try {
ServiceHelper.stopAndShutdownServices(consumers.values());
} finally {
// ensure consumers are removed, and also from JMX
for (PollingConsumer consumer : consumers.values()) {
getCamelContext().removeService(consumer);
}
}
consumers.clear();
if (statistics != null) {
statistics.clear();
}
}
use of org.apache.camel.PollingConsumer in project camel by apache.
the class ConsumerCache method receive.
public Exchange receive(Endpoint endpoint, long timeout) {
LOG.debug("<<<< {}", endpoint);
PollingConsumer consumer = null;
try {
consumer = acquirePollingConsumer(endpoint);
return consumer.receive(timeout);
} finally {
if (consumer != null) {
releasePollingConsumer(endpoint, consumer);
}
}
}
use of org.apache.camel.PollingConsumer in project camel by apache.
the class DefaultConsumerCacheTest method testCacheConsumers.
public void testCacheConsumers() throws Exception {
ConsumerCache cache = new ConsumerCache(this, context);
cache.start();
assertEquals("Size should be 0", 0, cache.size());
// test that we cache at most 1000 consumers to avoid it eating to much memory
for (int i = 0; i < 1003; i++) {
Endpoint e = context.getEndpoint("direct:queue:" + i);
PollingConsumer p = cache.getConsumer(e);
assertNotNull("the polling consumer should not be null", p);
}
// the eviction is async so force cleanup
cache.cleanUp();
assertEquals("Size should be 1000", 1000, cache.size());
cache.stop();
}
Aggregations