Updated Branches: refs/heads/camel-2.10.x bb9a50262 -> 95a3189d8 refs/heads/camel-2.11.x 17376da4f -> be7118702 refs/heads/master 99253d9c3 -> 372fd02a9
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/372fd02a Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/372fd02a Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/372fd02a Branch: refs/heads/master Commit: 372fd02a901677b824124f6e1e4d0f2cd8177187 Parents: 99253d9 Author: Claus Ibsen <davscl...@apache.org> Authored: Tue Jul 9 07:51:39 2013 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Jul 9 07:51:39 2013 +0200 ---------------------------------------------------------------------- .../camel/impl/ActiveMQUuidGenerator.java | 22 +++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/372fd02a/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); } }