use of org.apache.camel.support.EventNotifierSupport in project camel by apache.
the class AsyncEndpointEventNotifierTest 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 {
try {
ExchangeSentEvent sent = (ExchangeSentEvent) event;
time.set(sent.getTimeTaken());
} finally {
latch.countDown();
}
}
public boolean isEnabled(EventObject event) {
// we only want the async endpoint
if (event instanceof ExchangeSentEvent) {
ExchangeSentEvent sent = (ExchangeSentEvent) event;
return sent.getEndpoint().getEndpointUri().startsWith("async");
}
return false;
}
@Override
protected void doStart() throws Exception {
}
@Override
protected void doStop() throws Exception {
}
});
return context;
}
use of org.apache.camel.support.EventNotifierSupport in project camel by apache.
the class EventNotifierExchangeSentTest 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 true;
}
@Override
protected void doStart() throws Exception {
// filter out unwanted events
setIgnoreCamelContextEvents(true);
setIgnoreServiceEvents(true);
setIgnoreRouteEvents(true);
setIgnoreExchangeCreatedEvent(true);
setIgnoreExchangeCompletedEvent(true);
setIgnoreExchangeFailedEvents(true);
setIgnoreExchangeRedeliveryEvents(true);
}
@Override
protected void doStop() throws Exception {
}
});
return context;
}
use of org.apache.camel.support.EventNotifierSupport in project camel by apache.
the class AddEventNotifierTest method testAddAndRemove.
public void testAddAndRemove() throws Exception {
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
assertEquals(0, events.size());
// we should be able to add after CamelContext has been started
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 {
}
};
// must add notifier as a service so its started
context.addService(notifier);
context.getManagementStrategy().addEventNotifier(notifier);
resetMocks();
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:start", "Bye World");
assertMockEndpointsSatisfied();
assertEquals(8, events.size());
// remove and we should not get new events
context.getManagementStrategy().removeEventNotifier(notifier);
resetMocks();
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:start", "Hi World");
assertMockEndpointsSatisfied();
assertEquals(8, events.size());
}
use of org.apache.camel.support.EventNotifierSupport in project camel by apache.
the class ManagedCamelContextRestartTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
context.getManagementStrategy().addEventNotifier(new EventNotifierSupport() {
@Override
public void notify(EventObject event) throws Exception {
// Empty.
}
@Override
public boolean isEnabled(EventObject event) {
return true;
}
@Override
protected void doStart() throws Exception {
starts++;
}
@Override
protected void doStop() throws Exception {
stops++;
}
});
}
use of org.apache.camel.support.EventNotifierSupport in project camel by apache.
the class MultipleEventNotifierEventsTest 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 true;
}
@Override
protected void doStart() throws Exception {
}
@Override
protected void doStop() throws Exception {
}
});
context.getManagementStrategy().addEventNotifier(new EventNotifierSupport() {
public void notify(EventObject event) throws Exception {
events2.add(event);
}
public boolean isEnabled(EventObject event) {
return true;
}
@Override
protected void doStart() throws Exception {
setIgnoreCamelContextEvents(true);
setIgnoreServiceEvents(true);
setIgnoreRouteEvents(true);
}
@Override
protected void doStop() throws Exception {
}
});
return context;
}
Aggregations