use of java.util.EventObject in project camel by apache.
the class OsgiEventAdminNotifier method notify.
public void notify(EventObject event) throws Exception {
EventAdmin eventAdmin = tracker.getService();
if (eventAdmin == null) {
return;
}
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(TYPE, getType(event));
props.put(EVENT, event);
props.put(TIMESTAMP, System.currentTimeMillis());
props.put(BUNDLE, bundleContext.getBundle());
props.put(BUNDLE_SYMBOLICNAME, bundleContext.getBundle().getSymbolicName());
props.put(BUNDLE_ID, bundleContext.getBundle().getBundleId());
props.put(BUNDLE_VERSION, getBundleVersion(bundleContext.getBundle()));
try {
props.put(CAUSE, event.getClass().getMethod("getCause").invoke(event));
} catch (Throwable t) {
// ignore
}
eventAdmin.postEvent(new Event(getTopic(event), props));
}
use of java.util.EventObject 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 java.util.EventObject in project camel by apache.
the class EventHelper method notifyCamelContextSuspending.
public static void notifyCamelContextSuspending(CamelContext context) {
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.isIgnoreCamelContextEvents()) {
continue;
}
EventFactory factory = management.getEventFactory();
if (factory == null) {
return;
}
EventObject event = factory.createCamelContextSuspendingEvent(context);
if (event == null) {
return;
}
doNotifyEvent(notifier, event);
}
}
use of java.util.EventObject in project camel by apache.
the class EventHelper method notifyRouteStarted.
public static void notifyRouteStarted(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.createRouteStartedEvent(route);
if (event == null) {
return;
}
doNotifyEvent(notifier, event);
}
}
use of java.util.EventObject in project camel by apache.
the class EventHelper method notifyExchangeSending.
public static void notifyExchangeSending(CamelContext context, Exchange exchange, Endpoint endpoint) {
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.isIgnoreExchangeSentEvents()) {
continue;
}
EventFactory factory = management.getEventFactory();
if (factory == null) {
return;
}
EventObject event = factory.createExchangeSendingEvent(exchange, endpoint);
if (event == null) {
return;
}
doNotifyEvent(notifier, event);
}
}
Aggregations