Search in sources :

Example 1 with Breakpoint

use of org.apache.camel.spi.Breakpoint in project camel by apache.

the class DefaultDebugger method onEvent.

@Override
public boolean onEvent(Exchange exchange, EventObject event) {
    // is the exchange in single step mode?
    Breakpoint singleStep = singleSteps.get(exchange.getExchangeId());
    if (singleStep != null) {
        onEvent(exchange, event, singleStep);
        return true;
    }
    // does any of the breakpoints apply?
    boolean match = false;
    for (BreakpointConditions breakpoint : breakpoints) {
        // breakpoint must be active
        if (Breakpoint.State.Active.equals(breakpoint.getBreakpoint().getState())) {
            if (matchConditions(exchange, event, breakpoint)) {
                match = true;
                onEvent(exchange, event, breakpoint.getBreakpoint());
            }
        }
    }
    return match;
}
Also used : Breakpoint(org.apache.camel.spi.Breakpoint)

Example 2 with Breakpoint

use of org.apache.camel.spi.Breakpoint in project camel by apache.

the class DefaultDebugger method afterProcess.

@Override
public boolean afterProcess(Exchange exchange, Processor processor, ProcessorDefinition<?> definition, long timeTaken) {
    // is the exchange in single step mode?
    Breakpoint singleStep = singleSteps.get(exchange.getExchangeId());
    if (singleStep != null) {
        onAfterProcess(exchange, processor, definition, timeTaken, singleStep);
        return true;
    }
    // does any of the breakpoints apply?
    boolean match = false;
    for (BreakpointConditions breakpoint : breakpoints) {
        // breakpoint must be active
        if (Breakpoint.State.Active.equals(breakpoint.getBreakpoint().getState())) {
            if (matchConditions(exchange, processor, definition, breakpoint)) {
                match = true;
                onAfterProcess(exchange, processor, definition, timeTaken, breakpoint.getBreakpoint());
            }
        }
    }
    return match;
}
Also used : Breakpoint(org.apache.camel.spi.Breakpoint)

Example 3 with Breakpoint

use of org.apache.camel.spi.Breakpoint in project camel by apache.

the class CamelSpringTestContextLoader method handleProvidesBreakpoint.

/**
     * Handles the processing of the {@link ProvidesBreakpoint} annotation on a test class.  Exists here
     * as it is needed in 
     *
     * @param context the initialized Spring context containing the Camel context(s) to insert breakpoints into 
     * @param testClass the test class being processed
     *
     * @throws Exception if there is an error processing the class
     */
protected void handleProvidesBreakpoint(GenericApplicationContext context, Class<?> testClass) throws Exception {
    Collection<Method> methods = getAllMethods(testClass);
    final List<Breakpoint> breakpoints = new LinkedList<Breakpoint>();
    for (Method method : methods) {
        if (AnnotationUtils.findAnnotation(method, ProvidesBreakpoint.class) != null) {
            Class<?>[] argTypes = method.getParameterTypes();
            if (argTypes.length != 0) {
                throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with ProvidesBreakpoint but is not a no-argument method.");
            } else if (!Breakpoint.class.isAssignableFrom(method.getReturnType())) {
                throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with ProvidesBreakpoint but does not return a Breakpoint.");
            } else if (!Modifier.isStatic(method.getModifiers())) {
                throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with ProvidesBreakpoint but is not static.");
            } else if (!Modifier.isPublic(method.getModifiers())) {
                throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with ProvidesBreakpoint but is not public.");
            }
            try {
                breakpoints.add((Breakpoint) method.invoke(null));
            } catch (Exception e) {
                throw new RuntimeException("Method [" + method.getName() + "] threw exception during evaluation.", e);
            }
        }
    }
    if (breakpoints.size() != 0) {
        CamelSpringTestHelper.doToSpringCamelContexts(context, new DoToSpringCamelContextsStrategy() {

            @Override
            public void execute(String contextName, SpringCamelContext camelContext) throws Exception {
                Debugger debugger = camelContext.getDebugger();
                if (debugger == null) {
                    debugger = new DefaultDebugger();
                    camelContext.setDebugger(debugger);
                }
                for (Breakpoint breakpoint : breakpoints) {
                    LOG.info("Adding Breakpoint [{}] to CamelContext with name [{}].", breakpoint, contextName);
                    debugger.addBreakpoint(breakpoint);
                }
            }
        });
    }
}
Also used : Debugger(org.apache.camel.spi.Debugger) DefaultDebugger(org.apache.camel.impl.DefaultDebugger) Breakpoint(org.apache.camel.spi.Breakpoint) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) Method(java.lang.reflect.Method) LinkedList(java.util.LinkedList) DefaultDebugger(org.apache.camel.impl.DefaultDebugger) DoToSpringCamelContextsStrategy(org.apache.camel.test.spring.CamelSpringTestHelper.DoToSpringCamelContextsStrategy)

Example 4 with Breakpoint

use of org.apache.camel.spi.Breakpoint in project camel by apache.

the class CamelAnnotationsHandler method handleProvidesBreakpoint.

public static void handleProvidesBreakpoint(ConfigurableApplicationContext context, Class<?> testClass) throws Exception {
    Collection<Method> methods = getAllMethods(testClass);
    final List<Breakpoint> breakpoints = new LinkedList<Breakpoint>();
    for (Method method : methods) {
        if (AnnotationUtils.findAnnotation(method, ProvidesBreakpoint.class) != null) {
            Class<?>[] argTypes = method.getParameterTypes();
            if (argTypes.length != 0) {
                throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with ProvidesBreakpoint but is not a no-argument method.");
            } else if (!Breakpoint.class.isAssignableFrom(method.getReturnType())) {
                throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with ProvidesBreakpoint but does not return a Breakpoint.");
            } else if (!Modifier.isStatic(method.getModifiers())) {
                throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with ProvidesBreakpoint but is not static.");
            } else if (!Modifier.isPublic(method.getModifiers())) {
                throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with ProvidesBreakpoint but is not public.");
            }
            try {
                breakpoints.add((Breakpoint) method.invoke(null));
            } catch (Exception e) {
                throw new RuntimeException("Method [" + method.getName() + "] threw exception during evaluation.", e);
            }
        }
    }
    if (breakpoints.size() != 0) {
        CamelSpringTestHelper.doToSpringCamelContexts(context, new CamelSpringTestHelper.DoToSpringCamelContextsStrategy() {

            public void execute(String contextName, SpringCamelContext camelContext) throws Exception {
                Debugger debugger = camelContext.getDebugger();
                if (debugger == null) {
                    debugger = new DefaultDebugger();
                    camelContext.setDebugger(debugger);
                }
                for (Breakpoint breakpoint : breakpoints) {
                    LOGGER.info("Adding Breakpoint [{}] to CamelContext with name [{}].", breakpoint, contextName);
                    debugger.addBreakpoint(breakpoint);
                }
            }
        });
    }
}
Also used : Debugger(org.apache.camel.spi.Debugger) DefaultDebugger(org.apache.camel.impl.DefaultDebugger) Breakpoint(org.apache.camel.spi.Breakpoint) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) Method(java.lang.reflect.Method) LinkedList(java.util.LinkedList) DefaultDebugger(org.apache.camel.impl.DefaultDebugger)

Example 5 with Breakpoint

use of org.apache.camel.spi.Breakpoint in project camel by apache.

the class DefaultDebugger method beforeProcess.

@Override
public boolean beforeProcess(Exchange exchange, Processor processor, ProcessorDefinition<?> definition) {
    // is the exchange in single step mode?
    Breakpoint singleStep = singleSteps.get(exchange.getExchangeId());
    if (singleStep != null) {
        onBeforeProcess(exchange, processor, definition, singleStep);
        return true;
    }
    // does any of the breakpoints apply?
    boolean match = false;
    for (BreakpointConditions breakpoint : breakpoints) {
        // breakpoint must be active
        if (Breakpoint.State.Active.equals(breakpoint.getBreakpoint().getState())) {
            if (matchConditions(exchange, processor, definition, breakpoint)) {
                match = true;
                onBeforeProcess(exchange, processor, definition, breakpoint.getBreakpoint());
            }
        }
    }
    return match;
}
Also used : Breakpoint(org.apache.camel.spi.Breakpoint)

Aggregations

Breakpoint (org.apache.camel.spi.Breakpoint)6 Method (java.lang.reflect.Method)2 LinkedList (java.util.LinkedList)2 DefaultDebugger (org.apache.camel.impl.DefaultDebugger)2 Debugger (org.apache.camel.spi.Debugger)2 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)2 EventObject (java.util.EventObject)1 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)1 ExchangeCompletedEvent (org.apache.camel.management.event.ExchangeCompletedEvent)1 ExchangeCreatedEvent (org.apache.camel.management.event.ExchangeCreatedEvent)1 ProcessorDefinition (org.apache.camel.model.ProcessorDefinition)1 DoToSpringCamelContextsStrategy (org.apache.camel.test.spring.CamelSpringTestHelper.DoToSpringCamelContextsStrategy)1