Search in sources :

Example 6 with RejectedExecutionException

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

the class CircuitBreakerLoadBalancerTest method halfOpenAfterTimeout.

private void halfOpenAfterTimeout(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");
    Exchange exchangeFour = sendMessage(endpoint, "message four");
    assertMockEndpointsSatisfied();
    Thread.sleep(1000);
    result.reset();
    result.whenAnyExchangeReceived(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.setException(new MyCustomException());
        }
    });
    expectsMessageCount(1, result);
    Exchange exchangeFive = sendMessage(endpoint, "message five");
    Exchange exchangeSix = sendMessage(endpoint, "message six");
    assertMockEndpointsSatisfied();
    assertTrue(exchangeOne.getException() instanceof MyCustomException);
    assertTrue(exchangeTwo.getException() instanceof MyCustomException);
    assertTrue(exchangeThree.getException() instanceof RejectedExecutionException);
    assertTrue(exchangeFour.getException() instanceof RejectedExecutionException);
    assertTrue(exchangeFive.getException() instanceof MyCustomException);
    assertTrue(exchangeSix.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)

Example 7 with RejectedExecutionException

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

the class DefaultAsyncProcessorAwaitManager method interrupt.

@Override
public void interrupt(Exchange exchange) {
    AwaitThreadEntry entry = (AwaitThreadEntry) inflight.get(exchange);
    if (entry != null) {
        try {
            StringBuilder sb = new StringBuilder();
            sb.append("Interrupted while waiting for asynchronous callback, will release the following blocked thread which was waiting for exchange to finish processing with exchangeId: ");
            sb.append(exchange.getExchangeId());
            sb.append("\n");
            sb.append(dumpBlockedThread(entry));
            // dump a route stack trace of the exchange
            String routeStackTrace = MessageHelper.dumpMessageHistoryStacktrace(exchange, exchangeFormatter, false);
            if (routeStackTrace != null) {
                sb.append(routeStackTrace);
            }
            LOG.warn(sb.toString());
        } catch (Exception e) {
            throw ObjectHelper.wrapRuntimeCamelException(e);
        } finally {
            if (statistics.isStatisticsEnabled()) {
                interruptedCounter.incrementAndGet();
            }
            exchange.setException(new RejectedExecutionException("Interrupted while waiting for asynchronous callback for exchangeId: " + exchange.getExchangeId()));
            entry.getLatch().countDown();
        }
    }
}
Also used : RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 8 with RejectedExecutionException

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

the class ManagedThrottlerTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    final ScheduledExecutorService badService = new ScheduledThreadPoolExecutor(1) {

        @Override
        public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
            throw new RejectedExecutionException();
        }
    };
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").to("log:foo").throttle(10).id("mythrottler").to("mock:result");
            from("seda:throttleCount").throttle(1).timePeriodMillis(250).id("mythrottler2").to("mock:end");
            from("seda:throttleCountAsync").throttle(1).asyncDelayed().timePeriodMillis(250).id("mythrottler3").to("mock:endAsync");
            from("seda:throttleCountAsyncException").throttle(1).asyncDelayed().timePeriodMillis(250).id("mythrottler4").to("mock:endAsyncException").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    throw new RuntimeException("Fail me");
                }
            });
            from("seda:throttleCountRejectExecutionCallerRuns").onException(RejectedExecutionException.class).to("mock:rejectedExceptionEndpoint1").end().throttle(1).timePeriodMillis(250).asyncDelayed().executorService(badService).callerRunsWhenRejected(true).id("mythrottler5").to("mock:endAsyncRejectCallerRuns");
            from("seda:throttleCountRejectExecution").onException(RejectedExecutionException.class).to("mock:rejectedExceptionEndpoint1").end().throttle(1).timePeriodMillis(250).asyncDelayed().executorService(badService).callerRunsWhenRejected(false).id("mythrottler6").to("mock:endAsyncReject");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) TimeUnit(java.util.concurrent.TimeUnit) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 9 with RejectedExecutionException

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

the class SizedScheduledExecutorServiceTest method testSizedScheduledExecutorService.

public void testSizedScheduledExecutorService() throws Exception {
    ScheduledThreadPoolExecutor delegate = new ScheduledThreadPoolExecutor(5);
    SizedScheduledExecutorService sized = new SizedScheduledExecutorService(delegate, 2);
    Runnable task = new Runnable() {

        @Override
        public void run() {
        // noop
        }
    };
    sized.schedule(task, 2, TimeUnit.SECONDS);
    sized.schedule(task, 3, TimeUnit.SECONDS);
    try {
        sized.schedule(task, 4, TimeUnit.SECONDS);
        fail("Should have thrown exception");
    } catch (RejectedExecutionException e) {
        assertEquals("Task rejected due queue size limit reached", e.getMessage());
    }
    sized.shutdownNow();
    assertTrue("Should be shutdown", sized.isShutdown() || sized.isTerminating());
    assertTrue("Should be shutdown", delegate.isShutdown() || sized.isTerminating());
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 10 with RejectedExecutionException

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

the class Task method executeAsyncCallRunnable.

/**
	 * Utility method to dispatch an asynchronous call on the invokable.
	 * 
	 * @param runnable The async call runnable.
	 * @param callName The name of the call, for logging purposes.
	 */
private void executeAsyncCallRunnable(Runnable runnable, String callName) {
    // make sure the executor is initialized. lock against concurrent calls to this function
    synchronized (this) {
        if (executionState != ExecutionState.RUNNING) {
            return;
        }
        // get ourselves a reference on the stack that cannot be concurrently modified
        ExecutorService executor = this.asyncCallDispatcher;
        if (executor == null) {
            // first time use, initialize
            executor = Executors.newSingleThreadExecutor(new DispatcherThreadFactory(TASK_THREADS_GROUP, "Async calls on " + taskNameWithSubtask));
            this.asyncCallDispatcher = executor;
            // if we created the dispatcher while the task was concurrently canceled
            if (executionState != ExecutionState.RUNNING) {
                executor.shutdown();
                asyncCallDispatcher = null;
                return;
            }
        }
        LOG.debug("Invoking async call {} on task {}", callName, taskNameWithSubtask);
        try {
            executor.submit(runnable);
        } catch (RejectedExecutionException e) {
            // if not, report that something is fishy
            if (executionState == ExecutionState.RUNNING) {
                throw new RuntimeException("Async call was rejected, even though the task is running.", e);
            }
        }
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) 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