Author: jstrachan
Date: Mon Jun 23 09:37:34 2008
New Revision: 670668
URL: http://svn.apache.org/viewvc?rev=670668&view=rev
Log:
more improvements for the tracing support; making it easy to enable tracing on
the DefaultCamelContext or on the <camelContext trace="true"/> see
http://issues.apache.org/activemq/browse/CAMEL-619
Added:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceStrategy.java
- copied, changed from r670571,
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Debugger.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/SystemHelper.java
(with props)
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=670668&r1=670667&r2=670668&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
Mon Jun 23 09:37:34 2008
@@ -17,49 +17,25 @@
package org.apache.camel.impl;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.Callable;
-
-import javax.naming.Context;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.Component;
-import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.apache.camel.ProducerTemplate;
-import org.apache.camel.ResolveEndpointFailedException;
-import org.apache.camel.Route;
-import org.apache.camel.Routes;
-import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.Service;
-import org.apache.camel.TypeConverter;
+import org.apache.camel.*;
+import org.apache.camel.processor.interceptor.TraceStrategy;
+import org.apache.camel.converter.ObjectConverter;
import org.apache.camel.impl.converter.DefaultTypeConverter;
import org.apache.camel.management.InstrumentationLifecycleStrategy;
import org.apache.camel.management.JmxSystemPropertyKeys;
import org.apache.camel.model.RouteType;
-import org.apache.camel.spi.ComponentResolver;
-import org.apache.camel.spi.ExchangeConverter;
-import org.apache.camel.spi.Injector;
-import org.apache.camel.spi.InterceptStrategy;
-import org.apache.camel.spi.Language;
-import org.apache.camel.spi.LanguageResolver;
-import org.apache.camel.spi.LifecycleStrategy;
-import org.apache.camel.spi.Registry;
-import org.apache.camel.util.FactoryFinder;
-import org.apache.camel.util.NoFactoryAvailableException;
-import org.apache.camel.util.ObjectHelper;
-import org.apache.camel.util.ReflectionInjector;
+import org.apache.camel.spi.*;
+import org.apache.camel.util.*;
+import static org.apache.camel.util.ServiceHelper.startServices;
+import static org.apache.camel.util.ServiceHelper.stopServices;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import static org.apache.camel.util.ServiceHelper.startServices;
-import static org.apache.camel.util.ServiceHelper.stopServices;
+import javax.naming.Context;
+import java.io.IOException;
+import java.util.*;
+import java.util.concurrent.Callable;
+
/**
* Represents the context used to configure routes and the policies to use.
*
@@ -85,6 +61,7 @@
private LifecycleStrategy lifecycleStrategy;
private List<RouteType> routeDefinitions = new ArrayList<RouteType>();
private List<InterceptStrategy> interceptStrategies = new
ArrayList<InterceptStrategy>();
+ private Boolean tracing;
public DefaultCamelContext() {
name = NAME_PREFIX + ++nameSuffix;
@@ -168,7 +145,7 @@
return componentType.cast(component);
} else {
throw new IllegalArgumentException("The component is not of type:
" + componentType + " but is: "
- + component);
+ + component);
}
}
@@ -186,13 +163,13 @@
component = factory.call();
if (component == null) {
throw new RuntimeCamelException("Factory failed to
create the " + componentName
- + " component, it
returned null.");
+ + " component, it returned null.");
}
components.put(componentName, component);
component.setCamelContext(this);
} catch (Exception e) {
throw new RuntimeCamelException("Factory failed to create
the " + componentName
- + " component", e);
+ + " component", e);
}
}
return component;
@@ -282,7 +259,7 @@
return endpointType.cast(endpoint);
} else {
throw new IllegalArgumentException("The endpoint is not of type: "
+ endpointType + " but is: "
- + endpoint);
+ + endpoint);
}
}
@@ -439,10 +416,44 @@
getInterceptStrategies().add(interceptStrategy);
}
+ /**
+ * Returns true if tracing has been enabled or disabled via the [EMAIL
PROTECTED] #setTracing(Boolean)} method
+ * or it has not been specified then default to the <b>camel.trace</b>
system property
+ */
+ public boolean isTracing() {
+ final Boolean value = getTracing();
+ if (value != null) {
+ return value;
+ } else {
+ return SystemHelper.isSystemProperty("canel.trace");
+ }
+ }
+
+ public Boolean getTracing() {
+ return tracing;
+ }
+
+ public void setTracing(Boolean tracing) {
+ this.tracing = tracing;
+ }
+
// Implementation methods
// -----------------------------------------------------------------------
protected void doStart() throws Exception {
+ if (isTracing()) {
+ // lets check if we already have already been configured and if
not add the default
+ boolean found = false;
+ final List<InterceptStrategy> list = getInterceptStrategies();
+ for (InterceptStrategy strategy : list) {
+ if (strategy instanceof TraceStrategy) {
+ found = true;
+ }
+ }
+ if (!found) {
+ addInterceptStrategy(new TraceStrategy());
+ }
+ }
lifecycleStrategy.onContextStart(this);
forceLazyInitialization();
@@ -516,7 +527,7 @@
protected Injector createInjector() {
FactoryFinder finder = new FactoryFinder();
try {
- return (Injector)finder.newInstance("Injector");
+ return (Injector) finder.newInstance("Injector");
} catch (NoFactoryAvailableException e) {
// lets use the default
return new ReflectionInjector();
@@ -556,9 +567,9 @@
protected Endpoint createEndpoint(String uri) {
Object value = getRegistry().lookup(uri);
if (value instanceof Endpoint) {
- return (Endpoint)value;
+ return (Endpoint) value;
} else if (value instanceof Processor) {
- return new ProcessorEndpoint(uri, this, (Processor)value);
+ return new ProcessorEndpoint(uri, this, (Processor) value);
} else if (value != null) {
return convertBeanToEndpoint(uri, value);
}
@@ -569,13 +580,13 @@
* Attempt to convert the bean from a [EMAIL PROTECTED] Registry} to an
endpoint using
* some kind of transformation or wrapper
*
- * @param uri the uri for the endpoint (and name in the registry)
+ * @param uri the uri for the endpoint (and name in the registry)
* @param bean the bean to be converted to an endpoint, which will be not
null
* @return a new endpoint
*/
protected Endpoint convertBeanToEndpoint(String uri, Object bean) {
throw new IllegalArgumentException("uri: " + uri + " bean: " + bean
- + " could not be converted to an
Endpoint");
+ + " could not be converted to an Endpoint");
}
/**
Copied:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceStrategy.java
(from r670571,
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Debugger.java)
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceStrategy.java?p2=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceStrategy.java&p1=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Debugger.java&r1=670571&r2=670668&rev=670668&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Debugger.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceStrategy.java
Mon Jun 23 09:37:34 2008
@@ -16,108 +16,20 @@
*/
package org.apache.camel.processor.interceptor;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.Exchange;
import org.apache.camel.Processor;
-import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.model.ProcessorType;
import org.apache.camel.spi.InterceptStrategy;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
/**
- * An interceptor strategy for debugging and tracing routes
+ * An interceptor strategy for tracing routes
*
* @version $Revision$
*/
-public class Debugger implements InterceptStrategy {
- private static final transient Log LOG = LogFactory.getLog(Debugger.class);
+public class TraceStrategy implements InterceptStrategy {
- private int exchangeBufferSize = -1;
- private Map<String, DebugInterceptor> interceptors = new HashMap<String,
DebugInterceptor>();
- private boolean logExchanges = true;
private TraceFormatter formatter = new TraceFormatter();
-
- /**
- * A helper method to return the debugger instance for a given [EMAIL
PROTECTED] CamelContext} if one is enabled
- *
- * @param context the camel context the debugger is connected to
- * @return the debugger or null if none can be found
- */
- public static Debugger getDebugger(CamelContext context) {
- if (context instanceof DefaultCamelContext) {
- DefaultCamelContext defaultCamelContext = (DefaultCamelContext)
context;
- List<InterceptStrategy> list =
defaultCamelContext.getInterceptStrategies();
- for (InterceptStrategy interceptStrategy : list) {
- if (interceptStrategy instanceof Debugger) {
- return (Debugger)interceptStrategy;
- }
- }
- }
- return null;
- }
-
- public DebugInterceptor getInterceptor(String id) {
- return interceptors.get(id);
- }
-
- /**
- * Returns the list of exchanges sent to the given node in the DSL
- */
- public List<Exchange> getExchanges(String id) {
- DebugInterceptor interceptor = getInterceptor(id);
- if (interceptor == null) {
- return null;
- } else {
- return interceptor.getExchanges();
- }
- }
-
- /**
- * Returns the breakpoint object for the given node in the DSL
- */
- public Breakpoint getBreakpoint(String id) {
- DebugInterceptor interceptor = getInterceptor(id);
- if (interceptor == null) {
- return null;
- } else {
- return interceptor.getBreakpoint();
- }
- }
-
-
public Processor wrapProcessorInInterceptors(ProcessorType processorType,
Processor target) throws Exception {
- String id = processorType.idOrCreate();
- if (logExchanges) {
- target = new TraceInterceptor(processorType, target, formatter);
- }
- DebugInterceptor interceptor = new DebugInterceptor(processorType,
target, createExchangeList(), createExceptionsList());
- interceptors.put(id, interceptor);
- if (LOG.isDebugEnabled()) {
- LOG.debug("adding interceptor: " + interceptor);
- }
- return interceptor;
- }
-
- protected List<Exchange> createExchangeList() {
- if (exchangeBufferSize == 0) {
- return null;
- } else if (exchangeBufferSize > 0) {
- // TODO lets create a non blocking fixed size queue
- return new ArrayList<Exchange>();
- } else {
- return new ArrayList<Exchange>();
- }
- }
-
- protected List<ExceptionEvent> createExceptionsList() {
- // TODO allow some kinda LRU based fixed size list to be used?
- return new ArrayList<ExceptionEvent>();
+ return new TraceInterceptor(processorType, target, formatter);
}
-}
+}
\ No newline at end of file
Added:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/SystemHelper.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/SystemHelper.java?rev=670668&view=auto
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/SystemHelper.java
(added)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/SystemHelper.java
Mon Jun 23 09:37:34 2008
@@ -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.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.camel.converter.ObjectConverter;
+
+/**
+ * A helper class for various [EMAIL PROTECTED] System} related methods
+ *
+ * @version $Revision: 1.1 $
+ */
+public class SystemHelper {
+ private static final transient Log LOG =
LogFactory.getLog(SystemHelper.class);
+
+ /**
+ * Looks up the given system property name returning null if any
exceptions occur
+ * @param name
+ * @return
+ */
+ public static String getSystemProperty(String name) {
+ try {
+ return System.getProperty(name);
+ } catch (Exception e) {
+ LOG.debug("Caught exception looking for system property: " + name
+ " exception: " + e, e);
+ return null;
+ }
+ }
+
+ /**
+ * Looks up the given system property value and returns true or false if
it is not enabled
+ */
+ public static boolean isSystemProperty(String name) {
+ String text = getSystemProperty(name);
+ return ObjectConverter.toBool(text);
+
+ }
+}
Propchange:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/SystemHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=670668&r1=670667&r2=670668&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
(original)
+++
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
Mon Jun 23 09:37:34 2008
@@ -69,6 +69,8 @@
@XmlAttribute(required = false)
private Boolean autowireRouteBuilders = Boolean.TRUE;
+ @XmlAttribute(required = false)
+ private Boolean tracing;
@XmlElement(name = "package", required = false)
private String[] packages = {};
@XmlElement(name = "jmxAgent", type = CamelJMXAgentType.class, required =
false)
@@ -334,6 +336,9 @@
protected SpringCamelContext createContext() {
SpringCamelContext ctx = new
SpringCamelContext(getApplicationContext());
ctx.setName(getId());
+ if (tracing != null) {
+ ctx.setTracing(tracing);
+ }
return ctx;
}