Author: davsclaus
Date: Fri Apr 24 08:03:38 2009
New Revision: 768215

URL: http://svn.apache.org/viewvc?rev=768215&view=rev
Log:
CAMEL-1560: try .. catch .. finally does not reuse existing error handler as it 
handles exceptions itself. Removed not needed code anymore due CAMEL-1562.

Removed:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultErrorHandlerWrappingStrategy.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ErrorHandlerWrappingStrategy.java
Modified:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultLifecycleStrategy.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultLifecycleStrategy.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultLifecycleStrategy.java?rev=768215&r1=768214&r2=768215&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultLifecycleStrategy.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultLifecycleStrategy.java
 Fri Apr 24 08:03:38 2009
@@ -47,9 +47,7 @@
     }
 
     public void onRouteContextCreate(RouteContext routeContext) {
-        // set the error handler strategy containing the list of outputs added
-        // TODO: align this code with InstrumentationLifecycleStrategy
-        routeContext.setErrorHandlerWrappingStrategy(new 
DefaultErrorHandlerWrappingStrategy(routeContext));
+        // do nothing
     }
 
 }

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java?rev=768215&r1=768214&r2=768215&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
 Fri Apr 24 08:03:38 2009
@@ -37,7 +37,6 @@
 import org.apache.camel.processor.Pipeline;
 import org.apache.camel.processor.ProceedProcessor;
 import org.apache.camel.processor.UnitOfWorkProcessor;
-import org.apache.camel.spi.ErrorHandlerWrappingStrategy;
 import org.apache.camel.spi.InterceptStrategy;
 import org.apache.camel.spi.RouteContext;
 
@@ -55,7 +54,6 @@
     private Interceptor lastInterceptor;
     private CamelContext camelContext;
     private List<InterceptStrategy> interceptStrategies = new 
ArrayList<InterceptStrategy>();
-    private ErrorHandlerWrappingStrategy errorHandlerWrappingStrategy;
     private boolean routeAdded;
 
     public DefaultRouteContext(RouteDefinition route, FromDefinition from, 
Collection<Route> routes) {
@@ -184,14 +182,6 @@
         getInterceptStrategies().add(interceptStrategy);
     }
 
-    public ErrorHandlerWrappingStrategy getErrorHandlerWrappingStrategy() {
-        return errorHandlerWrappingStrategy;
-    }
-
-    public void setErrorHandlerWrappingStrategy(ErrorHandlerWrappingStrategy 
strategy) {
-        errorHandlerWrappingStrategy = strategy;
-    }
-
     public boolean isRouteAdded() {
         return routeAdded;
     }

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java?rev=768215&r1=768214&r2=768215&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
 Fri Apr 24 08:03:38 2009
@@ -30,7 +30,6 @@
 import org.apache.camel.Route;
 import org.apache.camel.Service;
 import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.camel.impl.DefaultErrorHandlerWrappingStrategy;
 import org.apache.camel.impl.ServiceSupport;
 import org.apache.camel.model.ProcessorDefinition;
 import org.apache.camel.model.RouteDefinition;
@@ -244,9 +243,8 @@
             }
         }
 
-        // TODO: align this code with DefaultLifecycleStrategy
+        // add intercept strategy that executes the JMX instrumentation for 
performance metrics
         routeContext.addInterceptStrategy(new 
InstrumentationInterceptStrategy(registeredCounters));
-        routeContext.setErrorHandlerWrappingStrategy(new 
DefaultErrorHandlerWrappingStrategy(routeContext));
 
         // Add an InstrumentationProcessor at the beginning of each route and
         // set up the interceptorMap for onRoutesAdd() method to register the

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java?rev=768215&r1=768214&r2=768215&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
 Fri Apr 24 08:03:38 2009
@@ -52,12 +52,10 @@
 import org.apache.camel.processor.aggregate.AggregationCollection;
 import org.apache.camel.processor.aggregate.AggregationStrategy;
 import org.apache.camel.spi.DataFormat;
-import org.apache.camel.spi.ErrorHandlerWrappingStrategy;
 import org.apache.camel.spi.IdempotentRepository;
 import org.apache.camel.spi.Policy;
 import org.apache.camel.spi.RouteContext;
 import org.apache.camel.spi.TransactedPolicy;
-import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import static org.apache.camel.builder.Builder.body;
@@ -89,6 +87,23 @@
         return createOutputsProcessor(routeContext, outputs);
     }
 
+    @SuppressWarnings("unchecked")
+    public void addOutput(ProcessorDefinition processorType) {
+        processorType.setParent(this);
+        configureChild(processorType);
+        if (blocks.isEmpty()) {
+            getOutputs().add(processorType);
+        } else {
+            Block block = blocks.getLast();
+            block.addOutput(processorType);
+        }
+    }
+
+    public void clearOutput() {
+        getOutputs().clear();
+        blocks.clear();
+    }
+
     public void addRoutes(RouteContext routeContext, Collection<Route> routes) 
throws Exception {
         Processor processor = makeProcessor(routeContext);
         if (!routeContext.isRouteAdded()) {
@@ -107,7 +122,7 @@
         return wrapChannel(routeContext, processor);
     }
 
-    private Processor wrapChannel(RouteContext routeContext, Processor 
processor) throws Exception {
+    protected Processor wrapChannel(RouteContext routeContext, Processor 
processor) throws Exception {
         // put a channel inbetween this and each output to control the route 
flow logic
         Channel channel = createChannel(routeContext);
         channel.setNextProcessor(processor);
@@ -120,14 +135,8 @@
         channel.initChannel(this, routeContext);
 
         // set the error handler, must be done after init as we can set the 
error handler as first in the chain
-        // skip error handlers in on exception and try .. catch .. finally 
routes
-        if (this instanceof OnExceptionDefinition) {
-            // also use error handler for on exception
-            Processor errorHandler = 
getErrorHandlerBuilder().createErrorHandler(routeContext, channel.getOutput());
-            channel.setErrorHandler(errorHandler);
-            return channel;
-        } else if (this instanceof TryDefinition || this instanceof 
CatchDefinition || this instanceof FinallyDefinition) {
-            // TODO: special error handler, where we have a local error 
handler with onlly the catch definitions
+        if (this instanceof TryDefinition || this instanceof CatchDefinition 
|| this instanceof FinallyDefinition) {
+            // do not use error handler for try .. catch .. finally blocks as 
it will handle errors itself
             return channel;
         } else {
             // regular definition so add the error handler
@@ -178,9 +187,26 @@
         return processor;
     }
 
-    public void clearOutput() {
-        getOutputs().clear();
-        blocks.clear();
+    /**
+     * Creates the processor and wraps it in any necessary interceptors and 
error handlers
+     */
+    protected Processor makeProcessor(RouteContext routeContext) throws 
Exception {
+        Processor processor = createProcessor(routeContext);
+        return wrapProcessor(routeContext, processor);
+    }
+
+    protected ErrorHandlerBuilder createErrorHandlerBuilder() {
+        if (errorHandlerRef != null) {
+            return new ErrorHandlerBuilderRef(errorHandlerRef);
+        }
+
+        // return a reference to the default error handler
+        return new 
ErrorHandlerBuilderRef(ErrorHandlerBuilderRef.DEFAULT_ERROR_HANDLER_BUILDER);
+    }
+
+    protected void configureChild(ProcessorDefinition output) {
+        output.setNodeFactory(getNodeFactory());
+        output.setErrorHandlerBuilder(getErrorHandlerBuilder());
     }
 
     // Fluent API
@@ -2008,55 +2034,5 @@
         return "";
     }
 
-    // Implementation methods
-    // 
-------------------------------------------------------------------------
-
-    /**
-     * Creates the processor and wraps it in any necessary interceptors and
-     * error handlers
-     */
-    protected Processor makeProcessor(RouteContext routeContext) throws 
Exception {
-        Processor processor = createProcessor(routeContext);
-        return wrapProcessor(routeContext, processor);
-    }
-
-    /**
-     * A strategy method to allow newly created processors to be wrapped in an
-     * error handler.
-     */
-    protected Processor wrapInErrorHandler(RouteContext routeContext, 
Processor target) throws Exception {
-        ObjectHelper.notNull(target, "target", this);
-        ErrorHandlerWrappingStrategy strategy = 
routeContext.getErrorHandlerWrappingStrategy();
-        if (strategy != null) {
-            return strategy.wrapProcessorInErrorHandler(this, target);
-        }
-        return getErrorHandlerBuilder().createErrorHandler(routeContext, 
target);
-    }
-
-    protected ErrorHandlerBuilder createErrorHandlerBuilder() {
-        if (errorHandlerRef != null) {
-            return new ErrorHandlerBuilderRef(errorHandlerRef);
-        }
-
-        // return a reference to the default error handler
-        return new 
ErrorHandlerBuilderRef(ErrorHandlerBuilderRef.DEFAULT_ERROR_HANDLER_BUILDER);
-    }
-
-    protected void configureChild(ProcessorDefinition output) {
-        output.setNodeFactory(getNodeFactory());
-        output.setErrorHandlerBuilder(getErrorHandlerBuilder());
-    }
-
-    @SuppressWarnings("unchecked")
-    public void addOutput(ProcessorDefinition processorType) {
-        processorType.setParent(this);
-        configureChild(processorType);
-        if (blocks.isEmpty()) {
-            getOutputs().add(processorType);
-        } else {
-            Block block = blocks.getLast();
-            block.addOutput(processorType);
-        }
-    }
 
 }

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java?rev=768215&r1=768214&r2=768215&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java
 Fri Apr 24 08:03:38 2009
@@ -99,7 +99,7 @@
 
     @Override
     protected void doStop() throws Exception {
-        ServiceHelper.startServices(output, errorHandler);
+        ServiceHelper.stopServices(output, errorHandler);
         super.doStop();
     }
 

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java?rev=768215&r1=768214&r2=768215&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java 
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java 
Fri Apr 24 08:03:38 2009
@@ -155,20 +155,6 @@
     void addInterceptStrategy(InterceptStrategy interceptStrategy);
 
     /**
-     * This method retrieves the ErrorHandlerWrappingStrategy.
-     *
-     * @return the strategy
-     */
-    ErrorHandlerWrappingStrategy getErrorHandlerWrappingStrategy();
-    
-    /**
-     * This method sets the ErrorHandlerWrappingStrategy.
-     *
-     * @param strategy the strategy
-     */
-    void setErrorHandlerWrappingStrategy(ErrorHandlerWrappingStrategy 
strategy);
-
-    /**
      * If this flag is true, {...@link 
ProcessorDefinition#addRoutes(RouteContext, java.util.Collection)}
      * will not add processor to addEventDrivenProcessor to the RouteContext 
and it
      * will prevent from adding an EventDrivenRoute.


Reply via email to