bindPort = PortUtil.findFreePort("localhost");
   public JMSRemotingConnection(String serverLocatorURI) throws Throwable   {      callbackManager = new CallbackManager();            id = new GUID().toString();            thisAddress = InetAddress.getLocalHost().getHostAddress();            bindPort = PortUtil.findFreePort("localhost");            serverLocator = new InvokerLocator(serverLocatorURI);            isMultiplex = serverLocator.getProtocol().equals("multiplex");                  final int MAX_RETRIES = 50;            boolean completed = false;            int count = 0;            while (!completed && count < MAX_RETRIES)      {         try         {            setUpConnection();                        completed = true;                  }         catch (Exception e)         {            log.warn("Failed to start connection", e);                        //Intermittently we can fail to open a socket on the address since it's already in use            //This is despite remoting having checked the port is free.            //This is either because the remoting implementation is buggy            //Or because of the small window between getting the port number and actually opening the connection            //during which some one else can use that port.            //Therefore we catch this and retry                   count++;                        if (client != null)            {               client.disconnect();            }                        if (callbackServer != null)            {               //Probably not necessary and may fail since it didn't get properly started               try               {                  callbackServer.stop();                                    callbackServer.destroy();               }               catch (Exception ignore)               {                  //Ignore - it may well fail - this is to be expected               }            }            if (count == MAX_RETRIES)            {               throw new JBossJMSException("Cannot start callbackserver after " + MAX_RETRIES + " retries", e);            }                     }      }               }