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

Ron Sigal ron_sigal at yahoo.com
Wed Apr 11 19:48:31 EDT 2007


  User: rsigal  
  Date: 07/04/11 19:48:31

  Modified:    src/main/org/jboss/remoting/transport/bisocket  Tag:
                        remoting_2_2_0_GA BisocketServerInvoker.java
  Log:
  JBREM-731:  Added some getters and setters.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.17.2.1 +106 -37   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.17.2.1
  diff -u -b -r1.1.2.17 -r1.1.2.17.2.1
  --- BisocketServerInvoker.java	15 Mar 2007 06:15:57 -0000	1.1.2.17
  +++ BisocketServerInvoker.java	11 Apr 2007 23:48:31 -0000	1.1.2.17.2.1
  @@ -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.17.2.1 $
    * <p>
    * Copyright Nov 23, 2006
    * </p>
  @@ -75,10 +75,12 @@
      private InvokerLocator secondaryLocator;
      private SecondaryServerSocketThread secondaryServerSocketThread;
      private Map controlConnectionThreadMap = new HashMap();
  +   private Map controlConnectionRestartsMap = Collections.synchronizedMap(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,30 @@
               throw new ClientUnavailableException();
            }
            
  +      InvokerLocator oldLocator = (InvokerLocator) listenerIdToInvokerLocatorMap.get(listenerId);
  +      InvokerLocator newLocator = null;
  +      
            try
            {
  -            locator = clientInvoker.getSecondaryLocator();
  -            listenerIdToInvokerLocatorMap.put(listenerId, locator);
  +         newLocator = clientInvoker.getSecondaryLocator();
            }
            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);
  +
  +      // If a server restarts, it is likely that it creates a new secondary server socket on
  +      // a different port.  It will possible to recreate the control connection, but if
  +      // there is no PingTimerTask running in the new server to keep it alive, it will just
  +      // die again.  Once a new secondary server socket address is detected, a count is kept
  +      // of the number of times the control connection is restarted, and when it hits a
  +      // configured maximum, it is allowed to die.  See JBREM-731.
  +      
  +      boolean locatorChanged = !newLocator.equals(oldLocator);
  +      listenerIdToInvokerLocatorMap.put(listenerId, newLocator);
  +      log.debug("creating control connection: " + newLocator);
   
         Socket socket = null;
         IOException savedException = null;
  @@ -212,9 +229,9 @@
            try
            {
               if (socketFactory != null)
  -               socket = socketFactory.createSocket(locator.getHost(), locator.getPort());
  +               socket = socketFactory.createSocket(newLocator.getHost(), newLocator.getPort());
               else
  -               socket = new Socket(locator.getHost(), locator.getPort());
  +               socket = new Socket(newLocator.getHost(), newLocator.getPort());
            }
            catch (IOException e)
            {
  @@ -262,6 +279,18 @@
            controlConnectionThreadMap.put(listenerId, thread);
         }
   
  +      Object o = controlConnectionRestartsMap.get(listenerId);
  +      if (o != null)
  +      {
  +         int restarts = ((Integer) o).intValue();
  +         if (locatorChanged || restarts > 0)
  +         controlConnectionRestartsMap.put(listenerId, new Integer(++restarts));
  +      }
  +      else
  +      {
  +         controlConnectionRestartsMap.put(listenerId, new Integer(0));
  +      }
  +
         thread.start();
         log.debug("created control connection: " + socket.toString());
      }
  @@ -270,6 +299,7 @@
      public void destroyControlConnection(String listenerId) throws IOException
      {
         listenerIdToInvokerLocatorMap.remove(listenerId);
  +      controlConnectionRestartsMap.remove(listenerId);
         Thread t = null;
         
         synchronized (controlConnectionThreadMap)
  @@ -288,6 +318,18 @@
      }
      
      
  +   public int getControlConnectionRestarts()
  +   {
  +      return controlConnectionRestarts;
  +   }
  +   
  +   
  +   public void setControlConnectionRestarts(int controlConnectionRestarts)
  +   {
  +      this.controlConnectionRestarts = controlConnectionRestarts;
  +   }
  +   
  +   
      public int getPingFrequency()
      {
         return pingFrequency;
  @@ -314,6 +356,18 @@
      }
   
   
  +   public int getSocketCreationRetries()
  +   {
  +      return socketCreationRetries;
  +   }
  +   
  +   
  +   public void setSocketCreationRetries(int socketCreationRetries)
  +   {
  +      this.socketCreationRetries = socketCreationRetries;
  +   }
  +   
  +   
      protected void setup() throws Exception
      {
         Object o = configuration.get(Bisocket.IS_CALLBACK_SERVER);
  @@ -798,12 +852,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()
  @@ -855,7 +913,6 @@
               
               if (!t.checkConnection())
               {
  -               log.warn(this + ": detected failure on control connection " + t + ": requesting new control connection");
                  t.shutdown();
                  
                  synchronized (this)
  @@ -864,6 +921,19 @@
                        return;
                     
                     controlConnectionThreadMap.remove(listenerId);
  +                  Object o = controlConnectionRestartsMap.get(listenerId);
  +                  int restarts = ((Integer)o).intValue();
  +                  
  +                  if (restarts + 1 > controlConnectionRestarts)
  +                  {
  +                     log.warn(this + ": detected failure on control connection " + t);
  +                     log.warn("Control connection " + listenerId + " has been recreated " + restarts + " times.");
  +                     log.warn("Assuming it is a connection to an old server, and will not restart");
  +                     controlConnectionRestartsMap.remove(listenerId);
  +                     continue;
  +                  }
  +                  
  +                  log.warn(this + ": detected failure on control connection " + t + ": requesting new control connection");
                  }
                  
                  Thread t2 = new Thread()
  @@ -875,7 +945,7 @@
                        
                        try
                        {
  -                        invoker.createControlConnection(listenerId, null);
  +                        invoker.createControlConnection(listenerId, false);
                        }
                        catch (ClientUnavailableException e)
                        {
  @@ -892,7 +962,6 @@
                  };
                  t2.setName("controlConnectionRecreate:" + t.getName());
                  t2.start();
  -
               }
            }
         }
  
  
  



More information about the jboss-cvs-commits mailing list