2 Replies Latest reply on Oct 15, 2002 2:14 AM by Alwyn Schoeman

    A fix for OILConnectionFactory on machines with multiple NIC

    geir rastad Newbie

      Hello,


      I'm using the OIL method for JMS connection, but I had some problems connecting from one machine to the other.
      I downloaded the jboss sources and looked at the OILClientILService.java, and it struck me that this class doesn't handle hosts with multiple ethernet interfaces.

      In my environment all machines have two NICs, one for internet access, and the other for internal access to development servers.

      The code, as it is in the OILClientILService.java just binds using new ServerSocket(0), which uses the default interface (and not the one I really want to bind to), so I wrote a new init() method (changes are in bold):


      public void init(org.jboss.mq.Connection connection, java.util.Properties props)
      throws java.lang.Exception
      {
      this.connection = connection;
      String myIF = System.getProperty("CUSTOM_OIL_BIND_ADDRESS");
      cat.debug("CUSTOM_OIL_BIND_ADDRESS=" + myIF);
      java.net.InetSocketAddress myAddress = null;
      if( myIF != null ) {
      // Select correct interface for systems with more than on IF
      serverSocket = new ServerSocket();
      myAddress = new java.net.InetSocketAddress(myIF, 0);
      serverSocket.bind( myAddress );
      }
      else {
      // Use default IF

      serverSocket = new ServerSocket(0);
      }

      cat.debug("Connection settings: " + ((java.net.InetSocketAddress)serverSocket.getLocalSocketAddress()).getHostName() +":" + serverSocket.getLocalPort());

      String t = props.getProperty(OILServerILFactory.OIL_TCPNODELAY_KEY);
      if (t != null)
      enableTcpNoDelay = t.equals("yes");

      if( myIF == null ) {
      clientIL = new OILClientIL(java.net.InetAddress.getLocalHost(), serverSocket.getLocalPort(), enableTcpNoDelay);
      }
      else {
      clientIL = new OILClientIL(java.net.InetAddress.getByName(myAddress.getHostName()), serverSocket.getLocalPort(), enableTcpNoDelay);
      }

      }



      The last 'if( myIF == null )' block could probably be replaced by a singe line like this:
      clientIL = new OILClientIL(((java.net.InetSocketAddress)serverSocket.getLocalSocketAddress()).getHostName(), serverSocket.getLocalPort(), enableTcpNoDelay);


      By applying this code I'm now able to use the OIL method between different machines with multiple NICs, and a great improvement in speed compared to the UIL method. However, the client side must pass a system property at startup, like this:
      -DCUSTOM_OIL_BIND_ADDRESS=address
      Where address is the IP address or hostname for the NIC (or a logical IF) to bind to.



      I hope this could be of any help to other people in the same situation (if any)!



        • 1. Re: A fix for OILConnectionFactory on machines with multiple
          Terry Rosenbaum Newbie

          As another possible solution, use the
          OIL2ConnectionFactory available in the
          latest builds.

          The OIL2Connection factory works fine when
          faced with the issue of multiple NICs. See
          earlier thread in this forum entitled
          "JMS and firewalls - Is it possible?" for
          more details.

          • 2. Re: A fix for OILConnectionFactory on machines with multiple
            Alwyn Schoeman Newbie

            I have the problem where if the JMS Queue and the client is not on the same machine the following happens:

            1) Start the external client implementing request listener.
            2) Wait a few seconds, maybe minutes.
            3) Put messages on the queue.

            The listener is never notified of any messages.

            If I now restart the client it will suddenly get the messages.

            I have narrowed it down to the server trying to connect back to the client upon connection, BUT I suspect it is trying to connect to localhost.

            My /etc/hosts is correct as in:
            127.0.0.1 localhost
            x.x.x.x hostname

            This only happens if client is on another machine.

            Any fixes for this?