Search in sources :

Example 1 with EventNotifierSupport

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;
}
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 2 with EventNotifierSupport

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

Example 3 with EventNotifierSupport

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

Example 4 with EventNotifierSupport

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

Example 5 with EventNotifierSupport

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

Aggregations

EventObject (java.util.EventObject)15 EventNotifierSupport (org.apache.camel.support.EventNotifierSupport)15 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)10 File (java.io.File)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExchangeCompletedEvent (org.apache.camel.management.event.ExchangeCompletedEvent)2 ExchangeSentEvent (org.apache.camel.management.event.ExchangeSentEvent)2 RouteAddedEvent (org.apache.camel.management.event.RouteAddedEvent)2 CamelContext (org.apache.camel.CamelContext)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 ExchangeSendingEvent (org.apache.camel.management.event.ExchangeSendingEvent)1