use of java.util.concurrent.CountDownLatch in project camel by apache.
the class SedaConsumer method doStart.
protected void doStart() throws Exception {
latch = new CountDownLatch(endpoint.getConcurrentConsumers());
shutdownPending = false;
forceShutdown = false;
setupTasks();
endpoint.onStarted(this);
}
use of java.util.concurrent.CountDownLatch in project camel by apache.
the class DefaultProducerTemplateAsyncTest method testAsyncCallbackInOnlyProcessor.
public void testAsyncCallbackInOnlyProcessor() throws Exception {
ORDER.set(0);
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
final CountDownLatch latch = new CountDownLatch(1);
template.asyncCallback("direct:start", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("Hello");
}
}, new SynchronizationAdapter() {
@Override
public void onDone(Exchange exchange) {
assertEquals("Hello World", exchange.getIn().getBody());
ORDER.addAndGet(2);
latch.countDown();
}
});
ORDER.addAndGet(1);
assertTrue(latch.await(10, TimeUnit.SECONDS));
ORDER.addAndGet(4);
assertMockEndpointsSatisfied();
assertEquals(7, ORDER.get());
}
use of java.util.concurrent.CountDownLatch in project camel by apache.
the class DefaultProducerTemplateAsyncTest method testAsyncCallbackBodyInOnly.
public void testAsyncCallbackBodyInOnly() throws Exception {
ORDER.set(0);
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
final CountDownLatch latch = new CountDownLatch(1);
template.asyncCallbackSendBody("direct:start", "Hello", new SynchronizationAdapter() {
@Override
public void onDone(Exchange exchange) {
assertEquals("Hello World", exchange.getIn().getBody());
ORDER.addAndGet(2);
latch.countDown();
}
});
ORDER.addAndGet(1);
assertTrue(latch.await(10, TimeUnit.SECONDS));
ORDER.addAndGet(4);
assertMockEndpointsSatisfied();
assertEquals(7, ORDER.get());
}
use of java.util.concurrent.CountDownLatch in project camel by apache.
the class DefaultProducerTemplateAsyncTest method testAsyncCallbackExchangeInOut.
public void testAsyncCallbackExchangeInOut() throws Exception {
ORDER.set(0);
final CountDownLatch latch = new CountDownLatch(1);
Exchange exchange = context.getEndpoint("direct:start").createExchange();
exchange.getIn().setBody("Hello");
exchange.setPattern(ExchangePattern.InOut);
template.asyncCallback("direct:echo", exchange, new SynchronizationAdapter() {
@Override
public void onDone(Exchange exchange) {
assertEquals("HelloHello", exchange.getOut().getBody());
ORDER.addAndGet(2);
latch.countDown();
}
});
ORDER.addAndGet(1);
assertTrue(latch.await(10, TimeUnit.SECONDS));
ORDER.addAndGet(4);
assertEquals(7, ORDER.get());
}
use of java.util.concurrent.CountDownLatch in project camel by apache.
the class DefaultProducerTemplateAsyncTest method testAsyncCallbackExchangeInOnly.
public void testAsyncCallbackExchangeInOnly() throws Exception {
ORDER.set(0);
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
final CountDownLatch latch = new CountDownLatch(1);
Exchange exchange = context.getEndpoint("direct:start").createExchange();
exchange.getIn().setBody("Hello");
template.asyncCallback("direct:start", exchange, new SynchronizationAdapter() {
@Override
public void onDone(Exchange exchange) {
assertEquals("Hello World", exchange.getIn().getBody());
ORDER.addAndGet(2);
latch.countDown();
}
});
ORDER.addAndGet(1);
assertTrue(latch.await(10, TimeUnit.SECONDS));
ORDER.addAndGet(4);
assertMockEndpointsSatisfied();
assertEquals(7, ORDER.get());
}
Aggregations