camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1413313 - in /camel/branches/camel-2.10.x: ./ camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/test/java/org/apache/camel/impl/
Date Sun, 25 Nov 2012 10:05:10 GMT
Author: davsclaus
Date: Sun Nov 25 10:05:09 2012
New Revision: 1413313

URL: http://svn.apache.org/viewvc?rev=1413313&view=rev
Log:
CAMEL-5812: Added getCamelContext method to producer and consumer templates.

Modified:
    camel/branches/camel-2.10.x/   (props changed)
    camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/ConsumerTemplate.java
    camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java
    camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultConsumerTemplate.java
    camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
    camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/impl/DefaultConsumerTemplateTest.java
    camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateTest.java

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1413312

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/ConsumerTemplate.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/ConsumerTemplate.java?rev=1413313&r1=1413312&r2=1413313&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/ConsumerTemplate.java
(original)
+++ camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/ConsumerTemplate.java
Sun Nov 25 10:05:09 2012
@@ -50,6 +50,13 @@ package org.apache.camel;
  */
 public interface ConsumerTemplate extends Service {
 
+    /**
+     * Get the {@link CamelContext}
+     *
+     * @return camelContext the Camel context
+     */
+    CamelContext getCamelContext();
+
     // Configuration methods
     // -----------------------------------------------------------------------
 

Modified: camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java?rev=1413313&r1=1413312&r2=1413313&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java
(original)
+++ camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java
Sun Nov 25 10:05:09 2012
@@ -60,6 +60,13 @@ import org.apache.camel.spi.Synchronizat
  */
 public interface ProducerTemplate extends Service {
 
+    /**
+     * Get the {@link CamelContext}
+     *
+     * @return camelContext the Camel context
+     */
+    CamelContext getCamelContext();
+
     // Configuration methods
     // -----------------------------------------------------------------------
 

Modified: camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultConsumerTemplate.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultConsumerTemplate.java?rev=1413313&r1=1413312&r2=1413313&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultConsumerTemplate.java
(original)
+++ camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultConsumerTemplate.java
Sun Nov 25 10:05:09 2012
@@ -42,12 +42,12 @@ import static org.apache.camel.util.Obje
 public class DefaultConsumerTemplate extends ServiceSupport implements ConsumerTemplate {
 
     private static final transient Logger LOG = LoggerFactory.getLogger(DefaultConsumerTemplate.class);
-    private final CamelContext context;
+    private final CamelContext camelContext;
     private ConsumerCache consumerCache;
     private int maximumCacheSize;
 
-    public DefaultConsumerTemplate(CamelContext context) {
-        this.context = context;
+    public DefaultConsumerTemplate(CamelContext camelContext) {
+        this.camelContext = camelContext;
     }
 
     public int getMaximumCacheSize() {
@@ -65,8 +65,16 @@ public class DefaultConsumerTemplate ext
         return consumerCache.size();
     }
 
+    /**
+     * @deprecated use {@link #getCamelContext()}
+     */
+    @Deprecated
+    public CamelContext getContext() {
+        return getCamelContext();
+    }
+
     public CamelContext getCamelContext() {
-        return context;
+        return camelContext;
     }
 
     public Exchange receive(String endpointUri) {
@@ -147,7 +155,7 @@ public class DefaultConsumerTemplate ext
         Exchange exchange = receive(endpointUri);
         try {
             answer = extractResultBody(exchange);
-            answer = context.getTypeConverter().convertTo(type, answer);
+            answer = camelContext.getTypeConverter().convertTo(type, answer);
         } finally {
             doneUoW(exchange);
         }
@@ -164,7 +172,7 @@ public class DefaultConsumerTemplate ext
         Exchange exchange = receive(endpointUri, timeout);
         try {
             answer = extractResultBody(exchange);
-            answer = context.getTypeConverter().convertTo(type, answer);
+            answer = camelContext.getTypeConverter().convertTo(type, answer);
         } finally {
             doneUoW(exchange);
         }
@@ -181,7 +189,7 @@ public class DefaultConsumerTemplate ext
         Exchange exchange = receiveNoWait(endpointUri);
         try {
             answer = extractResultBody(exchange);
-            answer = context.getTypeConverter().convertTo(type, answer);
+            answer = camelContext.getTypeConverter().convertTo(type, answer);
         } finally {
             doneUoW(exchange);
         }
@@ -213,7 +221,7 @@ public class DefaultConsumerTemplate ext
     }
 
     protected Endpoint resolveMandatoryEndpoint(String endpointUri) {
-        return CamelContextHelper.getMandatoryEndpoint(context, endpointUri);
+        return CamelContextHelper.getMandatoryEndpoint(camelContext, endpointUri);
     }
 
     /**
@@ -255,9 +263,9 @@ public class DefaultConsumerTemplate ext
     protected void doStart() throws Exception {
         if (consumerCache == null) {
             if (maximumCacheSize > 0) {
-                consumerCache = new ConsumerCache(this, context, maximumCacheSize);
+                consumerCache = new ConsumerCache(this, camelContext, maximumCacheSize);
             } else {
-                consumerCache = new ConsumerCache(this, context);
+                consumerCache = new ConsumerCache(this, camelContext);
             }
         }
         ServiceHelper.startService(consumerCache);

Modified: camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java?rev=1413313&r1=1413312&r2=1413313&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
(original)
+++ camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
Sun Nov 25 10:05:09 2012
@@ -47,23 +47,23 @@ import org.apache.camel.util.ServiceHelp
  * @version 
  */
 public class DefaultProducerTemplate extends ServiceSupport implements ProducerTemplate {
-    private final CamelContext context;
+    private final CamelContext camelContext;
     private volatile ProducerCache producerCache;
     private volatile ExecutorService executor;
     private Endpoint defaultEndpoint;
     private int maximumCacheSize;
 
-    public DefaultProducerTemplate(CamelContext context) {
-        this.context = context;
+    public DefaultProducerTemplate(CamelContext camelContext) {
+        this.camelContext = camelContext;
     }
 
-    public DefaultProducerTemplate(CamelContext context, ExecutorService executor) {
-        this.context = context;
+    public DefaultProducerTemplate(CamelContext camelContext, ExecutorService executor) {
+        this.camelContext = camelContext;
         this.executor = executor;
     }
 
-    public DefaultProducerTemplate(CamelContext context, Endpoint defaultEndpoint) {
-        this(context);
+    public DefaultProducerTemplate(CamelContext camelContext, Endpoint defaultEndpoint) {
+        this(camelContext);
         this.defaultEndpoint = defaultEndpoint;
     }
 
@@ -302,37 +302,37 @@ public class DefaultProducerTemplate ext
 
     public <T> T requestBody(Object body, Class<T> type) {
         Object answer = requestBody(body);
-        return context.getTypeConverter().convertTo(type, answer);
+        return camelContext.getTypeConverter().convertTo(type, answer);
     }
 
     public <T> T requestBody(Endpoint endpoint, Object body, Class<T> type) {
         Object answer = requestBody(endpoint, body);
-        return context.getTypeConverter().convertTo(type, answer);
+        return camelContext.getTypeConverter().convertTo(type, answer);
     }
 
     public <T> T requestBody(String endpointUri, Object body, Class<T> type)
{
         Object answer = requestBody(endpointUri, body);
-        return context.getTypeConverter().convertTo(type, answer);
+        return camelContext.getTypeConverter().convertTo(type, answer);
     }
 
     public <T> T requestBodyAndHeader(Endpoint endpoint, Object body, String header,
Object headerValue, Class<T> type) {
         Object answer = requestBodyAndHeader(endpoint, body, header, headerValue);
-        return context.getTypeConverter().convertTo(type, answer);
+        return camelContext.getTypeConverter().convertTo(type, answer);
     }
 
     public <T> T requestBodyAndHeader(String endpointUri, Object body, String header,
Object headerValue, Class<T> type) {
         Object answer = requestBodyAndHeader(endpointUri, body, header, headerValue);
-        return context.getTypeConverter().convertTo(type, answer);
+        return camelContext.getTypeConverter().convertTo(type, answer);
     }
 
     public <T> T requestBodyAndHeaders(String endpointUri, Object body, Map<String,
Object> headers, Class<T> type) {
         Object answer = requestBodyAndHeaders(endpointUri, body, headers);
-        return context.getTypeConverter().convertTo(type, answer);
+        return camelContext.getTypeConverter().convertTo(type, answer);
     }
 
     public <T> T requestBodyAndHeaders(Endpoint endpoint, Object body, Map<String,
Object> headers, Class<T> type) {
         Object answer = requestBodyAndHeaders(endpoint, body, headers);
-        return context.getTypeConverter().convertTo(type, answer);
+        return camelContext.getTypeConverter().convertTo(type, answer);
     }
 
     // Methods using the default endpoint
@@ -365,8 +365,16 @@ public class DefaultProducerTemplate ext
     // Properties
     // -----------------------------------------------------------------------
 
+    /**
+     * @deprecated use {@link #getCamelContext()}
+     */
+    @Deprecated
     public CamelContext getContext() {
-        return context;
+        return getCamelContext();
+    }
+
+    public CamelContext getCamelContext() {
+        return camelContext;
     }
 
     public Endpoint getDefaultEndpoint() {
@@ -381,11 +389,15 @@ public class DefaultProducerTemplate ext
      * Sets the default endpoint to use if none is specified
      */
     public void setDefaultEndpointUri(String endpointUri) {
-        setDefaultEndpoint(getContext().getEndpoint(endpointUri));
+        setDefaultEndpoint(getCamelContext().getEndpoint(endpointUri));
     }
 
+    /**
+     * @deprecated use {@link CamelContext#getEndpoint(String, Class)}
+     */
+    @Deprecated
     public <T extends Endpoint> T getResolvedEndpoint(String endpointUri, Class<T>
expectedClass) {
-        return context.getEndpoint(endpointUri, expectedClass);
+        return camelContext.getEndpoint(endpointUri, expectedClass);
     }
 
     // Implementation methods
@@ -421,7 +433,7 @@ public class DefaultProducerTemplate ext
     }
 
     protected Endpoint resolveMandatoryEndpoint(String endpointUri) {
-        Endpoint endpoint = context.getEndpoint(endpointUri);
+        Endpoint endpoint = camelContext.getEndpoint(endpointUri);
         if (endpoint == null) {
             throw new NoSuchEndpointException(endpointUri);
         }
@@ -483,11 +495,11 @@ public class DefaultProducerTemplate ext
     }
 
     public <T> T extractFutureBody(Future<Object> future, Class<T> type)
{
-        return ExchangeHelper.extractFutureBody(context, future, type);
+        return ExchangeHelper.extractFutureBody(camelContext, future, type);
     }
 
     public <T> T extractFutureBody(Future<Object> future, long timeout, TimeUnit
unit, Class<T> type) throws TimeoutException {
-        return ExchangeHelper.extractFutureBody(context, future, timeout, unit, type);
+        return ExchangeHelper.extractFutureBody(camelContext, future, timeout, unit, type);
     }
 
     public Future<Object> asyncCallbackSendBody(String uri, Object body, Synchronization
onCompletion) {
@@ -691,7 +703,7 @@ public class DefaultProducerTemplate ext
             if (executor != null) {
                 return executor;
             }
-            executor = context.getExecutorServiceManager().newDefaultThreadPool(this, "ProducerTemplate");
+            executor = camelContext.getExecutorServiceManager().newDefaultThreadPool(this,
"ProducerTemplate");
         }
 
         ObjectHelper.notNull(executor, "ExecutorService");
@@ -701,9 +713,9 @@ public class DefaultProducerTemplate ext
     protected void doStart() throws Exception {
         if (producerCache == null) {
             if (maximumCacheSize > 0) {
-                producerCache = new ProducerCache(this, context, maximumCacheSize);
+                producerCache = new ProducerCache(this, camelContext, maximumCacheSize);
             } else {
-                producerCache = new ProducerCache(this, context);
+                producerCache = new ProducerCache(this, camelContext);
             }
         }
         ServiceHelper.startService(producerCache);
@@ -714,7 +726,7 @@ public class DefaultProducerTemplate ext
         producerCache = null;
 
         if (executor != null) {
-            context.getExecutorServiceManager().shutdownNow(executor);
+            camelContext.getExecutorServiceManager().shutdownNow(executor);
             executor = null;
         }
     }

Modified: camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/impl/DefaultConsumerTemplateTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/impl/DefaultConsumerTemplateTest.java?rev=1413313&r1=1413312&r2=1413313&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/impl/DefaultConsumerTemplateTest.java
(original)
+++ camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/impl/DefaultConsumerTemplateTest.java
Sun Nov 25 10:05:09 2012
@@ -50,6 +50,8 @@ public class DefaultConsumerTemplateTest
         Exchange out = consumer.receive("seda:foo");
         assertNotNull(out);
         assertEquals("Hello", out.getIn().getBody());
+
+        assertSame(context, consumer.getCamelContext());
     }
 
     public void testConsumeTwiceReceive() throws Exception {

Modified: camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateTest.java?rev=1413313&r1=1413312&r2=1413313&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateTest.java
(original)
+++ camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateTest.java
Sun Nov 25 10:05:09 2012
@@ -43,6 +43,8 @@ public class DefaultProducerTemplateTest
         assertMockEndpointsSatisfied();
 
         assertEquals("Bye World", result);
+
+        assertSame(context, template.getCamelContext());
     }
 
     public void testInOut() throws Exception {



Mime
View raw message