Search in sources :

Example 1 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project camel by apache.

the class CamelOutputStream method asyncInvokeFromWorkQueue.

protected void asyncInvokeFromWorkQueue(final org.apache.camel.Exchange exchange) throws IOException {
    Runnable runnable = new Runnable() {

        public void run() {
            try {
                syncInvoke(exchange);
            } catch (Throwable e) {
                ((PhaseInterceptorChain) outMessage.getInterceptorChain()).abort();
                outMessage.setContent(Exception.class, e);
                ((PhaseInterceptorChain) outMessage.getInterceptorChain()).unwind(outMessage);
                MessageObserver mo = outMessage.getInterceptorChain().getFaultObserver();
                if (mo == null) {
                    mo = outMessage.getExchange().get(MessageObserver.class);
                }
                mo.onMessage(outMessage);
            }
        }
    };
    try {
        Executor ex = outMessage.getExchange().get(Executor.class);
        if (ex != null) {
            outMessage.getExchange().put(Executor.class.getName() + ".USING_SPECIFIED", Boolean.TRUE);
            ex.execute(runnable);
        } else {
            WorkQueueManager mgr = outMessage.getExchange().get(Bus.class).getExtension(WorkQueueManager.class);
            AutomaticWorkQueue qu = mgr.getNamedWorkQueue("camel-cxf-conduit");
            if (qu == null) {
                qu = mgr.getAutomaticWorkQueue();
            }
            // need to set the time out somewhere
            qu.execute(runnable);
        }
    } catch (RejectedExecutionException rex) {
        if (!hasLoggedAsyncWarning) {
            LOG.warn("Executor rejected background task to retrieve the response.  Suggest increasing the workqueue settings.");
            hasLoggedAsyncWarning = true;
        }
        LOG.info("Executor rejected background task to retrieve the response, running on current thread.");
        syncInvoke(exchange);
    }
}
Also used : Bus(org.apache.cxf.Bus) MessageObserver(org.apache.cxf.transport.MessageObserver) Executor(java.util.concurrent.Executor) AutomaticWorkQueue(org.apache.cxf.workqueue.AutomaticWorkQueue) WorkQueueManager(org.apache.cxf.workqueue.WorkQueueManager) IOException(java.io.IOException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 2 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project camel by apache.

the class DefaultLoadBalancer method process.

// *************************************
// Load Balancer
// *************************************
@Override
public <T> T process(String serviceName, LoadBalancerFunction<T> function) throws Exception {
    ServiceDefinition service;
    List<ServiceDefinition> services = serviceDiscovery.getServices(serviceName);
    if (services == null || services.isEmpty()) {
        throw new RejectedExecutionException("No active services with name " + serviceName);
    } else {
        // filter services
        services = serviceFilter.apply(services);
        // let the client service chooser find which server to use
        service = services.size() > 1 ? serviceChooser.choose(services) : services.get(0);
        if (service == null) {
            throw new RejectedExecutionException("No active services with name " + serviceName);
        }
    }
    return function.apply(service);
}
Also used : ServiceDefinition(org.apache.camel.cloud.ServiceDefinition) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 3 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project camel by apache.

the class CircuitBreakerLoadBalancer method process.

public boolean process(final Exchange exchange, final AsyncCallback callback) {
    // can we still run
    if (!isRunAllowed()) {
        log.trace("Run not allowed, will reject executing exchange: {}", exchange);
        if (exchange.getException() == null) {
            exchange.setException(new RejectedExecutionException("Run is not allowed"));
        }
        callback.done(true);
        return true;
    }
    return calculateState(exchange, callback);
}
Also used : RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 4 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project camel by apache.

the class CircuitBreakerLoadBalancerTest method halfOpenToCloseTransition.

private void halfOpenToCloseTransition(String endpoint) throws Exception {
    expectsMessageCount(2, result);
    result.whenAnyExchangeReceived(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.setException(new MyCustomException());
        }
    });
    Exchange exchangeOne = sendMessage(endpoint, "message one");
    Exchange exchangeTwo = sendMessage(endpoint, "message two");
    Exchange exchangeThree = sendMessage(endpoint, "message three");
    assertMockEndpointsSatisfied();
    Thread.sleep(1000);
    result.reset();
    expectsMessageCount(2, result);
    Exchange exchangeFour = sendMessage(endpoint, "message four");
    Exchange exchangeFive = sendMessage(endpoint, "message five");
    assertMockEndpointsSatisfied();
    assertTrue(exchangeOne.getException() instanceof MyCustomException);
    assertTrue(exchangeTwo.getException() instanceof MyCustomException);
    assertTrue(exchangeThree.getException() instanceof RejectedExecutionException);
    assertTrue(exchangeFour.getException() == null);
    assertTrue(exchangeFive.getException() == null);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 5 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project camel by apache.

the class CircuitBreakerLoadBalancerTest method failedMessagesOpenCircuitToPreventMessageThree.

private void failedMessagesOpenCircuitToPreventMessageThree(String endpoint) throws InterruptedException, Exception {
    expectsMessageCount(2, result);
    result.whenAnyExchangeReceived(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.setException(new MyCustomException());
        }
    });
    Exchange exchangeOne = sendMessage(endpoint, "message one");
    Exchange exchangeTwo = sendMessage(endpoint, "message two");
    Exchange exchangeThree = sendMessage(endpoint, "message three");
    assertMockEndpointsSatisfied();
    assertTrue(exchangeOne.getException() instanceof MyCustomException);
    assertTrue(exchangeTwo.getException() instanceof MyCustomException);
    assertTrue(exchangeThree.getException() instanceof RejectedExecutionException);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

RejectedExecutionException (java.util.concurrent.RejectedExecutionException)231 ExecutorService (java.util.concurrent.ExecutorService)42 IOException (java.io.IOException)31 Test (org.junit.Test)29 Future (java.util.concurrent.Future)19 ArrayList (java.util.ArrayList)18 ExecutionException (java.util.concurrent.ExecutionException)15 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)14 Executor (java.util.concurrent.Executor)13 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)12 List (java.util.List)11 TaskRejectedException (org.springframework.core.task.TaskRejectedException)11 BitmapDrawable (android.graphics.drawable.BitmapDrawable)10 Animation (android.view.animation.Animation)10 Map (java.util.Map)10 CancellationException (java.util.concurrent.CancellationException)10 CacheableBitmapDrawable (uk.co.senab.bitmapcache.CacheableBitmapDrawable)10 ParallelTest (com.hazelcast.test.annotation.ParallelTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9