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