2 Replies Latest reply on Sep 5, 2006 12:32 PM by clebert.suconic

    Problem getting correct IP for CallbackServer

    coyotesqrl

      My linux servers' /etc/hosts files have the loopback address associated with the hostname, so when the CallbackServerFactory gets the IP to report to the JMS server, it passes the loopback address. Obviously, this is a short-term problem, as http://jira.jboss.org/jira/browse/JBMESSAGING-92 will (fingers crossed) soon be available. However, for now, this is a problem.

      I suggest the following workaround:

      1. Allow a system property override (similar to the java.rmi.server.hostName property). In my solution I used java.rmi.override.host
      2. Change org.jboss.jms.client.remoting.CallbackServerFactory to support, like below:

      --- CallbackServerFactory.javaOLD 2006-08-29 08:30:03.599602300 -0700
      +++ CallbackServerFactory.java 2006-08-29 08:23:52.975018900 -0700
      @@ -126,5 +126,13 @@
       int count = 0;
      
      - String thisAddress = InetAddress.getLocalHost().getHostAddress();
      + // BEGIN HACK
      + String thisAddress = System.getProperty("java.rmi.override.host");
      + if (thisAddress == null)
      + {
      + thisAddress = InetAddress.getLocalHost().getHostAddress();
      + }
      + // END HACK
      +
      +
       boolean isSSL = serverLocator.getProtocol().equals("sslsocket");
       Map params = serverLocator.getParameters();


        • 1. Re: Problem getting correct IP for CallbackServer
          ovidiu.feodorov

          Thanks.

          I've opened this: http://jira.jboss.com/jira/browse/JBMESSAGING-536

          Scheduled it for CR5.

          • 2. Re: Problem getting correct IP for CallbackServer
            clebert.suconic

            I will fix this by getting the IP from serverLocator.

            This way, we will get the same IP configured.


             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 = serverLocator.getHost();
            
             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(thisAddress);
            
             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;
             }