camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r620773 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/component/list/ main/java/org/apache/camel/component/seda/ main/java/org/apache/camel/util/ main/resources/META-INF/services/org/apache/camel/component/ test/java...
Date Tue, 12 Feb 2008 12:04:55 GMT
Author: jstrachan
Date: Tue Feb 12 04:04:41 2008
New Revision: 620773

URL: http://svn.apache.org/viewvc?rev=620773&view=rev
Log:
added a simple ListEndpoint for https://issues.apache.org/activemq/browse/CAMEL-328

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/list/
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/list/ListComponent.java
  (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/list/ListEndpoint.java
  (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/list/package.html
      - copied, changed from r620478, activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/vm/package.html
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/ListPollingConsumer.java
  (with props)
    activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/list
      - copied, changed from r620478, activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/seda
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/list/
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/list/ListTest.java
  (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/list/ListComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/list/ListComponent.java?rev=620773&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/list/ListComponent.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/list/ListComponent.java
Tue Feb 12 04:04:41 2008
@@ -0,0 +1,32 @@
+/**
+ *
+ * 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.list;
+
+import java.util.Map;
+
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.Endpoint;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class ListComponent extends DefaultComponent {
+    protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws
Exception {
+        return new ListEndpoint(uri, this);
+    }
+}
\ No newline at end of file

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

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/list/ListEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/list/ListEndpoint.java?rev=620773&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/list/ListEndpoint.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/list/ListEndpoint.java
Tue Feb 12 04:04:41 2008
@@ -0,0 +1,91 @@
+/**
+ *
+ * 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.list;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Component;
+import org.apache.camel.processor.loadbalancer.LoadBalancerConsumer;
+import org.apache.camel.processor.loadbalancer.TopicLoadBalancer;
+import org.apache.camel.component.seda.CollectionProducer;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.impl.DefaultProducer;
+
+/**
+ * An endpoint which maintains a {@link List} of {@link Exchange} instances
+ * which can be useful for tooling, debugging and visualising routes.
+ *
+ * @version $Revision: 1.1 $
+ */
+public class ListEndpoint extends DefaultEndpoint<Exchange> {
+    private List<Exchange> exchanges = new ArrayList<Exchange>();
+    private TopicLoadBalancer loadBalancer = new TopicLoadBalancer();
+
+    public ListEndpoint(String uri, CamelContext camelContext) {
+        super(uri, camelContext);
+    }
+
+    public ListEndpoint(String uri, Component component) {
+        super(uri, component);
+    }
+
+    public boolean isSingleton() {
+        return true;
+    }
+
+    public List<Exchange> getExchanges() {
+        return exchanges;
+    }
+
+    public TopicLoadBalancer getLoadBalancer() {
+        return loadBalancer;
+    }
+
+    public Producer<Exchange> createProducer() throws Exception {
+        return new DefaultProducer<Exchange>(this) {
+            public void process(Exchange exchange) throws Exception {
+                onExchange(exchange);
+            }
+        };
+    }
+
+    public Consumer<Exchange> createConsumer(Processor processor) throws Exception
{
+        return new LoadBalancerConsumer(this, processor, loadBalancer);
+    }
+
+    public void reset() {
+        exchanges = new CopyOnWriteArrayList<Exchange>();
+    }
+
+    /**
+     * Invoked on a message exchange being sent by a producer
+     */
+    protected void onExchange(Exchange exchange) throws Exception {
+        exchanges.add(exchange);
+
+        // lets fire any consumers
+        loadBalancer.process(exchange);
+    }
+}

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

Copied: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/list/package.html
(from r620478, activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/vm/package.html)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/list/package.html?p2=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/list/package.html&p1=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/vm/package.html&r1=620478&r2=620773&rev=620773&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/vm/package.html
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/list/package.html
Tue Feb 12 04:04:41 2008
@@ -19,12 +19,8 @@
 </head>
 <body>
 
-The <a href="http://activemq.apache.org/camel/vm.html">VM Component</a> for asynchronous
-<a href="http://www.eecs.harvard.edu/~mdw/proj/seda/">SEDA</a> exchanges on a
-<a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/BlockingQueue.html">BlockingQueue</a>
-within the current JVM; so across CamelContext instances. Note that this communication can
only take place
-between ClassLoaders which share the same camel-core.jar. So to communicate across web applications
you
-need to put camel-core.jar on the system/boot classpath.
+The <a href="http://activemq.apache.org/camel/list.html">List Component</a> which
is a simple in memory
+component which maintains a List of all message exchanges which can be useful for debugging,
tooling or visualistion.
 
 
 </body>

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/ListPollingConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/ListPollingConsumer.java?rev=620773&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/ListPollingConsumer.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/ListPollingConsumer.java
Tue Feb 12 04:04:41 2008
@@ -0,0 +1,59 @@
+/**
+ *
+ * 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.seda;
+
+import java.util.List;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.PollingConsumerSupport;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class ListPollingConsumer extends PollingConsumerSupport {
+    private final List<Exchange> exchanges;
+
+    public ListPollingConsumer(Endpoint endpoint, List<Exchange> exchanges) {
+        super(endpoint);
+        this.exchanges = exchanges;
+    }
+
+    public Exchange receive() {
+        return receiveNoWait();
+    }
+
+    public Exchange receiveNoWait() {
+        if (exchanges.isEmpty()) {
+            return null;
+        }
+        else {
+            return exchanges.remove(0);
+        }
+    }
+
+    public Exchange receive(long timeout) {
+        return receiveNoWait();
+    }
+
+    protected void doStart() throws Exception {
+    }
+
+    protected void doStop() throws Exception {
+    }
+}

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

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java?rev=620773&r1=620772&r2=620773&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
Tue Feb 12 04:04:41 2008
@@ -16,6 +16,10 @@
  */
 package org.apache.camel.util;
 
+import java.util.List;
+import java.util.Collection;
+import java.util.ArrayList;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
@@ -55,6 +59,25 @@
         else {
             return endpoint;
         }
+    }
+
+    /**
+     * Returns a list of all endpoints of the given type
+     *
+     * @param camelContext
+     * @param type the type of the endpoints requested
+     * @return a list which may be empty of all the endpoint instances of the given type
+     */
+    public static <T> List<T> getSingletonEndpoints(CamelContext camelContext,
Class<T> type) {
+        List<T> answer = new ArrayList<T>();
+        Collection<Endpoint> endpoints = camelContext.getSingletonEndpoints();
+        for (Endpoint endpoint : endpoints) {
+            if (type.isInstance(endpoint)) {
+                T value = type.cast(endpoint);
+                answer.add(value);
+            }
+        }
+        return answer;
     }
 
     /**

Copied: activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/list
(from r620478, activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/seda)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/list?p2=activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/list&p1=activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/seda&r1=620478&r2=620773&rev=620773&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/seda
(original)
+++ activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/list
Tue Feb 12 04:04:41 2008
@@ -15,4 +15,4 @@
 # limitations under the License.
 #
 
-class=org.apache.camel.component.seda.SedaComponent
+class=org.apache.camel.component.list.ListComponent

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java?rev=620773&r1=620772&r2=620773&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java Tue Feb
12 04:04:41 2008
@@ -156,6 +156,28 @@
      * @param expected the expected value of the OUT message
      * @throws InvalidPayloadException
      */
+    protected void assertInMessageBodyEquals(Exchange exchange, Object expected) throws InvalidPayloadException
{
+        assertNotNull("Should have a response exchange!", exchange);
+
+        Object actual;
+        if (expected == null) {
+            actual = ExchangeHelper.getMandatoryInBody(exchange);
+            assertEquals("in body of: " + exchange, expected, actual);
+        }
+        else {
+            actual = ExchangeHelper.getMandatoryInBody(exchange, expected.getClass());
+        }
+        assertEquals("in body of: " + exchange, expected, actual);
+
+        log.debug("Received response: " + exchange + " with in: " + exchange.getIn());
+    }
+
+    /**
+     * Asserts that the given exchange has an OUT message of the given body value
+     * @param exchange the exchange which should have an OUT message
+     * @param expected the expected value of the OUT message
+     * @throws InvalidPayloadException
+     */
     protected void assertOutMessageBodyEquals(Exchange exchange, Object expected) throws
InvalidPayloadException {
         assertNotNull("Should have a response exchange!", exchange);
 

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/list/ListTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/list/ListTest.java?rev=620773&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/list/ListTest.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/list/ListTest.java
Tue Feb 12 04:04:41 2008
@@ -0,0 +1,65 @@
+/**
+ *
+ * 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.list;
+
+import java.util.List;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.util.CamelContextHelper;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class ListTest extends ContextTestSupport {
+    private static final transient Log LOG = LogFactory.getLog(ListTest.class);
+
+    protected Object body1 = "one";
+    protected Object body2 = "two";
+
+    public void testListEndpoints() throws Exception {
+        template.sendBody("list:foo", body1);
+        template.sendBody("list:foo", body2);
+
+        List<ListEndpoint> list = CamelContextHelper.getSingletonEndpoints(context,
ListEndpoint.class);
+        assertEquals("number of endpoints", 2, list.size());
+
+        for (ListEndpoint endpoint : list) {
+            List<Exchange> exchanges = endpoint.getExchanges();
+
+            LOG.debug(">>>> " + endpoint + " has: " + exchanges);
+
+            assertEquals("Exchanges received on " + endpoint, 2, exchanges.size());
+
+            assertInMessageBodyEquals(exchanges.get(0), body1);
+            assertInMessageBodyEquals(exchanges.get(1), body2);
+        }
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("list:foo").to("list:bar");
+            }
+        };
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/list/ListTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message