use of java.util.EventObject in project camel by apache.
the class EventHelper method notifyRouteAdded.
public static void notifyRouteAdded(CamelContext context, Route route) {
ManagementStrategy management = context.getManagementStrategy();
if (management == null) {
return;
}
List<EventNotifier> notifiers = management.getEventNotifiers();
if (notifiers == null || notifiers.isEmpty()) {
return;
}
for (EventNotifier notifier : notifiers) {
if (notifier.isIgnoreRouteEvents()) {
continue;
}
EventFactory factory = management.getEventFactory();
if (factory == null) {
return;
}
EventObject event = factory.createRouteAddedEvent(route);
if (event == null) {
return;
}
doNotifyEvent(notifier, event);
}
}
use of java.util.EventObject in project camel by apache.
the class EventHelper method notifyExchangeRedelivery.
public static void notifyExchangeRedelivery(CamelContext context, Exchange exchange, int attempt) {
if (exchange.getProperty(Exchange.NOTIFY_EVENT, false, Boolean.class)) {
// do not generate events for an notify event
return;
}
ManagementStrategy management = context.getManagementStrategy();
if (management == null) {
return;
}
List<EventNotifier> notifiers = management.getEventNotifiers();
if (notifiers == null || notifiers.isEmpty()) {
return;
}
for (EventNotifier notifier : notifiers) {
if (notifier.isIgnoreExchangeEvents() || notifier.isIgnoreExchangeFailedEvents()) {
continue;
}
EventFactory factory = management.getEventFactory();
if (factory == null) {
return;
}
EventObject event = factory.createExchangeRedeliveryEvent(exchange, attempt);
if (event == null) {
return;
}
doNotifyEvent(notifier, event);
}
}
use of java.util.EventObject 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 java.util.EventObject 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 java.util.EventObject 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++;
}
});
}
Aggregations