You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2007/04/20 18:07:46 UTC

svn commit: r530840 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/builder/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/processor/ camel-core/src/main/java/org/apache/camel/spi/ camel...

Author: chirino
Date: Fri Apr 20 09:07:45 2007
New Revision: 530840

URL: http://svn.apache.org/viewvc?view=rev&rev=530840
Log:
Renamed Interceptor to Policy

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/NoPolicy.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Policy.java
    activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringTransactionPolicy.java
Removed:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/NoInterceptor.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Interceptor.java
    activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringTransactionInterceptor.java
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DelegateProcessor.java
    activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringRouteBuilder.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java?view=diff&rev=530840&r1=530839&r2=530840
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java Fri Apr 20 09:07:45 2007
@@ -326,7 +326,7 @@
      * A strategy method which allows transaction interceptors to be applied to a processor
      */
     protected Processor<E> wrapInTransactionInterceptor(Processor<E> processor) throws Exception {
-        return getBuilder().getTransactionInterceptor().addIntercetors(processor);
+        return getBuilder().getTransactionPolicy().wrap(processor);
     }
 
     /**

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java?view=diff&rev=530840&r1=530839&r2=530840
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java Fri Apr 20 09:07:45 2007
@@ -29,11 +29,11 @@
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.util.FactoryFinder;
 import org.apache.camel.util.NoFactoryAvailableException;
-import org.apache.camel.spi.Interceptor;
+import org.apache.camel.spi.Policy;
 import org.apache.camel.spi.Injector;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.ReflectionInjector;
-import org.apache.camel.impl.NoInterceptor;
+import org.apache.camel.impl.NoPolicy;
 
 /**
  * A <a href="http://activemq.apache.org/camel/dsl.html">Java DSL</a>
@@ -45,7 +45,7 @@
     private List<FromBuilder<E>> fromBuilders = new ArrayList<FromBuilder<E>>();
     private AtomicBoolean initalized = new AtomicBoolean(false);
     private List<Route<E>> routes = new ArrayList<Route<E>>();
-    private Interceptor<E> transactionInterceptor;
+    private Policy<E> transactionPolicy;
 
     protected RouteBuilder() {
         this(null);
@@ -100,8 +100,8 @@
      * @param interceptor the transaction interceptor to use
      * @return the current builder
      */
-    public RouteBuilder<E> transactionInterceptor(Interceptor<E> interceptor) {
-        setTransactionInterceptor(interceptor);
+    public RouteBuilder<E> transactionPolicy(Policy<E> interceptor) {
+        setTransactionPolicy(interceptor);
         return this;
     }
 
@@ -132,18 +132,18 @@
         return fromBuilders;
     }
 
-    public Interceptor<E> getTransactionInterceptor() throws Exception {
-        if (transactionInterceptor == null) {
-            transactionInterceptor = createTransactionInterceptor();
+    public Policy<E> getTransactionPolicy() throws Exception {
+        if (transactionPolicy == null) {
+            transactionPolicy = createTransactionPolicy();
         }
-        return transactionInterceptor;
+        return transactionPolicy;
     }
 
     /**
      * Sets the interceptor used wrap processors in a transaction
      */
-    public void setTransactionInterceptor(Interceptor<E> transactionInterceptor) {
-        this.transactionInterceptor = transactionInterceptor;
+    public void setTransactionPolicy(Policy<E> transactionInterceptor) {
+        this.transactionPolicy = transactionInterceptor;
     }
 
     // Implementation methods
@@ -188,14 +188,14 @@
     /**
      * Factory method
      */
-    protected Interceptor<E> createTransactionInterceptor() throws Exception {
+    protected Policy<E> createTransactionPolicy() throws Exception {
         FactoryFinder finder = new FactoryFinder();
         try {
-            return (Interceptor<E>) finder.newInstance("TransactionInterceptor", getContext().getInjector());
+            return (Policy<E>) finder.newInstance("TransactionPolicy", getContext().getInjector());
         }
         catch (NoFactoryAvailableException e) {
             // lets use the default
-            return new NoInterceptor<E>();
+            return new NoPolicy<E>();
         }
     }
 

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/NoPolicy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/NoPolicy.java?view=auto&rev=530840
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/NoPolicy.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/NoPolicy.java Fri Apr 20 09:07:45 2007
@@ -0,0 +1,33 @@
+/**
+ *
+ * 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.spi.Policy;
+import org.apache.camel.Processor;
+
+/**
+ * Represents an {@link Policy} which adds no interceptors.
+ *
+ * @version $Revision: 1.1 $
+ */
+public class NoPolicy<E> implements Policy<E> {
+
+    public Processor<E> wrap(Processor<E> processor) {
+        return processor;
+    }
+}

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DelegateProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DelegateProcessor.java?view=diff&rev=530840&r1=530839&r2=530840
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DelegateProcessor.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DelegateProcessor.java Fri Apr 20 09:07:45 2007
@@ -18,13 +18,13 @@
 package org.apache.camel.processor;
 
 import org.apache.camel.Processor;
-import org.apache.camel.spi.Interceptor;
+import org.apache.camel.spi.Policy;
 import org.apache.camel.impl.ServiceSupport;
 import org.apache.camel.util.ServiceHelper;
 
 /**
  * A Delegate pattern which delegates processing to a nested processor which can be useful for implementation inheritence
- * when writing an {@link Interceptor}
+ * when writing an {@link Policy}
  *
  * @version $Revision: 519941 $
  */

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Policy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Policy.java?view=auto&rev=530840
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Policy.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Policy.java Fri Apr 20 09:07:45 2007
@@ -0,0 +1,37 @@
+/**
+ *
+ * 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.impl.ServiceSupport;
+import org.apache.camel.Processor;
+
+/**
+ * A strategy capable of applying interceptors to a processor
+ *
+ * @version $Revision: 1.1 $
+ */
+public interface Policy<E> {
+
+    /**
+     * Wraps any applicable interceptors around the given processor
+     *
+     * @param processor the processor to be intercepted
+     * @return either the original processor or a processor wrapped in one or more interceptors
+     */
+    Processor<E> wrap(Processor<E> processor);
+}

Modified: activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringRouteBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringRouteBuilder.java?view=diff&rev=530840&r1=530839&r2=530840
==============================================================================
--- activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringRouteBuilder.java (original)
+++ activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringRouteBuilder.java Fri Apr 20 09:07:45 2007
@@ -19,7 +19,7 @@
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
-import org.apache.camel.spring.spi.SpringTransactionInterceptor;
+import org.apache.camel.spring.spi.SpringTransactionPolicy;
 import org.apache.camel.builder.RouteBuilder;
 import org.springframework.context.ApplicationContext;
 import org.springframework.transaction.support.TransactionTemplate;
@@ -42,7 +42,7 @@
      */
     public SpringRouteBuilder<E> transactionInterceptor(String transactionTemplateName) {
         TransactionTemplate template = bean(TransactionTemplate.class, transactionTemplateName);
-        setTransactionInterceptor(new SpringTransactionInterceptor(template));
+        setTransactionPolicy(new SpringTransactionPolicy(template));
         return this;
     }
 

Added: activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringTransactionPolicy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringTransactionPolicy.java?view=auto&rev=530840
==============================================================================
--- activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringTransactionPolicy.java (added)
+++ activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringTransactionPolicy.java Fri Apr 20 09:07:45 2007
@@ -0,0 +1,77 @@
+/**
+ *
+ * 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.spring.spi;
+
+import org.apache.camel.Processor;
+import org.apache.camel.processor.DelegateProcessor;
+import org.apache.camel.spi.Policy;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.TransactionCallbackWithoutResult;
+import org.springframework.transaction.support.TransactionTemplate;
+
+/**
+ * Wraps the processor in a Spring transaction
+ *
+ * @version $Revision: 1.1 $
+ */
+public class SpringTransactionPolicy<E> implements Policy<E> {
+    private static final transient Log log = LogFactory.getLog(SpringTransactionPolicy.class);
+
+    private TransactionTemplate template;
+
+    public SpringTransactionPolicy() {
+    }
+
+    public SpringTransactionPolicy(TransactionTemplate template) {
+        this.template = template;
+    }
+
+    public Processor<E> wrap(Processor<E> processor) {
+        final TransactionTemplate transactionTemplate = getTemplate();
+        if (transactionTemplate == null) {
+            log.warn("No TransactionTemplate available so transactions will not be enabled!");
+            return processor;
+        }
+
+        return new DelegateProcessor<E>(processor) {
+
+            public void process(final E exchange) {
+                transactionTemplate.execute(new TransactionCallbackWithoutResult() {
+                    protected void doInTransactionWithoutResult(TransactionStatus status) {
+                        processNext(exchange);
+                    }
+                });
+            }
+
+            @Override
+            public String toString() {
+                return "SpringTransaction[" + getNext() + "]";
+            }
+        };
+    }
+
+    public TransactionTemplate getTemplate() {
+        return template;
+    }
+
+    public void setTemplate(TransactionTemplate template) {
+        this.template = template;
+    }
+}