Search in sources :

Example 1 with EventObject

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));
}
Also used : EventAdmin(org.osgi.service.event.EventAdmin) Hashtable(java.util.Hashtable) Event(org.osgi.service.event.Event) EventObject(java.util.EventObject)

Example 2 with EventObject

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;
}
Also used : ExchangeSentEvent(org.apache.camel.management.event.ExchangeSentEvent) EventNotifierSupport(org.apache.camel.support.EventNotifierSupport) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) EventObject(java.util.EventObject)

Example 3 with EventObject

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);
    }
}
Also used : ManagementStrategy(org.apache.camel.spi.ManagementStrategy) EventNotifier(org.apache.camel.spi.EventNotifier) EventFactory(org.apache.camel.spi.EventFactory) EventObject(java.util.EventObject)

Example 4 with EventObject

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);
    }
}
Also used : ManagementStrategy(org.apache.camel.spi.ManagementStrategy) EventNotifier(org.apache.camel.spi.EventNotifier) EventFactory(org.apache.camel.spi.EventFactory) EventObject(java.util.EventObject)

Example 5 with EventObject

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);
    }
}
Also used : ManagementStrategy(org.apache.camel.spi.ManagementStrategy) EventNotifier(org.apache.camel.spi.EventNotifier) EventFactory(org.apache.camel.spi.EventFactory) EventObject(java.util.EventObject)

Aggregations

EventObject (java.util.EventObject)91 EventFactory (org.apache.camel.spi.EventFactory)25 EventNotifier (org.apache.camel.spi.EventNotifier)25 ManagementStrategy (org.apache.camel.spi.ManagementStrategy)25 AlertHandler (edu.cmu.cs.hcii.cogtool.util.AlertHandler)21 EventNotifierSupport (org.apache.camel.support.EventNotifierSupport)15 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)10 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)9 ExchangeCompletedEvent (org.apache.camel.management.event.ExchangeCompletedEvent)4 ClientConfig (com.hazelcast.client.config.ClientConfig)3 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Design (edu.cmu.cs.hcii.cogtool.model.Design)3 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)3 DesignEditorFrame (edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame)3 MouseEvent (java.awt.event.MouseEvent)3 PreferencesHandler (jmri.plaf.macosx.PreferencesHandler)3 ExchangeSendingEvent (org.apache.camel.management.event.ExchangeSendingEvent)3 ListenerConfig (com.hazelcast.config.ListenerConfig)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2