[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting/transport/bisocket ...

Ron Sigal ron_sigal at yahoo.com
Thu Feb 22 22:41:59 EST 2007


  User: rsigal  
  Date: 07/02/22 22:41:59

  Modified:    src/main/org/jboss/remoting/transport/bisocket 
                        BisocketClientInvoker.java
  Log:
  JBREM-650:  Synchronized with 2_x branch.
  
  Revision  Changes    Path
  1.5       +57 -30    JBossRemoting/src/main/org/jboss/remoting/transport/bisocket/BisocketClientInvoker.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: BisocketClientInvoker.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/transport/bisocket/BisocketClientInvoker.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- BisocketClientInvoker.java	18 Jan 2007 21:47:39 -0000	1.4
  +++ BisocketClientInvoker.java	23 Feb 2007 03:41:59 -0000	1.5
  @@ -22,17 +22,6 @@
   
   package org.jboss.remoting.transport.bisocket;
   
  -import org.jboss.logging.Logger;
  -import org.jboss.remoting.Client;
  -import org.jboss.remoting.ConnectionFailedException;
  -import org.jboss.remoting.InvocationRequest;
  -import org.jboss.remoting.InvokerLocator;
  -import org.jboss.remoting.invocation.InternalInvocation;
  -import org.jboss.remoting.marshal.Marshaller;
  -import org.jboss.remoting.marshal.UnMarshaller;
  -import org.jboss.remoting.transport.BidirectionalClientInvoker;
  -import org.jboss.remoting.transport.socket.SocketClientInvoker;
  -
   import java.io.IOException;
   import java.io.OutputStream;
   import java.net.Socket;
  @@ -40,11 +29,23 @@
   import java.util.HashMap;
   import java.util.HashSet;
   import java.util.Iterator;
  +import java.util.LinkedList;
   import java.util.Map;
   import java.util.Set;
   import java.util.Timer;
   import java.util.TimerTask;
   
  +import org.jboss.logging.Logger;
  +import org.jboss.remoting.Client;
  +import org.jboss.remoting.ConnectionFailedException;
  +import org.jboss.remoting.InvocationRequest;
  +import org.jboss.remoting.InvokerLocator;
  +import org.jboss.remoting.invocation.InternalInvocation;
  +import org.jboss.remoting.marshal.Marshaller;
  +import org.jboss.remoting.marshal.UnMarshaller;
  +import org.jboss.remoting.transport.BidirectionalClientInvoker;
  +import org.jboss.remoting.transport.socket.SocketClientInvoker;
  +
   /**
    * The bisocket transport, an extension of the socket transport, is designed to allow
    * a callback server to function behind a firewall.  All connections are created by
  @@ -79,9 +80,13 @@
      private OutputStream controlOutputStream;
      private Object controlLock = new Object();
      private PingTimerTask pingTimerTask;
  -   private boolean isCallbackInvoker;
  +   protected boolean isCallbackInvoker;
   
   
  +   /**
  +    * @param listenerId
  +    * @return
  +    */
      static BisocketClientInvoker getBisocketClientInvoker(String listenerId)
      {
         return (BisocketClientInvoker) listenerIdToClientInvokerMap.get(listenerId);
  @@ -177,15 +182,18 @@
   
      protected void handleConnect() throws ConnectionFailedException
      {
  -      super.handleConnect();
  -
         // Callback client on server side.
  -      if (listenerId != null)
  +      if (isCallbackInvoker)
         {
  +         // Bisocket callback client invoker doesn't share socket pools because of the danger
  +         // that two distinct callback servers could have the same "artifical" port.
  +         pool = new LinkedList();
            return;
         }
   
         // Client on client side.
  +      super.handleConnect();
  +      
         try
         {
            secondaryLocator = getSecondaryLocator();
  @@ -200,18 +208,23 @@
   
      protected void handleDisconnect()
      {
  -      super.handleDisconnect();
         if (listenerId != null)
         {
            if (isCallbackInvoker)
  +         {
               listenerIdToCallbackClientInvokerMap.remove(listenerId);
  +         }
            else
  +         {
               listenerIdToClientInvokerMap.remove(listenerId);
  +         }
   
            listenerIdToSocketsMap.remove(listenerId);
            if (pingTimerTask != null)
               pingTimerTask.shutDown();
         }
  +      
  +      super.handleDisconnect();
      }
   
   
  @@ -229,7 +242,7 @@
               if (InternalInvocation.ADDLISTENER.equals(ii.getMethodName()))
               {
                  Map requestPayload = ir.getRequestPayload();
  -               String listenerId = (String) requestPayload.get(Client.LISTENER_ID_KEY);
  +               listenerId = (String) requestPayload.get(Client.LISTENER_ID_KEY);
                  listenerIdToClientInvokerMap.put(listenerId, this);
                  BisocketServerInvoker callbackServerInvoker;
                  callbackServerInvoker = BisocketServerInvoker.getBisocketServerInvoker(listenerId);
  @@ -242,10 +255,10 @@
      }
   
   
  -   protected Socket createSocket(String address, int port) throws IOException
  +   protected Socket createSocket(String address, int port, int timeout) throws IOException
      {
  -      if (listenerId == null)
  -         return super.createSocket(address, port);
  +      if (!isCallbackInvoker)
  +         return super.createSocket(address, port, timeout);
   
         Set sockets = null;
   
  @@ -286,7 +299,7 @@
               controlSocket = (Socket) it.next();
               it.remove();
               controlOutputStream = controlSocket.getOutputStream();
  -            log.debug("got control socket");
  +            log.debug("got control socket: " + controlSocket);
               pingTimerTask = new PingTimerTask();
               if (timer == null)
               {
  @@ -325,7 +338,7 @@
            Iterator it = sockets.iterator();
            Socket socket = (Socket) it.next();
            it.remove();
  -         log.debug("socket found");
  +         log.debug("found socket: " + socket);
            return socket;
         }
      }
  @@ -356,11 +369,25 @@
      {
         InternalInvocation ii = new InternalInvocation(Bisocket.GET_SECONDARY_INVOKER_LOCATOR, null);
         InvocationRequest r = new InvocationRequest(null, null, ii, null, null, null);
  +      log.debug("getting secondary locator");
  +      
  +      for (int i = 0; i < 5; i++)
  +      {
  +         try
  +         {
         Object o = invoke(r);
         log.debug("secondary locator: " + o);
         secondaryLocator = (InvokerLocator) o;
         return secondaryLocator;
      }
  +         catch (IOException e)
  +         {
  +            log.warn("unable to get secondary locator: trying again");
  +         }
  +      }
  +      
  +      throw new IOException("unable to get secondary locator");
  +   }
   
      protected Object checkType(Object o, Class c) throws IOException
      {
  
  
  



More information about the jboss-cvs-commits mailing list