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);
}
}
}
}
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);
}
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;
}
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);
}
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());
}
Aggregations