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);
}
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();
}
}
}
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");
}
};
}
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());
}
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);
}
}
}
}
Aggregations