Search in sources :

Example 1 with ExchangeSendingEvent

use of org.apache.camel.management.event.ExchangeSendingEvent in project camel by apache.

the class DefaultRuntimeEndpointRegistry method notify.

@Override
public void notify(EventObject event) throws Exception {
    if (event instanceof RouteAddedEvent) {
        RouteAddedEvent rse = (RouteAddedEvent) event;
        Endpoint endpoint = rse.getRoute().getEndpoint();
        String routeId = rse.getRoute().getId();
        // a HashSet is fine for inputs as we only have a limited number of those
        Set<String> uris = new HashSet<String>();
        uris.add(endpoint.getEndpointUri());
        inputs.put(routeId, uris);
        // use a LRUCache for outputs as we could potential have unlimited uris if dynamic routing is in use
        // and therefore need to have the limit in use
        outputs.put(routeId, new LRUCache<String, String>(limit));
    } else if (event instanceof RouteRemovedEvent) {
        RouteRemovedEvent rse = (RouteRemovedEvent) event;
        String routeId = rse.getRoute().getId();
        inputs.remove(routeId);
        outputs.remove(routeId);
        if (extended) {
            String uri = rse.getRoute().getEndpoint().getEndpointUri();
            String key = asUtilizationKey(routeId, uri);
            if (key != null) {
                inputUtilization.remove(key);
            }
        }
    } else if (extended && event instanceof ExchangeCreatedEvent) {
        // we only capture details in extended mode
        ExchangeCreatedEvent ece = (ExchangeCreatedEvent) event;
        Endpoint endpoint = ece.getExchange().getFromEndpoint();
        if (endpoint != null) {
            String routeId = ece.getExchange().getFromRouteId();
            String uri = endpoint.getEndpointUri();
            String key = asUtilizationKey(routeId, uri);
            if (key != null) {
                inputUtilization.onHit(key);
            }
        }
    } else if (event instanceof ExchangeSendingEvent) {
        ExchangeSendingEvent ese = (ExchangeSendingEvent) event;
        Endpoint endpoint = ese.getEndpoint();
        String routeId = getRouteId(ese.getExchange());
        String uri = endpoint.getEndpointUri();
        Map<String, String> uris = outputs.get(routeId);
        if (uris != null && !uris.containsKey(uri)) {
            uris.put(uri, uri);
        }
        if (extended) {
            String key = asUtilizationKey(routeId, uri);
            if (key != null) {
                outputUtilization.onHit(key);
            }
        }
    }
}
Also used : RouteAddedEvent(org.apache.camel.management.event.RouteAddedEvent) ExchangeCreatedEvent(org.apache.camel.management.event.ExchangeCreatedEvent) ExchangeSendingEvent(org.apache.camel.management.event.ExchangeSendingEvent) Endpoint(org.apache.camel.Endpoint) RouteRemovedEvent(org.apache.camel.management.event.RouteRemovedEvent) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with ExchangeSendingEvent

use of org.apache.camel.management.event.ExchangeSendingEvent in project camel by apache.

the class EventNotifierExchangeSentTest method testExchangeSent.

public void testExchangeSent() throws Exception {
    getMockEndpoint("mock:result").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    assertEquals(8, events.size());
    ExchangeSendingEvent e0 = assertIsInstanceOf(ExchangeSendingEvent.class, events.get(0));
    ExchangeSendingEvent e1 = assertIsInstanceOf(ExchangeSendingEvent.class, events.get(1));
    ExchangeSentEvent e2 = assertIsInstanceOf(ExchangeSentEvent.class, events.get(2));
    ExchangeSendingEvent e3 = assertIsInstanceOf(ExchangeSendingEvent.class, events.get(3));
    ExchangeSentEvent e4 = assertIsInstanceOf(ExchangeSentEvent.class, events.get(4));
    ExchangeSendingEvent e5 = assertIsInstanceOf(ExchangeSendingEvent.class, events.get(5));
    ExchangeSentEvent e6 = assertIsInstanceOf(ExchangeSentEvent.class, events.get(6));
    ExchangeSentEvent e7 = assertIsInstanceOf(ExchangeSentEvent.class, events.get(7));
    assertEquals("direct://start", e0.getEndpoint().getEndpointUri());
    assertEquals("log://foo", e1.getEndpoint().getEndpointUri());
    assertEquals("log://foo", e2.getEndpoint().getEndpointUri());
    assertEquals("direct://bar", e3.getEndpoint().getEndpointUri());
    assertEquals("direct://bar", e4.getEndpoint().getEndpointUri());
    long time = e4.getTimeTaken();
    assertTrue("Should take about 0.5 sec, was: " + time, time > 400);
    assertEquals("mock://result", e5.getEndpoint().getEndpointUri());
    assertEquals("mock://result", e6.getEndpoint().getEndpointUri());
    assertEquals("direct://start", e7.getEndpoint().getEndpointUri());
    time = e7.getTimeTaken();
    assertTrue("Should take about 0.5 sec, was: " + time, time > 400);
}
Also used : ExchangeSentEvent(org.apache.camel.management.event.ExchangeSentEvent) ExchangeSendingEvent(org.apache.camel.management.event.ExchangeSendingEvent)

Example 3 with ExchangeSendingEvent

use of org.apache.camel.management.event.ExchangeSendingEvent in project camel by apache.

the class AsyncEndpointEventNotifierSendingTest 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 event instanceof ExchangeSendingEvent || event instanceof ExchangeSentEvent;
        }

        @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) ExchangeSendingEvent(org.apache.camel.management.event.ExchangeSendingEvent) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) EventObject(java.util.EventObject)

Example 4 with ExchangeSendingEvent

use of org.apache.camel.management.event.ExchangeSendingEvent in project camel by apache.

the class EventNotifierExchangeSentParallelTest method testExchangeSentRecipient.

public void testExchangeSentRecipient() throws Exception {
    getMockEndpoint("mock:result").expectedMessageCount(1);
    template.sendBodyAndHeader("direct:foo", "Hello World", "foo", "direct:cool,direct:start");
    // wait for the message to be fully done using oneExchangeDone
    assertMockEndpointsSatisfied();
    assertTrue(oneExchangeDone.matchesMockWaitTime());
    // stop Camel to let all the events complete
    context.stop();
    assertTrue("Should be 11 or more, was: " + events.size(), events.size() >= 11);
    // we run parallel so just assert we got 6 sending and 6 sent events
    int sent = 0;
    int sending = 0;
    for (EventObject event : events) {
        if (event instanceof ExchangeSendingEvent) {
            sending++;
        } else {
            sent++;
        }
    }
    assertTrue("There should be 5 or more, was " + sending, sending >= 5);
    assertTrue("There should be 5 or more, was " + sent, sent >= 5);
}
Also used : ExchangeSendingEvent(org.apache.camel.management.event.ExchangeSendingEvent) EventObject(java.util.EventObject)

Example 5 with ExchangeSendingEvent

use of org.apache.camel.management.event.ExchangeSendingEvent in project camel by apache.

the class EventNotifierExchangeSentTest method testExchangeSentRecipient.

public void testExchangeSentRecipient() throws Exception {
    getMockEndpoint("mock:result").expectedMessageCount(1);
    template.sendBodyAndHeader("direct:foo", "Hello World", "foo", "direct:cool,direct:start");
    assertMockEndpointsSatisfied();
    // give it time to complete
    Thread.sleep(200);
    assertEquals(12, events.size());
    ExchangeSendingEvent e0 = assertIsInstanceOf(ExchangeSendingEvent.class, events.get(0));
    ExchangeSendingEvent e1 = assertIsInstanceOf(ExchangeSendingEvent.class, events.get(1));
    ExchangeSentEvent e2 = assertIsInstanceOf(ExchangeSentEvent.class, events.get(2));
    ExchangeSendingEvent e3 = assertIsInstanceOf(ExchangeSendingEvent.class, events.get(3));
    ExchangeSendingEvent e4 = assertIsInstanceOf(ExchangeSendingEvent.class, events.get(4));
    ExchangeSentEvent e5 = assertIsInstanceOf(ExchangeSentEvent.class, events.get(5));
    ExchangeSendingEvent e6 = assertIsInstanceOf(ExchangeSendingEvent.class, events.get(6));
    ExchangeSentEvent e7 = assertIsInstanceOf(ExchangeSentEvent.class, events.get(7));
    ExchangeSendingEvent e8 = assertIsInstanceOf(ExchangeSendingEvent.class, events.get(8));
    ExchangeSentEvent e9 = assertIsInstanceOf(ExchangeSentEvent.class, events.get(9));
    ExchangeSentEvent e10 = assertIsInstanceOf(ExchangeSentEvent.class, events.get(10));
    ExchangeSentEvent e11 = assertIsInstanceOf(ExchangeSentEvent.class, events.get(11));
    assertEquals("direct://foo", e0.getEndpoint().getEndpointUri());
    assertEquals("direct://cool", e1.getEndpoint().getEndpointUri());
    assertEquals("direct://cool", e2.getEndpoint().getEndpointUri());
    assertEquals("direct://start", e3.getEndpoint().getEndpointUri());
    assertEquals("log://foo", e4.getEndpoint().getEndpointUri());
    assertEquals("log://foo", e5.getEndpoint().getEndpointUri());
    assertEquals("direct://bar", e6.getEndpoint().getEndpointUri());
    assertEquals("direct://bar", e7.getEndpoint().getEndpointUri());
    assertEquals("mock://result", e8.getEndpoint().getEndpointUri());
    assertEquals("mock://result", e9.getEndpoint().getEndpointUri());
    assertEquals("direct://start", e10.getEndpoint().getEndpointUri());
    assertEquals("direct://foo", e11.getEndpoint().getEndpointUri());
}
Also used : ExchangeSentEvent(org.apache.camel.management.event.ExchangeSentEvent) ExchangeSendingEvent(org.apache.camel.management.event.ExchangeSendingEvent)

Aggregations

ExchangeSendingEvent (org.apache.camel.management.event.ExchangeSendingEvent)6 ExchangeSentEvent (org.apache.camel.management.event.ExchangeSentEvent)4 EventObject (java.util.EventObject)3 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Endpoint (org.apache.camel.Endpoint)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 ExchangeCreatedEvent (org.apache.camel.management.event.ExchangeCreatedEvent)1 RouteAddedEvent (org.apache.camel.management.event.RouteAddedEvent)1 RouteRemovedEvent (org.apache.camel.management.event.RouteRemovedEvent)1 EventNotifierSupport (org.apache.camel.support.EventNotifierSupport)1