You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ch...@apache.org on 2015/03/10 20:37:43 UTC

camel git commit: Fixes CAMEL-8471: Port [AMQ-5652] IdGenerator not optimal in port restricted environments.

Repository: camel
Updated Branches:
  refs/heads/master 379195278 -> 08e4143c7


Fixes CAMEL-8471: Port [AMQ-5652] IdGenerator not optimal in port restricted environments.


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

Branch: refs/heads/master
Commit: 08e4143c7caef627f1be41bcd44d2912643d48e8
Parents: 3791952
Author: Hiram Chirino <hi...@hiramchirino.com>
Authored: Tue Mar 10 15:37:12 2015 -0400
Committer: Hiram Chirino <hi...@hiramchirino.com>
Committed: Tue Mar 10 15:37:34 2015 -0400

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


http://git-wip-us.apache.org/repos/asf/camel/blob/08e4143c/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 c75d2d3..6817ad5 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
@@ -39,7 +39,10 @@ import org.slf4j.LoggerFactory;
 public class ActiveMQUuidGenerator implements UuidGenerator {
 
     // use same JVM property name as ActiveMQ
+    public static final String PROPERTY_IDGENERATOR_HOSTNAME = "activemq.idgenerator.hostname";
+    public static final String PROPERTY_IDGENERATOR_LOCALPORT = "activemq.idgenerator.localport";
     public static final String PROPERTY_IDGENERATOR_PORT = "activemq.idgenerator.port";
+
     private static final Logger LOG = LoggerFactory.getLogger(ActiveMQUuidGenerator.class);
     private static final String UNIQUE_STUB;
     private static int instanceCount;
@@ -61,15 +64,25 @@ public class ActiveMQUuidGenerator implements UuidGenerator {
         }
 
         if (canAccessSystemProps) {
+            hostName = System.getProperty(PROPERTY_IDGENERATOR_HOSTNAME);
+            int localPort = Integer.parseInt(System.getProperty(PROPERTY_IDGENERATOR_LOCALPORT, "0"));
+
             int idGeneratorPort = 0;
             ServerSocket ss = null;
             try {
-                idGeneratorPort = Integer.parseInt(System.getProperty(PROPERTY_IDGENERATOR_PORT, "0"));
-                LOG.trace("Using port {}", idGeneratorPort);
-                hostName = InetAddressUtil.getLocalHostName();
-                ss = new ServerSocket(idGeneratorPort);
-                stub = "-" + ss.getLocalPort() + "-" + System.currentTimeMillis() + "-";
-                Thread.sleep(100);
+                if (hostName == null) {
+                    hostName = InetAddressUtil.getLocalHostName();
+                }
+                if (localPort == 0) {
+                    idGeneratorPort = Integer.parseInt(System.getProperty(PROPERTY_IDGENERATOR_PORT, "0"));
+                    LOG.trace("Using port {}", idGeneratorPort);
+                    ss = new ServerSocket(idGeneratorPort);
+                    localPort = ss.getLocalPort();
+                    stub = "-" + localPort + "-" + System.currentTimeMillis() + "-";
+                    Thread.sleep(100);
+                } else {
+                    stub = "-" + localPort + "-" + System.currentTimeMillis() + "-";
+                }
             } catch (Exception e) {
                 if (LOG.isTraceEnabled()) {
                     LOG.trace("Cannot generate unique stub by using DNS and binding to local port: " + idGeneratorPort, e);