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();
}
use of org.apache.camel.PollingConsumer in project camel by apache.
the class EmptyConsumerCache method acquirePollingConsumer.
@Override
public PollingConsumer acquirePollingConsumer(Endpoint endpoint) {
// always create a new consumer
PollingConsumer answer;
try {
answer = endpoint.createPollingConsumer();
boolean singleton = true;
if (answer instanceof IsSingleton) {
singleton = ((IsSingleton) answer).isSingleton();
}
if (getCamelContext().isStartingRoutes() && singleton) {
// if we are currently starting a route, then add as service and enlist in JMX
// - but do not enlist non-singletons in JMX
// - note addService will also start the service
getCamelContext().addService(answer);
} else {
// must then start service so producer is ready to be used
ServiceHelper.startService(answer);
}
} catch (Exception e) {
throw new FailedToCreateConsumerException(endpoint, e);
}
return answer;
}
Aggregations