activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r520989 - in /activemq/camel/trunk: ./ camel-core/src/main/java/org/apache/camel/impl/ camel-mina/ camel-mina/src/main/java/org/apache/camel/component/mina/ camel-mina/src/test/java/org/apache/camel/component/mina/
Date Wed, 21 Mar 2007 20:19:56 GMT
Author: jstrachan
Date: Wed Mar 21 13:19:55 2007
New Revision: 520989

URL: http://svn.apache.org/viewvc?view=rev&rev=520989
Log:
got a very basic test case working for Mina

Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    activemq/camel/trunk/camel-mina/pom.xml
    activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
    activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
    activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTest.java
    activemq/camel/trunk/pom.xml

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?view=diff&rev=520989&r1=520988&r2=520989
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
Wed Mar 21 13:19:55 2007
@@ -17,13 +17,13 @@
  */
 package org.apache.camel.impl;
 
+import org.apache.camel.*;
+import org.apache.camel.builder.RouteBuilder;
+
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.Callable;
 
-import org.apache.camel.*;
-import org.apache.camel.builder.RouteBuilder;
-
 /**
  * Represents the context used to configure routes and the policies to use.
  *
@@ -31,20 +31,19 @@
  * @org.apache.xbean.XBean element="container" rootElement="true"
  */
 public class DefaultCamelContext<E extends Exchange> implements CamelContext<E>
{
-
     private EndpointResolver<E> endpointResolver;
     private ExchangeConverter exchangeConverter;
     private Map<String, Component> components = new HashMap<String, Component>();
-	private Map<Endpoint<E>, Processor<E>> routes;
+    private Map<Endpoint<E>, Processor<E>> routes;
     private TypeConverter typeConverter;
-    
+
     /**
      * Adds a component to the container.
      */
     public void addComponent(String componentName, final Component<E> component) {
         synchronized (components) {
-            if( components.containsKey(componentName) ) {
-            	throw new IllegalArgumentException("Component previously added: "+componentName);
+            if (components.containsKey(componentName)) {
+                throw new IllegalArgumentException("Component previously added: " + componentName);
             }
             component.setContext(this);
             components.put(componentName, component);
@@ -56,9 +55,10 @@
             return components.get(componentName);
         }
     }
-    
+
     /**
      * Removes a previously added component.
+     *
      * @param componentName
      * @return the previously added component or null if it had not been previously added.
      */
@@ -70,10 +70,10 @@
 
     /**
      * Gets the a previously added component by name or lazily creates the component
-     * using the factory Callback. 
-     * 
+     * using the factory Callback.
+     *
      * @param componentName
-     * @param factory used to create a new component instance if the component was not previously
added.
+     * @param factory       used to create a new component instance if the component was
not previously added.
      * @return
      */
     public Component getOrCreateComponent(String componentName, Callable<Component<E>>
factory) {
@@ -103,7 +103,7 @@
      * Resolves the given URI to an endpoint
      */
     public Endpoint<E> resolveEndpoint(String uri) {
-         EndpointResolver<E> er = getEndpointResolver();
+        EndpointResolver<E> er = getEndpointResolver();
         try {
             return er.resolveEndpoint(this, uri);
         }
@@ -111,7 +111,7 @@
             throw new ResolveEndpointFailedException(uri, e);
         }
     }
-    
+
     /**
      * Activates all the starting endpoints in that were added as routes.
      */
@@ -122,7 +122,7 @@
             endpoint.activate(processor);
         }
     }
-    
+
     /**
      * Deactivates all the starting endpoints in that were added as routes.
      */
@@ -134,13 +134,13 @@
 
     // Route Management Methods
     //-----------------------------------------------------------------------
-	public Map<Endpoint<E>, Processor<E>> getRoutes() {
-		return routes;
-	}
-
-	public void setRoutes(Map<Endpoint<E>, Processor<E>> routes) {
-		this.routes = routes;
-	}
+    public Map<Endpoint<E>, Processor<E>> getRoutes() {
+        return routes;
+    }
+
+    public void setRoutes(Map<Endpoint<E>, Processor<E>> routes) {
+        this.routes = routes;
+    }
 
     public void setRoutes(RouteBuilder<E> builder) {
         // lets now add the routes from the builder
@@ -202,7 +202,6 @@
         return new DefaultEndpointResolver<E>();
     }
 
-
     /**
      * Lazily create a default implementation
      */
@@ -210,12 +209,10 @@
         return new DefaultExchangeConverter();
     }
 
-
     /**
      * Lazily create a default implementation
      */
     private TypeConverter createTypeConverter() {
         return new DefaultTypeConverter();
     }
-
 }

Modified: activemq/camel/trunk/camel-mina/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-mina/pom.xml?view=diff&rev=520989&r1=520988&r2=520989
==============================================================================
--- activemq/camel/trunk/camel-mina/pom.xml (original)
+++ activemq/camel/trunk/camel-mina/pom.xml Wed Mar 21 13:19:55 2007
@@ -44,6 +44,10 @@
 			<groupId>org.apache.mina</groupId>
 			<artifactId>mina-java5</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+    </dependency>
 
     <dependency>
       <groupId>junit</groupId>

Modified: activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java?view=diff&rev=520989&r1=520988&r2=520989
==============================================================================
--- activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
(original)
+++ activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
Wed Mar 21 13:19:55 2007
@@ -27,11 +27,15 @@
 import org.apache.mina.transport.vmpipe.VmPipeConnector;
 
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * @version $Revision$
  */
 public class MinaComponent extends DefaultComponent<MinaExchange> {
+    private Map<String, MinaEndpoint> map = new HashMap<String, MinaEndpoint>();
+
     public MinaComponent() {
     }
 
@@ -39,22 +43,26 @@
         super(context);
     }
 
-    public MinaEndpoint createEndpoint(String uri, String[] urlParts) throws IOException
{
-        IoAcceptor acceptor = new VmPipeAcceptor();
-        MinaEndpoint endpoint = new MinaEndpoint(uri, getContext(), acceptor);
-
-        VmPipeAddress address = new VmPipeAddress(8080);
-
-        // Set up server
-        acceptor.bind(address, endpoint.getServerHandler());
-
-        // Connect to the server.
-        VmPipeConnector connector = new VmPipeConnector();
-        ConnectFuture future = connector.connect(address, endpoint.getClientHandler());
-        future.join();
-        IoSession session = future.getSession();
-
-        endpoint.setSession(session);
+    public synchronized MinaEndpoint createEndpoint(String uri, String[] urlParts) throws
IOException {
+        MinaEndpoint endpoint = map.get(uri);
+        if (endpoint == null) {
+            IoAcceptor acceptor = new VmPipeAcceptor();
+            endpoint = new MinaEndpoint(uri, getContext(), acceptor);
+
+            VmPipeAddress address = new VmPipeAddress(8080);
+
+            // Set up server
+            acceptor.bind(address, endpoint.getServerHandler());
+
+            // Connect to the server.
+            VmPipeConnector connector = new VmPipeConnector();
+            ConnectFuture future = connector.connect(address, endpoint.getClientHandler());
+            future.join();
+            IoSession session = future.getSession();
+
+            endpoint.setSession(session);
+            map.put(uri, endpoint);
+        }
 
         return endpoint;
     }

Modified: activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java?view=diff&rev=520989&r1=520988&r2=520989
==============================================================================
--- activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
(original)
+++ activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
Wed Mar 21 13:19:55 2007
@@ -38,14 +38,25 @@
         this.acceptor = acceptor;
     }
 
-    public void onExchange(MinaExchange minaExchange) {
-        session.write(minaExchange.getIn().getBody());
+    public void onExchange(MinaExchange exchange) {
+        Object body = exchange.getIn().getBody();
+        if (body == null) {
+            System.out.println("#### No payload for exchange: " + exchange);
+        }
+        session.write(body);
     }
 
     public MinaExchange createExchange() {
         return new MinaExchange(getContext());
     }
 
+    public MinaExchange createExchange(IoSession session, Object object) {
+        MinaExchange exchange = new MinaExchange(getContext());
+        exchange.getIn().setBody(object);
+        // TODO store session in exchange?
+        return exchange;
+    }
+
     public IoHandler getServerHandler() {
         if (serverHandler == null) {
             serverHandler = createServerHandler();
@@ -89,9 +100,13 @@
     protected IoHandler createServerHandler() {
         return new IoHandlerAdapter() {
             @Override
-            public void messageReceived(IoSession ioSession, Object object) throws Exception
{
-                super.messageReceived(ioSession, object);    /** TODO */
+            public void messageReceived(IoSession session, Object object) throws Exception
{
+                processInboundMessage(session, object);
             }
         };
+    }
+
+    private void processInboundMessage(IoSession session, Object object) {
+        getInboundProcessor().onExchange(createExchange(session, object));
     }
 }

Modified: activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTest.java?view=diff&rev=520989&r1=520988&r2=520989
==============================================================================
--- activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTest.java
(original)
+++ activemq/camel/trunk/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTest.java
Wed Mar 21 13:19:55 2007
@@ -26,6 +26,7 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.Endpoint;
+import org.apache.camel.Message;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.DefaultCamelContext;
 
@@ -42,8 +43,8 @@
         container.setRoutes(new RouteBuilder() {
             public void configure() {
                 from("mina:vm:8080").process(new Processor<MinaExchange>() {
-                    public void onExchange(MinaExchange exchange) {
-                        System.out.println("Received exchange: " + exchange.getIn());
+                    public void onExchange(MinaExchange e) {
+                        System.out.println("Received exchange: " + e.getIn());
                         latch.countDown();
                     }
                 });
@@ -55,14 +56,16 @@
 
         // now lets fire in a message
         Endpoint<MinaExchange> endpoint = container.resolveEndpoint("mina:vm:8080");
-        MinaExchange exchange2 = endpoint.createExchange();
-        //exchange2.setInBody("Hello there!")
-        exchange2.getIn().getHeaders().setHeader("cheese", 123);
-        endpoint.onExchange(exchange2);
+        MinaExchange exchange = endpoint.createExchange();
+        Message message = exchange.getIn();
+        message.setBody("Hello there!");
+        message.getHeaders().setHeader("cheese", 123);
+
+        endpoint.onExchange(exchange);
 
         // now lets sleep for a while
         boolean received = latch.await(5, TimeUnit.SECONDS);
-        assertTrue("Did not recieve the message!", received);
+        assertTrue("Did not receive the message!", received);
 
         container.deactivateEndpoints();
     }

Modified: activemq/camel/trunk/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/pom.xml?view=diff&rev=520989&r1=520988&r2=520989
==============================================================================
--- activemq/camel/trunk/pom.xml (original)
+++ activemq/camel/trunk/pom.xml Wed Mar 21 13:19:55 2007
@@ -18,7 +18,7 @@
 -->
 
 <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
-  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
 
   <modelVersion>4.0.0</modelVersion>
 
@@ -231,11 +231,17 @@
         </exclusions>
       </dependency>
 
+      <!-- optional mina dependencies -->
       <dependency>
         <groupId>org.apache.mina</groupId>
         <artifactId>mina-java5</artifactId>
         <version>1.0.2</version>
       </dependency>
+      <dependency>
+        <groupId>org.slf4j</groupId>
+        <artifactId>slf4j-simple</artifactId>
+        <version>1.2</version>
+      </dependency>
 
       <dependency>
         <groupId>junit</groupId>
@@ -251,14 +257,14 @@
   <build>
     <pluginManagement>
       <plugins>
-	      <plugin>
-	        <groupId>org.apache.maven.plugins</groupId>
-	        <artifactId>maven-compiler-plugin</artifactId>
-	        <configuration>
-	          <source>1.5</source>
-	          <target>1.5</target>
-	        </configuration>
-	      </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <configuration>
+            <source>1.5</source>
+            <target>1.5</target>
+          </configuration>
+        </plugin>
       </plugins>
     </pluginManagement>
   </build>
@@ -267,30 +273,30 @@
       <plugin>
         <artifactId>maven-javadoc-plugin</artifactId>
       </plugin>
-<!--
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-jxr-plugin</artifactId>
-      </plugin>
--->
+      <!--
+            <plugin>
+              <groupId>org.apache.maven.plugins</groupId>
+              <artifactId>maven-jxr-plugin</artifactId>
+            </plugin>
+      -->
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-report-plugin</artifactId>
       </plugin>
-<!--
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-checkstyle-plugin</artifactId>
-      </plugin>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-pmd-plugin</artifactId>
-      </plugin>
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>cobertura-maven-plugin</artifactId>
-      </plugin>
--->
+      <!--
+            <plugin>
+              <groupId>org.apache.maven.plugins</groupId>
+              <artifactId>maven-checkstyle-plugin</artifactId>
+            </plugin>
+            <plugin>
+              <groupId>org.apache.maven.plugins</groupId>
+              <artifactId>maven-pmd-plugin</artifactId>
+            </plugin>
+            <plugin>
+              <groupId>org.codehaus.mojo</groupId>
+              <artifactId>cobertura-maven-plugin</artifactId>
+            </plugin>
+      -->
       <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>taglist-maven-plugin</artifactId>
@@ -312,7 +318,7 @@
             <link>http://logging.apache.org/log4j/docs/api/</link>
             <link>http://mina.apache.org/report/trunk/apidocs/</link>
           </links>
-           <stylesheetfile>${basedir}/../etc/css/stylesheet.css</stylesheetfile>
+          <stylesheetfile>${basedir}/../etc/css/stylesheet.css</stylesheetfile>
           <linksource>true</linksource>
           <maxmemory>900m</maxmemory>
           <source>1.5</source>



Mime
View raw message