use of org.apache.camel.support.EventNotifierSupport in project camel by apache.
the class EventNotifierExchangeCompletedTest method createCamelContext.
@Override
protected CamelContext createCamelContext() throws Exception {
DefaultCamelContext context = new DefaultCamelContext(createRegistry());
context.getManagementStrategy().addEventNotifier(new EventNotifierSupport() {
public void notify(EventObject event) throws Exception {
events.add(event);
}
public boolean isEnabled(EventObject event) {
// we only want the completed event
return event instanceof ExchangeCompletedEvent;
// you can add additional filtering such as the exchange
// should be from a specific endpoint or route
// just return true for the events you like
}
protected void doStart() throws Exception {
// noop
}
protected void doStop() throws Exception {
// noop
}
});
return context;
}
use of org.apache.camel.support.EventNotifierSupport in project camel by apache.
the class FileWatcherReloadStrategyTest method testUpdateXmlRoute.
public void testUpdateXmlRoute() throws Exception {
deleteDirectory("target/dummy");
createDirectory("target/dummy");
// the bar route is added two times, at first, and then when updated
final CountDownLatch latch = new CountDownLatch(2);
context.getManagementStrategy().addEventNotifier(new EventNotifierSupport() {
@Override
public void notify(EventObject event) throws Exception {
latch.countDown();
}
@Override
public boolean isEnabled(EventObject event) {
return event instanceof RouteAddedEvent;
}
});
context.start();
// there are 0 routes to begin with
assertEquals(0, context.getRoutes().size());
Thread.sleep(1000);
log.info("Copying file to target/dummy");
// create an xml file with some routes
FileUtil.copyFile(new File("src/test/resources/org/apache/camel/model/barRoute.xml"), new File("target/dummy/barRoute.xml"));
// (is slow on osx, so wait up till 20 seconds)
for (int i = 0; i < 20; i++) {
if (context.getRoutes().size() > 0) {
break;
}
Thread.sleep(1000);
}
assertEquals(1, context.getRoutes().size());
// and the route should work
getMockEndpoint("mock:bar").expectedMessageCount(1);
template.sendBody("direct:bar", "Hello World");
assertMockEndpointsSatisfied();
resetMocks();
// now update the file
log.info("Updating file in target/dummy");
// create an xml file with some routes
FileUtil.copyFile(new File("src/test/resources/org/apache/camel/model/barUpdatedRoute.xml"), new File("target/dummy/barRoute.xml"));
// wait for that file to be processed and remove/add the route
// (is slow on osx, so wait up till 20 seconds)
boolean done = latch.await(20, TimeUnit.SECONDS);
assertTrue("Should reload file within 20 seconds", done);
// and the route should work with the update
Thread.sleep(1000);
getMockEndpoint("mock:bar").expectedBodiesReceived("Bye Camel");
template.sendBody("direct:bar", "Camel");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.support.EventNotifierSupport in project camel by apache.
the class FileWatcherReloadStrategyTest method testUpdateExistingRoute.
public void testUpdateExistingRoute() throws Exception {
deleteDirectory("target/dummy");
createDirectory("target/dummy");
// the bar route is added two times, at first, and then when updated
final CountDownLatch latch = new CountDownLatch(2);
context.getManagementStrategy().addEventNotifier(new EventNotifierSupport() {
@Override
public void notify(EventObject event) throws Exception {
latch.countDown();
}
@Override
public boolean isEnabled(EventObject event) {
return event instanceof RouteAddedEvent;
}
});
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:bar").routeId("bar").to("mock:foo");
}
});
context.start();
assertEquals(1, context.getRoutes().size());
// and the route should work sending to mock:foo
getMockEndpoint("mock:bar").expectedMessageCount(0);
getMockEndpoint("mock:foo").expectedMessageCount(1);
template.sendBody("direct:bar", "Hello World");
assertMockEndpointsSatisfied();
resetMocks();
Thread.sleep(1000);
log.info("Copying file to target/dummy");
// create an xml file with some routes
FileUtil.copyFile(new File("src/test/resources/org/apache/camel/model/barRoute.xml"), new File("target/dummy/barRoute.xml"));
// wait for that file to be processed and remove/add the route
// (is slow on osx, so wait up till 20 seconds)
boolean done = latch.await(20, TimeUnit.SECONDS);
assertTrue("Should reload file within 20 seconds", done);
// and the route should be changed to route to mock:bar instead of mock:foo
Thread.sleep(1000);
getMockEndpoint("mock:bar").expectedMessageCount(1);
getMockEndpoint("mock:foo").expectedMessageCount(0);
template.sendBody("direct:bar", "Bye World");
assertMockEndpointsSatisfied();
}
use of org.apache.camel.support.EventNotifierSupport in project camel by apache.
the class RemoveEventNotifierTest method createCamelContext.
@Override
protected CamelContext createCamelContext() throws Exception {
DefaultCamelContext context = new DefaultCamelContext(createRegistry());
notifier = new EventNotifierSupport() {
public void notify(EventObject event) throws Exception {
events.add(event);
}
public boolean isEnabled(EventObject event) {
return true;
}
@Override
protected void doStart() throws Exception {
}
@Override
protected void doStop() throws Exception {
}
};
context.getManagementStrategy().addEventNotifier(notifier);
return context;
}
use of org.apache.camel.support.EventNotifierSupport in project camel by apache.
the class AsyncEndpointEventNotifierSendingTest method createCamelContext.
@Override
protected CamelContext createCamelContext() throws Exception {
DefaultCamelContext context = new DefaultCamelContext(createRegistry());
context.getManagementStrategy().addEventNotifier(new EventNotifierSupport() {
public void notify(EventObject event) throws Exception {
events.add(event);
}
public boolean isEnabled(EventObject event) {
return event instanceof ExchangeSendingEvent || event instanceof ExchangeSentEvent;
}
@Override
protected void doStart() throws Exception {
}
@Override
protected void doStop() throws Exception {
}
});
return context;
}
Aggregations