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