river-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter_firmst...@apache.org
Subject svn commit: r1570769 - /river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/reggie/RegistrarImpl.java
Date Sat, 22 Feb 2014 00:42:20 GMT
Author: peter_firmstone
Date: Sat Feb 22 00:42:20 2014
New Revision: 1570769

URL: http://svn.apache.org/r1570769
Log:
Prevent BindException during construction of Reggie by selecting an arbitrary port if the
configured port is in use, an admin can use DiscoveryAdmin to change the Unicast Discovery
port later if desired.

Modified:
    river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/reggie/RegistrarImpl.java

Modified: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/reggie/RegistrarImpl.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/reggie/RegistrarImpl.java?rev=1570769&r1=1570768&r2=1570769&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/reggie/RegistrarImpl.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/reggie/RegistrarImpl.java Sat Feb
22 00:42:20 2014
@@ -2759,19 +2759,30 @@ class RegistrarImpl implements Registrar
 	public Unicast(RegistrarImpl reggie, int port) throws IOException {
             this.reggie = reggie;
             ServerSocket listen = null;
+            boolean ephemeral = false;
             if (port == 0) {
 		try {
 		    listen = reggie.serverSocketFactory.createServerSocket(Constants.discoveryPort);
+                    port = Constants.discoveryPort;
 		} catch (IOException e) {
 		    logger.log(
 			Levels.HANDLED, "failed to bind to default port", e);
 		}
 	    }
 	    if (listen == null) {
-                listen = reggie.serverSocketFactory.createServerSocket(port);
+                try {
+                    listen = reggie.serverSocketFactory.createServerSocket(port);
+                } catch (IOException e){
+                    logger.log(Level.INFO, "failed to bind to port " + port, e);
+                    listen = reggie.serverSocketFactory.createServerSocket(0);
+                    ephemeral = true;
+                    port = listen.getLocalPort();
+                    logger.log(Level.INFO, "bound to ephemeral port {0}", port);
+                }
 	    }
             this.listen = listen;
-	    this.port = listen.getLocalPort();
+	    this.port = port;
+            if (ephemeral) reggie.unicastPort = port;
         }
 
 	public void run() {



Mime
View raw message