avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/packet Acceptor.java DefaultPacketManager.java
Date Wed, 21 Nov 2001 11:17:08 GMT
donaldp     01/11/21 03:17:08

  Modified:    src/java/org/apache/avalon/cornerstone/blocks/packet
                        Acceptor.java DefaultPacketManager.java
  Log:
  Fixed bug in Packet Acceptor that would cause the PacketManager to block indefinetly when
asked to dispose itself.
  
  This was the same bug that occured in SocketManager. Like the bug in SocketManager this
was due to differences between socket support between win32 and unix.
  
  Revision  Changes    Path
  1.4       +36 -15    jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/packet/Acceptor.java
  
  Index: Acceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/packet/Acceptor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Acceptor.java	2001/11/19 12:27:25	1.3
  +++ Acceptor.java	2001/11/21 11:17:08	1.4
  @@ -8,6 +8,7 @@
   package org.apache.avalon.cornerstone.blocks.packet;
   
   import java.io.IOException;
  +import java.io.InterruptedIOException;
   import java.net.DatagramPacket;
   import java.net.DatagramSocket;
   import java.util.ArrayList;
  @@ -28,12 +29,12 @@
       extends AbstractLogEnabled
       implements Component, Runnable
   {
  -    protected final DatagramSocket          m_datagramSocket;
  -    protected final PacketHandlerFactory    m_handlerFactory;
  -    protected final ThreadPool              m_threadPool;
  -    protected final ArrayList               m_runners          = new ArrayList();
  +    private final DatagramSocket          m_datagramSocket;
  +    private final PacketHandlerFactory    m_handlerFactory;
  +    private final ThreadPool              m_threadPool;
  +    private final ArrayList               m_runners          = new ArrayList();
   
  -    protected Thread                           m_thread;
  +    private Thread                        m_thread;
   
       public Acceptor( final DatagramSocket datagramSocket,
                        final PacketHandlerFactory handlerFactory,
  @@ -42,16 +43,26 @@
           m_datagramSocket = datagramSocket;
           m_handlerFactory = handlerFactory;
           m_threadPool = threadPool;
  +
       }
   
       public void dispose()
           throws Exception
       {
  -        if( null != m_thread )
  +        synchronized( this )
           {
  -            m_thread.interrupt();
  -            m_thread.join( /* 1000 ??? */ );
  -            m_thread = null;
  +            if( null != m_thread )
  +            {
  +                final Thread thread = m_thread;
  +                m_thread = null;
  +                thread.interrupt();
  +
  +                //Can not join as threads are part of pool 
  +                //and will never finish
  +                //m_thread.join();
  +                
  +                wait( /*1000*/ );
  +            }
           }
   
           final Iterator runners = m_runners.iterator();
  @@ -68,11 +79,11 @@
       {
           m_thread = Thread.currentThread();
   
  -        while( !Thread.interrupted() )
  +        while( null != m_thread && !Thread.interrupted() )
           {
               try
               {
  -                //TODO: packets hould really be pooled...
  +                //TODO: packets should really be pooled...
                   DatagramPacket packet = null;
   
                   try
  @@ -94,6 +105,10 @@
                   setupLogger( runner );
                   m_threadPool.execute( runner );
               }
  +            catch( final InterruptedIOException iioe )
  +            {
  +                //Consume exception
  +            }
               catch( final IOException ioe )
               {
                   getLogger().error( "Exception accepting connection", ioe );
  @@ -103,6 +118,12 @@
                   getLogger().error( "Exception executing runner", e );
               }
           }
  +
  +        synchronized( this )
  +        {
  +            notifyAll();
  +            m_thread = null;
  +        }
       }
   }
   
  @@ -110,10 +131,10 @@
       extends AbstractLogEnabled
       implements Runnable, Component
   {
  -    protected DatagramPacket  m_packet;
  -    protected Thread          m_thread;
  -    protected ArrayList       m_runners;
  -    protected PacketHandler   m_handler;
  +    private DatagramPacket  m_packet;
  +    private Thread          m_thread;
  +    private ArrayList       m_runners;
  +    private PacketHandler   m_handler;
   
       PacketHandlerRunner( final DatagramPacket packet,
                            final ArrayList runners,
  
  
  
  1.7       +6 -0      jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/packet/DefaultPacketManager.java
  
  Index: DefaultPacketManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/packet/DefaultPacketManager.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DefaultPacketManager.java	2001/11/19 12:27:25	1.6
  +++ DefaultPacketManager.java	2001/11/21 11:17:08	1.7
  @@ -78,6 +78,12 @@
                                                   name );
           }
   
  +        //Make sure timeout is specified for socket.
  +        if( 0 == socket.getSoTimeout() )
  +        {
  +            socket.setSoTimeout( 500 );
  +        }
  +
           final Acceptor acceptor = new Acceptor( socket, handlerFactory, threadPool );
           setupLogger( acceptor );
           m_acceptors.put( name, acceptor );
  
  
  

--
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