You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/07/07 17:32:36 UTC
svn commit: r961408 - in /camel/trunk:
camel-core/src/main/java/org/apache/camel/
camel-core/src/main/java/org/apache/camel/impl/
camel-core/src/main/java/org/apache/camel/model/
camel-core/src/main/java/org/apache/camel/processor/interceptor/ camel-co...
Author: davsclaus
Date: Wed Jul 7 15:32:36 2010
New Revision: 961408
URL: http://svn.apache.org/viewvc?rev=961408&view=rev
Log:
CAMEL-2919: Added first spike of the Debugger SPI API.
Added:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/BreakpointSupport.java (with props)
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultDebugger.java (with props)
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Debug.java (with props)
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Breakpoint.java (with props)
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Condition.java (with props)
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Debugger.java (with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/DebugTest.java (with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
camel/trunk/camel-core/src/main/java/org/apache/camel/model/SendDefinition.java
camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?rev=961408&r1=961407&r2=961408&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java Wed Jul 7 15:32:36 2010
@@ -27,6 +27,7 @@ import org.apache.camel.model.RouteDefin
import org.apache.camel.spi.ClassResolver;
import org.apache.camel.spi.DataFormat;
import org.apache.camel.spi.DataFormatResolver;
+import org.apache.camel.spi.Debugger;
import org.apache.camel.spi.EndpointStrategy;
import org.apache.camel.spi.ExecutorServiceStrategy;
import org.apache.camel.spi.FactoryFinder;
@@ -759,4 +760,18 @@ public interface CamelContext extends Se
*/
void setProcessorFactory(ProcessorFactory processorFactory);
+ /**
+ * Gets the current {@link Debugger}
+ *
+ * @return the debugger
+ */
+ Debugger getDebugger();
+
+ /**
+ * Sets a custom {@link Debugger}
+ *
+ * @param debugger the debugger
+ */
+ void setDebugger(Debugger debugger);
+
}
Added: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/BreakpointSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/BreakpointSupport.java?rev=961408&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/BreakpointSupport.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/BreakpointSupport.java Wed Jul 7 15:32:36 2010
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.Breakpoint;
+
+/**
+ * A support class for {@link Breakpoint} implementations to use as base class.
+ * <p/>
+ * Will be in active state and match any {@link Exchange}s.
+ *
+ * @version $Revision$
+ */
+public abstract class BreakpointSupport implements Breakpoint {
+
+ private State state = State.Active;
+
+ public State getState() {
+ return state;
+ }
+
+ public void suspend() {
+ state = State.Suspended;
+ }
+
+ public void activate() {
+ state = State.Active;
+ }
+
+}
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/BreakpointSupport.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/BreakpointSupport.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=961408&r1=961407&r2=961408&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Wed Jul 7 15:32:36 2010
@@ -67,6 +67,7 @@ import org.apache.camel.management.JmxSy
import org.apache.camel.management.ManagedManagementStrategy;
import org.apache.camel.model.DataFormatDefinition;
import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.processor.interceptor.Debug;
import org.apache.camel.processor.interceptor.Delayer;
import org.apache.camel.processor.interceptor.HandleFault;
import org.apache.camel.processor.interceptor.StreamCaching;
@@ -75,6 +76,7 @@ import org.apache.camel.spi.ClassResolve
import org.apache.camel.spi.ComponentResolver;
import org.apache.camel.spi.DataFormat;
import org.apache.camel.spi.DataFormatResolver;
+import org.apache.camel.spi.Debugger;
import org.apache.camel.spi.EndpointStrategy;
import org.apache.camel.spi.EventNotifier;
import org.apache.camel.spi.ExecutorServiceStrategy;
@@ -173,6 +175,7 @@ public class DefaultCamelContext extends
private ShutdownRoute shutdownRoute = ShutdownRoute.Default;
private ShutdownRunningTask shutdownRunningTask = ShutdownRunningTask.CompleteCurrentTaskOnly;
private ExecutorServiceStrategy executorServiceStrategy = new DefaultExecutorServiceStrategy(this);
+ private Debugger debugger;
private final StopWatch stopWatch = new StopWatch(false);
private Date startDate;
@@ -1000,7 +1003,7 @@ public class DefaultCamelContext extends
if (isTracing()) {
// tracing is added in the DefaultChannel so we can enable it on the fly
- LOG.info("Tracing is enabled on CamelContext" + getName());
+ LOG.info("Tracing is enabled on CamelContext: " + getName());
}
if (isHandleFault()) {
@@ -1019,6 +1022,11 @@ public class DefaultCamelContext extends
addInterceptStrategy(new Delayer(millis));
}
}
+
+ if (getDebugger() != null) {
+ LOG.info("Debugger: " + getDebugger() + " is enabled on CamelContext: " + getName());
+ addInterceptStrategy(new Debug(getDebugger()));
+ }
// start management strategy before lifecycles are started
getManagementStrategy().start();
@@ -1654,6 +1662,14 @@ public class DefaultCamelContext extends
this.processorFactory = processorFactory;
}
+ public Debugger getDebugger() {
+ return debugger;
+ }
+
+ public void setDebugger(Debugger debugger) {
+ this.debugger = debugger;
+ }
+
protected String getEndpointKey(String uri, Endpoint endpoint) {
if (endpoint.isSingleton()) {
return uri;
Added: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultDebugger.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultDebugger.java?rev=961408&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultDebugger.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultDebugger.java Wed Jul 7 15:32:36 2010
@@ -0,0 +1,146 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.spi.Breakpoint;
+import org.apache.camel.spi.Condition;
+import org.apache.camel.spi.Debugger;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * The default implementation of the {@link Debugger}.
+ *
+ * @version $Revision$
+ */
+public class DefaultDebugger implements Debugger {
+
+ private static final Log LOG = LogFactory.getLog(DefaultDebugger.class);
+ private final List<BreakpointConditions> breakpoints = new ArrayList<BreakpointConditions>();
+
+ /**
+ * Holder class for breakpoint and the associated conditions
+ */
+ private final class BreakpointConditions {
+ private Breakpoint breakpoint;
+ private List<Condition> conditions;
+
+ private BreakpointConditions(Breakpoint breakpoint) {
+ this(breakpoint, null);
+ }
+
+ private BreakpointConditions(Breakpoint breakpoint, List<Condition> conditions) {
+ this.breakpoint = breakpoint;
+ this.conditions = conditions;
+ }
+
+ public Breakpoint getBreakpoint() {
+ return breakpoint;
+ }
+
+ public List<Condition> getConditions() {
+ return conditions;
+ }
+ }
+
+ public void addBreakpoint(Breakpoint breakpoint) {
+ breakpoints.add(new BreakpointConditions(breakpoint));
+ }
+
+ public void addBreakpoint(Breakpoint breakpoint, Condition... conditions) {
+ breakpoints.add(new BreakpointConditions(breakpoint, Arrays.asList(conditions)));
+ }
+
+ public void removeBreakpoint(Breakpoint breakpoint) {
+ breakpoints.remove(breakpoint);
+ }
+
+ public void suspendAllBreakpoints() {
+ for (BreakpointConditions breakpoint : breakpoints) {
+ breakpoint.getBreakpoint().suspend();
+ }
+ }
+
+ public void activateAllBreakpoints() {
+ for (BreakpointConditions breakpoint : breakpoints) {
+ breakpoint.getBreakpoint().activate();
+ }
+ }
+
+ public List<Breakpoint> getBreakpoints() {
+ List<Breakpoint> answer = new ArrayList<Breakpoint>(breakpoints.size());
+ for (BreakpointConditions e : breakpoints) {
+ answer.add(e.getBreakpoint());
+ }
+ return Collections.unmodifiableList(answer);
+ }
+
+ public boolean onExchange(Exchange exchange, Processor processor, ProcessorDefinition definition) {
+ boolean match = false;
+
+ // does any of the breakpoints apply?
+ for (BreakpointConditions breakpoint : breakpoints) {
+ // breakpoint must be active
+ if (Breakpoint.State.Active.equals(breakpoint.getBreakpoint().getState())) {
+ if (matchConditions(exchange, processor, definition, breakpoint)) {
+ match = true;
+ onBreakpoint(exchange, processor, definition, breakpoint.getBreakpoint());
+ }
+ }
+ }
+
+ return match;
+ }
+
+ private boolean matchConditions(Exchange exchange, Processor processor, ProcessorDefinition definition, BreakpointConditions breakpoint) {
+ if (breakpoint.getConditions() != null && !breakpoint.getConditions().isEmpty()) {
+ for (Condition condition : breakpoint.getConditions()) {
+ if (!condition.match(exchange, definition)) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ protected void onBreakpoint(Exchange exchange, Processor processor, ProcessorDefinition definition, Breakpoint breakpoint) {
+ breakpoint.onExchange(exchange, processor, definition);
+ }
+
+ public void start() throws Exception {
+ // noop
+ }
+
+ public void stop() throws Exception {
+ breakpoints.clear();
+ // noop
+ }
+
+ @Override
+ public String toString() {
+ return "DefaultDebugger";
+ }
+}
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultDebugger.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultDebugger.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/SendDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/SendDefinition.java?rev=961408&r1=961407&r2=961408&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/SendDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/SendDefinition.java Wed Jul 7 15:32:36 2010
@@ -105,7 +105,7 @@ public abstract class SendDefinition<Typ
/**
* Returns the endpoint URI or the name of the reference to it
*/
- public Object getUriOrRef() {
+ public String getUriOrRef() {
String uri = getUri();
if (ObjectHelper.isNotEmpty(uri)) {
return uri;
Added: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Debug.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Debug.java?rev=961408&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Debug.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Debug.java Wed Jul 7 15:32:36 2010
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor.interceptor;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.processor.DelegateAsyncProcessor;
+import org.apache.camel.spi.Debugger;
+import org.apache.camel.spi.InterceptStrategy;
+
+/**
+ * @version $Revision$
+ */
+public class Debug implements InterceptStrategy {
+
+ private final Debugger debugger;
+
+ public Debug(Debugger debugger) {
+ this.debugger = debugger;
+ }
+
+ public Processor wrapProcessorInInterceptors(final CamelContext context, final ProcessorDefinition<?> definition,
+ final Processor target, final Processor nextTarget) throws Exception {
+ return new DelegateAsyncProcessor(target) {
+ @Override
+ public boolean process(Exchange exchange, AsyncCallback callback) {
+ debugger.onExchange(exchange, target, definition);
+ return super.process(exchange, callback);
+ }
+
+ @Override
+ public String toString() {
+ return "Debug[" + target + "]";
+ }
+ };
+ }
+}
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Debug.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Debug.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Breakpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Breakpoint.java?rev=961408&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Breakpoint.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Breakpoint.java Wed Jul 7 15:32:36 2010
@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spi;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.model.ProcessorDefinition;
+
+/**
+ * {@link org.apache.camel.spi.Breakpoint} are used by the {@link org.apache.camel.spi.Debugger} API.
+ * <p/>
+ * This allows you to register {@link org.apache.camel.spi.Breakpoint}s to the {@link org.apache.camel.spi.Debugger}
+ * and have those breakpoints activated when their {@link org.apache.camel.spi.Condition}s match.
+ * <p/>
+ * If any exceptions is thrown from the {@link #onExchange(org.apache.camel.Exchange, org.apache.camel.Processor, org.apache.camel.model.ProcessorDefinition)}
+ * method then the {@link org.apache.camel.spi.Debugger} will catch and log those at <tt>WARN</tt> level and continue.
+ *
+ * @see org.apache.camel.spi.Debugger
+ * @see org.apache.camel.spi.Condition
+ * @version $Revision$
+ */
+public interface Breakpoint {
+
+ // TODO: Hook into the EventNotifier so we can have breakpoints trigger on those conditions as well
+ // exceptions, create, done, etc. and a FollowMe condition to follow a single exchange
+ // while others are being routed so you can follow one only, eg need an API on Debugger for that
+
+ enum State { Active, Suspended }
+
+ /**
+ * Gets the state of this break
+ *
+ * @return the state
+ */
+ State getState();
+
+ /**
+ * Suspend this breakpoint
+ */
+ void suspend();
+
+ /**
+ * Activates this breakpoint
+ */
+ void activate();
+
+ /**
+ * Callback invoked when the breakpoint was hit.
+ *
+ * @param exchange the {@link Exchange}
+ * @param processor the {@link Processor} which is the next target
+ * @param definition the {@link org.apache.camel.model.ProcessorDefinition} definition of the processor
+ */
+ void onExchange(Exchange exchange, Processor processor, ProcessorDefinition definition);
+
+}
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Breakpoint.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Breakpoint.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Condition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Condition.java?rev=961408&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Condition.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Condition.java Wed Jul 7 15:32:36 2010
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spi;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.model.ProcessorDefinition;
+
+/**
+ * A condition to define when a given {@link Exchange} matches when is being routed.
+ * <p/>
+ * Is used by the {@link org.apache.camel.spi.Debugger} to apply {@link Condition}s
+ * to {@link org.apache.camel.spi.Breakpoint}s to define rules when the breakpoints should match.
+ *
+ * @version $Revision$
+ */
+public interface Condition {
+
+ /**
+ * Does the condition match
+ *
+ * @param exchange the exchange
+ * @param definition the current node in the route where the Exchange is at
+ * @return <tt>true</tt> to match, <tt>false</tt> otherwise
+ */
+ boolean match(Exchange exchange, ProcessorDefinition definition);
+
+}
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Condition.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Condition.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Debugger.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Debugger.java?rev=961408&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Debugger.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Debugger.java Wed Jul 7 15:32:36 2010
@@ -0,0 +1,84 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spi;
+
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Service;
+import org.apache.camel.model.ProcessorDefinition;
+
+/**
+ * A debugger which allows tooling to attach breakpoints which is is being invoked
+ * when {@link Exchange}s is being routed.
+ *
+ * @version $Revision$
+ */
+public interface Debugger extends Service {
+
+ /**
+ * Add the given breakpoint
+ *
+ * @param breakpoint the breakpoint
+ */
+ void addBreakpoint(Breakpoint breakpoint);
+
+ /**
+ * Add the given breakpoint
+ *
+ * @param breakpoint the breakpoint
+ * @param conditions a number of {@link org.apache.camel.spi.Condition}s
+ */
+ void addBreakpoint(Breakpoint breakpoint, Condition... conditions);
+
+ /**
+ * Removes the given breakpoint
+ *
+ * @param breakpoint the breakpoint
+ */
+ void removeBreakpoint(Breakpoint breakpoint);
+
+ /**
+ * Suspends all breakpoints.
+ */
+ void suspendAllBreakpoints();
+
+ /**
+ * Activate all breakpoints.
+ */
+ void activateAllBreakpoints();
+
+ /**
+ * Gets a list of all the breakpoints
+ *
+ * @return the breakpoints wrapped in an unmodifiable list, is never <tt>null</tt>.
+ */
+ List<Breakpoint> getBreakpoints();
+
+ /**
+ * Callback invoked when an {@link Exchange} is being processed which allows implementators
+ * to notify breakpoints.
+ *
+ * @param exchange the exchange
+ * @param processor the target processor (to be processed next)
+ * @param definition the definition of the processor
+ * @return <tt>true</tt> if any breakpoint was hit, <tt>false</tt> if not breakpoint was hit
+ */
+ boolean onExchange(Exchange exchange, Processor processor, ProcessorDefinition definition);
+
+}
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Debugger.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Debugger.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/DebugTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/DebugTest.java?rev=961408&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/DebugTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/DebugTest.java Wed Jul 7 15:32:36 2010
@@ -0,0 +1,132 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor.interceptor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.BreakpointSupport;
+import org.apache.camel.impl.DefaultDebugger;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.ToDefinition;
+import org.apache.camel.spi.Breakpoint;
+import org.apache.camel.spi.Condition;
+
+/**
+ * @version $Revision$
+ */
+public class DebugTest extends ContextTestSupport {
+
+ private List<String> logs = new ArrayList<String>();
+ private Condition camelCondition;
+ private Condition mockCondition;
+ private Breakpoint breakpoint;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ breakpoint = new BreakpointSupport() {
+ public void onExchange(Exchange exchange, Processor processor, ProcessorDefinition definition) {
+ String body = exchange.getIn().getBody(String.class);
+ logs.add("Breakpoint at " + definition + " with body: " + body);
+ }
+ };
+
+ camelCondition = new Condition() {
+ public boolean match(Exchange exchange, ProcessorDefinition definition) {
+ return body().contains("Camel").matches(exchange);
+ }
+ };
+
+ mockCondition = new Condition() {
+ public boolean match(Exchange exchange, ProcessorDefinition definition) {
+ // match when sending to mocks
+ if (definition instanceof ToDefinition) {
+ ToDefinition to = (ToDefinition) definition;
+ return to.getUriOrRef().startsWith("mock");
+ }
+ return false;
+ }
+ };
+ }
+
+ public void testDebug() throws Exception {
+ context.getDebugger().addBreakpoint(breakpoint, camelCondition);
+
+ getMockEndpoint("mock:result").expectedBodiesReceived("Hello World", "Hello Camel");
+
+ template.sendBody("direct:start", "Hello World");
+ template.sendBody("direct:start", "Hello Camel");
+
+ assertMockEndpointsSatisfied();
+
+ assertEquals(2, logs.size());
+ assertEquals("Breakpoint at To[log:foo] with body: Hello Camel", logs.get(0));
+ assertEquals("Breakpoint at To[mock:result] with body: Hello Camel", logs.get(1));
+ }
+
+ public void testDebugSuspended() throws Exception {
+ context.getDebugger().addBreakpoint(breakpoint, mockCondition, camelCondition);
+
+ // suspend the breakpoint
+ context.getDebugger().suspendAllBreakpoints();
+
+ getMockEndpoint("mock:result").expectedBodiesReceived("Hello World", "Hello Camel");
+
+ template.sendBody("direct:start", "Hello World");
+ template.sendBody("direct:start", "Hello Camel");
+
+ assertMockEndpointsSatisfied();
+
+ assertEquals(0, logs.size());
+
+ // resume the breakpoint
+ context.getDebugger().activateAllBreakpoints();
+
+ // reset and test again now the breakpoint is active
+ resetMocks();
+
+ getMockEndpoint("mock:result").expectedBodiesReceived("Hello World", "Hello Camel");
+
+ template.sendBody("direct:start", "Hello World");
+ template.sendBody("direct:start", "Hello Camel");
+
+ assertMockEndpointsSatisfied();
+
+ assertEquals(1, logs.size());
+ assertEquals("Breakpoint at To[mock:result] with body: Hello Camel", logs.get(0));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // use debugger
+ context.setDebugger(new DefaultDebugger());
+
+ from("direct:start").to("log:foo").to("mock:result");
+ }
+ };
+ }
+
+}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/DebugTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/DebugTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java?rev=961408&r1=961407&r2=961408&view=diff
==============================================================================
--- camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java (original)
+++ camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java Wed Jul 7 15:32:36 2010
@@ -62,6 +62,7 @@ import org.apache.camel.processor.interc
import org.apache.camel.processor.interceptor.TraceFormatter;
import org.apache.camel.processor.interceptor.Tracer;
import org.apache.camel.spi.ClassResolver;
+import org.apache.camel.spi.Debugger;
import org.apache.camel.spi.EventFactory;
import org.apache.camel.spi.EventNotifier;
import org.apache.camel.spi.ExecutorServiceStrategy;
@@ -155,6 +156,12 @@ public abstract class AbstractCamelConte
getContext().setProcessorFactory(processorFactory);
}
+ Debugger debugger = getBeanForType(Debugger.class);
+ if (debugger != null) {
+ LOG.info("Using custom Debugger: " + debugger);
+ getContext().setDebugger(debugger);
+ }
+
// set the custom registry if defined
initCustomRegistry(getContext());