use of org.apache.camel.util.StopWatch in project camel by apache.
the class AggregateProcessor method doForceCompletionOnStop.
private void doForceCompletionOnStop() {
int expected = forceCompletionOfAllGroups();
StopWatch watch = new StopWatch();
while (inProgressCompleteExchanges.size() > 0) {
LOG.trace("Waiting for {} inflight exchanges to complete", getInProgressCompleteExchanges());
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// break out as we got interrupted such as the JVM terminating
LOG.warn("Interrupted while waiting for {} inflight exchanges to complete.", getInProgressCompleteExchanges());
break;
}
}
if (expected > 0) {
LOG.info("Forcing completion of all groups with {} exchanges completed in {}", expected, TimeUtils.printDuration(watch.stop()));
}
}
use of org.apache.camel.util.StopWatch in project camel by apache.
the class SendProcessor method process.
public boolean process(Exchange exchange, final AsyncCallback callback) {
if (!isStarted()) {
exchange.setException(new IllegalStateException("SendProcessor has not been started: " + this));
callback.done(true);
return true;
}
// we should preserve existing MEP so remember old MEP
// if you want to permanently to change the MEP then use .setExchangePattern in the DSL
final ExchangePattern existingPattern = exchange.getPattern();
counter++;
// if we have a producer then use that as its optimized
if (producer != null) {
// record timing for sending the exchange using the producer
final StopWatch watch = new StopWatch();
final Exchange target = configureExchange(exchange, pattern);
EventHelper.notifyExchangeSending(exchange.getContext(), target, destination);
LOG.debug(">>>> {} {}", destination, exchange);
boolean sync = true;
try {
sync = producer.process(exchange, new AsyncCallback() {
@Override
public void done(boolean doneSync) {
try {
// restore previous MEP
target.setPattern(existingPattern);
// emit event that the exchange was sent to the endpoint
long timeTaken = watch.stop();
EventHelper.notifyExchangeSent(target.getContext(), target, destination, timeTaken);
} finally {
callback.done(doneSync);
}
}
});
} catch (Throwable throwable) {
exchange.setException(throwable);
callback.done(sync);
}
return sync;
}
// send the exchange to the destination using the producer cache for the non optimized producers
return producerCache.doInAsyncProducer(destination, exchange, pattern, callback, new AsyncProducerCallback() {
public boolean doInAsyncProducer(Producer producer, AsyncProcessor asyncProducer, final Exchange exchange, ExchangePattern pattern, final AsyncCallback callback) {
final Exchange target = configureExchange(exchange, pattern);
LOG.debug(">>>> {} {}", destination, exchange);
return asyncProducer.process(target, new AsyncCallback() {
public void done(boolean doneSync) {
// restore previous MEP
target.setPattern(existingPattern);
// signal we are done
callback.done(doneSync);
}
});
}
});
}
use of org.apache.camel.util.StopWatch in project camel by apache.
the class Debug method wrapProcessorInInterceptors.
public Processor wrapProcessorInInterceptors(final CamelContext context, final ProcessorDefinition<?> definition, final Processor target, final Processor nextTarget) throws Exception {
return new DelegateAsyncProcessor(target) {
@Override
public boolean process(final Exchange exchange, final AsyncCallback callback) {
debugger.beforeProcess(exchange, target, definition);
final StopWatch watch = new StopWatch();
return processor.process(exchange, new AsyncCallback() {
public void done(boolean doneSync) {
long diff = watch.stop();
debugger.afterProcess(exchange, processor, definition, diff);
// must notify original callback
callback.done(doneSync);
}
});
}
@Override
public String toString() {
return "Debug[" + target + "]";
}
};
}
use of org.apache.camel.util.StopWatch in project camel by apache.
the class BeanOgnlPerformanceTest method testBeanOgnlPerformance.
public void testBeanOgnlPerformance() throws Exception {
StopWatch watch = new StopWatch();
getMockEndpoint("mock:result").expectedMessageCount(size);
for (int i = 0; i < size; i++) {
template.sendBody("direct:start", "Hello World");
}
assertMockEndpointsSatisfied();
log.info("Took {} millis", watch.stop());
}
use of org.apache.camel.util.StopWatch in project camel by apache.
the class SedaInOutChainedTimeoutTest method testSedaInOutChainedTimeout.
public void testSedaInOutChainedTimeout() throws Exception {
// time timeout after 2 sec should trigger a immediately reply
StopWatch watch = new StopWatch();
try {
template.requestBody("seda:a?timeout=5000", "Hello World");
fail("Should have thrown an exception");
} catch (CamelExecutionException e) {
ExchangeTimedOutException cause = assertIsInstanceOf(ExchangeTimedOutException.class, e.getCause());
assertEquals(2000, cause.getTimeout());
}
long delta = watch.stop();
assertTrue("Should be faster than 4000 millis, was: " + delta, delta < 4000);
}
Aggregations