mirror of https://github.com/apache/activemq.git
https://issues.apache.org/jira/browse/AMQ-4588 - id generator; some improvements in the socket close routine
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1503627 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ec11e82664
commit
975b7819cf
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.activemq.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
|
@ -50,20 +51,34 @@ public class IdGenerator {
|
|||
}
|
||||
|
||||
if (canAccessSystemProps) {
|
||||
int idGeneratorPort = 0;
|
||||
ServerSocket ss = null;
|
||||
try {
|
||||
int idGeneratorPort = Integer.parseInt(System.getProperty(PROPERTY_IDGENERATOR_PORT, "0"));
|
||||
idGeneratorPort = Integer.parseInt(System.getProperty(PROPERTY_IDGENERATOR_PORT, "0"));
|
||||
LOG.trace("Using port {}", idGeneratorPort);
|
||||
hostName = InetAddressUtil.getLocalHostName();
|
||||
ServerSocket ss = new ServerSocket(idGeneratorPort);
|
||||
ss = new ServerSocket(idGeneratorPort);
|
||||
stub = "-" + ss.getLocalPort() + "-" + System.currentTimeMillis() + "-";
|
||||
Thread.sleep(100);
|
||||
ss.close();
|
||||
} catch (Exception ioe) {
|
||||
if (LOG.isTraceEnabled()) {
|
||||
LOG.trace("could not generate unique stub by using DNS and binding to local port", ioe);
|
||||
} else {
|
||||
LOG.warn("could not generate unique stub by using DNS and binding to local port: {} {}", ioe.getClass().getCanonicalName(), ioe.getMessage());
|
||||
}
|
||||
} finally {
|
||||
if (ss != null) {
|
||||
try {
|
||||
// TODO: replace the following line with IOHelper.close(ss) when Java 6 support is dropped
|
||||
ss.close();
|
||||
} catch (IOException ioe) {
|
||||
if (LOG.isTraceEnabled()) {
|
||||
LOG.trace("Closing the server socket failed", ioe);
|
||||
} else {
|
||||
LOG.warn("Closing the server socket failed" + " due " + ioe.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// fallback
|
||||
|
|
Loading…
Reference in New Issue