camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r595630 - in /activemq/camel/trunk/camel-core/src/main/java/org/apache/camel: component/direct/DirectEndpoint.java component/direct/DirectProducer.java impl/DefaultProducer.java
Date Fri, 16 Nov 2007 11:40:27 GMT
Author: jstrachan
Date: Fri Nov 16 03:40:16 2007
New Revision: 595630

URL: http://svn.apache.org/viewvc?rev=595630&view=rev
Log:
minor refactor to make the code easier to navigate and improved the toString() for DefaultProducer

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectProducer.java
  (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducer.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java?rev=595630&r1=595629&r2=595630&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java
Fri Nov 16 03:40:16 2007
@@ -16,22 +16,15 @@
  */
 package org.apache.camel.component.direct;
 
-import java.util.ArrayList;
+import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
 
-import org.apache.camel.AsyncCallback;
-import org.apache.camel.AsyncProcessor;
 import org.apache.camel.Consumer;
-import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
-import org.apache.camel.ExchangePattern;
 import org.apache.camel.impl.DefaultConsumer;
 import org.apache.camel.impl.DefaultEndpoint;
-import org.apache.camel.impl.DefaultExchange;
-import org.apache.camel.impl.DefaultProducer;
-import org.apache.camel.impl.converter.AsyncProcessorTypeConverter;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -42,59 +35,17 @@
  * @version $Revision: 519973 $
  */
 public class DirectEndpoint<E extends Exchange> extends DefaultEndpoint<E> {
-
-    private final class DirectProducer extends DefaultProducer implements AsyncProcessor
{
-        private DirectProducer(Endpoint endpoint) {
-            super(endpoint);
-        }
-
-        public void process(Exchange exchange) throws Exception {
-            if (consumers.isEmpty()) {
-                LOG.warn("No consumers available on " + this + " for " + exchange);
-            } else {
-                for (DefaultConsumer<E> consumer : consumers) {
-                    consumer.getProcessor().process(exchange);
-                }
-            }
-        }
-
-        public boolean process(Exchange exchange, AsyncCallback callback) {
-            int size = consumers.size();
-            if (size == 0) {
-                LOG.warn("No consumers available on " + this + " for " + exchange);
-            } else {
-                if (size > 1) {
-                    // Too hard to do multiple async.. do it sync
-                    try {
-                        for (DefaultConsumer<E> consumer : consumers) {
-                            consumer.getProcessor().process(exchange);
-                        }
-                    } catch (Throwable error) {
-                        exchange.setException(error);
-                    }
-                } else {
-                    for (DefaultConsumer<E> consumer : consumers) {
-                        AsyncProcessor processor = AsyncProcessorTypeConverter.convert(consumer.getProcessor());
-                        return processor.process(exchange, callback);
-                    }
-                }
-            }
-            callback.done(true);
-            return true;
-        }
-    }
-
     private static final Log LOG = LogFactory.getLog(DirectEndpoint.class);
 
-    boolean allowMultipleConsumers = true;
     private final CopyOnWriteArrayList<DefaultConsumer<E>> consumers = new CopyOnWriteArrayList<DefaultConsumer<E>>();
+    boolean allowMultipleConsumers = true;
 
     public DirectEndpoint(String uri, DirectComponent<E> component) {
         super(uri, component);
     }
 
     public Producer createProducer() throws Exception {
-        return new DirectProducer(this);
+        return new DirectProducer<E>(this);
     }
 
     public Consumer<E> createConsumer(Processor processor) throws Exception {
@@ -129,4 +80,7 @@
         return true;
     }
 
+    public List<DefaultConsumer<E>> getConsumers() {
+        return consumers;
+    }
 }

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectProducer.java?rev=595630&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectProducer.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectProducer.java
Fri Nov 16 03:40:16 2007
@@ -0,0 +1,79 @@
+/**
+ *
+ * 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.component.direct;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.AsyncProcessor;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultConsumer;
+import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.impl.converter.AsyncProcessorTypeConverter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class DirectProducer<E extends Exchange> extends DefaultProducer implements
AsyncProcessor {
+    private static final transient Log LOG = LogFactory.getLog(DirectProducer.class);
+    private DirectEndpoint<E> endpoint;
+
+    public DirectProducer(DirectEndpoint<E> endpoint) {
+        super(endpoint);
+        this.endpoint = endpoint;
+    }
+
+    public void process(Exchange exchange) throws Exception {
+        if (endpoint.getConsumers().isEmpty()) {
+            LOG.warn("No getConsumers() available on " + this + " for " + exchange);
+        }
+        else {
+            for (DefaultConsumer<E> consumer : endpoint.getConsumers()) {
+                consumer.getProcessor().process(exchange);
+            }
+        }
+    }
+
+    public boolean process(Exchange exchange, AsyncCallback callback) {
+        int size = endpoint.getConsumers().size();
+        if (size == 0) {
+            LOG.warn("No getConsumers() available on " + this + " for " + exchange);
+        }
+        else {
+            if (size > 1) {
+                // Too hard to do multiple async.. do it sync
+                try {
+                    for (DefaultConsumer<E> consumer : endpoint.getConsumers()) {
+                        consumer.getProcessor().process(exchange);
+                    }
+                }
+                catch (Throwable error) {
+                    exchange.setException(error);
+                }
+            }
+            else {
+                for (DefaultConsumer<E> consumer : endpoint.getConsumers()) {
+                    AsyncProcessor processor = AsyncProcessorTypeConverter.convert(consumer.getProcessor());
+                    return processor.process(exchange, callback);
+                }
+            }
+        }
+        callback.done(true);
+        return true;
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectProducer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducer.java?rev=595630&r1=595629&r2=595630&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducer.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducer.java
Fri Nov 16 03:40:16 2007
@@ -33,6 +33,11 @@
         this.endpoint = endpoint;
     }
 
+    @Override
+    public String toString() {
+        return "Producer[" + endpoint.getEndpointUri() + "]";
+    }
+
     public Endpoint<E> getEndpoint() {
         return endpoint;
     }



Mime
View raw message