You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2015/03/09 18:50:14 UTC
activemq git commit: Fix for AMQ-5652: IdGenerator not optimal in
port restricted environments.
Repository: activemq
Updated Branches:
refs/heads/master 1c72579d7 -> e25a6aa8a
Fix for AMQ-5652: IdGenerator not optimal in port restricted environments.
We now support configuring via system props activemq.idgenerator.hostname and activemq.idgenerator.localport which are used as the base part of GUIDs.
Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/e25a6aa8
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/e25a6aa8
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/e25a6aa8
Branch: refs/heads/master
Commit: e25a6aa8a18fbd1e0ada5bfa2b5655b80b053b9e
Parents: 1c72579
Author: Hiram Chirino <hi...@hiramchirino.com>
Authored: Mon Mar 9 13:45:20 2015 -0400
Committer: Hiram Chirino <hi...@hiramchirino.com>
Committed: Mon Mar 9 13:50:04 2015 -0400
----------------------------------------------------------------------
.../org/apache/activemq/util/IdGenerator.java | 25 +++++++++++++++-----
1 file changed, 19 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq/blob/e25a6aa8/activemq-client/src/main/java/org/apache/activemq/util/IdGenerator.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/util/IdGenerator.java b/activemq-client/src/main/java/org/apache/activemq/util/IdGenerator.java
index 3bf10a5..071a35e 100755
--- a/activemq-client/src/main/java/org/apache/activemq/util/IdGenerator.java
+++ b/activemq-client/src/main/java/org/apache/activemq/util/IdGenerator.java
@@ -35,6 +35,8 @@ public class IdGenerator {
private String seed;
private final AtomicLong sequence = new AtomicLong(1);
private int length;
+ 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";
static {
@@ -50,15 +52,26 @@ public class IdGenerator {
}
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("could not generate unique stub by using DNS and binding to local port", e);