directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 7006 - in incubator/directory/eve/trunk/eve/frontend/input: merlin-impl/src/java/org/apache/eve/input pojo-impl/src/java/org/apache/eve/input spi/src/java/org/apache/eve/input
Date Fri, 05 Mar 2004 04:11:18 GMT
Author: akarasulu
Date: Thu Mar  4 20:11:16 2004
New Revision: 7006

Modified:
   incubator/directory/eve/trunk/eve/frontend/input/merlin-impl/src/java/org/apache/eve/input/AvalonInputManagerMonitor.java
   incubator/directory/eve/trunk/eve/frontend/input/pojo-impl/src/java/org/apache/eve/input/DefaultInputManager.java
   incubator/directory/eve/trunk/eve/frontend/input/spi/src/java/org/apache/eve/input/InputManagerMonitor.java
   incubator/directory/eve/trunk/eve/frontend/input/spi/src/java/org/apache/eve/input/InputManagerMonitorAdapter.java
Log:
Added an InputManagerMonitor method cleanedStaleKey(SelectionKey) and made
sure we 'WARN' of stale key cleanups in components.  This commit completes
the following JIRA request:

http://nagoya.apache.org/jira/secure/ViewIssue.jspa?key=DIR-20



Modified: incubator/directory/eve/trunk/eve/frontend/input/merlin-impl/src/java/org/apache/eve/input/AvalonInputManagerMonitor.java
==============================================================================
--- incubator/directory/eve/trunk/eve/frontend/input/merlin-impl/src/java/org/apache/eve/input/AvalonInputManagerMonitor.java
(original)
+++ incubator/directory/eve/trunk/eve/frontend/input/merlin-impl/src/java/org/apache/eve/input/AvalonInputManagerMonitor.java
Thu Mar  4 20:11:16 2004
@@ -19,6 +19,7 @@
 
 import java.io.IOException ;
 import java.nio.ByteBuffer ;
+import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector ;
 import java.nio.channels.SocketChannel ;
 
@@ -45,13 +46,13 @@
      * @see org.apache.eve.input.InputManagerMonitor#bufferUnavailable(
      * org.apache.eve.buffer.BufferPool, org.apache.eve.ResourceException)
      */
-    public void bufferUnavailable( BufferPool a_bp, ResourceException a_fault )
+    public void bufferUnavailable( BufferPool bp, ResourceException fault )
     {
         if ( getLogger().isErrorEnabled() )
         {    
             getLogger().error( 
                     "Failed to acquire buffer resource from buffer pool "
-                    + a_bp, a_fault ) ;
+                    + bp, fault ) ;
         }
     }
 
@@ -60,13 +61,13 @@
      * @see org.apache.eve.input.InputManagerMonitor#channelCloseFailure(
      * java.nio.channels.SocketChannel, java.io.IOException)
      */
-    public void channelCloseFailure( SocketChannel a_channel, 
-                                     IOException a_fault )
+    public void channelCloseFailure( SocketChannel channel, 
+                                     IOException fault )
     {
         if ( getLogger().isErrorEnabled() )
         {    
             getLogger().error( "Could not properly close socket channel " 
-                    + a_channel, a_fault ) ;
+                    + channel, fault ) ;
         }
     }
 
@@ -76,16 +77,16 @@
      * java.nio.channels.Selector, java.nio.channels.SocketChannel, int, 
      * java.io.IOException)
      */
-    public void channelRegistrationFailure( Selector a_selector,
-											SocketChannel a_channel,
-											int a_key,
-											IOException a_fault )
+    public void channelRegistrationFailure( Selector selector,
+											SocketChannel channel,
+											int key,
+											IOException fault )
     {
         if ( getLogger().isErrorEnabled() )
         {    
-            getLogger().error( "Could not register socket channel " + a_channel 
-                    + " for selector " + a_selector 
-                    + " using selection key mode " + a_key, a_fault ) ;
+            getLogger().error( "Could not register socket channel " + channel 
+                    + " for selector " + selector 
+                    + " using selection key mode " + key, fault ) ;
         }
     }
     
@@ -94,11 +95,11 @@
      * @see org.apache.eve.input.InputManagerMonitor#disconnectedClient(
      * org.apache.eve.listener.ClientKey)
      */
-    public void disconnectedClient( ClientKey a_key )
+    public void disconnectedClient( ClientKey key )
     {
         if ( getLogger().isInfoEnabled() )
         {    
-            getLogger().info( "Disconnected client with key: " + a_key ) ;
+            getLogger().info( "Disconnected client with key: " + key ) ;
         }
     }
 
@@ -107,12 +108,12 @@
      * @see org.apache.eve.input.InputManagerMonitor#enteringSelect(
      * java.nio.channels.Selector)
      */
-    public void enteringSelect( Selector a_selector )
+    public void enteringSelect( Selector selector )
     {
         if ( getLogger().isDebugEnabled() )
         {    
             getLogger().debug( "About to enter select() on selector " 
-                    + a_selector ) ;
+                    + selector ) ;
         }
     }
 
@@ -121,11 +122,11 @@
      * @see org.apache.eve.input.InputManagerMonitor#inputRecieved(
      * org.apache.eve.listener.ClientKey)
      */
-    public void inputRecieved( ClientKey a_key )
+    public void inputRecieved( ClientKey key )
     {
         if ( getLogger().isDebugEnabled() )
         {
-            getLogger().debug( "Got some input from " + a_key ) ;
+            getLogger().debug( "Got some input from " + key ) ;
         }
     }
 
@@ -135,12 +136,12 @@
      * org.apache.eve.listener.ClientKey, 
      * org.apache.eve.listener.KeyExpiryException)
      */
-    public void keyExpiryFailure( ClientKey a_key, KeyExpiryException a_fault )
+    public void keyExpiryFailure( ClientKey key, KeyExpiryException fault )
     {
         if ( getLogger().isInfoEnabled() )
         {
-            getLogger().info( "While working with client key " + a_key 
-                    + " it was prematurely expired!", a_fault ) ;
+            getLogger().info( "While working with client key " + key 
+                    + " it was prematurely expired!", fault ) ;
         }
     }
 
@@ -149,12 +150,12 @@
      * @see org.apache.eve.input.InputManagerMonitor#readFailed(
      * org.apache.eve.listener.ClientKey, java.io.IOException)
      */
-    public void readFailed( ClientKey a_key, IOException a_fault )
+    public void readFailed( ClientKey key, IOException fault )
     {
         if ( getLogger().isErrorEnabled() )
         {
             getLogger().error( "Encountered failure while reading from " 
-                    + a_key, a_fault ) ;
+                    + key, fault ) ;
         }
     }
 
@@ -163,12 +164,12 @@
      * @see org.apache.eve.input.InputManagerMonitor#registeredChannel(
      * org.apache.eve.listener.ClientKey, java.nio.channels.Selector)
      */
-    public void registeredChannel( ClientKey a_key, Selector a_selector )
+    public void registeredChannel( ClientKey key, Selector selector )
     {
         if ( getLogger().isDebugEnabled() )
         {
-            getLogger().debug( "Succeeded in registering " + a_key 
-                    + " with selector " + a_selector ) ;
+            getLogger().debug( "Succeeded in registering " + key 
+                    + " with selector " + selector ) ;
         }
     }
 
@@ -177,12 +178,12 @@
      * @see org.apache.eve.input.InputManagerMonitor#selectFailure(
      * java.nio.channels.Selector, java.io.IOException)
      */
-    public void selectFailure( Selector a_selector, IOException a_fault )
+    public void selectFailure( Selector selector, IOException fault )
     {
         if ( getLogger().isErrorEnabled() )
         {
-            getLogger().error( "Failed on select() of selector " + a_selector, 
-                    a_fault ) ;
+            getLogger().error( "Failed on select() of selector " + selector, 
+                    fault ) ;
         }
     }
 
@@ -191,11 +192,11 @@
      * @see org.apache.eve.input.InputManagerMonitor#selectorReturned(
      * java.nio.channels.Selector)
      */
-    public void selectorReturned( Selector a_selector )
+    public void selectorReturned( Selector selector )
     {
         if ( getLogger().isDebugEnabled() )
         {
-            getLogger().debug( "Select on " + a_selector + " returned" ) ;
+            getLogger().debug( "Select on " + selector + " returned" ) ;
         }
     }
 
@@ -204,11 +205,11 @@
      * @see org.apache.eve.input.InputManagerMonitor#selectTimedOut(
      * java.nio.channels.Selector)
      */
-    public void selectTimedOut( Selector a_selector )
+    public void selectTimedOut( Selector selector )
     {
         if ( getLogger().isWarnEnabled() )
         {
-            getLogger().warn( "Select on " + a_selector + " timed out" ) ;
+            getLogger().warn( "Select on " + selector + " timed out" ) ;
         }
     }
     
@@ -217,12 +218,26 @@
      * @see org.apache.eve.input.InputManagerMonitor#inputRecieved(
      * java.nio.Buffer, org.apache.eve.listener.ClientKey)
      */
-    public void inputRecieved( ByteBuffer a_buffer, ClientKey a_key )
+    public void inputRecieved( ByteBuffer buffer, ClientKey key )
     {
         if ( getLogger().isDebugEnabled() )
         {
-            getLogger().debug( "Recieved input [" +  toHexString( a_buffer ) 
-                    + "] from client " + a_key ) ;
+            getLogger().debug( "Recieved input [" +  toHexString( buffer ) 
+                    + "] from client " + key ) ;
+        }
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see org.apache.eve.input.InputManagerMonitor#cleanedStaleKey(
+     * java.nio.channels.SelectionKey)
+     */
+    public void cleanedStaleKey( SelectionKey key )
+    {
+        if ( getLogger().isWarnEnabled() )
+        {
+            getLogger().warn( "Cleaning up stale connection key for client: " 
+                    + key.attachment() ) ;
         }
     }
     
@@ -230,10 +245,10 @@
     /*
      * Generates a hex string for a buffer.
      */
-    public String toHexString( ByteBuffer a_buf )
+    public String toHexString( ByteBuffer buf )
     {
-        byte[] l_bites = new byte[a_buf.remaining()] ;
-        a_buf.get( l_bites ) ;
+        byte[] l_bites = new byte[buf.remaining()] ;
+        buf.get( l_bites ) ;
         return new String ( l_bites ) ;
     }
 }

Modified: incubator/directory/eve/trunk/eve/frontend/input/pojo-impl/src/java/org/apache/eve/input/DefaultInputManager.java
==============================================================================
--- incubator/directory/eve/trunk/eve/frontend/input/pojo-impl/src/java/org/apache/eve/input/DefaultInputManager.java
(original)
+++ incubator/directory/eve/trunk/eve/frontend/input/pojo-impl/src/java/org/apache/eve/input/DefaultInputManager.java
Thu Mar  4 20:11:16 2004
@@ -47,7 +47,7 @@
  * @version $Rev: 1452 $
  */
 public class DefaultInputManager extends AbstractSubscriber
-    implements InputManager, ConnectSubscriber, DisconnectSubscriber
+    implements InputManager, ConnectSubscriber, DisconnectSubscriber, Runnable
 {
     /** the thread driving this Runnable */ 
     private Thread m_thread = null ;
@@ -75,17 +75,17 @@
     /**
      * Creates a default InputManager implementation
      *  
-     * @param a_router an event router service
-     * @param a_bp a buffer pool service
+     * @param router an event router service
+     * @param bp a buffer pool service
      */
-    public DefaultInputManager( EventRouter a_router, BufferPool a_bp )
+    public DefaultInputManager( EventRouter router, BufferPool bp )
         throws IOException
     {
-        m_bp = a_bp ;
+        m_bp = bp ;
         m_hasStarted = new Boolean( false ) ;
         m_selector = Selector.open() ;
 
-        m_router = a_router ;
+        m_router = router ;
         m_router.subscribe( ConnectEvent.class, null, this ) ;
         m_router.subscribe( DisconnectEvent.class, null, this ) ;
     }
@@ -95,68 +95,73 @@
     // start, stop and runnable code
     // ------------------------------------------------------------------------
     
-    
+
     /**
-     * Runnable used to drive the selection loop. 
-     *
-     * @author <a href="mailto:aok123@bellsouth.net">Alex Karasulu</a>
-     * @author $Author: akarasulu $
-     * @version $Revision$
+     * Runnable run method implementation.
      */
-    class SelectionDriver implements Runnable
+    public void run()
     {
-        public void run()
+        /*
+         * Loop here solves a bug where some lingering phantom clients (that are
+         * long gone) have sockets and channels that appear valid and connected.
+         * These sockets and channels are cleaned up here in this loop.  Keep 
+         * in mind they have triggered a wakeup on select() and are appear 
+         * ready for reads yet were not selected w/i the last iteration since 
+         * the selected count was zero.  For more information on this you can 
+         * refer to the Jira Issue:
+         *  
+         *     http://nagoya.apache.org/jira/secure/ViewIssue.jspa?key=DIR-18
+         */
+        while ( m_hasStarted.booleanValue() ) 
         {
-            while ( m_hasStarted.booleanValue() ) 
+            int l_count = 0 ;
+            
+            try
             {
-                int l_count = 0 ;
+                m_monitor.enteringSelect( m_selector ) ;
                 
                 /*
-                 * check if we have input waiting and continue if there is
-                 * nothing to read from any of the registered channels  
+                 * Register newly arrived connections and unregister thosed 
+                 * that were dropped while we were blocked on the select call
                  */
-                try
+                registerNewConnections() ;
+                unregisterDroppedConnections() ;
+                
+                /*
+                 * Clean stale connections that do not have and data: select
+                 * returns indicating that the count of active connections with
+                 * input is 0.  However the list still has these "stale" 
+                 * connections lingering around.  We remove them since they
+                 * are prematurely triggering selection to return w/o input.
+                 */  
+                if ( 0 == ( l_count = m_selector.select() ) )
                 {
-                    m_monitor.enteringSelect( m_selector ) ;
-                    maintainConnections() ;
-                    
-                    if ( 0 == ( l_count = m_selector.select() ) )
+                    Iterator l_list = m_selector.selectedKeys().iterator() ;
+                    while( l_list.hasNext() )
                     {
-                        /*
-                         * Loop here solves a bug where some lingering phantom
-                         * clients (long gone) have sockets and channels that 
-                         * appear valid and connected.  These sockets and 
-                         * channels are cleaned up here in this loop.  Keep in
-                         * mind they have triggered a wakeup on select() and 
-                         * are appear ready for reads yet were not selected w/i
-                         * the last iteration since the selected count was zero.
-                         * 
-                         * For more information on this you can refer to the 
-                         * Jira Issue: 
-                 http://nagoya.apache.org/jira/secure/ViewIssue.jspa?key=DIR-18
-                         */
-                        Iterator l_list = m_selector.selectedKeys().iterator() ;
-                        while( l_list.hasNext() )
-                        {
-                            SelectionKey l_key = ( SelectionKey ) 
-                                l_list.next() ;
-                            l_key.channel().close() ;
-                            l_key.cancel() ;
-                            l_list.remove() ;
-                        }
+                        SelectionKey l_key = ( SelectionKey ) l_list.next() ;
+                        l_key.channel().close() ;
+                        l_key.cancel() ;
+                        l_list.remove() ;
                         
-                        m_monitor.selectTimedOut( m_selector ) ;
-                        continue ;
+                        m_monitor.cleanedStaleKey( l_key ) ;
                     }
-                } 
-                catch( IOException e )
-                {
-                    m_monitor.selectFailure( m_selector, e ) ;
+                    
+                    m_monitor.selectTimedOut( m_selector ) ;
                     continue ;
                 }
-                
-                processInput() ;
+            } 
+            catch( IOException e )
+            {
+                m_monitor.selectFailure( m_selector, e ) ;
+                continue ;
             }
+            
+            /*
+             * At this point we've come out of the select call with valid
+             * input on channels and need to process that input.
+             */
+            processInput() ;
         }
     }
 
@@ -174,7 +179,7 @@
             }
             
             m_hasStarted = new Boolean( true ) ;
-            m_thread = new Thread( new SelectionDriver() ) ;
+            m_thread = new Thread( this ) ;
             m_thread.start() ;
         }
     }
@@ -239,43 +244,29 @@
     
     
     /**
-     * Maintains connections by registering newly established connections within
-     * ConnectEvents and cancelling the selection keys of dropped connections.
-     * 
-     * @see created in response to a <a href=
-     * "http://nagoya.apache.org/jira/secure/ViewIssue.jspa?id=13574">JIRA Issue
-     * </a>
+     * Register new connections that have arrived since the last select call. 
      */
-    private void maintainConnections()
+    private void registerNewConnections()
     {
-        /* Register New Connections 
-         * ========================
-         * 
-         * Here we perform a synchronized transfer of newly arrived events 
-         * which are batched in the list of ConnectEvents.  This is done to
-         * minimize the chances of contention.  Next we cycle through each
-         * event registering the new connection's channel with the selector.
-         */
-        
-        // copy all events into a separate list first and clear
-        ConnectEvent[] l_connectEvents = null ;
+        // copy of newly arrived events batched in the list of ConnectEvents
+        ConnectEvent[] l_events = null ;
         synchronized( m_connectEvents ) 
         {
-            l_connectEvents = new ConnectEvent[m_connectEvents.size()] ;
-            l_connectEvents = ( ConnectEvent[] ) 
-                m_connectEvents.toArray( l_connectEvents ) ;
+            l_events = new ConnectEvent[m_connectEvents.size()] ;
+            l_events = ( ConnectEvent[] ) 
+                m_connectEvents.toArray( l_events ) ;
             m_connectEvents.clear() ;
         }
 
         // cycle through connections and register them with the selector
-        for ( int ii = 0; ii < l_connectEvents.length ; ii++ )
+        for ( int ii = 0; ii < l_events.length ; ii++ )
         {    
             ClientKey l_key = null ;
             SocketChannel l_channel = null ;
             
             try
             {
-                l_key = l_connectEvents[ii].getClientKey() ;
+                l_key = l_events[ii].getClientKey() ;
                 l_channel = l_key.getSocket().getChannel() ;
                 
                 // hands-off blocking sockets!
@@ -298,30 +289,35 @@
                         SelectionKey.OP_READ, e ) ;
             }
         }
-        
-        
-        /* Cancel/Unregister Dropped Connections 
-         * =====================================
-         *
-         * To do this we simply cancel the selection key for the client the
-         * disconnect event is associated with.  
-         */
-        
-        // copy all events into a separate list first and clear
-        DisconnectEvent[] l_disconnectEvents = null ;
+    }
+
+    
+    /**
+     *  Cancel/Unregister dropped connections since the last call to select.
+     * 
+     * @see created in response to a <a href=
+     * "http://nagoya.apache.org/jira/secure/ViewIssue.jspa?id=13574">JIRA Issue
+     * </a>
+     */
+    private void unregisterDroppedConnections()
+    {
+        SelectionKey l_key = null ;
+        DisconnectEvent[] l_events = null ;
+
+        // synchronized copy all events into a separate list first and clear
         synchronized( m_disconnectEvents ) 
         {
-            l_disconnectEvents = new DisconnectEvent[m_disconnectEvents.size()] ;
-            l_disconnectEvents = ( DisconnectEvent[] ) 
-                m_disconnectEvents.toArray( l_disconnectEvents ) ;
+            l_events = new DisconnectEvent[m_disconnectEvents.size()] ;
+            l_events = ( DisconnectEvent[] ) 
+                m_disconnectEvents.toArray( l_events ) ;
             m_disconnectEvents.clear() ;
         }
 
-        SelectionKey l_key = null ;
-        for ( int ii = 0; ii < l_disconnectEvents.length; ii++ )
+        // cancel selection key for the disconnect event's client  
+        for ( int ii = 0; ii < l_events.length; ii++ )
         {
             Iterator l_keys = m_selector.keys().iterator() ;
-            ClientKey l_clientKey = l_disconnectEvents[ii].getClientKey() ;
+            ClientKey l_clientKey = l_events[ii].getClientKey() ;
 
             while ( l_keys.hasNext() )
             {
@@ -436,20 +432,20 @@
      */
     class ConcreteInputEvent extends InputEvent
     {
-        ConcreteInputEvent( ClientKey a_key, ByteBuffer a_buffer )
+        ConcreteInputEvent( ClientKey key, ByteBuffer buffer )
         {
-            super( DefaultInputManager.this, a_key, a_buffer ) ;
+            super( DefaultInputManager.this, key, buffer ) ;
         }
         
-        public ByteBuffer claimInterest( Object a_party )
+        public ByteBuffer claimInterest( Object party )
         {
-            m_bp.claimInterest( getBuffer(), a_party ) ;
+            m_bp.claimInterest( getBuffer(), party ) ;
             return getBuffer().asReadOnlyBuffer() ;
         }
         
-        public void releaseInterest( Object a_party )
+        public void releaseInterest( Object party )
         {
-            m_bp.releaseClaim( getBuffer(), a_party ) ;
+            m_bp.releaseClaim( getBuffer(), party ) ;
         }
     }
     
@@ -468,10 +464,10 @@
     /**
      * Sets the monitor associated with this InputManager.
      * 
-     * @param a_monitor the monitor to set
+     * @param monitor the monitor to set
      */
-    public void setMonitor( InputManagerMonitor a_monitor )
+    public void setMonitor( InputManagerMonitor monitor )
     {
-        m_monitor = a_monitor ;
+        m_monitor = monitor ;
     }
 }

Modified: incubator/directory/eve/trunk/eve/frontend/input/spi/src/java/org/apache/eve/input/InputManagerMonitor.java
==============================================================================
--- incubator/directory/eve/trunk/eve/frontend/input/spi/src/java/org/apache/eve/input/InputManagerMonitor.java
(original)
+++ incubator/directory/eve/trunk/eve/frontend/input/spi/src/java/org/apache/eve/input/InputManagerMonitor.java
Thu Mar  4 20:11:16 2004
@@ -1,58 +1,26 @@
 /*
-
- ============================================================================
-                   The Apache Software License, Version 1.1
- ============================================================================
-
- Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
-
- Redistribution and use in source and binary forms, with or without modifica-
- tion, are permitted provided that the following conditions are met:
-
- 1. Redistributions of  source code must  retain the above copyright  notice,
-    this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright notice,
-    this list of conditions and the following disclaimer in the documentation
-    and/or other materials provided with the distribution.
-
- 3. The end-user documentation included with the redistribution, if any, must
-    include  the following  acknowledgment:  "This product includes  software
-    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
-    Alternately, this  acknowledgment may  appear in the software itself,  if
-    and wherever such third-party acknowledgments normally appear.
-
- 4. The names "Eve Directory Server", "Apache Directory Project", "Apache Eve" 
-    and "Apache Software Foundation"  must not be used to endorse or promote
-    products derived  from this  software without  prior written
-    permission. For written permission, please contact apache@apache.org.
-
- 5. Products  derived from this software may not  be called "Apache", nor may
-    "Apache" appear  in their name,  without prior written permission  of the
-    Apache Software Foundation.
-
- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
- APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
- INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
- DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
- OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
- ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
- (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- This software  consists of voluntary contributions made  by many individuals
- on  behalf of the Apache Software  Foundation. For more  information on the
- Apache Software Foundation, please see <http://www.apache.org/>.
-
-*/
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
 package org.apache.eve.input ;
 
 
 import java.io.IOException ;
 
 import java.nio.ByteBuffer ;
+import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector ;
 import java.nio.channels.SocketChannel ;
 
@@ -74,40 +42,40 @@
     /**
      * Monitors client disconnections.
      * 
-     * @param a_key the key of the client that was disconnected
+     * @param key the key of the client that was disconnected
      */
-    void disconnectedClient( ClientKey a_key ) ;
+    void disconnectedClient( ClientKey key ) ;
     
     /**
      * Monitors channel registrations which occur on client sockets.
      * 
-     * @param a_key the key of the client whose channel got registered
-     * @param a_selector the selector used to register the client's channel
+     * @param key the key of the client whose channel got registered
+     * @param selector the selector used to register the client's channel
      */
-    void registeredChannel( ClientKey a_key, Selector a_selector ) ;
+    void registeredChannel( ClientKey key, Selector selector ) ;
     
     /**
      * Monitors returns from the selector denoting a timeout or a wakeup due to
      * input availability.
      *
-     * @param a_selector the selector that has returned
+     * @param selector the selector that has returned
      */
-    void selectorReturned( Selector a_selector ) ;
+    void selectorReturned( Selector selector ) ;
     
     /**
      * Monitors input read from a client socket channel.
      * 
-     * @param a_key the key of the client sending the request
+     * @param key the key of the client sending the request
      */
-    void inputRecieved( ClientKey a_key ) ;
+    void inputRecieved( ClientKey key ) ;
 
     /**
      * Monitors input read from a client socket channel.
      * 
-     * @param a_buffer the input recieved
-     * @param a_key the key of the client sending the request
+     * @param buffer the input recieved
+     * @param key the key of the client sending the request
      */
-    void inputRecieved( ByteBuffer a_buffer, ClientKey a_key ) ;
+    void inputRecieved( ByteBuffer buffer, ClientKey key ) ;
 
     
     // ------------------------------------------------------------------------
@@ -118,67 +86,76 @@
     /**
      * Monitor method for handling selector select call failures.
      * 
-     * @param a_selector the selector the select was called on
-     * @param a_fault the faulting exception
+     * @param selector the selector the select was called on
+     * @param fault the faulting exception
      */
-    void selectFailure( Selector a_selector, IOException a_fault ) ;
+    void selectFailure( Selector selector, IOException fault ) ;
     
     /**
      * Monitors attempts to use client key's that have expired.
      *  
-     * @param a_key the client key that expired
-     * @param a_fault the faulting exception
+     * @param key the client key that expired
+     * @param fault the faulting exception
      */
-    void keyExpiryFailure( ClientKey a_key, KeyExpiryException a_fault ) ;
+    void keyExpiryFailure( ClientKey key, KeyExpiryException fault ) ;
     
     /**
      * Monitors failed read attempts from client socket channel.
      * 
-     * @param a_key the key of the client the read failed on
-     * @param a_fault the faulting exception
+     * @param key the key of the client the read failed on
+     * @param fault the faulting exception
      */
-    void readFailed( ClientKey a_key, IOException a_fault ) ;
+    void readFailed( ClientKey key, IOException fault ) ;
 
     /**
      * Monitors failed attempts to acquire a buffer from the BufferPool.
      * 
-     * @param a_bp the buffer pool a buffer was requested from
-     * @param a_fault the faulting exception
+     * @param bp the buffer pool a buffer was requested from
+     * @param fault the faulting exception
      */
-    void bufferUnavailable( BufferPool a_bp, ResourceException a_fault ) ;
+    void bufferUnavailable( BufferPool bp, ResourceException fault ) ;
     
     /**
      * Monitors failures to register channels with a selector.
      * 
-     * @param a_selector the selector the register method was called on
-     * @param a_channel the channel that failed registeration
-     * @param a_selectionKey the selection key used to register
-     * @param a_fault the faulting exception
-     */
-    void channelRegistrationFailure( Selector a_selector, 
-                                     SocketChannel a_channel,
-                                     int a_selectionKey,
-                                     IOException a_fault ) ;
+     * @param selector the selector the register method was called on
+     * @param channel the channel that failed registeration
+     * @param selectionKey the selection key used to register
+     * @param fault the faulting exception
+     */
+    void channelRegistrationFailure( Selector selector, SocketChannel channel,
+                                     int selectionKey, IOException fault ) ;
     
     /**
      * Monitors failures to close a client's socket channel.
      * 
-     * @param a_channel the channel that failed to close
-     * @param a_fault the faulting exception
+     * @param channel the channel that failed to close
+     * @param fault the faulting exception
      */
-    void channelCloseFailure( SocketChannel a_channel, IOException a_fault ) ;
+    void channelCloseFailure( SocketChannel channel, IOException fault ) ;
     
     /**
      * Monitors the occurrence of successful select timeouts on a selector
      * 
-     * @param a_selector
+     * @param selector
      */
-    void selectTimedOut( Selector a_selector ) ;
+    void selectTimedOut( Selector selector ) ;
     
     /**
      * A select call is about to be made.
      *
-     * @param a_selector the selector on which the select is called
+     * @param selector the selector on which the select is called
+     */
+    void enteringSelect( Selector selector ) ;
+    
+    /**
+     * Monitors the removal of stale keys from the selection set.  This occurs
+     * when connections are abrubtly dropped by clients and are left 
+     * inconsistant.  These keys wakeup threads in select calls yet have 
+     * no incomming IO on them.  They are removed to cleanup and this method
+     * is called when one is cleaned up.
+     * 
+     * @param key the selection key of the client that was cleaned up
      */
-    void enteringSelect( Selector a_selector ) ;
+    void cleanedStaleKey( SelectionKey key ) ;
 }

Modified: incubator/directory/eve/trunk/eve/frontend/input/spi/src/java/org/apache/eve/input/InputManagerMonitorAdapter.java
==============================================================================
--- incubator/directory/eve/trunk/eve/frontend/input/spi/src/java/org/apache/eve/input/InputManagerMonitorAdapter.java
(original)
+++ incubator/directory/eve/trunk/eve/frontend/input/spi/src/java/org/apache/eve/input/InputManagerMonitorAdapter.java
Thu Mar  4 20:11:16 2004
@@ -1,52 +1,19 @@
 /*
-
- ============================================================================
-                   The Apache Software License, Version 1.1
- ============================================================================
-
- Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
-
- Redistribution and use in source and binary forms, with or without modifica-
- tion, are permitted provided that the following conditions are met:
-
- 1. Redistributions of  source code must  retain the above copyright  notice,
-    this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright notice,
-    this list of conditions and the following disclaimer in the documentation
-    and/or other materials provided with the distribution.
-
- 3. The end-user documentation included with the redistribution, if any, must
-    include  the following  acknowledgment:  "This product includes  software
-    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
-    Alternately, this  acknowledgment may  appear in the software itself,  if
-    and wherever such third-party acknowledgments normally appear.
-
- 4. The names "Eve Directory Server", "Apache Directory Project", "Apache Eve" 
-    and "Apache Software Foundation"  must not be used to endorse or promote
-    products derived  from this  software without  prior written
-    permission. For written permission, please contact apache@apache.org.
-
- 5. Products  derived from this software may not  be called "Apache", nor may
-    "Apache" appear  in their name,  without prior written permission  of the
-    Apache Software Foundation.
-
- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
- APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
- INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
- DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
- OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
- ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
- (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- This software  consists of voluntary contributions made  by many individuals
- on  behalf of the Apache Software  Foundation. For more  information on the
- Apache Software Foundation, please see <http://www.apache.org/>.
-
-*/
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
 package org.apache.eve.input ;
 
 
@@ -54,6 +21,7 @@
 
 import java.nio.ByteBuffer ;
 import java.nio.channels.Selector ; 
+import java.nio.channels.SelectionKey ;
 import java.nio.channels.SocketChannel ;
 
 import org.apache.eve.ResourceException ;
@@ -65,8 +33,8 @@
 /**
  * An adaptor for the InputManagerMonitor interface.
  *
- * @author <a href="mailto:akarasulu@apache.org">Alex Karasulu</a>
- * @author $Author$
+ * @author <a href="mailto:directory-dev@incubator.apache.org">
+ * Apache Directory Project</a>
  * @version $Rev$
  */
 public class InputManagerMonitorAdapter implements InputManagerMonitor
@@ -75,7 +43,7 @@
      * @see org.apache.eve.input.InputManagerMonitor#
      * disconnectedClient(org.apache.eve.listener.ClientKey)
      */
-    public void disconnectedClient( ClientKey a_key )
+    public void disconnectedClient( ClientKey key )
     {
     }
     
@@ -85,7 +53,7 @@
      * registeredChannel(org.apache.eve.listener.ClientKey, 
      * java.nio.channels.Selector)
      */
-    public void registeredChannel( ClientKey a_key, Selector a_selector )
+    public void registeredChannel( ClientKey key, Selector selector )
     {
     }
 
@@ -94,7 +62,7 @@
      * @see org.apache.eve.input.InputManagerMonitor#
      * selectorReturned(java.nio.channels.Selector)
      */
-    public void selectorReturned( Selector a_selector )
+    public void selectorReturned( Selector selector )
     {
     }
 
@@ -103,7 +71,7 @@
      * @see org.apache.eve.input.InputManagerMonitor#
      * inputRecieved(org.apache.eve.listener.ClientKey)
      */
-    public void inputRecieved( ClientKey a_key )
+    public void inputRecieved( ClientKey key )
     {
     }
 
@@ -112,7 +80,7 @@
      * @see org.apache.eve.input.InputManagerMonitor#
      * selectFailure(java.nio.channels.Selector, java.io.IOException)
      */
-    public void selectFailure( Selector a_selector, IOException a_fault )
+    public void selectFailure( Selector selector, IOException fault )
     {
     }
 
@@ -122,7 +90,7 @@
      * org.apache.eve.listener.ClientKey, 
      * org.apache.eve.listener.KeyExpiryException)
      */
-    public void keyExpiryFailure( ClientKey a_key, KeyExpiryException a_fault )
+    public void keyExpiryFailure( ClientKey key, KeyExpiryException fault )
     {
     }
 
@@ -131,7 +99,7 @@
      * @see org.apache.eve.input.InputManagerMonitor#
      * readFailed(org.apache.eve.listener.ClientKey, java.io.IOException)
      */
-    public void readFailed( ClientKey a_key, IOException a_fault ) 
+    public void readFailed( ClientKey key, IOException fault ) 
     {
     }
     
@@ -141,7 +109,7 @@
      * bufferUnavailable(org.apache.eve.buffer.BufferPool, 
      * org.apache.eve.ResourceException)
      */
-    public void bufferUnavailable( BufferPool a_bp, ResourceException a_fault )
+    public void bufferUnavailable( BufferPool bp, ResourceException fault )
     {
     }
 
@@ -151,8 +119,8 @@
      * channelRegistrationFailure(java.nio.channels.Selector, 
      * java.nio.channels.SocketChannel, int, java.io.IOException)
      */
-    public void channelRegistrationFailure( Selector a_selector,
-        SocketChannel a_channel, int a_key, IOException a_fault)
+    public void channelRegistrationFailure( Selector selector,
+        SocketChannel channel, int key, IOException fault)
     {
     }
 
@@ -161,8 +129,8 @@
      * @see org.apache.eve.input.InputManagerMonitor#
      * channelCloseFailure(java.nio.channels.SocketChannel, java.io.IOException)
      */
-    public void channelCloseFailure( SocketChannel a_channel, 
-                                     IOException a_fault )
+    public void channelCloseFailure( SocketChannel channel, 
+                                     IOException fault )
     {
     }
     
@@ -171,7 +139,7 @@
      * @see org.apache.eve.input.InputManagerMonitor#enteringSelect(
      * java.nio.channels.Selector)
      */
-    public void enteringSelect( Selector a_selector )
+    public void enteringSelect( Selector selector )
     {
     }
 
@@ -180,7 +148,7 @@
      * @see org.apache.eve.input.InputManagerMonitor#selectTimedOut(
      * java.nio.channels.Selector)
      */
-    public void selectTimedOut( Selector a_selector )
+    public void selectTimedOut( Selector selector )
     {
     }
     
@@ -189,7 +157,16 @@
      * @see org.apache.eve.input.InputManagerMonitor#inputRecieved(
      * java.nio.ByteBuffer, org.apache.eve.listener.ClientKey)
      */
-    public void inputRecieved( ByteBuffer a_buffer, ClientKey a_key )
+    public void inputRecieved( ByteBuffer buffer, ClientKey key )
+    {
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see org.apache.eve.input.InputManagerMonitor#cleanedStaleKey(
+     * java.nio.channels.SelectionKey)
+     */
+    public void cleanedStaleKey( SelectionKey key )
     {
     }
 }

Mime
View raw message