activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r534129 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/component/pojo/ camel-core/src/test/java/org/apache/camel/component/pojo/ camel-rmi/src/test/java/org/apache/camel/component/rmi/
Date Tue, 01 May 2007 15:48:27 GMT
Author: chirino
Date: Tue May  1 08:48:27 2007
New Revision: 534129

URL: http://svn.apache.org/viewvc?view=rev&rev=534129
Log:
Removed the ability to consume from a pojo: endpoint since it is easier to consume from a
direct: or queue: endpoint.

Removed:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoConsumer.java
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoComponent.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoEndpoint.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java
    activemq/camel/trunk/camel-rmi/src/test/java/org/apache/camel/component/rmi/RmiRouteTest.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoComponent.java?view=diff&rev=534129&r1=534128&r2=534129
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoComponent.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoComponent.java
Tue May  1 08:48:27 2007
@@ -16,12 +16,17 @@
  */
 package org.apache.camel.component.pojo;
 
-import org.apache.camel.impl.DefaultComponent;
-import org.apache.camel.Endpoint;
-
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.camel.Endpoint;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultComponent;
+
 /**
  * Represents the component that manages {@link PojoEndpoint}.  It holds the
  * list of named pojos that queue endpoints reference.
@@ -30,7 +35,6 @@
  */
 public class PojoComponent extends DefaultComponent<PojoExchange> {
     protected final HashMap<String, Object> services = new HashMap<String, Object>();
-    protected final HashMap<String, PojoConsumer> consumers = new HashMap<String,
PojoConsumer>();
 
     public void addService(String uri, Object pojo) {
         services.put(uri, pojo);
@@ -38,28 +42,66 @@
 
     public void removeService(String uri) {
         services.remove(uri);
-        removeConsumer(uri);
     }
 
     public Object getService(String uri) {
         return services.get(uri);
     }
 
-    void addConsumer(String uri, PojoConsumer endpoint) {
-        consumers.put(uri, endpoint);
+    @Override
+    protected Endpoint<PojoExchange> createEndpoint(String uri, String remaining, Map
parameters) throws Exception {
+        return new PojoEndpoint(uri, this, remaining);
     }
-
-    void removeConsumer(String uri) {
-        consumers.remove(uri);
+    
+    /**
+     * Creates a Proxy which sends PojoExchange to the endpoint.
+     * @throws Exception 
+     */
+    static public Object createProxy(final Endpoint endpoint, ClassLoader cl, Class interfaces[])
throws Exception {
+    	final Producer producer = endpoint.createProducer();
+        return Proxy.newProxyInstance(cl, interfaces, new InvocationHandler() {        	
+        	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
+                PojoInvocation invocation = new PojoInvocation(proxy, method, args);
+                PojoExchange exchange = new PojoExchange(endpoint.getContext());        
       
+                exchange.setInvocation(invocation);
+                producer.process(exchange);                
+                Throwable fault = exchange.getException();
+                if (fault != null) {
+                    throw new InvocationTargetException(fault);
+                }
+                return exchange.getOut().getBody();
+        	}
+        });
+    }
+    
+    /**
+     * Creates a Proxy which sends PojoExchange to the endpoint.
+     * @throws Exception 
+     */
+    static public Object createProxy(Endpoint endpoint, Class interfaces[]) throws Exception
{
+    	if( interfaces.length < 1 ) {
+    		throw new IllegalArgumentException("You must provide at least 1 interface class.");
+    	}
+        return createProxy(endpoint, interfaces[0].getClassLoader(), interfaces);
+    }    
+    /**
+     * Creates a Proxy which sends PojoExchange to the endpoint.
+     * @throws Exception 
+     */
+    @SuppressWarnings("unchecked")
+	static public <T> T createProxy(Endpoint endpoint, ClassLoader cl, Class<T>
interfaceClass) throws Exception {
+        return (T) createProxy(endpoint, cl, new Class[]{interfaceClass});
+    }
+    
+    /**
+     * Creates a Proxy which sends PojoExchange to the endpoint.
+     * @throws Exception 
+     */
+    @SuppressWarnings("unchecked")
+	static public <T> T createProxy(Endpoint endpoint, Class<T> interfaceClass)
throws Exception {
+        return (T) createProxy(endpoint, new Class[]{interfaceClass});
     }
 
-    public PojoConsumer getConsumer(String uri) {
-        return consumers.get(uri);
-    }
 
 
-    @Override
-    protected Endpoint<PojoExchange> createEndpoint(String uri, String remaining, Map
parameters) throws Exception {
-        return new PojoEndpoint(uri, this, remaining);
-    }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoEndpoint.java?view=diff&rev=534129&r1=534128&r2=534129
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoEndpoint.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/PojoEndpoint.java
Tue May  1 08:48:27 2007
@@ -54,8 +54,7 @@
     }
 
     public Consumer<PojoExchange> createConsumer(Processor<PojoExchange> processor)
throws Exception {    	
-    	PojoConsumer consumer = new PojoConsumer(this, processor);
-        return startService(consumer);
+        throw new Exception("You cannot consume from pojo endpoints.");
     }
 
     /**

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java?view=diff&rev=534129&r1=534128&r2=534129
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java
Tue May  1 08:48:27 2007
@@ -20,6 +20,7 @@
 import junit.framework.TestCase;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.DefaultCamelContext;
 
@@ -33,8 +34,7 @@
         CamelContext camelContext = new DefaultCamelContext();
         
         // START SNIPPET: register
-        PojoComponent component = new PojoComponent();
-        camelContext.addComponent("pojo", component);
+        PojoComponent component = (PojoComponent)camelContext.getComponent("pojo");
         component.addService("bye", new SayService("Good Bye!"));
         // END SNIPPET: register
         
@@ -42,7 +42,7 @@
         // lets add simple route
         camelContext.addRoutes(new RouteBuilder() {
             public void configure() {
-                from("pojo:hello").to("pojo:bye");
+                from("direct:hello").to("pojo:bye");
             }
         });
         // END SNIPPET: route
@@ -50,8 +50,8 @@
         camelContext.start();
         
         // START SNIPPET: invoke
-        PojoConsumer consumer = component.getConsumer("hello");        
-        ISay proxy = consumer.createProxy(ISay.class);
+        Endpoint endpoint = camelContext.getEndpoint("direct:hello");
+        ISay proxy = PojoComponent.createProxy(endpoint, ISay.class);
         String rc = proxy.say();
         assertEquals("Good Bye!", rc);
         // END SNIPPET: invoke

Modified: activemq/camel/trunk/camel-rmi/src/test/java/org/apache/camel/component/rmi/RmiRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-rmi/src/test/java/org/apache/camel/component/rmi/RmiRouteTest.java?view=diff&rev=534129&r1=534128&r2=534129
==============================================================================
--- activemq/camel/trunk/camel-rmi/src/test/java/org/apache/camel/component/rmi/RmiRouteTest.java
(original)
+++ activemq/camel/trunk/camel-rmi/src/test/java/org/apache/camel/component/rmi/RmiRouteTest.java
Tue May  1 08:48:27 2007
@@ -24,9 +24,9 @@
 import junit.framework.TestCase;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.pojo.PojoComponent;
-import org.apache.camel.component.pojo.PojoConsumer;
 import org.apache.camel.impl.DefaultCamelContext;
 
 /**
@@ -45,8 +45,7 @@
         CamelContext camelContext = new DefaultCamelContext();
         
         // START SNIPPET: register
-        PojoComponent component = new PojoComponent();
-        camelContext.addComponent("pojo", component);
+        PojoComponent component = (PojoComponent)camelContext.getComponent("pojo");
         component.addService("bye", new SayService("Good Bye!"));
         // END SNIPPET: register
         
@@ -54,7 +53,7 @@
         // lets add simple route
         camelContext.addRoutes(new RouteBuilder() {
             public void configure() {
-            	from("pojo:hello").to("rmi://localhost:1099/bye");                
+            	from("direct:hello").to("rmi://localhost:1099/bye");                
 
             	// When exposing an RMI endpoint, the interfaces it exposes must be configured.
                 RmiEndpoint bye = (RmiEndpoint) endpoint("rmi://localhost:1099/bye");
@@ -67,8 +66,8 @@
         camelContext.start();
         
         // START SNIPPET: invoke
-        PojoConsumer consumer = component.getConsumer("hello");        
-        ISay proxy = consumer.createProxy(ISay.class);
+        Endpoint endpoint = camelContext.getEndpoint("direct:hello");
+        ISay proxy = PojoComponent.createProxy(endpoint, ISay.class);
         String rc = proxy.say();
         assertEquals("Good Bye!", rc);
         // END SNIPPET: invoke



Mime
View raw message