use of org.apache.camel.management.event.ExchangeCompletedEvent in project camel by apache.
the class EventNotifierExchangeCompletedTest method testExchangeCompleted.
public void testExchangeCompleted() throws Exception {
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
assertEquals(1, events.size());
// get the event
ExchangeCompletedEvent event = (ExchangeCompletedEvent) events.get(0);
assertNotNull(event.getExchange());
assertNotNull(event.getExchange().getFromEndpoint());
assertEquals("direct://start", event.getExchange().getFromEndpoint().getEndpointUri());
// grab the created timestamp
Date created = event.getExchange().getProperty(Exchange.CREATED_TIMESTAMP, Date.class);
assertNotNull(created);
// calculate elapsed time
Date now = new Date();
long elapsed = now.getTime() - created.getTime();
assertTrue("Should be > 400, was: " + elapsed, elapsed > 400);
log.info("Elapsed time in millis: " + elapsed);
}
use of org.apache.camel.management.event.ExchangeCompletedEvent in project camel by apache.
the class UnitOfWorkProducerTest 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 ExchangeCompletedEvent;
}
@Override
protected void doStart() throws Exception {
}
@Override
protected void doStop() throws Exception {
}
});
return context;
}
use of org.apache.camel.management.event.ExchangeCompletedEvent in project camel by apache.
the class DebugTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
breakpoint = new BreakpointSupport() {
public void beforeProcess(Exchange exchange, Processor processor, ProcessorDefinition<?> definition) {
String body = exchange.getIn().getBody(String.class);
logs.add("Breakpoint at " + definition + " with body: " + body);
}
public void onEvent(Exchange exchange, EventObject event, ProcessorDefinition<?> definition) {
String body = exchange.getIn().getBody(String.class);
logs.add("Breakpoint event " + event.getClass().getSimpleName() + " with body: " + body);
}
};
camelCondition = new ConditionSupport() {
public boolean matchProcess(Exchange exchange, Processor processor, ProcessorDefinition<?> definition) {
return body().contains("Camel").matches(exchange);
}
};
mockCondition = new ConditionSupport() {
public boolean matchProcess(Exchange exchange, Processor processor, ProcessorDefinition<?> definition) {
// match when sending to mocks
if (definition instanceof ToDefinition) {
ToDefinition to = (ToDefinition) definition;
return to.getUriOrRef().startsWith("mock");
}
return false;
}
};
doneCondition = new ConditionSupport() {
@Override
public boolean matchEvent(Exchange exchange, EventObject event) {
return event instanceof ExchangeCompletedEvent;
}
};
}
use of org.apache.camel.management.event.ExchangeCompletedEvent in project camel by apache.
the class DefaultDebugger method addSingleStepBreakpoint.
@Override
public void addSingleStepBreakpoint(final Breakpoint breakpoint, Condition... conditions) {
// wrap the breakpoint into single step breakpoint so we can automatic enable/disable the single step mode
Breakpoint singlestep = new Breakpoint() {
@Override
public State getState() {
return breakpoint.getState();
}
@Override
public void suspend() {
breakpoint.suspend();
}
@Override
public void activate() {
breakpoint.activate();
}
@Override
public void beforeProcess(Exchange exchange, Processor processor, ProcessorDefinition<?> definition) {
breakpoint.beforeProcess(exchange, processor, definition);
}
@Override
public void afterProcess(Exchange exchange, Processor processor, ProcessorDefinition<?> definition, long timeTaken) {
breakpoint.afterProcess(exchange, processor, definition, timeTaken);
}
@Override
public void onEvent(Exchange exchange, EventObject event, ProcessorDefinition<?> definition) {
if (event instanceof ExchangeCreatedEvent) {
exchange.getContext().getDebugger().startSingleStepExchange(exchange.getExchangeId(), this);
} else if (event instanceof ExchangeCompletedEvent) {
exchange.getContext().getDebugger().stopSingleStepExchange(exchange.getExchangeId());
}
breakpoint.onEvent(exchange, event, definition);
}
@Override
public String toString() {
return breakpoint.toString();
}
};
addBreakpoint(singlestep, conditions);
}
use of org.apache.camel.management.event.ExchangeCompletedEvent in project camel by apache.
the class EventNotifierExchangeCompletedTest 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) {
// we only want the completed event
return event instanceof ExchangeCompletedEvent;
// you can add additional filtering such as the exchange
// should be from a specific endpoint or route
// just return true for the events you like
}
protected void doStart() throws Exception {
// noop
}
protected void doStop() throws Exception {
// noop
}
});
return context;
}
Aggregations