avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hamm...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/client/impl DefaultConnectionPingerTestCase.java DummyInvocationHandler.java
Date Mon, 02 Sep 2002 22:36:23 GMT
hammant     2002/09/02 15:36:23

  Modified:    altrmi/src/java/org/apache/excalibur/altrmi/client/impl
                        AbstractConnectionPinger.java
                        DefaultConnectionPinger.java
                        PerpetualConnectionPinger.java
               altrmi/src/java/org/apache/excalibur/altrmi/generator/ant
                        AltrmiProxyTask.java
  Added:       altrmi/src/test/org/apache/excalibur/altrmi/client/impl
                        DefaultConnectionPingerTestCase.java
                        DummyInvocationHandler.java
  Log:
  New test for pinger.  Thread not being killed thread squished.
  
  Revision  Changes    Path
  1.7       +91 -61    jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/AbstractConnectionPinger.java
  
  Index: AbstractConnectionPinger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/AbstractConnectionPinger.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AbstractConnectionPinger.java	23 Aug 2002 10:03:03 -0000	1.6
  +++ AbstractConnectionPinger.java	2 Sep 2002 22:36:23 -0000	1.7
  @@ -13,119 +13,149 @@
   import org.apache.excalibur.altrmi.common.AltrmiInvocationException;
   
   /**
  - * Interface DefaultConnectionPinger
  + * Interface AbstractConnectionPinger
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
    * @version * $Revision$
    */
  -public abstract class AbstractConnectionPinger implements AltrmiConnectionPinger, Runnable
  +public abstract class AbstractConnectionPinger implements AltrmiConnectionPinger
   {
   
  -    protected AltrmiClientInvocationHandler mAltrmiInvocationHandler;
  -    protected boolean mContinue = true;
  -    protected Thread mThread;
  -    protected final int mPingInterval;
  -    protected final int mGiveupInterval;
  +    private AltrmiClientInvocationHandler m_altrmiInvocationHandler;
  +    private boolean m_continue = true;
  +    private Runnable m_runnable;
  +    private Thread m_thread;
  +    private final long m_pingInterval;
  +    private final long m_giveupInterval;
   
       /**
  -     * Constructor DefaultConnectionPinger
  +     * Construct a AbstractConnectionPinger with seconds for interval.
        *
        *
  -     * @param pingIntervalSeconds
  -     * @param giveupIntervalSeconds
  +     * @param pingIntervalSeconds the interval to wait
  +     * @param giveupIntervalSeconds when to give up
        *
        */
       public AbstractConnectionPinger( int pingIntervalSeconds, int giveupIntervalSeconds
)
       {
  -        mPingInterval = pingIntervalSeconds * 1000;
  -        mGiveupInterval = giveupIntervalSeconds * 1000;
  +        m_pingInterval = pingIntervalSeconds * 1000;
  +        m_giveupInterval = giveupIntervalSeconds * 1000;
       }
   
       /**
  -     * Constructor DefaultConnectionPinger
  +     * Construct a AbstractConnectionPinger with millisecond intervals
        *
        *
  +     * @param pingIntervalMilliSeconds the interval to wait
  +     * @param giveupIntervalMilliSeconds when to give up
  +     *
        */
  -    public AbstractConnectionPinger()
  +    public AbstractConnectionPinger( long pingIntervalMilliSeconds, long giveupIntervalMilliSeconds
)
       {
  -        mPingInterval = 10 * 1000;       // ten seconds
  -        mGiveupInterval = 100 * 1000;    // one hundred seconds.
  +        m_pingInterval = pingIntervalMilliSeconds;
  +        m_giveupInterval = giveupIntervalMilliSeconds;
       }
   
  +
       /**
  -     * Method setAltrmiInvocationHandler
  -     *
  +     * Constructor AbstractConnectionPinger
        *
        *
        */
  -    public void setAltrmiInvocationHandler( AltrmiClientInvocationHandler altrmiInvocationHandler
)
  +    public AbstractConnectionPinger()
       {
  -        mAltrmiInvocationHandler = altrmiInvocationHandler;
  +        m_pingInterval = 10 * 1000;       // ten seconds
  +        m_giveupInterval = 100 * 1000;    // one hundred seconds.
       }
   
       /**
  -     * Method start
  +     * Method setAltrmiInvocationHandler
  +     *
        *
        *
        */
  -    public void start()
  +    public void setAltrmiInvocationHandler( AltrmiClientInvocationHandler altrmiInvocationHandler
)
       {
  -
  -        mThread = new Thread( this ,"AltrmiConnectionPinger Thread");
  -
  -        mThread.start();
  +        m_altrmiInvocationHandler = altrmiInvocationHandler;
       }
   
       /**
  -     * Method stop
  -     *
  -     *
  +     * Get the Invocation handler.
  +     * @return
        */
  -    public void stop()
  +    protected AltrmiClientInvocationHandler getAltrmiInvocationHandler()
       {
  -        mContinue = false;
  +        return m_altrmiInvocationHandler;
       }
   
       /**
  -     * Method run
  +     * Start the pinger
        *
        *
        */
  -    public void run()
  +    public void start()
       {
   
  -        try
  -        {
  -            while( mContinue )
  +        m_runnable = new Runnable() {
  +            public void run()
               {
  -                Thread.sleep( mPingInterval );
  -                ping();
  +
  +                try
  +                {
  +                    while( m_continue )
  +                    {
  +                        Thread.sleep( m_pingInterval );
  +                        ping();
  +                    }
  +                }
  +                catch( AltrmiInvocationException ie )
  +                {
  +
  +                    // We really need a logger or something to be able to see this
  +                    //  for debugging.
  +                    //System.out.println( "Pinger Connection closed" );
  +
  +                    // no need to ping anymore.
  +                }
  +                catch( AltrmiConnectionClosedException cce )
  +                {
  +                    // We really need a logger or something to be able to see this
  +                    //  for debugging.
  +                    //System.out.println( "Pinger Connection closed" );
  +
  +                    // no need to ping anymore.
  +                }
  +                catch( InterruptedException e )
  +                {
  +                    if (m_continue)
  +                    {
  +                        System.err.println("Unexpected interuption of pnger thread - "
+ e.getMessage());
  +                    }
  +                }
               }
  -        }
  -        catch( AltrmiInvocationException ie )
  -        {
  -            // We really need a logger or something to be able to see this
  -            //  for debugging.
  -            //System.out.println( "Pinger Connection closed" );
  -
  -            // no need to ping anymore.
  -        }
  -        catch( AltrmiConnectionClosedException cce )
  -        {
  -            // We really need a logger or something to be able to see this
  -            //  for debugging.
  -            //System.out.println( "Pinger Connection closed" );
  -
  -            // no need to ping anymore.
  -        }
  -        catch( InterruptedException e )
  -        {
  -            System.out.println( "Pinger Interrupted!" );
  +        };
   
  -            // do nothing.
  -        }
  +        m_thread = new Thread( m_runnable ,"AltrmiConnectionPinger Thread");
  +        m_thread.start();
  +    }
  +
  +    /**
  +     * Stop the pinger
  +     *
  +     *
  +     */
  +    public void stop()
  +    {
  +        m_continue = false;
  +        m_thread.interrupt();
  +        m_thread = null;
       }
   
       protected abstract void ping();
  +
  +    public long getGiveupInterval()
  +    {
  +        return m_giveupInterval;
  +    }
   }
  
  
  
  1.4       +22 -5     jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/DefaultConnectionPinger.java
  
  Index: DefaultConnectionPinger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/DefaultConnectionPinger.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultConnectionPinger.java	24 Apr 2002 12:42:56 -0000	1.3
  +++ DefaultConnectionPinger.java	2 Sep 2002 22:36:23 -0000	1.4
  @@ -34,24 +34,41 @@
        * Constructor DefaultConnectionPinger
        *
        *
  +     * @param pingIntervalMilliSeconds
  +     * @param giveupIntervalMilliSeconds
  +     *
  +     */
  +    public DefaultConnectionPinger( long pingIntervalMilliSeconds, long giveupIntervalMilliSeconds
)
  +    {
  +        super( pingIntervalMilliSeconds, giveupIntervalMilliSeconds );
  +    }
  +
  +
  +    /**
  +     * Constructor DefaultConnectionPinger
  +     *
  +     *
        */
       public DefaultConnectionPinger()
       {
       }
   
  +    /**
  +     * Implemnt the abstract ping() from the AbstractConnectionPinger
  +     */
       protected void ping()
       {
   
  -        if( mAltrmiInvocationHandler.getLastRealRequest()
  -            > ( System.currentTimeMillis() - ( mGiveupInterval ) ) )
  +        if( getAltrmiInvocationHandler().getLastRealRequest()
  +            > ( System.currentTimeMillis() - ( getGiveupInterval() ) ) )
           {
  -            mAltrmiInvocationHandler.ping();
  +            getAltrmiInvocationHandler().ping();
           }
           else
           {
   
               //TODO should be restartable after reconnect of socket.
  -            mContinue = false;
  +            stop();
   
               // if more than 100 seconds since last request, stop pinging
               // Let the server do a disconnect according to its rules.
  
  
  
  1.4       +2 -3      jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/PerpetualConnectionPinger.java
  
  Index: PerpetualConnectionPinger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/PerpetualConnectionPinger.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PerpetualConnectionPinger.java	24 Apr 2002 12:42:56 -0000	1.3
  +++ PerpetualConnectionPinger.java	2 Sep 2002 22:36:23 -0000	1.4
  @@ -7,7 +7,6 @@
    */
   package org.apache.excalibur.altrmi.client.impl;
   
  -import org.apache.excalibur.altrmi.common.AltrmiReply;
   import org.apache.excalibur.altrmi.common.PingRequest;
   
   /**
  @@ -46,6 +45,6 @@
   
       protected void ping()
       {
  -        AltrmiReply ar = mAltrmiInvocationHandler.handleInvocation( new PingRequest() );
  +        getAltrmiInvocationHandler().handleInvocation( new PingRequest() );
       }
   }
  
  
  
  1.8       +1 -2      jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/generator/ant/AltrmiProxyTask.java
  
  Index: AltrmiProxyTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/generator/ant/AltrmiProxyTask.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AltrmiProxyTask.java	15 Jul 2002 21:52:19 -0000	1.7
  +++ AltrmiProxyTask.java	2 Sep 2002 22:36:23 -0000	1.8
  @@ -17,7 +17,6 @@
   import org.apache.tools.ant.Task;
   import org.apache.tools.ant.types.Path;
   import org.apache.tools.ant.types.Reference;
  -import org.apache.tools.ant.util.FileUtils;
   
   /**
    * Class AltrmiProxyTask
  
  
  
  1.1                  jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/client/impl/DefaultConnectionPingerTestCase.java
  
  Index: DefaultConnectionPingerTestCase.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.excalibur.altrmi.client.impl;
  
  import junit.framework.TestCase;
  
  public class DefaultConnectionPingerTestCase extends TestCase
  {
  
      public DefaultConnectionPingerTestCase(String name)
      {
          super(name);
      }
  
      protected void setUp() throws Exception
      {
          super.setUp();
      }
  
      public void testBasic() throws Exception
      {
          DefaultConnectionPinger pinger = new DefaultConnectionPinger(1L,10000L);
          DummyInvocationHandler dummy = new DummyInvocationHandler();
          pinger.start();
          pinger.setAltrmiInvocationHandler(dummy);
          Thread.sleep(1000);
          assertTrue("Should have pinged", dummy.isPinged());
          pinger.stop();
          dummy.reset();
          Thread.sleep(1000);
          assertTrue("Should have stopped pinging", !dummy.isPinged());
  
      }
  
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/client/impl/DummyInvocationHandler.java
  
  Index: DummyInvocationHandler.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.excalibur.altrmi.client.impl;
  
  import org.apache.excalibur.altrmi.common.AltrmiReply;
  import org.apache.excalibur.altrmi.common.AltrmiRequest;
  import org.apache.excalibur.altrmi.client.AltrmiClientInvocationHandler;
  import org.apache.excalibur.altrmi.client.AltrmiConnectionListener;
  import org.apache.excalibur.altrmi.client.AltrmiConnectionPinger;
  
  import java.io.IOException;
  
  
  public class DummyInvocationHandler implements AltrmiClientInvocationHandler
  {
  
      boolean pinged = false;
      long lastReq = System.currentTimeMillis();
  
      public boolean isPinged()
      {
          return pinged;
      }
  
      public void reset()
      {
          pinged = false;
      }
  
      public AltrmiReply handleInvocation(AltrmiRequest request)
      {
          throw new java.lang.UnsupportedOperationException();
      }
  
      public void ping()
      {
          System.out.println("pinged!");
          pinged = true;
      }
  
      public long getLastRealRequest()
      {
          return lastReq;
      }
  
      public ClassLoader getInterfacesClassLoader()
      {
          throw new java.lang.UnsupportedOperationException();
      }
  
      public void setAltrmiConnectionListener(AltrmiConnectionListener altrmiConnectionListener)
      {
          throw new java.lang.UnsupportedOperationException();
      }
  
      public void setConnectionPinger(AltrmiConnectionPinger connectionPinger)
      {
          throw new java.lang.UnsupportedOperationException();
      }
  
      public void initialize() throws IOException
      {
          throw new java.lang.UnsupportedOperationException();
      }
  
      public void close()
      {
          throw new java.lang.UnsupportedOperationException();
      }
  }
  
  
  

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


Mime
View raw message