You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by cs...@apache.org on 2011/10/07 17:33:53 UTC
svn commit: r1180079 - in
/camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel:
management/mbean/JMXNotificationTraceEventHandler.java
processor/interceptor/DefaultTraceEventHandler.java
processor/interceptor/TraceInterceptor.java
Author: cschneider
Date: Fri Oct 7 15:33:53 2011
New Revision: 1180079
URL: http://svn.apache.org/viewvc?rev=1180079&view=rev
Log:
CAMEL-4500 Fix to always run the default tracing before the jmx notifications
Added:
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultTraceEventHandler.java
Modified:
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/management/mbean/JMXNotificationTraceEventHandler.java
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceInterceptor.java
Modified: camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/management/mbean/JMXNotificationTraceEventHandler.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/management/mbean/JMXNotificationTraceEventHandler.java?rev=1180079&r1=1180078&r2=1180079&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/management/mbean/JMXNotificationTraceEventHandler.java (original)
+++ camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/management/mbean/JMXNotificationTraceEventHandler.java Fri Oct 7 15:33:53 2011
@@ -27,6 +27,7 @@ import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.processor.Traceable;
+import org.apache.camel.processor.interceptor.DefaultTraceEventHandler;
import org.apache.camel.processor.interceptor.TraceEventHandler;
import org.apache.camel.processor.interceptor.TraceInterceptor;
import org.apache.camel.processor.interceptor.Tracer;
@@ -39,22 +40,26 @@ public final class JMXNotificationTraceE
private long num;
private NotificationPublisher notificationSender;
private Tracer tracer;
+ private DefaultTraceEventHandler defaultTracer;
public JMXNotificationTraceEventHandler(Tracer tracer) {
this.tracer = tracer;
+ this.defaultTracer = new DefaultTraceEventHandler(tracer);
}
@SuppressWarnings("rawtypes")
public void traceExchangeOut(ProcessorDefinition node, Processor target, TraceInterceptor traceInterceptor, Exchange exchange, Object traceState) throws Exception {
+ defaultTracer.traceExchangeOut(node, target, traceInterceptor, exchange, traceState);
}
@SuppressWarnings("rawtypes")
public Object traceExchangeIn(ProcessorDefinition node, Processor target, TraceInterceptor traceInterceptor, Exchange exchange) throws Exception {
- return null;
+ return defaultTracer.traceExchangeIn(node, target, traceInterceptor, exchange);
}
@SuppressWarnings("rawtypes")
public void traceExchange(ProcessorDefinition node, Processor target, TraceInterceptor traceInterceptor, Exchange exchange) throws Exception {
+ defaultTracer.traceExchange(node, target, traceInterceptor, exchange);
if (notificationSender != null && tracer.isJmxTraceNotifications()) {
String body = MessageHelper.extractBodyForLogging(exchange.getIn(), "", false, tracer.getTraceBodySize());
Added: camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultTraceEventHandler.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultTraceEventHandler.java?rev=1180079&view=auto
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultTraceEventHandler.java (added)
+++ camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultTraceEventHandler.java Fri Oct 7 15:33:53 2011
@@ -0,0 +1,148 @@
+/**
+ * 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.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.Service;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.ServiceHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DefaultTraceEventHandler implements TraceEventHandler, Service {
+ private static final transient Logger LOG = LoggerFactory.getLogger(DefaultTraceEventHandler.class);
+
+ private Producer traceEventProducer;
+ private Class<?> jpaTraceEventMessageClass;
+ private String jpaTraceEventMessageClassName;
+
+ private final Tracer tracer;
+
+ public DefaultTraceEventHandler(Tracer tracer) {
+ this.tracer = tracer;
+ }
+
+ private synchronized void loadJpaTraceEventMessageClass(Exchange exchange) {
+ if (jpaTraceEventMessageClass == null) {
+ jpaTraceEventMessageClassName = tracer.getJpaTraceEventMessageClassName();
+ }
+ if (jpaTraceEventMessageClass == null) {
+ jpaTraceEventMessageClass = exchange.getContext().getClassResolver().resolveClass(jpaTraceEventMessageClassName);
+ if (jpaTraceEventMessageClass == null) {
+ throw new IllegalArgumentException("Cannot find class: " + jpaTraceEventMessageClassName
+ + ". Make sure camel-jpa.jar is in the classpath.");
+ }
+ }
+ }
+
+ private synchronized Producer getTraceEventProducer(Exchange exchange) throws Exception {
+ if (traceEventProducer == null) {
+ // create producer when we have access the the camel context (we dont in doStart)
+ Endpoint endpoint = tracer.getDestination() != null ? tracer.getDestination() : exchange.getContext().getEndpoint(tracer.getDestinationUri());
+ traceEventProducer = endpoint.createProducer();
+ ServiceHelper.startService(traceEventProducer);
+ }
+ return traceEventProducer;
+ }
+
+ @Override
+ public void traceExchange(ProcessorDefinition node, Processor target, TraceInterceptor traceInterceptor, Exchange exchange) throws Exception {
+ if (tracer.getDestination() != null || tracer.getDestinationUri() != null) {
+
+ // create event exchange and add event information
+ Date timestamp = new Date();
+ Exchange event = new DefaultExchange(exchange);
+ event.setProperty(Exchange.TRACE_EVENT_NODE_ID, node.getId());
+ event.setProperty(Exchange.TRACE_EVENT_TIMESTAMP, timestamp);
+ // keep a reference to the original exchange in case its needed
+ event.setProperty(Exchange.TRACE_EVENT_EXCHANGE, exchange);
+
+ // create event message to sent as in body containing event information such as
+ // from node, to node, etc.
+ TraceEventMessage msg = new DefaultTraceEventMessage(timestamp, node, exchange);
+
+ // should we use ordinary or jpa objects
+ if (tracer.isUseJpa()) {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Using class: " + this.jpaTraceEventMessageClassName + " for tracing event messages");
+ }
+
+ // load the jpa event message class
+ loadJpaTraceEventMessageClass(exchange);
+ // create a new instance of the event message class
+ Object jpa = ObjectHelper.newInstance(jpaTraceEventMessageClass);
+
+ // copy options from event to jpa
+ Map<String, Object> options = new HashMap<String, Object>();
+ IntrospectionSupport.getProperties(msg, options, null);
+ IntrospectionSupport.setProperties(jpa, options);
+ // and set the timestamp as its not a String type
+ IntrospectionSupport.setProperty(jpa, "timestamp", msg.getTimestamp());
+
+ event.getIn().setBody(jpa);
+ } else {
+ event.getIn().setBody(msg);
+ }
+
+ // marker property to indicate its a tracing event being routed in case
+ // new Exchange instances is created during trace routing so we can check
+ // for this marker when interceptor also kick in during routing of trace events
+ event.setProperty(Exchange.TRACE_EVENT, Boolean.TRUE);
+ try {
+ // process the trace route
+ getTraceEventProducer(exchange).process(event);
+ } catch (Exception e) {
+ // log and ignore this as the original Exchange should be allowed to continue
+ LOG.error("Error processing trace event (original Exchange will continue): " + event, e);
+ }
+ }
+ }
+
+ @Override
+ public Object traceExchangeIn(ProcessorDefinition node, Processor target, TraceInterceptor traceInterceptor, Exchange exchange) throws Exception {
+ traceExchange(node, target, traceInterceptor, exchange);
+ return null;
+ }
+
+ @Override
+ public void traceExchangeOut(ProcessorDefinition node, Processor target, TraceInterceptor traceInterceptor, Exchange exchange, Object traceState) throws Exception {
+ traceExchange(node, target, traceInterceptor, exchange);
+ }
+
+ @Override
+ public void start() throws Exception {
+ traceEventProducer = null;
+ }
+
+ @Override
+ public void stop() throws Exception {
+ if (traceEventProducer != null) {
+ ServiceHelper.stopService(traceEventProducer);
+ }
+ }
+
+}
Modified: camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceInterceptor.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceInterceptor.java?rev=1180079&r1=1180078&r2=1180079&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceInterceptor.java (original)
+++ camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceInterceptor.java Fri Oct 7 15:33:53 2011
@@ -16,17 +16,12 @@
*/
package org.apache.camel.processor.interceptor;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
import org.apache.camel.AsyncCallback;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.impl.AggregateRouteNode;
-import org.apache.camel.impl.DefaultExchange;
import org.apache.camel.impl.DefaultRouteNode;
import org.apache.camel.impl.DoCatchRouteNode;
import org.apache.camel.impl.DoFinallyRouteNode;
@@ -46,8 +41,6 @@ import org.apache.camel.spi.ExchangeForm
import org.apache.camel.spi.InterceptStrategy;
import org.apache.camel.spi.RouteContext;
import org.apache.camel.spi.TracedRouteNodes;
-import org.apache.camel.util.IntrospectionSupport;
-import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.ServiceHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -65,10 +58,8 @@ public class TraceInterceptor extends De
private final ProcessorDefinition node;
private final Tracer tracer;
private TraceFormatter formatter;
- private Class<?> jpaTraceEventMessageClass;
private RouteContext routeContext;
private TraceEventHandler traceHandler;
- private String jpaTraceEventMessageClassName;
public TraceInterceptor(ProcessorDefinition node, Processor target, TraceFormatter formatter, Tracer tracer) {
super(target);
@@ -79,8 +70,8 @@ public class TraceInterceptor extends De
if (tracer.getFormatter() != null) {
this.formatter = tracer.getFormatter();
}
- this.traceHandler = tracer.getTraceHandler();
- this.jpaTraceEventMessageClassName = tracer.getJpaTraceEventMessageClassName();
+ this.traceHandler = tracer.getTraceHandler() != null ? tracer.getTraceHandler()
+ : new DefaultTraceEventHandler(tracer);
}
@Override
@@ -305,84 +296,15 @@ public class TraceInterceptor extends De
}
protected void traceExchange(Exchange exchange) throws Exception {
- if (traceHandler != null) {
- traceHandler.traceExchange(node, processor, this, exchange);
- } else if (tracer.getDestination() != null || tracer.getDestinationUri() != null) {
-
- // create event exchange and add event information
- Date timestamp = new Date();
- Exchange event = new DefaultExchange(exchange);
- event.setProperty(Exchange.TRACE_EVENT_NODE_ID, node.getId());
- event.setProperty(Exchange.TRACE_EVENT_TIMESTAMP, timestamp);
- // keep a reference to the original exchange in case its needed
- event.setProperty(Exchange.TRACE_EVENT_EXCHANGE, exchange);
-
- // create event message to sent as in body containing event information such as
- // from node, to node, etc.
- TraceEventMessage msg = new DefaultTraceEventMessage(timestamp, node, exchange);
-
- // should we use ordinary or jpa objects
- if (tracer.isUseJpa()) {
- if (LOG.isTraceEnabled()) {
- LOG.trace("Using class: " + this.jpaTraceEventMessageClassName + " for tracing event messages");
- }
-
- // load the jpa event message class
- loadJpaTraceEventMessageClass(exchange);
- // create a new instance of the event message class
- Object jpa = ObjectHelper.newInstance(jpaTraceEventMessageClass);
-
- // copy options from event to jpa
- Map<String, Object> options = new HashMap<String, Object>();
- IntrospectionSupport.getProperties(msg, options, null);
- IntrospectionSupport.setProperties(jpa, options);
- // and set the timestamp as its not a String type
- IntrospectionSupport.setProperty(jpa, "timestamp", msg.getTimestamp());
-
- event.getIn().setBody(jpa);
- } else {
- event.getIn().setBody(msg);
- }
-
- // marker property to indicate its a tracing event being routed in case
- // new Exchange instances is created during trace routing so we can check
- // for this marker when interceptor also kick in during routing of trace events
- event.setProperty(Exchange.TRACE_EVENT, Boolean.TRUE);
- try {
- // process the trace route
- getTraceEventProducer(exchange).process(event);
- } catch (Exception e) {
- // log and ignore this as the original Exchange should be allowed to continue
- LOG.error("Error processing trace event (original Exchange will continue): " + event, e);
- }
- }
- }
-
- private synchronized void loadJpaTraceEventMessageClass(Exchange exchange) {
- if (jpaTraceEventMessageClass == null) {
- jpaTraceEventMessageClass = exchange.getContext().getClassResolver().resolveClass(jpaTraceEventMessageClassName);
- if (jpaTraceEventMessageClass == null) {
- throw new IllegalArgumentException("Cannot find class: " + jpaTraceEventMessageClassName
- + ". Make sure camel-jpa.jar is in the classpath.");
- }
- }
+ traceHandler.traceExchange(node, processor, this, exchange);
}
protected Object traceExchangeIn(Exchange exchange) throws Exception {
- if (traceHandler != null) {
- return traceHandler.traceExchangeIn(node, processor, this, exchange);
- } else {
- traceExchange(exchange);
- }
- return null;
+ return traceHandler.traceExchangeIn(node, processor, this, exchange);
}
protected void traceExchangeOut(Exchange exchange, Object traceState) throws Exception {
- if (traceHandler != null) {
- traceHandler.traceExchangeOut(node, processor, this, exchange, traceState);
- } else {
- traceExchange(exchange);
- }
+ traceHandler.traceExchangeOut(node, processor, this, exchange, traceState);
}
protected void logException(Exchange exchange, Throwable throwable) {
@@ -429,16 +351,6 @@ public class TraceInterceptor extends De
return true;
}
- private synchronized Producer getTraceEventProducer(Exchange exchange) throws Exception {
- if (traceEventProducer == null) {
- // create producer when we have access the the camel context (we dont in doStart)
- Endpoint endpoint = tracer.getDestination() != null ? tracer.getDestination() : exchange.getContext().getEndpoint(tracer.getDestinationUri());
- traceEventProducer = endpoint.createProducer();
- ServiceHelper.startService(traceEventProducer);
- }
- return traceEventProducer;
- }
-
@Override
protected void doStart() throws Exception {
super.doStart();