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 [EMAIL PROTECTED] Set} of currently avaliable port numbers
([EMAIL PROTECTED] Integer})
* between the specified port range.
*