You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ha...@apache.org on 2012/01/21 03:11:18 UTC
svn commit: r1234234 - in /camel/branches/camel-2.9.x: ./
components/camel-test/src/main/java/org/apache/camel/test/AvailablePortFinder.java
components/camel-test/src/test/java/org/apache/camel/test/AvailablePortFinderTest.java
Author: hadrian
Date: Sat Jan 21 02:11:17 2012
New Revision: 1234234
URL: http://svn.apache.org/viewvc?rev=1234234&view=rev
Log:
Merged revisions 1232762 via svnmerge from
https://svn.apache.org/repos/asf/camel/trunk
........
r1232762 | davsclaus | 2012-01-18 02:02:46 -0500 (Wed, 18 Jan 2012) | 1 line
Polished
........
Modified:
camel/branches/camel-2.9.x/ (props changed)
camel/branches/camel-2.9.x/components/camel-test/src/main/java/org/apache/camel/test/AvailablePortFinder.java
camel/branches/camel-2.9.x/components/camel-test/src/test/java/org/apache/camel/test/AvailablePortFinderTest.java
Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: camel/branches/camel-2.9.x/components/camel-test/src/main/java/org/apache/camel/test/AvailablePortFinder.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-test/src/main/java/org/apache/camel/test/AvailablePortFinder.java?rev=1234234&r1=1234233&r2=1234234&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-test/src/main/java/org/apache/camel/test/AvailablePortFinder.java (original)
+++ camel/branches/camel-2.9.x/components/camel-test/src/main/java/org/apache/camel/test/AvailablePortFinder.java Sat Jan 21 02:11:17 2012
@@ -20,8 +20,14 @@ import java.io.IOException;
import java.net.DatagramSocket;
import java.net.ServerSocket;
import java.util.NoSuchElementException;
+import java.util.Random;
+import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.camel.util.IOHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* Finds currently available server ports.
@@ -29,6 +35,7 @@ import java.util.concurrent.atomic.Atomi
* @see <a href="http://www.iana.org/assignments/currentMinPort-numbers">IANA.org</a>
*/
public final class AvailablePortFinder {
+
/**
* The minimum server currentMinPort number. Set at 1100 to avoid returning privileged
* currentMinPort numbers.
@@ -40,6 +47,8 @@ public final class AvailablePortFinder {
*/
public static final int MAX_PORT_NUMBER = 49151;
+ private static final Logger LOG = LoggerFactory.getLogger(AvailablePortFinder.class);
+
/**
* We'll hold open the lowest port in this process
* so parallel processes won't use the same block
@@ -83,14 +92,15 @@ public final class AvailablePortFinder {
});
currentMinPort.set(port + 1);
}
-
/**
- * Gets the next available currentMinPort starting at the lowest currentMinPort number. This is the preferred
+ * Gets the next available port starting at the lowest number. This is the preferred
* method to use. The port return is immediately marked in use and doesn't rely on the caller actually opening
* the port.
*
+ * @throws IllegalArgumentException is thrown if the port number is out of range
* @throws NoSuchElementException if there are no ports available
+ * @return the available port
*/
public static synchronized int getNextAvailable() {
int next = getNextAvailable(currentMinPort.get());
@@ -99,31 +109,36 @@ public final class AvailablePortFinder {
}
/**
- * Gets the next available currentMinPort starting at a currentMinPort.
+ * Gets the next available port starting at a given from port.
*
- * @param fromPort the currentMinPort to scan for availability
+ * @param fromPort the from port to scan for availability
+ * @throws IllegalArgumentException is thrown if the port number is out of range
* @throws NoSuchElementException if there are no ports available
+ * @return the available port
*/
public static synchronized int getNextAvailable(int fromPort) {
if (fromPort < currentMinPort.get() || fromPort > MAX_PORT_NUMBER) {
- throw new IllegalArgumentException("Invalid start currentMinPort: " + fromPort);
+ throw new IllegalArgumentException("From port number not in valid range: " + fromPort);
}
for (int i = fromPort; i <= MAX_PORT_NUMBER; i++) {
if (available(i)) {
+ LOG.info("getNextAvailable({}) -> {}", fromPort, i);
return i;
}
}
- throw new NoSuchElementException("Could not find an available currentMinPort above " + fromPort);
+ throw new NoSuchElementException("Could not find an available port above " + fromPort);
}
/**
- * Checks to see if a specific currentMinPort is available.
+ * Checks to see if a specific port is available.
*
- * @param port the currentMinPort to check for availability
+ * @param port the port number to check for availability
+ * @return <tt>true</tt> if the port is available, or <tt>false</tt> if not
+ * @throws IllegalArgumentException is thrown if the port number is out of range
*/
- public static boolean available(int port) {
+ public static boolean available(int port) throws IllegalArgumentException {
if (port < currentMinPort.get() || port > MAX_PORT_NUMBER) {
throw new IllegalArgumentException("Invalid start currentMinPort: " + port);
}
Modified: camel/branches/camel-2.9.x/components/camel-test/src/test/java/org/apache/camel/test/AvailablePortFinderTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-test/src/test/java/org/apache/camel/test/AvailablePortFinderTest.java?rev=1234234&r1=1234233&r2=1234234&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-test/src/test/java/org/apache/camel/test/AvailablePortFinderTest.java (original)
+++ camel/branches/camel-2.9.x/components/camel-test/src/test/java/org/apache/camel/test/AvailablePortFinderTest.java Sat Jan 21 02:11:17 2012
@@ -23,7 +23,6 @@ import org.junit.Test;
public class AvailablePortFinderTest {
-
@Test
public void getNextAvailablePort() throws Exception {
int p1 = AvailablePortFinder.getNextAvailable();
@@ -59,5 +58,4 @@ public class AvailablePortFinderTest {
AvailablePortFinder.getNextAvailable(AvailablePortFinder.MAX_PORT_NUMBER + 1);
}
-
}