Search in sources :

Example 16 with PollingConsumer

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);
        }
    }
}
Also used : PollingConsumer(org.apache.camel.PollingConsumer)

Example 17 with PollingConsumer

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();
    }
}
Also used : PollingConsumer(org.apache.camel.PollingConsumer)

Example 18 with PollingConsumer

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);
        }
    }
}
Also used : PollingConsumer(org.apache.camel.PollingConsumer)

Example 19 with PollingConsumer

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();
}
Also used : PollingConsumer(org.apache.camel.PollingConsumer) Endpoint(org.apache.camel.Endpoint) Endpoint(org.apache.camel.Endpoint)

Example 20 with PollingConsumer

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;
}
Also used : PollingConsumer(org.apache.camel.PollingConsumer) FailedToCreateConsumerException(org.apache.camel.FailedToCreateConsumerException) IsSingleton(org.apache.camel.IsSingleton) FailedToCreateConsumerException(org.apache.camel.FailedToCreateConsumerException)

Aggregations

PollingConsumer (org.apache.camel.PollingConsumer)21 Endpoint (org.apache.camel.Endpoint)9 Exchange (org.apache.camel.Exchange)9 Test (org.junit.Test)5 File (java.io.File)2 FailedToCreateConsumerException (org.apache.camel.FailedToCreateConsumerException)2 IsSingleton (org.apache.camel.IsSingleton)2 ArrayList (java.util.ArrayList)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 CamelExchangeException (org.apache.camel.CamelExchangeException)1 CamelExecutionException (org.apache.camel.CamelExecutionException)1 Consumer (org.apache.camel.Consumer)1 NoSuchBeanException (org.apache.camel.NoSuchBeanException)1 Processor (org.apache.camel.Processor)1 ProxyInstantiationException (org.apache.camel.ProxyInstantiationException)1 RuntimeCamelException (org.apache.camel.RuntimeCamelException)1 ServicePoolAware (org.apache.camel.ServicePoolAware)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 GenericFileOperationFailedException (org.apache.camel.component.file.GenericFileOperationFailedException)1