Search in sources :

Example 6 with EventObject

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);
    }
}
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 7 with EventObject

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);
    }
}
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 8 with EventObject

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

Example 9 with EventObject

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

Example 10 with EventObject

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++;
        }
    });
}
Also used : EventNotifierSupport(org.apache.camel.support.EventNotifierSupport) 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