You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2004/11/09 05:34:50 UTC
svn commit: rev 57000 - incubator/directory/seda/trunk/src/java/org/apache/seda/listener
Author: akarasulu
Date: Mon Nov 8 20:34:50 2004
New Revision: 57000
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/AvailablePortFinder.java
Log:
added extra available method
Modified: incubator/directory/seda/trunk/src/java/org/apache/seda/listener/AvailablePortFinder.java
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/listener/AvailablePortFinder.java (original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/listener/AvailablePortFinder.java Mon Nov 8 20:34:50 2004
@@ -122,6 +122,44 @@
}
/**
+ * Checks to see if a specific port is available.
+ *
+ * @param port the port to check for availability
+ */
+ public static boolean available( int port )
+ {
+ if ( ( port < MIN_PORT_NUMBER) || ( port > MAX_PORT_NUMBER ) )
+ {
+ throw new IllegalArgumentException( "Invalid start port: " + port );
+ }
+
+ ServerSocket s = null;
+ try
+ {
+ s = new ServerSocket( port );
+ return true;
+ }
+ catch ( IOException e )
+ {
+ return false;
+ }
+ finally
+ {
+ if ( s != null )
+ {
+ try
+ {
+ s.close();
+ }
+ catch (IOException e)
+ {
+ /* should not be thrown */
+ }
+ }
+ }
+ }
+
+ /**
* Returns the {@link Set} of currently avaliable port numbers ({@link Integer})
* between the specified port range.
*