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

Ron Sigal ron_sigal at yahoo.com
Sat Apr 7 00:05:47 EDT 2007


  User: rsigal  
  Date: 07/04/07 00:05:47

  Modified:    src/main/org/jboss/remoting/transport/bisocket    Tag:
                        remoting_2_x BisocketServerInvoker.java
                        BisocketClientInvoker.java Bisocket.java
  Log:
  JBREM-731:  (1) Address of secondary server socket is acquired every time a control connection is created; (2) A limit is imposed on the number of times a control connection is recreated.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.18  +64 -33    JBossRemoting/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: BisocketServerInvoker.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java,v
  retrieving revision 1.1.2.17
  retrieving revision 1.1.2.18
  diff -u -b -r1.1.2.17 -r1.1.2.18
  --- BisocketServerInvoker.java	15 Mar 2007 06:15:57 -0000	1.1.2.17
  +++ BisocketServerInvoker.java	7 Apr 2007 04:05:47 -0000	1.1.2.18
  @@ -58,7 +58,7 @@
   /**
    *
    * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
  - * @version $Revision: 1.1.2.17 $
  + * @version $Revision: 1.1.2.18 $
    * <p>
    * Copyright Nov 23, 2006
    * </p>
  @@ -75,10 +75,12 @@
      private InvokerLocator secondaryLocator;
      private SecondaryServerSocketThread secondaryServerSocketThread;
      private Map controlConnectionThreadMap = new HashMap();
  +   private Map controlConnectionRestartsMap = new HashMap();
      private int pingFrequency = Bisocket.PING_FREQUENCY_DEFAULT;
      private int pingWindowFactor = Bisocket.PING_WINDOW_FACTOR_DEFAULT;
      private int pingWindow = pingWindowFactor * pingFrequency;
      private int socketCreationRetries = Bisocket.MAX_RETRIES_DEFAULT;
  +   private int controlConnectionRestarts = Bisocket.MAX_CONTROL_CONNECTION_RESTARTS_DEFAULT;
      private ControlMonitorTimerTask controlMonitorTimerTask;
      protected boolean isCallbackServer = false;
   
  @@ -121,6 +123,22 @@
               }
            }
            
  +         val = configuration.get(Bisocket.MAX_CONTROL_CONNECTION_RESTARTS);
  +         if (val != null)
  +         {
  +            try
  +            {
  +               int nVal = Integer.valueOf((String) val).intValue();
  +               controlConnectionRestarts = nVal;
  +               log.debug("Setting control connection restart limit: " + controlConnectionRestarts);
  +            }
  +            catch (Exception e)
  +            {
  +               log.warn("Could not convert " + Bisocket.MAX_CONTROL_CONNECTION_RESTARTS +
  +                     " value of " + val + " to an int value.");
  +            }
  +         }
  +         
            if(maxPoolSize <= 0)
            {
               maxPoolSize = MAX_POOL_SIZE_DEFAULT;
  @@ -167,15 +185,9 @@
      }
   
   
  -   public void createControlConnection(String listenerId, InvokerLocator locator)
  +   public void createControlConnection(String listenerId, boolean firstConnection)
      throws IOException
      {
  -      boolean firstConnection;
  -
  -      if (locator == null)
  -      {
  -         // restarting connection
  -         firstConnection = false;
            BisocketClientInvoker clientInvoker = BisocketClientInvoker.getBisocketClientInvoker(listenerId);
   
            if (clientInvoker == null)
  @@ -184,25 +196,20 @@
               throw new ClientUnavailableException();
            }
            
  +      InvokerLocator locator = null;
  +      
            try
            {
               locator = clientInvoker.getSecondaryLocator();
  -            listenerIdToInvokerLocatorMap.put(listenerId, locator);
            }
            catch (Throwable t)
            {
               log.error("unable to get secondary locator", t);
               throw new IOException("unable to get secondary locator: " + t.getMessage());
            }
  -      }
  -      else
  -      {
  -         // first connection
  -         firstConnection = true;
  -         listenerIdToInvokerLocatorMap.put(listenerId, locator);
  -      }
   
  -      log.debug("creating control connection: " + locator);
  +      listenerIdToInvokerLocatorMap.put(listenerId, locator);
  +      log.trace("creating control connection: " + locator);
   
         Socket socket = null;
         IOException savedException = null;
  @@ -260,6 +267,16 @@
         synchronized (controlConnectionThreadMap)
         {
            controlConnectionThreadMap.put(listenerId, thread);
  +         Object o = controlConnectionRestartsMap.get(listenerId);
  +         if (o != null)
  +         {
  +            int restarts = ((Integer) o).intValue();
  +            controlConnectionRestartsMap.put(listenerId, new Integer(++restarts));
  +         }
  +         else
  +         {
  +            controlConnectionRestartsMap.put(listenerId, new Integer(0));
  +         }
         }
   
         thread.start();
  @@ -275,6 +292,7 @@
         synchronized (controlConnectionThreadMap)
         {
            t = (Thread) controlConnectionThreadMap.remove(listenerId);
  +         controlConnectionRestartsMap.remove(listenerId);
         }
         
         if (t != null)
  @@ -798,12 +816,16 @@
         private BisocketServerInvoker invoker;
         private Map listenerIdToInvokerLocatorMap;
         private Map controlConnectionThreadMap;
  +      private Map controlConnectionRestartsMap;
  +      private int controlConnectionRestarts;
         
         ControlMonitorTimerTask(BisocketServerInvoker invoker)
         {
            this.invoker = invoker;
            listenerIdToInvokerLocatorMap = invoker.listenerIdToInvokerLocatorMap;
            controlConnectionThreadMap = invoker.controlConnectionThreadMap;
  +         controlConnectionRestartsMap = invoker.controlConnectionRestartsMap;
  +         controlConnectionRestarts = invoker.controlConnectionRestarts;
         }
   
         synchronized void shutdown()
  @@ -864,6 +886,16 @@
                        return;
                     
                     controlConnectionThreadMap.remove(listenerId);
  +                  Object o = controlConnectionRestartsMap.get(listenerId);
  +                  int restarts = ((Integer)o).intValue();
  +                  
  +                  if (restarts + 1 >= controlConnectionRestarts)
  +                  {
  +                     log.warn("Control connection " + listenerId + " has been recreated " + restarts + " times.");
  +                     log.warn("Assuming it is a connection to an old server, will not restart");
  +                     controlConnectionRestartsMap.remove(listenerId);
  +                     continue;
  +                  }
                  }
                  
                  Thread t2 = new Thread()
  @@ -875,7 +907,7 @@
                        
                        try
                        {
  -                        invoker.createControlConnection(listenerId, null);
  +                        invoker.createControlConnection(listenerId, false);
                        }
                        catch (ClientUnavailableException e)
                        {
  @@ -892,7 +924,6 @@
                  };
                  t2.setName("controlConnectionRecreate:" + t.getName());
                  t2.start();
  -
               }
            }
         }
  
  
  
  1.1.2.14  +3 -15     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.1.2.13
  retrieving revision 1.1.2.14
  diff -u -b -r1.1.2.13 -r1.1.2.14
  --- BisocketClientInvoker.java	14 Mar 2007 06:13:22 -0000	1.1.2.13
  +++ BisocketClientInvoker.java	7 Apr 2007 04:05:47 -0000	1.1.2.14
  @@ -78,7 +78,6 @@
   
      private int pingFrequency = Bisocket.PING_FREQUENCY_DEFAULT;
      private int maxRetries = Bisocket.MAX_RETRIES_DEFAULT;
  -   private InvokerLocator secondaryLocator;
      private Socket controlSocket;
      private OutputStream controlOutputStream;
      private Object controlLock = new Object();
  @@ -257,16 +256,6 @@
   
         // Client on client side.
         super.handleConnect();
  -      
  -      try
  -      {
  -         secondaryLocator = getSecondaryLocator();
  -      }
  -      catch (Throwable e)
  -      {
  -         log.error("Unable to retrieve address/port of secondary server socket", e);
  -         throw new ConnectionFailedException(e.getMessage());
  -      }
      }
      
      
  @@ -325,7 +314,7 @@
                  listenerIdToClientInvokerMap.put(listenerId, this);
                  BisocketServerInvoker callbackServerInvoker;
                  callbackServerInvoker = BisocketServerInvoker.getBisocketServerInvoker(listenerId);
  -               callbackServerInvoker.createControlConnection(listenerId, secondaryLocator);
  +               callbackServerInvoker.createControlConnection(listenerId, true);
               }
               
               // Rather than handle the REMOVELISTENER case symmetrically, it is
  @@ -425,13 +414,12 @@
            {
               Object o = invoke(r);
               log.debug("secondary locator: " + o);
  -            secondaryLocator = (InvokerLocator) o;
  -            return secondaryLocator;
  +            return (InvokerLocator) o;
            }
            catch (Exception e)
            {
               savedException = e;
  -            log.info("unable to get secondary locator: trying again");
  +            log.debug("unable to get secondary locator: trying again");
            }
         }
         
  
  
  
  1.1.2.5   +8 -1      JBossRemoting/src/main/org/jboss/remoting/transport/bisocket/Bisocket.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Bisocket.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/transport/bisocket/Bisocket.java,v
  retrieving revision 1.1.2.4
  retrieving revision 1.1.2.5
  diff -u -b -r1.1.2.4 -r1.1.2.5
  --- Bisocket.java	14 Mar 2007 04:52:13 -0000	1.1.2.4
  +++ Bisocket.java	7 Apr 2007 04:05:47 -0000	1.1.2.5
  @@ -23,7 +23,7 @@
   
   /** 
    * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
  - * @version $Revision: 1.1.2.4 $
  + * @version $Revision: 1.1.2.5 $
    * <p>
    * Copyright Nov 22, 2006
    * </p>
  @@ -61,4 +61,11 @@
       */
      public static final String MAX_RETRIES = "maxRetries";
      public static final int MAX_RETRIES_DEFAULT = 10;
  +   
  +   /**
  +    * Configuration key and default value for number of times a control connection
  +    * will be restarted.
  +    */
  +   public static final String MAX_CONTROL_CONNECTION_RESTARTS = "maxRetries";
  +   public static final int MAX_CONTROL_CONNECTION_RESTARTS_DEFAULT = 10;
   }
  
  
  



More information about the jboss-cvs-commits mailing list