activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject svn commit: r1503627 - /activemq/trunk/activemq-client/src/main/java/org/apache/activemq/util/IdGenerator.java
Date Tue, 16 Jul 2013 09:29:16 GMT
Author: dejanb
Date: Tue Jul 16 09:29:16 2013
New Revision: 1503627

URL: http://svn.apache.org/r1503627
Log:
https://issues.apache.org/jira/browse/AMQ-4588 - id generator; some improvements in the socket
close routine

Modified:
    activemq/trunk/activemq-client/src/main/java/org/apache/activemq/util/IdGenerator.java

Modified: activemq/trunk/activemq-client/src/main/java/org/apache/activemq/util/IdGenerator.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-client/src/main/java/org/apache/activemq/util/IdGenerator.java?rev=1503627&r1=1503626&r2=1503627&view=diff
==============================================================================
--- activemq/trunk/activemq-client/src/main/java/org/apache/activemq/util/IdGenerator.java
(original)
+++ activemq/trunk/activemq-client/src/main/java/org/apache/activemq/util/IdGenerator.java
Tue Jul 16 09:29:16 2013
@@ -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



Mime
View raw message