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

Ron Sigal ron_sigal at yahoo.com
Wed Jan 17 03:53:43 EST 2007


  User: rsigal  
  Date: 07/01/17 03:53:43

  Modified:    src/main/org/jboss/remoting  ConnectionValidator.java
  Log:
  JBREM-662:  (1) checkConnection() makes a copy of config map; (2) addConnectionListener synch's on listeners (instead of listener); (3) incorporated some logging additions made by Ovidiu on remoting_2_x branch.
  
  Revision  Changes    Path
  1.16      +65 -27    JBossRemoting/src/main/org/jboss/remoting/ConnectionValidator.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ConnectionValidator.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/ConnectionValidator.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -b -r1.15 -r1.16
  --- ConnectionValidator.java	12 Dec 2006 14:49:22 -0000	1.15
  +++ ConnectionValidator.java	17 Jan 2007 08:53:43 -0000	1.16
  @@ -35,6 +35,7 @@
   
   /**
    * @author <a href="mailto:tom.elrod at jboss.com">Tom Elrod</a>
  + * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
    */
   public class ConnectionValidator extends TimerTask
   {
  @@ -44,6 +45,7 @@
      private long pingPeriod = DEFAULT_PING_PERIOD;
   
      protected static final Logger log = Logger.getLogger(ConnectionValidator.class.getName());
  +   private static boolean trace = log.isTraceEnabled();
   
      private Object lock = new Object();
      private boolean stopped = false;
  @@ -55,19 +57,23 @@
   
      public ConnectionValidator(Client client)
      {
  -      this.client = client;
  +      this(client, (int)DEFAULT_PING_PERIOD);
      }
   
      public ConnectionValidator(Client client, int pingPeriod)
      {
         this.client = client;
         this.pingPeriod = pingPeriod;
  +
  +      log.debug(this + " created");
      }
   
      private void start()
      {
         TimerUtil.schedule(this, pingPeriod);
         stopped = false;
  +
  +      log.debug(this + " started");
      }
   
      public void stop()
  @@ -81,6 +87,8 @@
      }
            stopped = true;
      }
  +
  +      log.debug(this + " stopped");
      }
   
   
  @@ -88,7 +96,7 @@
      {
         if (listener != null)
         {
  -         synchronized (listener)
  +         synchronized (listeners)
            {
               if (listeners.size() == 0)
               {
  @@ -127,14 +135,21 @@
            {
         try
         {
  -         boolean isValid = checkConnection(client.getInvoker().getLocator(), client.getConfiguration());
  +               if (trace) { log.trace(this + " pinging ..."); }
  +
  +               boolean isValid =
  +                  checkConnection(client.getInvoker().getLocator(), client.getConfiguration());
  +
            if (!isValid)
            {
  -            notifyListeners(new Exception("Could not connect to server."));
  +                  log.debug(this + "'s connections is invalid");
  +
  +                  notifyListeners(new Exception("Could not connect to server!"));
            }
         }
         catch (Throwable thr)
         {
  +               log.debug(this + " got throwable while pinging", thr);
            notifyListeners(thr);
         }
      }
  @@ -176,11 +191,15 @@
      {
         boolean pingWorked = false;
   
  -      Map configMap = config;
  +      Map configMap = null;
         if (configMap == null)
         {
            configMap = new HashMap();
         }
  +      else
  +      {
  +         configMap = new HashMap(config);
  +      }
         configMap.put("connection_checker", "true");
         configMap.put("timeout", "1000");
         configMap.put("NumberOfRetries", "1");
  @@ -188,25 +207,38 @@
   
         try
         {
  -
            innerClientInvoker = InvokerRegistry.createClientInvoker(locator, configMap);
   
            if (!innerClientInvoker.isConnected())
            {
  +            if (trace) { log.trace("inner client invoker not connected, connecting ..."); }
               innerClientInvoker.connect();
            }
  +
  +         if (trace)
  +         {
  +            log.trace("ConnectionValidator pinging " +
  +               innerClientInvoker.getLocator().getProtocol() + "://" +
  +               innerClientInvoker.getLocator().getHost() + ":" +
  +               innerClientInvoker.getLocator().getPort());
  +         }
  +
            /**
             * Sending null client id as don't want to trigger lease on server side.
             * This also means that client connection validator will NOT impact client
             * lease, so can not depend on it to maintain client lease with the server.
             */
  -         Object o = innerClientInvoker.invoke(new InvocationRequest(null, Subsystem.SELF,
  -                                                                    "$PING$", null, null, null));
  +         innerClientInvoker.
  +            invoke(new InvocationRequest(null, Subsystem.SELF, "$PING$", null, null, null));
  +
            pingWorked = true;
         }
         catch (Throwable throwable)
         {
  -         log.debug("ConnectionValidator could not successfully ping server (" + innerClientInvoker.getLocator());
  +         log.debug("ConnectionValidator failed to ping server " +
  +            innerClientInvoker.getLocator().getProtocol() + "://" +
  +            innerClientInvoker.getLocator().getHost() + ":" +
  +            innerClientInvoker.getLocator().getPort(), throwable);
         }
         finally
         {
  @@ -217,8 +249,14 @@
         }
   
         return pingWorked;
  -
      }
   
   
  +   public String toString()
  +   {
  +      InvokerLocator locator = client.getInvoker().getLocator();
  +      return "ConnectionValidator[" + locator.getProtocol() + "://" + locator.getHost() + ":" +
  +         locator.getPort() + ", pingPeriod=" + pingPeriod + " ms]";
  +   }
  +
   }
  \ No newline at end of file
  
  
  



More information about the jboss-cvs-commits mailing list