Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A7A5DFB0B for ; Tue, 9 Jul 2013 05:54:23 +0000 (UTC) Received: (qmail 28597 invoked by uid 500); 9 Jul 2013 05:54:22 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 28454 invoked by uid 500); 9 Jul 2013 05:54:21 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 28416 invoked by uid 99); 9 Jul 2013 05:54:12 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Jul 2013 05:54:12 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 4109B889008; Tue, 9 Jul 2013 05:54:12 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Tue, 09 Jul 2013 05:54:13 -0000 Message-Id: In-Reply-To: <1b21f3ce90084f9285d255373efd7445@git.apache.org> References: <1b21f3ce90084f9285d255373efd7445@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/3] git commit: CAMEL-6521: ActiveMQUuidGenerator should allow configuring server socket port number 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 Authored: Tue Jul 9 07:51:39 2013 +0200 Committer: Claus Ibsen 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; *

* This implementation is not synchronized but it leverages API which may not be accessible * in the cloud (such as Google App Engine). + *

+ * 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); } }