Search in sources :

Example 1 with ExchangeCompletedEvent

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);
}
Also used : ExchangeCompletedEvent(org.apache.camel.management.event.ExchangeCompletedEvent) Date(java.util.Date)

Example 2 with ExchangeCompletedEvent

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

Example 3 with ExchangeCompletedEvent

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;
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) ToDefinition(org.apache.camel.model.ToDefinition) Processor(org.apache.camel.Processor) BreakpointSupport(org.apache.camel.impl.BreakpointSupport) ConditionSupport(org.apache.camel.impl.ConditionSupport) ExchangeCompletedEvent(org.apache.camel.management.event.ExchangeCompletedEvent) EventObject(java.util.EventObject)

Example 4 with 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);
}
Also used : Exchange(org.apache.camel.Exchange) Breakpoint(org.apache.camel.spi.Breakpoint) ExchangeCreatedEvent(org.apache.camel.management.event.ExchangeCreatedEvent) Processor(org.apache.camel.Processor) ProcessorDefinition(org.apache.camel.model.ProcessorDefinition) ExchangeCompletedEvent(org.apache.camel.management.event.ExchangeCompletedEvent) EventObject(java.util.EventObject)

Example 5 with ExchangeCompletedEvent

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

Aggregations

ExchangeCompletedEvent (org.apache.camel.management.event.ExchangeCompletedEvent)5 EventObject (java.util.EventObject)4 Exchange (org.apache.camel.Exchange)2 Processor (org.apache.camel.Processor)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 EventNotifierSupport (org.apache.camel.support.EventNotifierSupport)2 Date (java.util.Date)1 BreakpointSupport (org.apache.camel.impl.BreakpointSupport)1 ConditionSupport (org.apache.camel.impl.ConditionSupport)1 ExchangeCreatedEvent (org.apache.camel.management.event.ExchangeCreatedEvent)1 ProcessorDefinition (org.apache.camel.model.ProcessorDefinition)1 ToDefinition (org.apache.camel.model.ToDefinition)1 Breakpoint (org.apache.camel.spi.Breakpoint)1