Author: hadrian
Date: Wed Oct 1 18:54:14 2008
New Revision: 700984
URL: http://svn.apache.org/viewvc?rev=700984&view=rev
Log:
CAMEL-955
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
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=700984&r1=700983&r2=700984&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
Wed Oct 1 18:54:14 2008
@@ -119,6 +119,22 @@
<T extends Endpoint> T getEndpoint(String name, Class<T> endpointType);
/**
+ * Returns the collection of all registered endpoints.
+ *
+ * @return all endpoints
+ */
+ Collection<Endpoint> getEndpoints();
+
+ /**
+ * Returns the collection of all registered endpoints for a uri or an
empty collection.
+ * For a singleton endpoint the collection will contain exactly one
element.
+ *
+ * @param uri the URI of the endpoints
+ * @return all non-singleton endpoints
+ */
+ Collection<Endpoint> getEndpoints(String uri);
+
+ /**
* Returns the collection of all registered singleton endpoints.
*
* @return all the singleton endpoints
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=700984&r1=700983&r2=700984&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
Wed Oct 1 18:54:14 2008
@@ -233,10 +233,40 @@
// Endpoint Management Methods
// -----------------------------------------------------------------------
- public Collection<Endpoint> getSingletonEndpoints() {
+ public Collection<Endpoint> getEndpoints() {
synchronized (endpoints) {
return new ArrayList<Endpoint>(endpoints.values());
}
+ }
+
+ public Collection<Endpoint> getEndpoints(String uri) {
+ Collection<Endpoint> answer = new ArrayList<Endpoint>();
+ Collection<Endpoint> coll;
+ synchronized (endpoints) {
+ Endpoint ep = endpoints.get(uri);
+ if (ep != null) {
+ answer.add(ep);
+ return answer;
+ }
+ coll = new ArrayList<Endpoint>(endpoints.values());
+ }
+ for (Endpoint ep : coll) {
+ if (!ep.isSingleton() &&
uri.equals(ep.getEndpointUri())) {
+ answer.add(ep);
+ }
+ }
+ return answer;
+ }
+
+ public Collection<Endpoint> getSingletonEndpoints() {
+ Collection<Endpoint> answer = new ArrayList<Endpoint>();
+ Collection<Endpoint> coll = getEndpoints();
+ for (Endpoint ep : coll) {
+ if (ep.isSingleton()) {
+ answer.add(ep);
+ }
+ }
+ return answer;
}
public Endpoint addSingletonEndpoint(String uri, Endpoint endpoint) throws
Exception {
@@ -260,7 +290,7 @@
}
public Endpoint getEndpoint(String uri) {
- Endpoint answer;
+ Endpoint<?> answer;
synchronized (endpoints) {
answer = endpoints.get(uri);
if (answer == null) {
@@ -270,7 +300,7 @@
String splitURI[] = ObjectHelper.splitOnCharacter(uri,
":", 2);
if (splitURI[1] != null) {
String scheme = splitURI[0];
- Component component = getComponent(scheme);
+ Component<?> component = getComponent(scheme);
// Ask the component to resolve the endpoint.
if (component != null) {
@@ -290,12 +320,11 @@
if (answer != null) {
addService(answer);
- if (answer.isSingleton()) {
- endpoints.put(uri, answer);
-
- // TODO we should support non-singletons in the
lifecycle
- lifecycleStrategy.onEndpointAdd(answer);
- }
+ String key = answer.isSingleton() ? uri :
+ ("Ox" + Integer.toHexString(answer.hashCode())
+ ":" + uri);
+
+ endpoints.put(key, answer);
+ lifecycleStrategy.onEndpointAdd(answer);
}
} catch (Exception e) {
LOG.debug("Failed to resolve endpoint " + uri + ". Reason:
" + e, e);
@@ -306,7 +335,6 @@
return answer;
}
-
public <T extends Endpoint> T getEndpoint(String name, Class<T>
endpointType) {
Endpoint endpoint = getEndpoint(name);
if (endpointType.isInstance(endpoint)) {