Author: davsclaus
Date: Wed Dec 31 04:22:14 2008
New Revision: 730380

URL: http://svn.apache.org/viewvc?rev=730380&view=rev
Log:
CAMEL-1186: consumer. prefix can now be omitted for scheduled poll consumers 
such as File, FTP.

Modified:
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java
    
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentValidateURITest.java
    
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ScheduledPollConsumerTest.java

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java?rev=730380&r1=730379&r2=730380&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java
 Wed Dec 31 04:22:14 2008
@@ -31,18 +31,19 @@
  * 
  * @version $Revision$
  */
-public abstract class ScheduledPollConsumer extends DefaultConsumer implements
-    Runnable {
+public abstract class ScheduledPollConsumer extends DefaultConsumer implements 
Runnable {
     private static final transient Log LOG = 
LogFactory.getLog(ScheduledPollConsumer.class);
 
     private final ScheduledExecutorService executor;
+    private ScheduledFuture<?> future;
+    private Exception firstExceptionThrown;
+
+    // if adding more options then align with 
ScheduledPollEndpoint#configureScheduledPollConsumerProperties
     private long initialDelay = 1000;
     private long delay = 500;
     private TimeUnit timeUnit = TimeUnit.MILLISECONDS;
     private boolean useFixedDelay;
-    private ScheduledFuture<?> future;
-    private Exception firstExceptionThrown;
-    
+
     public ScheduledPollConsumer(DefaultEndpoint endpoint, Processor 
processor) {
         this(endpoint, processor, endpoint.getExecutorService());
     }

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java?rev=730380&r1=730379&r2=730380&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java
 Wed Dec 31 04:22:14 2008
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.impl;
 
+import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.camel.CamelContext;
@@ -58,7 +59,6 @@
 
     protected void configureConsumer(Consumer consumer) throws Exception {
         if (consumerProperties != null) {
-            // TODO pass in type converter
             
IntrospectionSupport.setProperties(getCamelContext().getTypeConverter(), 
consumer, consumerProperties);
             if (!this.isLenientProperties() && consumerProperties.size() > 0) {
                 throw new 
ResolveEndpointFailedException(this.getEndpointUri(), "There are " + 
consumerProperties.size()
@@ -74,6 +74,33 @@
         if (consumerProperties != null) {
             setConsumerProperties(consumerProperties);
         }
+        configureScheduledPollConsumerProperties(options, consumerProperties);
+    }
+
+    private void configureScheduledPollConsumerProperties(Map options, Map 
consumerProperties) {
+        // special for scheduled poll consumers as we want to allow end users 
to configure its options
+        // from the URI parameters without the consumer. prefix
+        Object initialDelay = options.remove("initialDelay");
+        Object delay = options.remove("delay");
+        Object timeUnit = options.remove("timeUnit");
+        Object useFixedDelay = options.remove("useFixedDelay");
+        if (initialDelay != null || delay != null || timeUnit != null || 
useFixedDelay != null) {
+            if (consumerProperties == null) {
+                consumerProperties = new HashMap();
+            }
+            if (initialDelay != null) {
+                consumerProperties.put("initialDelay", initialDelay);
+            }
+            if (delay != null) {
+                consumerProperties.put("delay", delay);
+            }
+            if (timeUnit != null) {
+                consumerProperties.put("timeUnit", timeUnit);
+            }
+            if (useFixedDelay != null) {
+                consumerProperties.put("useFixedDelay", useFixedDelay);
+            }
+        }
     }
 
 }

Modified: 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentValidateURITest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentValidateURITest.java?rev=730380&r1=730379&r2=730380&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentValidateURITest.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentValidateURITest.java
 Wed Dec 31 04:22:14 2008
@@ -56,5 +56,33 @@
             // ok
         }
     }
+    
+    public void testScheduledPollConsumerOptions() throws Exception {
+        // test that we support both notations of scheduled polling consumer 
options
+
+        // with consumer. prefix
+        Endpoint endpint = 
context.getEndpoint("file://target/foo?consumer.delay=1000");
+        assertNotNull(endpint);
+
+        endpint = 
context.getEndpoint("file://target/foo?consumer.delay=1000&consumer.initialDelay=5000");
+        assertNotNull(endpint);
+
+        endpint = 
context.getEndpoint("file://target/foo?consumer.delay=1000&consumer.initialDelay=5000&consumer.useFixedDelay=true");
+        assertNotNull(endpint);
+
+        // without consumer. prefix
+        endpint = context.getEndpoint("file://foo2?delay=1000");
+        assertNotNull(endpint);
+
+        endpint = 
context.getEndpoint("file://foo2?delay=1000&initialDelay=5000");
+        assertNotNull(endpint);
+
+        endpint = 
context.getEndpoint("file://foo2?delay=1000&initialDelay=5000&useFixedDelay=true");
+        assertNotNull(endpint);
+
+        // combined with and without consumer. prefix
+        endpint = 
context.getEndpoint("file://foo3?delay=1000&consumer.initialDelay=5000&useFixedDelay=true");
+        assertNotNull(endpint);
+    }
 
 }

Modified: 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ScheduledPollConsumerTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ScheduledPollConsumerTest.java?rev=730380&r1=730379&r2=730380&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ScheduledPollConsumerTest.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ScheduledPollConsumerTest.java
 Wed Dec 31 04:22:14 2008
@@ -14,12 +14,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.impl;
 
 import junit.framework.Assert;
 import org.apache.camel.ContextTestSupport;
-import org.apache.camel.Exchange;
 
 public class ScheduledPollConsumerTest extends ContextTestSupport {
     


Reply via email to