activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r525634 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/component/pojo/ camel-core/src/main/java/org/apache/camel/component/pojo/timer/ camel-core/src/main/java/org/apache/camel/component/queue/ camel-core/src/main/jav...
Date Wed, 04 Apr 2007 22:46:57 GMT
Author: chirino
Date: Wed Apr  4 15:46:55 2007
New Revision: 525634

URL: http://svn.apache.org/viewvc?view=rev&rev=525634
Log:
Made endpoint resolution more deterministic.  Endpoint resolution now maps the uri prefix
to the registered component name.  If the component does not exist, the 
ComponentResolver is used to auto create it and it assigned to the component name.  This avoid
the problem of where multiple components think they map to the same prefix.
 - Components now do not need to know what component prefix they have been assigned.  
 - So that eliminated the need of getUriPrefixes

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/timer/TimerComponent.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/queue/QueueComponent.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponentResolver.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/timer/TimerRouteTest.java
    activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java
    activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
    activemq/camel/trunk/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteTest.java
    activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java
    activemq/camel/trunk/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
    activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringComponentResolver.java
    activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppComponent.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=525634&r1=525633&r2=525634
==============================================================================
--- 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
Wed Apr  4 15:46:55 2007
@@ -57,11 +57,7 @@
         return consumers.get(uri);
     }
 
-    @Override
-    public String[] getUriPrefixes() {
-        return new String[] {"pojo"};
-    }
-    
+
     @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/timer/TimerComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/timer/TimerComponent.java?view=diff&rev=525634&r1=525633&r2=525634
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/timer/TimerComponent.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/pojo/timer/TimerComponent.java
Wed Apr  4 15:46:55 2007
@@ -40,12 +40,6 @@
         return timers.remove(consumer);
     }
 
-
-    @Override
-    public String[] getUriPrefixes() {
-        return new String[] {"timer"};
-    }
-
     @Override
     protected Endpoint<PojoExchange> createEndpoint(String uri, String remaining, Map
parameters) throws Exception {
         return new TimerEndpoint(uri, this, remaining);

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/queue/QueueComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/queue/QueueComponent.java?view=diff&rev=525634&r1=525633&r2=525634
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/queue/QueueComponent.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/queue/QueueComponent.java
Wed Apr  4 15:46:55 2007
@@ -41,11 +41,6 @@
 	}
 
     @Override
-    public String[] getUriPrefixes() {
-        return new String[] {"queue"};
-    }
-
-    @Override
     protected Endpoint<E> createEndpoint(String uri, String remaining, Map parameters)
throws Exception {
         return new QueueEndpoint<E>(uri, this);
     }

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=525634&r1=525633&r2=525634
==============================================================================
--- 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 Apr  4 15:46:55 2007
@@ -17,17 +17,6 @@
  */
 package org.apache.camel.impl;
 
-import org.apache.camel.*;
-import org.apache.camel.spi.ComponentResolver;
-import org.apache.camel.spi.Injector;
-import org.apache.camel.spi.ExchangeConverter;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.impl.converter.DefaultTypeConverter;
-import org.apache.camel.impl.ReflectionInjector;
-import org.apache.camel.util.FactoryFinder;
-import org.apache.camel.util.NoFactoryAvailableException;
-import org.apache.camel.util.ServiceHelper;
-
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -36,6 +25,28 @@
 import java.util.Map;
 import java.util.concurrent.Callable;
 
+import org.apache.camel.CamelContext;
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.Route;
+import org.apache.camel.RouteFactory;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.Service;
+import org.apache.camel.TypeConverter;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.converter.DefaultTypeConverter;
+import org.apache.camel.spi.ComponentResolver;
+import org.apache.camel.spi.ExchangeConverter;
+import org.apache.camel.spi.Injector;
+import org.apache.camel.util.FactoryFinder;
+import org.apache.camel.util.NoFactoryAvailableException;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.ServiceHelper;
+
 /**
  * Represents the context used to configure routes and the policies to use.
  *
@@ -129,22 +140,37 @@
             answer = endpoints.get(uri);
             if (answer == null) {
                 try {
+                	
+                	// Use the URI prefix to find the component.
+                    String splitURI[] = ObjectHelper.splitOnCharacter(uri, ":", 2);
+                    if (splitURI[1] == null) {
+                        throw new IllegalArgumentException("Invalid URI, it did not contain
a scheme: " + uri);
+                    }
+                    String scheme = splitURI[0];
+                    Component component = null;
+                    
+                	// synchronize the look up and auto create so that 2 threads can't 
+                	// concurrently auto create the same component. 
                     synchronized (components) {
-                        Collection<Component> componentSet = components.values();
-                        for (Component component : componentSet) {
-                            answer = component.resolveEndpoint(uri);
-                            if (answer != null) {
-                                break;
-                            }
-                        }
+                    	component = components.get(scheme);
+                    	if( component == null ) {
+                            component = getComponentResolver().resolveComponent(uri, this);
+                    		addComponent(scheme, component);
+                    		if( isStarted() ) {
+                    			// If the component is looked up after the context is started,
+                    			// lets start it up.
+                    			ServiceHelper.startServices(component);
+                    		}
+                    	}
                     }
-                    if (answer == null) {
-                        Component component = getComponentResolver().resolveComponent(uri,
this);
-                        if (component != null) {
-                            ServiceHelper.startServices(component);
-                            answer = component.resolveEndpoint(uri);
-                        }
+                    
+                	// Ask the component to resolve the endpoint.
+                    if (component != null) {
+                        answer = component.resolveEndpoint(uri);
                     }
+                    
+                    // HC: What's the idea behind starting an endpoint?
+                    // I don't think we have any endpoints that are services do we?
                     if (answer != null) {
                         ServiceHelper.startServices(answer);
                         endpoints.put(uri, answer);

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java?view=diff&rev=525634&r1=525633&r2=525634
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
Wed Apr  4 15:46:55 2007
@@ -35,8 +35,8 @@
  * @version $Revision$
  */
 public class DefaultComponent<E extends Exchange> extends ServiceSupport implements
Component<E> {
-    protected static String[] EMPTY_ARRAY = {};
-    private int defaultThreadPoolSize = 5;
+
+	private int defaultThreadPoolSize = 5;
     private CamelContext camelContext;
     private ScheduledExecutorService executorService;
 
@@ -47,19 +47,9 @@
         this.camelContext = context;
     }
 
-    public String[] getUriPrefixes() {
-        return EMPTY_ARRAY;
-    }
 
     public Endpoint<E> resolveEndpoint(String uri) throws Exception {
-        ObjectHelper.notNull(getCamelContext(), "camelContext");
-        String remaining = matchesPrefixes(uri);
-        if (remaining == null) {
-            return null;
-        }
-        if (remaining.startsWith(":")) {
-            remaining = remaining.substring(1);
-        }
+        ObjectHelper.notNull(getCamelContext(), "camelContext");        
         URI u = new URI(uri);
         String path = u.getHost();
         if (path == null) {
@@ -120,21 +110,6 @@
         }
     }
 
-    /**
-     * Returns true if the uri matches one of the available prefixes from {@link #getUriPrefixes()}
-     *
-     * @param uri the URI
-     * @return true if the URI matches one of the available prefixes
-     */
-    protected String matchesPrefixes(String uri) {
-        String[] prefixes = getUriPrefixes();
-        for (String prefix : prefixes) {
-            if (uri.startsWith(prefix)) {
-                return uri.substring(prefix.length());
-            }
-        }
-        return null;
-    }
 
     /**
      * A factory method allowing derived components to create a new endpoint from the given
URI,

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponentResolver.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponentResolver.java?view=diff&rev=525634&r1=525633&r2=525634
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponentResolver.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponentResolver.java
Wed Apr  4 15:46:55 2007
@@ -56,11 +56,7 @@
             return null;
         }
         if (Component.class.isAssignableFrom(type)) {
-            Component<E> answer = (Component<E>) context.getInjector().newInstance(type);
-            // lets add the component using the prefix
-            context.addComponent(scheme, answer);
-            // TODO should we start it?
-            return answer;
+            return (Component<E>)context.getInjector().newInstance(type);
         }
         else {
             throw new IllegalArgumentException("Type is not a Component implementation. Found:
" + type.getName());

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/timer/TimerRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/timer/TimerRouteTest.java?view=diff&rev=525634&r1=525633&r2=525634
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/timer/TimerRouteTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/timer/TimerRouteTest.java
Wed Apr  4 15:46:55 2007
@@ -44,7 +44,7 @@
 				hitCount.incrementAndGet();
 			}
         });
-        container.addComponent("default", component);
+        container.addComponent("pojo", component);
         
         // lets add some routes
         container.addRoutes(new RouteBuilder() {

Modified: activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java?view=diff&rev=525634&r1=525633&r2=525634
==============================================================================
--- activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java
(original)
+++ activemq/camel/trunk/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java
Wed Apr  4 15:46:55 2007
@@ -17,6 +17,9 @@
  */
 package org.apache.camel.component.cxf;
 
+import java.net.URI;
+import java.util.Map;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.impl.DefaultComponent;
@@ -28,11 +31,6 @@
 import org.apache.cxf.transport.local.LocalTransportFactory;
 import org.xmlsoap.schemas.wsdl.http.AddressType;
 
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Map;
-
 /**
  * @version $Revision$
  */
@@ -44,11 +42,6 @@
 
     public CxfComponent(CamelContext context) {
         super(context);
-    }
-
-    @Override
-    public String[] getUriPrefixes() {
-        return new String[] {"cxf"};
     }
 
     @Override

Modified: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java?view=diff&rev=525634&r1=525633&r2=525634
==============================================================================
--- activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
(original)
+++ activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
Wed Apr  4 15:46:55 2007
@@ -80,11 +80,6 @@
     }
 
     @Override
-    public String[] getUriPrefixes() {
-        return new String[]{"jms"};
-    }
-
-    @Override
     protected Endpoint<JmsExchange> createEndpoint(String uri, String remaining, Map
parameters) throws Exception {
 
         boolean pubSubDomain = false;

Modified: activemq/camel/trunk/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteTest.java?view=diff&rev=525634&r1=525633&r2=525634
==============================================================================
--- activemq/camel/trunk/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteTest.java
(original)
+++ activemq/camel/trunk/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteTest.java
Wed Apr  4 15:46:55 2007
@@ -102,8 +102,8 @@
         // lets add some routes
         container.addRoutes(new RouteBuilder() {
             public void configure() {
-                from("jms:queue:test.a").to("jms:queue:test.b");
-                from("jms:queue:test.b").process(new Processor<JmsExchange>() {
+                from("activemq:queue:test.a").to("activemq:queue:test.b");
+                from("activemq:queue:test.b").process(new Processor<JmsExchange>()
{
                     public void process(JmsExchange e) {
                         System.out.println("Received exchange: " + e.getIn());
                         receivedExchange = e;
@@ -112,7 +112,7 @@
                 });
             }
         });
-        endpoint = container.resolveEndpoint("jms:queue:test.a");
+        endpoint = container.resolveEndpoint("activemq:queue:test.a");
         assertNotNull("No endpoint found!", endpoint);
 
         container.start();

Modified: activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java?view=diff&rev=525634&r1=525633&r2=525634
==============================================================================
--- activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java
(original)
+++ activemq/camel/trunk/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaComponent.java
Wed Apr  4 15:46:55 2007
@@ -54,11 +54,6 @@
     //-------------------------------------------------------------------------
 
     @Override
-    public String[] getUriPrefixes() {
-        return new String[]{"jpa"};
-    }
-
-    @Override
     protected Endpoint<Exchange> createEndpoint(String uri, String path, Map options)
throws Exception {
         JpaEndpoint endpoint = new JpaEndpoint(uri, this);
         Map consumerProperties = IntrospectionSupport.extractProperties(options, "consumer.");

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=525634&r1=525633&r2=525634
==============================================================================
--- 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 Apr  4 15:46:55 2007
@@ -53,11 +53,6 @@
     }
 
     @Override
-    public String[] getUriPrefixes() {
-        return new String[] { "mina" };
-    }
-
-    @Override
     protected Endpoint<MinaExchange> createEndpoint(String uri, String remaining, Map
parameters) throws Exception {
         URI u = new URI(remaining);
 

Modified: activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringComponentResolver.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringComponentResolver.java?view=diff&rev=525634&r1=525633&r2=525634
==============================================================================
--- activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringComponentResolver.java
(original)
+++ activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/SpringComponentResolver.java
Wed Apr  4 15:46:55 2007
@@ -18,13 +18,13 @@
 package org.apache.camel.spring;
 
 import static org.apache.camel.util.ObjectHelper.notNull;
-import org.apache.camel.spi.ComponentResolver;
-import org.apache.camel.Component;
-import org.apache.camel.CamelContext;
-import org.apache.camel.util.ObjectHelper;
-import org.springframework.context.ApplicationContext;
 
 import java.net.URI;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Component;
+import org.apache.camel.spi.ComponentResolver;
+import org.springframework.context.ApplicationContext;
 
 /**
  * An implementation of {@link ComponentResolver} which tries to find a Camel {@link Component}

Modified: activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppComponent.java?view=diff&rev=525634&r1=525633&r2=525634
==============================================================================
--- activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppComponent.java
(original)
+++ activemq/camel/trunk/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppComponent.java
Wed Apr  4 15:46:55 2007
@@ -48,11 +48,6 @@
     }
 
     @Override
-    public String[] getUriPrefixes() {
-        return new String[] {"xmpp"};
-    }
-
-    @Override
     protected Endpoint<XmppExchange> createEndpoint(String uri, String remaining, Map
parameters) throws Exception {
         XmppEndpoint endpoint = new XmppEndpoint(uri, this);
 



Mime
View raw message