Author: jstrachan
Date: Mon Aug  9 10:24:15 2010
New Revision: 983574

URL: http://svn.apache.org/viewvc?rev=983574&view=rev
Log:
fix for CAMEL-3035

Added:
    camel/trunk/camel-core/src/main/java/org/apache/camel/spi/HasId.java
Modified:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java?rev=983574&r1=983573&r2=983574&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java 
(original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java 
Mon Aug  9 10:24:15 2010
@@ -27,6 +27,8 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.PollingConsumer;
+import org.apache.camel.spi.HasId;
+import org.apache.camel.util.EndpointHelper;
 import org.apache.camel.util.ObjectHelper;
 
 /**
@@ -39,13 +41,15 @@ import org.apache.camel.util.ObjectHelpe
  *
  * @version $Revision$
  */
-public abstract class DefaultEndpoint implements Endpoint, CamelContextAware {
+public abstract class DefaultEndpoint implements Endpoint, HasId, 
CamelContextAware {
+
     private String endpointUri;
     private CamelContext camelContext;
     private Component component;
     private ExchangePattern exchangePattern = ExchangePattern.InOnly;
     // option to allow end user to dictate whether async processing should be 
used or not (if possible)
     private boolean synchronous;
+    private final String id = EndpointHelper.createEndpointId();
 
     protected DefaultEndpoint(String endpointUri, Component component) {
         this(endpointUri, component.getCamelContext());
@@ -83,6 +87,14 @@ public abstract class DefaultEndpoint im
         return "Endpoint[" + getEndpointUri() + "]";
     }
 
+    /**
+     * Returns a unique String ID which can be used for aliasing without 
having to use the whole URI which
+     * is not unique 
+     */
+    public String getId() {
+        return id;
+    }
+
     public String getEndpointUri() {
         if (endpointUri == null) {
             endpointUri = createEndpointUri();

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/HasId.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/HasId.java?rev=983574&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/HasId.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/HasId.java Mon 
Aug  9 10:24:15 2010
@@ -0,0 +1,26 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spi;
+
+/**
+ * A simple marker interface for an object which has a unique ID which is 
useful for referring to objects
+ * in REST or JMX style APIs
+ */
+public interface HasId {
+    String getId();
+}

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java?rev=983574&r1=983573&r2=983574&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java 
(original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java 
Mon Aug  9 10:24:15 2010
@@ -22,6 +22,7 @@ import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.atomic.AtomicLong;
 import java.util.regex.PatternSyntaxException;
 
 import org.apache.camel.CamelContext;
@@ -42,6 +43,7 @@ import org.apache.commons.logging.LogFac
 public final class EndpointHelper {
 
     private static final transient Log LOG = 
LogFactory.getLog(EndpointHelper.class);
+    private static final AtomicLong endpointCounter = new AtomicLong(0);
 
     private EndpointHelper() {
         //Utility Class
@@ -363,4 +365,10 @@ public final class EndpointHelper {
         return null;
     }
 
+    /**
+     * A helper method for Endpoint implementations to create new Ids for 
Endpoints which also implement {...@link HasId}
+     */
+    public static String createEndpointId() {
+        return "endpoint" + endpointCounter.incrementAndGet();
+    }
 }


Reply via email to