directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 57000 - incubator/directory/seda/trunk/src/java/org/apache/seda/listener
Date Tue, 09 Nov 2004 04:34:50 GMT
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.
      *

Mime
View raw message