camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/3] git commit: CAMEL-6521: ActiveMQUuidGenerator should allow configuring server socket port number
Date Tue, 09 Jul 2013 05:54:13 GMT
CAMEL-6521: ActiveMQUuidGenerator should allow configuring server socket port number


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/be711870
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/be711870
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/be711870

Branch: refs/heads/camel-2.11.x
Commit: be7118702f331e9e0d37318896ce8513bea90d8d
Parents: 17376da
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Jul 9 07:51:39 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Jul 9 07:53:03 2013 +0200

----------------------------------------------------------------------
 .../camel/impl/ActiveMQUuidGenerator.java       | 22 +++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/be711870/camel-core/src/main/java/org/apache/camel/impl/ActiveMQUuidGenerator.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/ActiveMQUuidGenerator.java b/camel-core/src/main/java/org/apache/camel/impl/ActiveMQUuidGenerator.java
index 40618fd..297860c 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/ActiveMQUuidGenerator.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/ActiveMQUuidGenerator.java
@@ -20,6 +20,7 @@ import java.net.ServerSocket;
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.camel.spi.UuidGenerator;
+import org.apache.camel.util.IOHelper;
 import org.apache.camel.util.InetAddressUtil;
 import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
@@ -31,10 +32,15 @@ import org.slf4j.LoggerFactory;
  * <p/>
  * This implementation is not synchronized but it leverages API which may not be accessible
  * in the cloud (such as Google App Engine).
+ * <p/>
+ * The JVM system property {@link #PROPERTY_IDGENERATOR_PORT} can be used to set a specific
port
+ * number to be used as part of the initialization process to generate unique UUID.
  */
 public class ActiveMQUuidGenerator implements UuidGenerator {
 
-    private static final transient Logger LOG = LoggerFactory.getLogger(ActiveMQUuidGenerator.class);

+    // use same JVM property name as ActiveMQ
+    public static final String PROPERTY_IDGENERATOR_PORT = "activemq.idgenerator.port";
+    private static final transient Logger LOG = LoggerFactory.getLogger(ActiveMQUuidGenerator.class);
     private static final String UNIQUE_STUB;
     private static int instanceCount;
     private static String hostName;
@@ -55,14 +61,24 @@ public class ActiveMQUuidGenerator implements UuidGenerator {
         }
 
         if (canAccessSystemProps) {
+            int idGeneratorPort = 0;
+            ServerSocket ss = null;
             try {
+                idGeneratorPort = Integer.parseInt(System.getProperty(PROPERTY_IDGENERATOR_PORT,
"0"));
+                LOG.trace("Using port {}", idGeneratorPort);
                 hostName = InetAddressUtil.getLocalHostName();
-                ServerSocket ss = new ServerSocket(0);
+                ss = new ServerSocket(idGeneratorPort);
                 stub = "-" + ss.getLocalPort() + "-" + System.currentTimeMillis() + "-";
                 Thread.sleep(100);
                 ss.close();
             } catch (Exception ioe) {
-                LOG.warn("Could not generate unique stub by using DNS and binding to local
port, will fallback and use localhost as name", ioe);
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("Cannot generate unique stub by using DNS and binding to local
port: " + idGeneratorPort, ioe);
+                } else {
+                    LOG.warn("Cannot generate unique stub by using DNS and binding to local
port: " + idGeneratorPort + " due " + ioe.getMessage());
+                }
+            } finally {
+                IOHelper.close(ss);
             }
         }
 


Mime
View raw message