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

Ron Sigal ron_sigal at yahoo.com
Wed Aug 22 22:52:54 EDT 2007


  User: rsigal  
  Date: 07/08/22 22:52:54

  Modified:    src/main/org/jboss/remoting  Tag: remoting_2_2_0_GA
                        ConnectionValidator.java
  Log:
  JBREM-755:  Merged with remoting_2_2_2_experimental branch: dded ability to configure parameters.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.13.2.10.4.1 +132 -26   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.13.2.10
  retrieving revision 1.13.2.10.4.1
  diff -u -b -r1.13.2.10 -r1.13.2.10.4.1
  --- ConnectionValidator.java	29 Jan 2007 07:10:00 -0000	1.13.2.10
  +++ ConnectionValidator.java	23 Aug 2007 02:52:54 -0000	1.13.2.10.4.1
  @@ -44,10 +44,29 @@
   
      private static final Logger log = Logger.getLogger(ConnectionValidator.class.getName());
   
  +   /** Configuration map key for ping period. */
  +   public static final String VALIDATOR_PING_PERIOD = "validatorPingPeriod";
  +   
  +   /** Default ping period. Value is 2 seconds. */
  +   public static final long DEFAULT_PING_PERIOD = 2000;
  +   
  +   /** Configuration map key for ping timeout. */
  +   public static final String VALIDATOR_PING_TIMEOUT = "validatorPingTimeout";
  +   
  +   /** Default ping timeout period.  Value is 1 second. */
  +   public static final String DEFAULT_PING_TIMEOUT = "1000";
  +   
      /**
  -    * Default ping period. Value is 2 seconds.
  +    * Default number of ping retries.  Value is 1.
  +    * Currently implemented only on socket transport family.
       */
  -   public static final long DEFAULT_PING_PERIOD = 2000;
  +   public static final String DEFAULT_NUMBER_OF_PING_RETRIES = "1";
  +   
  +   /**
  +    * Default number of connection acquisition retries.  Value is 1.
  +    * Currently implemented only on socket transport family.
  +    */
  +   public static final String DEFAULT_NUMBER_OF_CONNECTION_RETRIES = "1";
   
      // Static ---------------------------------------------------------------------------------------
   
  @@ -64,19 +83,7 @@
      public static boolean checkConnection(InvokerLocator locator, Map config) throws Throwable
      {
         boolean pingWorked = false;
  -
  -      Map configMap = null;
  -      if (config == null)
  -      {
  -         configMap = new HashMap();
  -      }
  -      else
  -      {
  -         configMap = new HashMap(config);
  -      }
  -      configMap.put("connection_checker", "true");
  -      configMap.put("timeout", "1000");
  -      configMap.put("NumberOfRetries", "1");
  +      Map configMap = createPingConfig(config, null);
         ClientInvoker innerClientInvoker = null;
   
         try
  @@ -137,10 +144,53 @@
         return pingWorked;
      }
   
  +   private static Map createPingConfig(Map config, Map metadata)
  +   {
  +      Map localConfig = new HashMap();
  +      localConfig.put("connection_checker", "true");
  +
  +      if (config != null)
  +      {
  +         Object o = config.get(VALIDATOR_PING_TIMEOUT);
  +         log.trace("config timeout: " + o);
  +         if (o != null)
  +            localConfig.put(ServerInvoker.TIMEOUT, o);
  +         
  +         o = config.get("NumberOfCallRetries");
  +         if (o != null)
  +            localConfig.put("NumberOfCallRetries", o);
  +         
  +         o = config.get("NumberOfRetries");
  +         if (o != null)
  +            localConfig.put("NumberOfRetries", o);
  +      }
  +      
  +      if (metadata != null)
  +      {
  +         metadata.remove(ServerInvoker.TIMEOUT);
  +         localConfig.putAll(metadata);
  +         Object o = metadata.get(VALIDATOR_PING_TIMEOUT);
  +         if (o != null)
  +            localConfig.put(ServerInvoker.TIMEOUT, o);
  +      }
  +      
  +      if (localConfig.get(ServerInvoker.TIMEOUT) == null)
  +         localConfig.put(ServerInvoker.TIMEOUT, DEFAULT_PING_TIMEOUT);
  +      
  +      if (localConfig.get("NumberOfCallRetries") == null)
  +         localConfig.put("NumberOfCallRetries", DEFAULT_NUMBER_OF_PING_RETRIES);
  +      
  +      if (localConfig.get("NumberOfRetries") == null)
  +         localConfig.put("NumberOfRetries", DEFAULT_NUMBER_OF_CONNECTION_RETRIES);
  +      
  +      return localConfig;
  +   }
  +
      // Attributes -----------------------------------------------------------------------------------
   
      private Client client;
      private long pingPeriod;
  +   private Map metadata;
      private InvokerLocator locator;
      private Map configMap;
      private List listeners;
  @@ -165,6 +215,69 @@
         log.debug(this + " created");
      }
   
  +   public ConnectionValidator(Client client, Map metadata)
  +   {
  +      this.client = client;
  +      this.pingPeriod = DEFAULT_PING_PERIOD;
  +      this.listeners = new ArrayList();
  +      this.stopped = false;
  +      
  +      Map config = client.getConfiguration();
  +      if (config != null)
  +      {  
  +         Object o = config.get(VALIDATOR_PING_PERIOD);
  +         if (o != null)
  +         {
  +            if (o instanceof String)
  +            {
  +               try 
  +               {
  +                  pingPeriod = Long.parseLong((String)o);
  +               }
  +               catch (Exception e)
  +               {
  +                  log.warn(this + " could not convert " + VALIDATOR_PING_PERIOD +
  +                           " value of " + o + " to a long value");
  +               }
  +            }
  +            else
  +            {
  +               log.warn(this + " could not convert " + VALIDATOR_PING_PERIOD +
  +                        " value of " + o + " to a long value: must be a String");
  +            }
  +         }
  +      }
  +
  +      if (metadata != null)
  +      {
  +         this.metadata = new HashMap(metadata);
  +
  +         Object o = metadata.get(VALIDATOR_PING_PERIOD);
  +         if (o != null)
  +         {
  +            if (o instanceof String)
  +            {
  +               try 
  +               {
  +                  pingPeriod = Long.parseLong((String)o);
  +               }
  +               catch (Exception e)
  +               {
  +                  log.warn(this + " could not convert " + VALIDATOR_PING_PERIOD +
  +                           " value of " + o + " to a long value");
  +               }
  +            }
  +            else
  +            {
  +               log.warn(this + " could not convert " + VALIDATOR_PING_PERIOD +
  +                        " value of " + o + " to a long value: must be a String");
  +            }
  +         }
  +      }
  +
  +      log.debug(this + " created");
  +   }
  +
      // StoppableTimerTask implementation ------------------------------------------------------------
   
      public void stop()
  @@ -272,17 +385,10 @@
   
      private void start()
      {
  -      if (client.getConfiguration() == null)
  -      {
  -         configMap = new HashMap();
  -      }
  -      else
  -      {
  -         configMap = new HashMap(client.getConfiguration());
  -      }
  -      configMap.put("connection_checker", "true");
  -      configMap.put("timeout", "1000");
  -      configMap.put("NumberOfRetries", "1");
  +      configMap = createPingConfig(client.getConfiguration(), metadata);
  +      log.debug(this + " timeout: " + configMap.get(ServerInvoker.TIMEOUT));
  +      log.debug(this + " ping retries: " + configMap.get("NumberOfCallRetries"));
  +      log.debug(this + " connection retries: " + configMap.get("NumberOfRetries"));
         locator = client.getInvoker().getLocator();
   
         try
  
  
  



More information about the jboss-cvs-commits mailing list