commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hamm...@apache.org
Subject cvs commit: jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl AbstractConnectionPinger.java DefaultConnectionPinger.java PerpetualConnectionPinger.java
Date Wed, 27 Mar 2002 21:51:57 GMT
hammant     02/03/27 13:51:57

  Modified:    altrmi/src/java/org/apache/commons/altrmi/client/impl
                        DefaultConnectionPinger.java
                        PerpetualConnectionPinger.java
  Added:       altrmi/src/java/org/apache/commons/altrmi/client/impl
                        AbstractConnectionPinger.java
  Log:
  refactoring of pingers
  
  Revision  Changes    Path
  1.5       +4 -82     jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/DefaultConnectionPinger.java
  
  Index: DefaultConnectionPinger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/DefaultConnectionPinger.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultConnectionPinger.java	27 Mar 2002 20:58:24 -0000	1.4
  +++ DefaultConnectionPinger.java	27 Mar 2002 21:51:57 -0000	1.5
  @@ -22,96 +22,18 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version * $Revision: 1.4 $
  + * @version * $Revision: 1.5 $
    */
  -public class DefaultConnectionPinger implements AltrmiConnectionPinger, Runnable {
  +public class DefaultConnectionPinger extends AbstractConnectionPinger {
   
  -    private AltrmiClientInvocationHandler mAltrmiInvocationHandler;
  -    private boolean mContinue = true;
  -    private Thread mThread;
  -    private int mPingInterval;
  -    private int mGiveupInterval;
  -
  -    /**
  -     * Constructor DefaultConnectionPinger
  -     *
  -     *
  -     * @param pingIntervalSeconds
  -     * @param giveupIntervalSeconds
  -     *
  -     */
       public DefaultConnectionPinger(int pingIntervalSeconds, int giveupIntervalSeconds)
{
  -        mPingInterval = pingIntervalSeconds * 1000;
  -        mGiveupInterval = giveupIntervalSeconds * 1000;
  +        super(pingIntervalSeconds, giveupIntervalSeconds);
       }
   
  -    /**
  -     * Constructor DefaultConnectionPinger
  -     *
  -     *
  -     */
       public DefaultConnectionPinger() {
  -        mPingInterval = 10 * 1000;       // ten seconds
  -        mGiveupInterval = 100 * 1000;    // one hundred seconds.
  -    }
  -
  -    /**
  -     * Method setAltrmiInvocationHandler
  -     *
  -     *
  -     *
  -     */
  -    public void setAltrmiInvocationHandler(
  -            AltrmiClientInvocationHandler altrmiInvocationHandler) {
  -        mAltrmiInvocationHandler = altrmiInvocationHandler;
  -    }
  -
  -    /**
  -     * Method start
  -     *
  -     *
  -     */
  -    public void start() {
  -
  -        mThread = new Thread(this);
  -
  -        mThread.start();
  -    }
  -
  -    /**
  -     * Method stop
  -     *
  -     *
  -     */
  -    public void stop() {
  -
  -        mContinue = false;
  -    }
  -
  -    /**
  -     * Method run
  -     *
  -     *
  -     */
  -    public void run() {
  -
  -        try {
  -            while (mContinue) {
  -                Thread.sleep(mPingInterval);
  -                ping();
  -            }
  -        } catch (AltrmiConnectionClosedException cce) {
  -            System.out.println("Pinger Connection closed");
  -
  -            // no need to ping anymore.
  -        } catch (InterruptedException e) {
  -            System.out.println("Pinger Interrupted!");
  -
  -            // do nothing.
  -        }
       }
   
  -    private void ping() {
  +    protected void ping() {
           if (mAltrmiInvocationHandler.getLastRealRequest()
                   > (System.currentTimeMillis() - (mGiveupInterval))) {
               mAltrmiInvocationHandler.ping();
  
  
  
  1.2       +6 -40     jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/PerpetualConnectionPinger.java
  
  Index: PerpetualConnectionPinger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/PerpetualConnectionPinger.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PerpetualConnectionPinger.java	19 Jan 2002 15:06:58 -0000	1.1
  +++ PerpetualConnectionPinger.java	27 Mar 2002 21:51:57 -0000	1.2
  @@ -23,53 +23,19 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version * $Revision: 1.1 $
  + * @version * $Revision: 1.2 $
    */
  -public class PerpetualConnectionPinger implements AltrmiConnectionPinger, Runnable {
  +public class PerpetualConnectionPinger extends AbstractConnectionPinger {
   
  -    private AltrmiClientInvocationHandler mAltrmiInvocationHandler;
  -    private boolean mContinue = true;
  -    private Thread mThread;
  -
  -
  -    /**
  -     * Method setAltrmiInvocationHandler
  -     *
  -     *
  -     *
  -     */
  -    public void setAltrmiInvocationHandler(AltrmiClientInvocationHandler altrmiInvocationHandler)
{
  -        mAltrmiInvocationHandler = altrmiInvocationHandler;
  +    public PerpetualConnectionPinger(int pingIntervalSeconds, int giveupIntervalSeconds)
{
  +        super(pingIntervalSeconds, giveupIntervalSeconds);
       }
   
  -    /**
  -     * Method start
  -     *
  -     *
  -     */
  -    public void start() {
  -        mThread = new Thread(this);
  -        mThread.start();
  +    public PerpetualConnectionPinger() {
       }
   
  -    public void stop() {
  -        mContinue = false;
  +    protected void ping() {
  +        AltrmiReply ar = mAltrmiInvocationHandler.handleInvocation(new PingRequest());
       }
   
  -    /**
  -     * Method run
  -     *
  -     *
  -     */
  -    public void run() {
  -        try {
  -            while (mContinue) {
  -                Thread.sleep(10 * 1000);
  -                AltrmiReply ar = mAltrmiInvocationHandler.handleInvocation(new PingRequest());
  -            }
  -        } catch (InterruptedException e) {
  -
  -            // do nothing.
  -        }
  -    }
   }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/AbstractConnectionPinger.java
  
  Index: AbstractConnectionPinger.java
  ===================================================================
  
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.commons.altrmi.client.impl;
  
  
  
  import org.apache.commons.altrmi.client.AltrmiConnectionPinger;
  import org.apache.commons.altrmi.client.AltrmiClientInvocationHandler;
  import org.apache.commons.altrmi.common.AltrmiReply;
  import org.apache.commons.altrmi.common.PingRequest;
  import org.apache.commons.altrmi.common.AltrmiConnectionClosedException;
  
  
  /**
   * Interface DefaultConnectionPinger
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version * $Revision: 1.1 $
   */
  public abstract class AbstractConnectionPinger implements AltrmiConnectionPinger, Runnable
{
  
      protected AltrmiClientInvocationHandler mAltrmiInvocationHandler;
      protected boolean mContinue = true;
      protected Thread mThread;
      protected final int mPingInterval;
      protected final int mGiveupInterval;
  
      /**
       * Constructor DefaultConnectionPinger
       *
       *
       * @param pingIntervalSeconds
       * @param giveupIntervalSeconds
       *
       */
      public AbstractConnectionPinger(int pingIntervalSeconds, int giveupIntervalSeconds)
{
          mPingInterval = pingIntervalSeconds * 1000;
          mGiveupInterval = giveupIntervalSeconds * 1000;
      }
  
      /**
       * Constructor DefaultConnectionPinger
       *
       *
       */
      public AbstractConnectionPinger() {
          mPingInterval = 10 * 1000;       // ten seconds
          mGiveupInterval = 100 * 1000;    // one hundred seconds.
      }
  
      /**
       * Method setAltrmiInvocationHandler
       *
       *
       *
       */
      public void setAltrmiInvocationHandler(
              AltrmiClientInvocationHandler altrmiInvocationHandler) {
          mAltrmiInvocationHandler = altrmiInvocationHandler;
      }
  
      /**
       * Method start
       *
       *
       */
      public void start() {
  
          mThread = new Thread(this);
  
          mThread.start();
      }
  
      /**
       * Method stop
       *
       *
       */
      public void stop() {
  
          mContinue = false;
      }
  
      /**
       * Method run
       *
       *
       */
      public void run() {
  
          try {
              while (mContinue) {
                  Thread.sleep(mPingInterval);
                  ping();
              }
          } catch (AltrmiConnectionClosedException cce) {
              System.out.println("Pinger Connection closed");
  
              // no need to ping anymore.
          } catch (InterruptedException e) {
              System.out.println("Pinger Interrupted!");
  
              // do nothing.
          }
      }
  
      protected abstract void ping();
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message