String thisAddress = InetAddress.getLocalHost().getHostAddress();
String thisAddress = serverLocator.getHost();
   protected Connector startCallbackServer(InvokerLocator serverLocator) throws Exception   {      if (log.isTraceEnabled()) { log.trace(this + " setting up connection to " + serverLocator); }      final int MAX_RETRIES = 50;      boolean completed = false;      Connector server = null;      String serializationType = null;      int count = 0;      String thisAddress = InetAddress.getLocalHost().getHostAddress();      boolean isSSL = serverLocator.getProtocol().equals("sslsocket");      Map params = serverLocator.getParameters();      if (params != null)      {         serializationType = (String)params.get("serializationtype");      }                  while (!completed && count < MAX_RETRIES)      {         try         {                  int bindPort = PortUtil.findFreePort("localhost");                  String callbackServerURI;                  if (isSSL)            {               // See http://jira.jboss.com/jira/browse/JBREM-470               callbackServerURI =                  "sslsocket://" + thisAddress + ":" +  bindPort + CALLBACK_SERVER_PARAMS +                  "&" + SSLSocketBuilder.REMOTING_SERVER_SOCKET_USE_CLIENT_MODE + "=true";            }            else            {               callbackServerURI = serverLocator.getProtocol() + "://" + thisAddress +                                   ":" + bindPort + CALLBACK_SERVER_PARAMS;            }                             if (serializationType != null)            {               callbackServerURI += "&serializationType=" + serializationType;            }                  InvokerLocator callbackServerLocator = new InvokerLocator(callbackServerURI);                  log.debug(this + " starting callback server " + callbackServerLocator.getLocatorURI());                  server = new Connector();            server.setInvokerLocator(callbackServerLocator.getLocatorURI());            server.create();            server.addInvocationHandler(JMS_CALLBACK_SUBSYSTEM, new CallbackManager());            server.start();                  if (log.isTraceEnabled()) { log.trace("callback server started"); }                        completed = true;         }         catch (Exception e)         {            log.warn("Failed to start connection. Will retry", 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 probably because            // of the small window between remoting checking the port is free and 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 (count == MAX_RETRIES)            {               final String msg = "Cannot start callbackserver after " + MAX_RETRIES + " retries";               log.error(msg, e);               throw new MessagingJMSException(msg, e);            }         }      }            return server;   }