You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2008/12/03 08:59:25 UTC

svn commit: r722803 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/component/browse/ main/java/org/apache/camel/component/list/ main/resources/META-INF/services/org/apache/camel/component/ test/java/org/apache/camel/component/bro...

Author: davsclaus
Date: Tue Dec  2 23:59:24 2008
New Revision: 722803

URL: http://svn.apache.org/viewvc?rev=722803&view=rev
Log:
CAMEL-1067: camel-list renamed to camel-browse

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/browse/
      - copied from r722800, 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/browse/BrowseComponent.java   (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/browse/BrowseEndpoint.java   (with props)
    activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/browse   (contents, props changed)
      - copied, changed from r722800, activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/list
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/browse/
      - copied from r722800, 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/browse/BrowseRouteTest.java   (with props)
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/browse/BrowseTest.java   (with props)
Removed:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/browse/ListComponent.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/browse/ListEndpoint.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/list/
    activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/list
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/browse/ListRouteTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/browse/ListTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/list/
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/browse/package.html

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/browse/BrowseComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/browse/BrowseComponent.java?rev=722803&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/browse/BrowseComponent.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/browse/BrowseComponent.java Tue Dec  2 23:59:24 2008
@@ -0,0 +1,34 @@
+/**
+ * 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.browse;
+
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+
+/**
+ * The <a href="http://activemq.apache.org/camel/browse.html">browse</a> component.
+ *
+ * @version $Revision$
+ */
+public class BrowseComponent extends DefaultComponent {
+
+    protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception {
+        return new BrowseEndpoint(uri, this);
+    }
+}
\ No newline at end of file

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

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/browse/BrowseComponent.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/browse/BrowseEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/browse/BrowseEndpoint.java?rev=722803&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/browse/BrowseEndpoint.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/browse/BrowseEndpoint.java Tue Dec  2 23:59:24 2008
@@ -0,0 +1,120 @@
+/**
+ * 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.browse;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.Service;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.processor.loadbalancer.LoadBalancerConsumer;
+import org.apache.camel.processor.loadbalancer.TopicLoadBalancer;
+import org.apache.camel.spi.BrowsableEndpoint;
+
+/**
+ * An endpoint which maintains a {@link List} of {@link Exchange} instances
+ * which can be useful for tooling, debugging and visualising routes.
+ *
+ * @version $Revision$
+ */
+public class BrowseEndpoint extends DefaultEndpoint implements BrowsableEndpoint, Service {
+    private List<Exchange> exchanges;
+    private TopicLoadBalancer loadBalancer = new TopicLoadBalancer();
+    // TODO: firing of property changes not implemented
+    private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
+
+    public BrowseEndpoint(String uri, CamelContext camelContext) {
+        super(uri, camelContext);
+    }
+
+    public BrowseEndpoint(String uri, Component component) {
+        super(uri, component);
+    }
+
+    public BrowseEndpoint(String endpointUri) {
+        super(endpointUri);
+    }
+
+    public boolean isSingleton() {
+        return true;
+    }
+
+    public List<Exchange> getExchanges() {
+        return exchanges;
+    }
+
+    public TopicLoadBalancer getLoadBalancer() {
+        return loadBalancer;
+    }
+
+    public void addPropertyChangeListener(PropertyChangeListener listener) {
+        propertyChangeSupport.addPropertyChangeListener(listener);
+    }
+
+    public void removePropertyChangeListener(PropertyChangeListener listener) {
+        propertyChangeSupport.removePropertyChangeListener(listener);
+    }
+
+    public Producer createProducer() throws Exception {
+        return new DefaultProducer(this) {
+            public void process(Exchange exchange) throws Exception {
+                onExchange(exchange);
+            }
+        };
+    }
+
+    public Consumer createConsumer(Processor processor) throws Exception {
+        return new LoadBalancerConsumer(this, processor, loadBalancer);
+    }
+
+    protected List<Exchange> createExchangeList() {
+        return new CopyOnWriteArrayList<Exchange>();
+    }
+
+    /**
+     * Invoked on a message exchange being sent by a producer
+     *
+     * @param exchange the exchange
+     * @throws Exception is thrown if failed to process the exchange
+     */
+    protected void onExchange(Exchange exchange) throws Exception {
+        exchanges.add(exchange);
+
+        // lets fire any consumers
+        loadBalancer.process(exchange);
+    }
+
+    public void start() throws Exception {
+        exchanges = createExchangeList();
+    }
+
+    public void stop() throws Exception {
+        if (exchanges != null) {
+            exchanges.clear();
+            exchanges = null;
+        }
+    }
+}

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

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/browse/BrowseEndpoint.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/browse/package.html
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/browse/package.html?rev=722803&r1=722800&r2=722803&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/browse/package.html (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/browse/package.html Tue Dec  2 23:59:24 2008
@@ -19,9 +19,8 @@
 </head>
 <body>
 
-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.
-
+The <a href="http://activemq.apache.org/camel/browse.html">Browse 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>
 </html>

Copied: activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/browse (from r722800, activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/list)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/browse?p2=activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/browse&p1=activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/list&r1=722800&r2=722803&rev=722803&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/list (original)
+++ activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/browse Tue Dec  2 23:59:24 2008
@@ -15,4 +15,4 @@
 # limitations under the License.
 #
 
-class=org.apache.camel.component.list.ListComponent
+class=org.apache.camel.component.browse.BrowseComponent

Propchange: activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/browse
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/browse
------------------------------------------------------------------------------
    svn:mergeinfo = 

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/browse/BrowseRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/browse/BrowseRouteTest.java?rev=722803&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/browse/BrowseRouteTest.java (added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/browse/BrowseRouteTest.java Tue Dec  2 23:59:24 2008
@@ -0,0 +1,52 @@
+/**
+ * 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.browse;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spi.BrowsableEndpoint;
+
+/**
+ * @version $Revision$
+ */
+public class BrowseRouteTest extends ContextTestSupport {
+
+    public void testBrowseRoute() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello World", "Bye World");
+
+        template.sendBody("direct:start", "Hello World");
+        template.sendBody("direct:start", "Bye World");
+
+        assertMockEndpointsSatisfied();
+
+        BrowsableEndpoint list = context.getEndpoint("browse:foo", BrowsableEndpoint.class);
+
+        mock.getExchanges().get(0).equals(list.getExchanges().get(0));
+        mock.getExchanges().get(1).equals(list.getExchanges().get(1));
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("direct:start").to("browse:foo").to("mock:result");
+            }
+        };
+    }
+}
\ No newline at end of file

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

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/browse/BrowseRouteTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/browse/BrowseRouteTest.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/browse/BrowseTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/browse/BrowseTest.java?rev=722803&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/browse/BrowseTest.java (added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/browse/BrowseTest.java Tue Dec  2 23:59:24 2008
@@ -0,0 +1,67 @@
+/**
+ * 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.browse;
+
+import java.util.List;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.BrowsableEndpoint;
+import org.apache.camel.util.CamelContextHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @version $Revision$
+ */
+public class BrowseTest extends ContextTestSupport {
+    private static final transient Log LOG = LogFactory.getLog(BrowseTest.class);
+
+    protected Object body1 = "one";
+    protected Object body2 = "two";
+
+    public void testListEndpoints() throws Exception {
+        template.sendBody("browse:foo", body1);
+        template.sendBody("browse:foo", body2);
+
+        List<BrowsableEndpoint> list = CamelContextHelper.getSingletonEndpoints(context, BrowsableEndpoint.class);
+        assertEquals("number of endpoints", 2, list.size());
+
+        Thread.sleep(2000);
+
+        for (BrowsableEndpoint 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("browse:foo").to("browse:bar");
+            }
+        };
+    }
+}

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

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/browse/BrowseTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date