tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andygumbre...@apache.org
Subject tomee git commit: Using 0 for system allocated port means forcing a ServerSocket call
Date Tue, 02 Dec 2014 10:29:00 GMT
Repository: tomee
Updated Branches:
  refs/heads/tomee-1.7.x 0115555c8 -> 987b71b83


Using 0 for system allocated port means forcing a ServerSocket call


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/987b71b8
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/987b71b8
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/987b71b8

Branch: refs/heads/tomee-1.7.x
Commit: 987b71b83dcb69cdd57960b7834d76ed27fcb292
Parents: 0115555
Author: andygumbrecht <andygumbrecht@apache.org>
Authored: Tue Dec 2 11:28:15 2014 +0100
Committer: andygumbrecht <andygumbrecht@apache.org>
Committed: Tue Dec 2 11:28:15 2014 +0100

----------------------------------------------------------------------
 .../java/org/apache/openejb/util/NetworkUtil.java   | 16 ++++++++++++----
 .../org/apache/openejb/util/NetworkUtilTest.java    |  2 +-
 2 files changed, 13 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/987b71b8/container/openejb-core/src/main/java/org/apache/openejb/util/NetworkUtil.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/util/NetworkUtil.java
b/container/openejb-core/src/main/java/org/apache/openejb/util/NetworkUtil.java
index 7feef7e..dc0a04e 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/util/NetworkUtil.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/util/NetworkUtil.java
@@ -185,17 +185,25 @@ public final class NetworkUtil {
 
     private static ServerSocket create(final int[] ports, final Collection<LastPort>
lastPort) throws IOException {
 
-        for (final int port : ports) {
+        for (int port : ports) {
             try {
+
+                final ServerSocket ss = new ServerSocket(port);
+                port = ss.getLocalPort();
+
                 final LastPort lp = new LastPort(port, System.currentTimeMillis());
+
                 if (lastPort != null) {
-                    if (lastPort.contains(lp)) { // actually doesn't mean much things excepted
"it has been locked recently"
+                    if (lastPort.contains(lp)) {
+                        try {
+                            ss.close();
+                        } catch (final Exception e) {
+                            //Ignore
+                        }
                         continue;
                     }
                 }
 
-                final ServerSocket ss = new ServerSocket(port);
-
                 if (!checkLockFile(port)) {
                     try {
                         ss.close();

http://git-wip-us.apache.org/repos/asf/tomee/blob/987b71b8/container/openejb-core/src/test/java/org/apache/openejb/util/NetworkUtilTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/util/NetworkUtilTest.java
b/container/openejb-core/src/test/java/org/apache/openejb/util/NetworkUtilTest.java
index 98de662..c64889f 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/util/NetworkUtilTest.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/util/NetworkUtilTest.java
@@ -62,7 +62,7 @@ public class NetworkUtilTest {
         for (int i = 0; i < count; i++) {
             final Thread thread = new Thread(new Runnable() {
                 public void run() {
-                    final int nextAvailablePort = NetworkUtil.getNextAvailablePort(NetworkUtil.PORT_MIN,
NetworkUtil.PORT_MAX, Collections.<Integer>emptyList(), lastPorts);
+                    final int nextAvailablePort = NetworkUtil.getNextAvailablePort();
                     if (list.contains(nextAvailablePort)) {
                         if ((System.currentTimeMillis() - start) < 10000) {
                             Assert.fail("Got a duplicate port with ten seconds");


Mime
View raw message