Author: hadrian
Date: Thu Oct 2 08:18:28 2008
New Revision: 701149
URL: http://svn.apache.org/viewvc?rev=701149&view=rev
Log:
CAMEL-955. Deprecated singleton endpoint apis in CamelContext
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.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/util/CamelContextHelper.java
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?rev=701149&r1=701148&r2=701149&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
Thu Oct 2 08:18:28 2008
@@ -129,7 +129,7 @@
* For a singleton endpoint the collection will contain exactly one
element.
*
* @param uri the URI of the endpoints
- * @return all non-singleton endpoints
+ * @return collection of endpoints
*/
Collection<Endpoint> getEndpoints(String uri);
@@ -141,6 +141,27 @@
Collection<Endpoint> getSingletonEndpoints();
/**
+ * Adds the endpoint to the context using the given URI.
+ *
+ * @param uri the URI to be used to resolve this endpoint
+ * @param endpoint the endpoint to be added to the context
+ * @return the old endpoint that was previously registered to the context
if
+ * there was already an singleton endpoint for that URI or null
+ * @throws Exception if the new endpoint could not be started or the old
+ * singleton endpoint could not be stopped
+ */
+ Endpoint addEndpoint(String uri, Endpoint endpoint) throws Exception;
+
+ /**
+ * Removes all endpoints with the given URI
+ *
+ * @param uri the URI to be used to remove
+ * @return a collection of endpoints removed or null if there are no
endpoints for this URI
+ * @throws Exception if at least one endpoint could not be stopped
+ */
+ Collection<Endpoint> removeEndpoints(String uri) throws Exception;
+
+ /**
* Adds the endpoint to the context using the given URI. The endpoint
will be registered as a singleton.
*
* @param uri the URI to be used to resolve this endpoint
@@ -149,6 +170,7 @@
* already an endpoint for that URI
* @throws Exception if the new endpoint could not be started or the old
endpoint could not be stopped
*/
+ @Deprecated
Endpoint addSingletonEndpoint(String uri, Endpoint endpoint) throws
Exception;
/**
@@ -158,6 +180,7 @@
* @return the endpoint that was removed or null if there is no endpoint
for this URI
* @throws Exception if endpoint could not be stopped
*/
+ @Deprecated
Endpoint removeSingletonEndpoint(String uri) throws Exception;
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?rev=701149&r1=701148&r2=701149&view=diff
==============================================================================
---
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
Thu Oct 2 08:18:28 2008
@@ -55,6 +55,7 @@
import org.apache.camel.spi.LanguageResolver;
import org.apache.camel.spi.LifecycleStrategy;
import org.apache.camel.spi.Registry;
+import org.apache.camel.util.CamelContextHelper;
import org.apache.camel.util.FactoryFinder;
import org.apache.camel.util.NoFactoryAvailableException;
import org.apache.camel.util.ObjectHelper;
@@ -269,24 +270,47 @@
return answer;
}
- public Endpoint addSingletonEndpoint(String uri, Endpoint endpoint) throws
Exception {
+ public Endpoint addEndpoint(String uri, Endpoint endpoint) throws
Exception {
Endpoint oldEndpoint;
synchronized (endpoints) {
startServices(endpoint);
oldEndpoint = endpoints.remove(uri);
- endpoints.put(uri, endpoint);
- stopServices(oldEndpoint);
+ endpoints.put(CamelContextHelper.getEndpointKey(uri, endpoint),
endpoint);
+ if (oldEndpoint != null) {
+ stopServices(oldEndpoint);
+ }
}
return oldEndpoint;
}
- public Endpoint removeSingletonEndpoint(String uri) throws Exception {
- Endpoint oldEndpoint;
+ public Collection<Endpoint> removeEndpoints(String uri) throws Exception {
+ Collection<Endpoint> answer = new ArrayList<Endpoint>();
synchronized (endpoints) {
- oldEndpoint = endpoints.remove(uri);
- stopServices(oldEndpoint);
+ Endpoint oldEndpoint = endpoints.remove(uri);
+ if (oldEndpoint != null) {
+ answer.add(oldEndpoint);
+ stopServices(oldEndpoint);
+ } else {
+ for (Map.Entry entry : endpoints.entrySet()) {
+ oldEndpoint = (Endpoint)entry.getValue();
+ if (!oldEndpoint.isSingleton() &&
uri.equals(oldEndpoint.getEndpointUri())) {
+ answer.add(oldEndpoint);
+ stopServices(oldEndpoint);
+ endpoints.remove(entry.getKey());
+ }
+ }
+ }
}
- return oldEndpoint;
+ return answer;
+ }
+
+ public Endpoint addSingletonEndpoint(String uri, Endpoint endpoint) throws
Exception {
+ return addEndpoint(uri, endpoint);
+ }
+
+ public Endpoint removeSingletonEndpoint(String uri) throws Exception {
+ Collection<Endpoint> answer = removeEndpoints(uri);
+ return (Endpoint) (answer.size() > 0 ? answer.toArray()[0] : null);
}
public Endpoint getEndpoint(String uri) {
@@ -320,10 +344,7 @@
if (answer != null) {
addService(answer);
- String key = answer.isSingleton() ? uri :
- ("Ox" + Integer.toHexString(answer.hashCode()) +
":" + uri);
-
- endpoints.put(key, answer);
+ endpoints.put(CamelContextHelper.getEndpointKey(uri,
answer), answer);
lifecycleStrategy.onEndpointAdd(answer);
}
} catch (Exception e) {
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=701149&r1=701148&r2=701149&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
Thu Oct 2 08:18:28 2008
@@ -57,6 +57,10 @@
}
}
+ public static String getEndpointKey(String uri, Endpoint ep) {
+ return ep.isSingleton() ? uri : ("Ox" +
Integer.toHexString(ep.hashCode()) + ":" + uri);
+ }
+
/**
* Returns the mandatory endpoint for the given URI and type or the
* [EMAIL PROTECTED] org.apache.camel.NoSuchEndpointException} is thrown