camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jans...@apache.org
Subject svn commit: r933053 - in /camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources: META-INF/maven/ archetype-resources/src/main/java/
Date Mon, 12 Apr 2010 00:13:32 GMT
Author: janstey
Date: Mon Apr 12 00:13:32 2010
New Revision: 933053

URL: http://svn.apache.org/viewvc?rev=933053&view=rev
Log:
fixed up Camel component archetype - generated projects were not even compiling

Added:
    camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectConsumer.java
  (with props)
Modified:
    camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/META-INF/maven/archetype.xml
    camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectComponent.java
    camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectEndpoint.java
    camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectProducer.java

Modified: camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/META-INF/maven/archetype.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/META-INF/maven/archetype.xml?rev=933053&r1=933052&r2=933053&view=diff
==============================================================================
--- camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/META-INF/maven/archetype.xml
(original)
+++ camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/META-INF/maven/archetype.xml
Mon Apr 12 00:13:32 2010
@@ -21,6 +21,7 @@
   <id>camel-component</id>  
   <sources>
     <source>src/main/java/DirectComponent.java</source>
+    <source>src/main/java/DirectConsumer.java</source>         
     <source>src/main/java/DirectEndpoint.java</source>
     <source>src/main/java/DirectProducer.java</source>         
   </sources>

Modified: camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectComponent.java?rev=933053&r1=933052&r2=933053&view=diff
==============================================================================
--- camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectComponent.java
(original)
+++ camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectComponent.java
Mon Apr 12 00:13:32 2010
@@ -16,17 +16,16 @@
  */
 package ${packageName};
 
+import java.util.Map;
+
 import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
 import org.apache.camel.impl.DefaultComponent;
 
-import java.util.Map;
-
 /**
  * Represents the component that manages {@link DirectEndpoint}. It holds the
  * list of named direct endpoints.
  *
- * @version
+ * @version $Revision$
  */
 public class DirectComponent extends DefaultComponent {
 

Added: camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectConsumer.java?rev=933053&view=auto
==============================================================================
--- camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectConsumer.java
(added)
+++ camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectConsumer.java
Mon Apr 12 00:13:32 2010
@@ -0,0 +1,68 @@
+/**
+ * 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 ${packageName};
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Processor;
+import org.apache.camel.ShutdownRunningTask;
+import org.apache.camel.impl.DefaultConsumer;
+import org.apache.camel.spi.ShutdownAware;
+
+/**
+ * The direct consumer.
+ *
+ * @version $Revision$
+ */
+public class DirectConsumer extends DefaultConsumer implements ShutdownAware {
+
+    private DirectEndpoint endpoint;
+
+    public DirectConsumer(Endpoint endpoint, Processor processor) {
+        super(endpoint, processor);
+        this.endpoint = (DirectEndpoint) endpoint;
+    }
+
+    @Override
+    public void start() throws Exception {
+        // only add as consumer if not already registered
+        if (!endpoint.getConsumers().contains(this)) {
+            if (!endpoint.getConsumers().isEmpty()) {
+                throw new IllegalStateException("Endpoint " + endpoint.getEndpointUri() +
" only allows 1 active consumer but you attempted to start a 2nd consumer.");
+            }
+            endpoint.getConsumers().add(this);
+        }
+        super.start();
+    }
+
+    @Override
+    public void stop() throws Exception {
+        super.stop();
+        endpoint.getConsumers().remove(this);
+    }
+
+    public boolean deferShutdown(ShutdownRunningTask shutdownRunningTask) {
+        // deny stopping on shutdown as we want direct consumers to run in case some other
queues
+        // depend on this consumer to run, so it can complete its exchanges
+        return true;
+    }
+
+    public int getPendingExchangesSize() {
+        // return 0 as we do not have an internal memory queue with a variable size
+        // of inflight messages. 
+        return 0;
+    }
+}

Propchange: camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectConsumer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectEndpoint.java?rev=933053&r1=933052&r2=933053&view=diff
==============================================================================
--- camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectEndpoint.java
(original)
+++ camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectEndpoint.java
Mon Apr 12 00:13:32 2010
@@ -20,60 +20,37 @@ import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.apache.camel.Consumer;
-import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.impl.DefaultConsumer;
 import org.apache.camel.impl.DefaultEndpoint;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 /**
  * Represents a direct endpoint that synchronously invokes the consumers of the
  * endpoint when a producer sends a message to it.
- * 
- * @version 
+ *
+ * @version $Revision$
  */
 public class DirectEndpoint extends DefaultEndpoint {
-    private static final Log LOG = LogFactory.getLog(DirectEndpoint.class);
-
     private final CopyOnWriteArrayList<DefaultConsumer> consumers = new CopyOnWriteArrayList<DefaultConsumer>();
-    boolean allowMultipleConsumers = true;
+
+    public DirectEndpoint() {
+    }
 
     public DirectEndpoint(String uri, DirectComponent component) {
         super(uri, component);
     }
 
+    public DirectEndpoint(String endpointUri) {
+        super(endpointUri);
+    }
+
     public Producer createProducer() throws Exception {
         return new DirectProducer(this);
     }
 
     public Consumer createConsumer(Processor processor) throws Exception {
-        return new DefaultConsumer(this, processor) {
-            @Override
-            public void start() throws Exception {
-                if (!allowMultipleConsumers && !consumers.isEmpty()) {
-                    throw new IllegalStateException("Endpoint " + getEndpointUri() + " only
allows 1 active consumer but you attempted to start a 2nd consumer.");
-                }
-
-                consumers.add(this);
-                super.start();
-            }
-
-            @Override
-            public void stop() throws Exception {
-                super.stop();
-                consumers.remove(this);
-            }
-        };
-    }
-
-    public boolean isAllowMultipleConsumers() {
-        return allowMultipleConsumers;
-    }
-
-    public void setAllowMultipleConsumers(boolean allowMutlipleConsumers) {
-        this.allowMultipleConsumers = allowMutlipleConsumers;
+        return new DirectConsumer(this, processor);
     }
 
     public boolean isSingleton() {

Modified: camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectProducer.java?rev=933053&r1=933052&r2=933053&view=diff
==============================================================================
--- camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectProducer.java
(original)
+++ camel/trunk/tooling/archetypes/camel-archetype-component/src/main/resources/archetype-resources/src/main/java/DirectProducer.java
Mon Apr 12 00:13:32 2010
@@ -1,5 +1,4 @@
 /**
- *
  * 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.
@@ -7,7 +6,7 @@
  * (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
+ *      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,
@@ -17,19 +16,19 @@
  */
 package ${packageName};
 
-import org.apache.camel.AsyncCallback;
-import org.apache.camel.AsyncProcessor;
 import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
 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 $
+ * The direct producer.
+ *
+ * @version $Revision$
  */
-public class DirectProducer extends DefaultProducer implements AsyncProcessor {
+public class DirectProducer extends DefaultProducer implements Processor {
     private static final transient Log LOG = LogFactory.getLog(DirectProducer.class);
     private DirectEndpoint endpoint;
 
@@ -40,40 +39,12 @@ public class DirectProducer extends Defa
 
     public void process(Exchange exchange) throws Exception {
         if (endpoint.getConsumers().isEmpty()) {
-            LOG.warn("No getConsumers() available on " + this + " for " + exchange);
-        }
-        else {
+            LOG.warn("No consumers available on endpoint: " + endpoint + " to process: "
+ exchange);
+        } else {
             for (DefaultConsumer 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 consumer : endpoint.getConsumers()) {
-                        consumer.getProcessor().process(exchange);
-                    }
-                }
-                catch (Throwable error) {
-                    exchange.setException(error);
-                }
-            }
-            else {
-                for (DefaultConsumer consumer : endpoint.getConsumers()) {
-                    AsyncProcessor processor = AsyncProcessorTypeConverter.convert(consumer.getProcessor());
-                    return processor.process(exchange, callback);
-                }
-            }
-        }
-        callback.done(true);
-        return true;
-    }
 }



Mime
View raw message