You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2003/12/06 23:55:29 UTC
svn commit: rev 1375 - in incubator/directory/ldap/trunk/eve/frontend: event/spi/src/java/org/apache/eve/event listener/impl/src/java/org/apache/eve/listener listener/spi/src/java/org/apache/eve/listener
Author: akarasulu
Date: Sat Dec 6 14:55:28 2003
New Revision: 1375
Added:
incubator/directory/ldap/trunk/eve/frontend/event/spi/src/java/org/apache/eve/event/EventRouterMonitor.java
incubator/directory/ldap/trunk/eve/frontend/event/spi/src/java/org/apache/eve/event/EventRouterMonitorAdapter.java
incubator/directory/ldap/trunk/eve/frontend/listener/impl/src/java/org/apache/eve/listener/AvalonListenerManagerMonitor.java
incubator/directory/ldap/trunk/eve/frontend/listener/impl/src/java/org/apache/eve/listener/ListenerManagerMonitorAdapter.java
incubator/directory/ldap/trunk/eve/frontend/listener/impl/src/java/org/apache/eve/listener/MerlinListenerManager.java
incubator/directory/ldap/trunk/eve/frontend/listener/spi/src/java/org/apache/eve/listener/ListenerManagerMonitor.java
Modified:
incubator/directory/ldap/trunk/eve/frontend/listener/impl/src/java/org/apache/eve/listener/DefaultListenerManager.java
incubator/directory/ldap/trunk/eve/frontend/listener/spi/src/java/org/apache/eve/listener/ListenerManager.java
Log:
Adding more changes to round out some classes and make them easier to
test.
Added: incubator/directory/ldap/trunk/eve/frontend/event/spi/src/java/org/apache/eve/event/EventRouterMonitor.java
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/eve/frontend/event/spi/src/java/org/apache/eve/event/EventRouterMonitor.java Sat Dec 6 14:55:28 2003
@@ -0,0 +1,85 @@
+/*
+
+ ============================================================================
+ 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/>.
+
+*/
+package org.apache.eve.event ;
+
+
+import java.util.EventObject ;
+
+
+/**
+ * Monitors the activities of the event router.
+ *
+ * @author <a href="mailto:aok123@bellsouth.net">Alex Karasulu</a>
+ * @author $Author$
+ * @version $Revision$
+ */
+public interface EventRouterMonitor
+{
+ /**
+ * Monitors events that are published.
+ *
+ * @param a_event the published event object
+ */
+ void eventPublished( EventObject a_event ) ;
+
+ /**
+ * Monitores the addition of new subscriptions.
+ *
+ * @param a_subscription
+ */
+ void addedSubscription( Subscription a_subscription ) ;
+
+ /**
+ * Monitors the removal of new subscriptions
+ *
+ * @param a_subscription
+ */
+ void removedSubscription( Subscription a_subscription ) ;
+}
Added: incubator/directory/ldap/trunk/eve/frontend/event/spi/src/java/org/apache/eve/event/EventRouterMonitorAdapter.java
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/eve/frontend/event/spi/src/java/org/apache/eve/event/EventRouterMonitorAdapter.java Sat Dec 6 14:55:28 2003
@@ -0,0 +1,85 @@
+/*
+
+ ============================================================================
+ 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/>.
+
+*/
+package org.apache.eve.event ;
+
+
+import java.util.EventObject ;
+
+
+/**
+ * Does nothing and created by the default constructor.
+ *
+ * @author <a href="mailto:aok123@bellsouth.net">Alex Karasulu</a>
+ * @author $Author$
+ * @version $Revision$
+ */
+public class EventRouterMonitorAdapter implements EventRouterMonitor
+{
+ /* (non-Javadoc)
+ * @see org.apache.eve.event.EventRouterMonitor#eventPublished(java.util.EventObject)
+ */
+ public void eventPublished(EventObject a_a_event)
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.eve.event.EventRouterMonitor#addedSubscription(org.apache.eve.event.Subscription)
+ */
+ public void addedSubscription(Subscription a_a_subscription)
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.eve.event.EventRouterMonitor#removedSubscription(org.apache.eve.event.Subscription)
+ */
+ public void removedSubscription(Subscription a_a_subscription)
+ {
+ }
+}
Added: incubator/directory/ldap/trunk/eve/frontend/listener/impl/src/java/org/apache/eve/listener/AvalonListenerManagerMonitor.java
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/eve/frontend/listener/impl/src/java/org/apache/eve/listener/AvalonListenerManagerMonitor.java Sat Dec 6 14:55:28 2003
@@ -0,0 +1,194 @@
+/*
+
+ ============================================================================
+ 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/>.
+
+*/
+package org.apache.eve.listener ;
+
+
+import java.io.IOException ;
+import java.nio.channels.Selector ;
+import java.nio.channels.SelectionKey ;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled ;
+
+
+/**
+ * Uses an Avalon logging to monitor component activity.
+ *
+ * @author <a href="mailto:aok123@bellsouth.net">Alex Karasulu</a>
+ * @author $Author$
+ * @version $Revision$
+ */
+public class AvalonListenerManagerMonitor extends AbstractLogEnabled
+ implements ListenerManagerMonitor
+{
+ /* (non-Javadoc)
+ * @see org.apache.eve.listener.ListenerManagerMonitor#started()
+ */
+ public void started()
+ {
+ getLogger().info( "started ..." ) ;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.eve.listener.ListenerManagerMonitor#stopped()
+ */
+ public void stopped()
+ {
+ getLogger().info( "... stopped" ) ;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.eve.listener.ListenerManagerMonitor#bindOccured(
+ * org.apache.eve.listener.ServerListener)
+ */
+ public void bindOccured( ServerListener a_listener )
+ {
+ getLogger().info( "binding " + a_listener ) ;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.eve.listener.ListenerManagerMonitor#unbindOccured(
+ * org.apache.eve.listener.ServerListener)
+ */
+ public void unbindOccured( ServerListener a_listener )
+ {
+ getLogger().info( "unbinding " + a_listener ) ;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.eve.listener.ListenerManagerMonitor#acceptOccured(
+ * java.nio.channels.SelectionKey)
+ */
+ public void acceptOccured( SelectionKey a_key )
+ {
+ // may occur frequently so we do this right
+ if ( getLogger().isInfoEnabled() )
+ {
+ StringBuffer l_buf = new StringBuffer( "accepted client " ) ;
+ l_buf.append( a_key.attachment() ) ;
+ getLogger().info( l_buf.toString() ) ;
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.eve.listener.ListenerManagerMonitor#selectOccured(
+ * java.nio.channels.Selector)
+ */
+ public void selectOccured( Selector a_selector )
+ {
+ // may occur very very frequently so we do this right
+ if ( getLogger().isDebugEnabled() )
+ {
+ StringBuffer l_buf = new StringBuffer( "select on " ) ;
+ l_buf.append( a_selector ) ;
+ getLogger().debug( l_buf.toString() ) ;
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.eve.listener.ListenerManagerMonitor#failedToBind(
+ * org.apache.eve.listener.ServerListener, java.io.IOException)
+ */
+ public void failedToBind( ServerListener a_listener, IOException a_failure )
+ {
+ getLogger().error( "failed to bind listener to " + a_listener
+ + " encountered exception: " + a_failure.getMessage() ) ;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.eve.listener.ListenerManagerMonitor#failedToUnbind(
+ * org.apache.eve.listener.ServerListener, java.io.IOException)
+ */
+ public void failedToUnbind( ServerListener a_listener,
+ IOException a_failure )
+ {
+ getLogger().error( "failed to unbind listener from " + a_listener
+ + " encountered exception: " + a_failure.getMessage() ) ;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.eve.listener.ListenerManagerMonitor#failedToExpire(
+ * org.apache.eve.listener.ClientKey, java.io.IOException)
+ */
+ public void failedToExpire( ClientKey a_key, IOException a_failure )
+ {
+ getLogger().error( "failed to expire client key " + a_key
+ + " encountered exception: " + a_failure.getMessage() ) ;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.eve.listener.ListenerManagerMonitor#failedToAccept(
+ * java.nio.channels.SelectionKey, java.io.IOException)
+ */
+ public void failedToAccept( SelectionKey a_key, IOException a_failure )
+ {
+ getLogger().error( "failed to accept on selection key " + a_key
+ + " encountered exception: " + a_failure.getMessage() ) ;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.eve.listener.ListenerManagerMonitor#failedToSelect(
+ * java.nio.channels.Selector, java.io.IOException)
+ */
+ public void failedToSelect( Selector a_selector, IOException a_failure )
+ {
+ getLogger().error( "failed on select of selector " + a_selector
+ + " encountered exception: " + a_failure.getMessage() ) ;
+ }
+}
Modified: incubator/directory/ldap/trunk/eve/frontend/listener/impl/src/java/org/apache/eve/listener/DefaultListenerManager.java
==============================================================================
--- incubator/directory/ldap/trunk/eve/frontend/listener/impl/src/java/org/apache/eve/listener/DefaultListenerManager.java (original)
+++ incubator/directory/ldap/trunk/eve/frontend/listener/impl/src/java/org/apache/eve/listener/DefaultListenerManager.java Sat Dec 6 14:55:28 2003
@@ -22,8 +22,8 @@
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
- 4. The names "Jakarta", "Apache Directory Project", "Apache Eve" and
- "Apache Software Foundation" must not be used to endorse or promote
+ 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.
@@ -50,10 +50,11 @@
package org.apache.eve.listener ;
-import java.util.EventObject;
import java.util.Set ;
import java.util.HashSet ;
import java.util.Iterator ;
+import java.util.EventObject ;
+
import java.io.IOException ;
import java.net.InetSocketAddress ;
@@ -62,17 +63,10 @@
import java.nio.channels.SocketChannel ;
import java.nio.channels.ServerSocketChannel ;
-import org.apache.avalon.framework.activity.Startable ;
-import org.apache.avalon.framework.activity.Initializable ;
-import org.apache.avalon.framework.logger.AbstractLogEnabled ;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager ;
-import org.apache.avalon.framework.service.Serviceable ;
-
-import org.apache.eve.event.DisconnectSubscriber;
import org.apache.eve.event.EventRouter ;
import org.apache.eve.event.ConnectEvent ;
import org.apache.eve.event.DisconnectEvent ;
+import org.apache.eve.event.DisconnectSubscriber ;
/**
@@ -83,40 +77,90 @@
* @author $Author$
* @version $Revision$
*/
-public class DefaultListenerManager extends AbstractLogEnabled
+public class DefaultListenerManager
implements
DisconnectSubscriber,
ListenerManager,
- Initializable,
- Serviceable,
- Startable,
Runnable
{
- /** the thread driving this Runnable */
- private Thread m_thread = null ;
- /** parameter used to politely stop running thread */
- private Boolean m_hasStarted = null ;
/** event manager used to decouple source to sink relationships */
- private EventRouter m_router ;
+ private final EventRouter m_router ;
/** selector used to select a acceptable socket channel */
- private Selector m_selector = null ;
+ private final Selector m_selector ;
/** the client keys for accepted connections */
- private Set m_clients = new HashSet() ;
+ private final Set m_clients ;
+ /** the thread driving this Runnable */
+ private Thread m_thread = null ;
+ /** parameter used to politely stop running thread */
+ private Boolean m_hasStarted = null ;
+ /** the listner manager's monitor */
+ private ListenerManagerMonitor m_monitor =
+ new ListenerManagerMonitorAdapter() ;
+
+
+ /**
+ * Creates a default listener manager using an event router.
+ *
+ * @param a_router the router to publish events to
+ * @throws IOException
+ */
+ public DefaultListenerManager( EventRouter a_router ) throws IOException
+ {
+ m_router = a_router ;
+ m_clients = new HashSet() ;
+ m_selector = Selector.open() ;
+ m_hasStarted = new Boolean( false ) ;
+ m_router.subscribe( DisconnectEvent.class, null, this ) ;
+ }
- /**
+
+ /**
+ * Gets the monitor.
+ *
+ * @return Returns the monitor.
+ */
+ public ListenerManagerMonitor getMonitor()
+ {
+ return m_monitor ;
+ }
+
+
+ /**
+ * Sets the monitor.
+ *
+ * @param a_monitor The monitor to set.
+ */
+ public void setMonitor( ListenerManagerMonitor a_monitor )
+ {
+ m_monitor = a_monitor ;
+ }
+
+
+ /**
* @see org.apache.eve.listener.ListenerManager#register(org.apache.eve.
* listener.ServerListener)
*/
- public void register( ServerListener a_listener ) throws IOException
+ public void bind( ServerListener a_listener ) throws IOException
{
- ServerSocketChannel l_channel = ServerSocketChannel.open() ;
- InetSocketAddress l_address = new InetSocketAddress(
- a_listener.getAddress(),
- a_listener.getPort() ) ;
- l_channel.socket().bind( l_address, a_listener.getBacklog() ) ;
- l_channel.configureBlocking( false ) ;
- l_channel.register( m_selector, SelectionKey.OP_ACCEPT, a_listener ) ;
+ try
+ {
+ ServerSocketChannel l_channel = ServerSocketChannel.open() ;
+ InetSocketAddress l_address = new InetSocketAddress(
+ a_listener.getAddress(),
+ a_listener.getPort() ) ;
+ l_channel.socket().bind( l_address, a_listener.getBacklog() ) ;
+ l_channel.configureBlocking( false ) ;
+ l_channel.register( m_selector, SelectionKey.OP_ACCEPT,
+ a_listener ) ;
+ }
+ catch ( IOException e )
+ {
+ m_monitor.failedToBind( a_listener, e ) ;
+ throw e ;
+ }
+
+ m_monitor.bindOccured( a_listener ) ;
}
@@ -124,7 +168,7 @@
* @see org.apache.eve.listener.ListenerManager#unregister(org.apache.eve.
* listener.ServerListener)
*/
- public void unregister( ServerListener a_listener ) throws IOException
+ public void unbind( ServerListener a_listener ) throws IOException
{
SelectionKey l_key = null ;
Iterator l_keys = m_selector.keys().iterator() ;
@@ -138,8 +182,18 @@
}
}
- l_key.channel().close() ;
+ try
+ {
+ l_key.channel().close() ;
+ }
+ catch ( IOException e )
+ {
+ m_monitor.failedToUnbind( a_listener, e ) ;
+ throw e ;
+ }
+
l_key.cancel() ;
+ m_monitor.unbindOccured( a_listener ) ;
}
@@ -163,11 +217,15 @@
}
catch ( IOException e )
{
- getLogger().error( "Could not properly expire client & close", e ) ;
+ m_monitor.failedToExpire( an_event.getClientKey(), e ) ;
}
}
+ /*
+ * (non-Javadoc)
+ * @see org.apache.eve.event.Subscriber#inform(java.util.EventObject)
+ */
public void inform( EventObject an_event )
{
inform( ( DisconnectEvent ) an_event ) ;
@@ -175,7 +233,7 @@
// ------------------------------------------------------------------------
- // Runnable Implementation
+ // Runnable implementation and start/stop controls
// ------------------------------------------------------------------------
@@ -190,14 +248,15 @@
try
{
- if ( 0 == ( l_count = m_selector.select( 100 ) ) )
+ if ( 0 == ( l_count = m_selector.select() ) )
{
+ m_monitor.selectOccured( m_selector ) ;
continue ;
}
}
catch( IOException e )
{
- getLogger().error( "Failure on select()", e ) ;
+ m_monitor.failedToSelect( m_selector, e ) ;
continue ;
}
@@ -216,10 +275,11 @@
try
{
l_channel = l_server.accept() ;
+ m_monitor.acceptOccured( l_key ) ;
}
catch ( IOException e )
{
- getLogger().error( "Failure on accept()", e ) ;
+ m_monitor.failedToAccept( l_key, e ) ;
continue ;
}
@@ -234,17 +294,13 @@
}
- // ------------------------------------------------------------------------
- // Life Cycle Methods
- // ------------------------------------------------------------------------
-
-
/**
- * Starts up this module.
+ * Starts up this ListnerManager service.
*
- * @see org.apache.avalon.framework.activity.Startable#start()
+ * @throws InterruptedException if this service's driver thread cannot start
+ * @throws IllegalStateException if this service has already started
*/
- public void start() throws Exception
+ public void start() throws InterruptedException
{
synchronized( m_hasStarted )
{
@@ -257,15 +313,18 @@
m_thread = new Thread( this ) ;
m_thread.start() ;
}
+
+ m_monitor.started() ;
}
/**
- * Blocks calling thread until this module gracefully stops.
+ * Gracefully stops this ListenerManager service. Blocks calling thread
+ * until the service has fully stopped.
*
- * @see org.apache.avalon.framework.activity.Startable#stop()
+ * @throws InterruptedException if this service's driver thread cannot start
*/
- public void stop() throws Exception
+ public void stop() throws InterruptedException
{
synchronized( m_hasStarted )
{
@@ -276,29 +335,7 @@
Thread.sleep( 100 ) ;
}
}
- }
-
-
- /**
- * @avalon.dependency type="org.apache.eve.EventRouter"
- * key="event-router" version="1.0"
- * @see org.apache.avalon.framework.service.Serviceable#service(
- * org.apache.avalon.framework.service.ServiceManager)
- */
- public void service( ServiceManager a_manager )
- throws ServiceException
- {
- m_router = ( EventRouter ) a_manager.lookup( "event-router" ) ;
- }
-
-
- /**
- * @see org.apache.avalon.framework.activity.Initializable#initialize()
- */
- public void initialize() throws Exception
- {
- m_hasStarted = new Boolean( false ) ;
- m_selector = Selector.open() ;
- m_router.subscribe( DisconnectEvent.class, null, this ) ;
+
+ m_monitor.stopped() ;
}
}
Added: incubator/directory/ldap/trunk/eve/frontend/listener/impl/src/java/org/apache/eve/listener/ListenerManagerMonitorAdapter.java
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/eve/frontend/listener/impl/src/java/org/apache/eve/listener/ListenerManagerMonitorAdapter.java Sat Dec 6 14:55:28 2003
@@ -0,0 +1,167 @@
+/*
+
+ ============================================================================
+ 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/>.
+
+*/
+package org.apache.eve.listener ;
+
+
+import java.io.IOException ;
+import java.nio.channels.Selector ;
+import java.nio.channels.SelectionKey ;
+
+
+/**
+ * Null adapter for the ListenerManagerMonitor.
+ *
+ * @author <a href="mailto:aok123@bellsouth.net">Alex Karasulu</a>
+ * @author $Author$
+ * @version $Revision$
+ */
+public class ListenerManagerMonitorAdapter implements ListenerManagerMonitor
+{
+ /*
+ * (non-Javadoc)
+ * @see org.apache.eve.listener.ListenerManagerMonitor#started()
+ */
+ public void started()
+ {
+ }
+
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.eve.listener.ListenerManagerMonitor#stopped()
+ */
+ public void stopped()
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.eve.listener.ListenerManagerMonitor#bindOccured(
+ * org.apache.eve.listener.ServerListener)
+ */
+ public void bindOccured( ServerListener a_listener )
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.eve.listener.ListenerManagerMonitor#unbindOccured(
+ * org.apache.eve.listener.ServerListener)
+ */
+ public void unbindOccured( ServerListener a_listener )
+ {
+ }
+
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.eve.listener.ListenerManagerMonitor#acceptOccured(
+ * java.nio.channels.SelectionKey)
+ */
+ public void acceptOccured( SelectionKey a_key )
+ {
+ }
+
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.eve.listener.ListenerManagerMonitor#selectOccured(
+ * java.nio.channels.Selector)
+ */
+ public void selectOccured( Selector a_selector )
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.eve.listener.ListenerManagerMonitor#failedToBind(
+ * org.apache.eve.listener.ServerListener, java.io.IOException)
+ */
+ public void failedToBind( ServerListener a_listener, IOException a_failure )
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.eve.listener.ListenerManagerMonitor#failedToUnbind(
+ * org.apache.eve.listener.ServerListener, java.io.IOException)
+ */
+ public void failedToUnbind( ServerListener a_listener,
+ IOException a_failure )
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.eve.listener.ListenerManagerMonitor#failedToExpire(
+ * org.apache.eve.listener.ClientKey, java.io.IOException)
+ */
+ public void failedToExpire( ClientKey a_key, IOException a_failure )
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.eve.listener.ListenerManagerMonitor#failedToAccept(
+ * java.nio.channels.SelectionKey, java.io.IOException)
+ */
+ public void failedToAccept( SelectionKey a_key, IOException a_failure )
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.eve.listener.ListenerManagerMonitor#failedToSelect(
+ * java.nio.channels.Selector, java.io.IOException)
+ */
+ public void failedToSelect( Selector a_selector, IOException a_failure )
+ {
+ }
+}
Added: incubator/directory/ldap/trunk/eve/frontend/listener/impl/src/java/org/apache/eve/listener/MerlinListenerManager.java
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/eve/frontend/listener/impl/src/java/org/apache/eve/listener/MerlinListenerManager.java Sat Dec 6 14:55:28 2003
@@ -0,0 +1,181 @@
+/*
+
+ ============================================================================
+ 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/>.
+
+*/
+package org.apache.eve.listener ;
+
+
+import java.io.IOException ;
+import java.util.EventObject ;
+
+import org.apache.avalon.framework.activity.Startable ;
+import org.apache.avalon.framework.service.Serviceable ;
+import org.apache.avalon.framework.activity.Initializable ;
+import org.apache.avalon.framework.service.ServiceManager ;
+import org.apache.avalon.framework.service.ServiceException ;
+import org.apache.avalon.framework.logger.AbstractLogEnabled ;
+
+import org.apache.eve.event.EventRouter ;
+import org.apache.eve.event.DisconnectEvent ;
+
+
+/**
+ * A listener manager that uses non-blocking NIO based constructs to detect
+ * client connections on server socket listeners.
+ *
+ * @author <a href="mailto:aok123@bellsouth.net">Alex Karasulu</a>
+ * @author $Author$
+ * @version $Revision$
+ */
+public class MerlinListenerManager extends AbstractLogEnabled
+ implements
+ ListenerManager,
+ Initializable,
+ Serviceable,
+ Startable
+{
+ /** the listener manager implementation wrapped by this service */
+ private DefaultListenerManager m_manager ;
+ /** a temporary handle on the event router to bridge life-cycle methods */
+ private EventRouter m_router ;
+
+
+ // ------------------------------------------------------------------------
+ // ListenerManager delegating methods ...
+ // ------------------------------------------------------------------------
+
+
+ /**
+ * @see org.apache.eve.listener.ListenerManager#register(org.apache.eve.
+ * listener.ServerListener)
+ */
+ public void bind( ServerListener a_listener ) throws IOException
+ {
+ m_manager.bind( a_listener ) ;
+ }
+
+
+ /**
+ * @see org.apache.eve.listener.ListenerManager#unregister(org.apache.eve.
+ * listener.ServerListener)
+ */
+ public void unbind( ServerListener a_listener ) throws IOException
+ {
+ m_manager.unbind( a_listener ) ;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.eve.event.DisconnectSubscriber#inform(
+ * org.apache.eve.event.DisconnectEvent)
+ */
+ public void inform( DisconnectEvent an_event )
+ {
+ m_manager.inform( an_event ) ;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.eve.event.Subscriber#inform(java.util.EventObject)
+ */
+ public void inform( EventObject an_event )
+ {
+ m_manager.inform( an_event ) ;
+ }
+
+
+ // ------------------------------------------------------------------------
+ // Life Cycle Methods
+ // ------------------------------------------------------------------------
+
+
+ /**
+ * Starts up this module.
+ *
+ * @see org.apache.avalon.framework.activity.Startable#start()
+ */
+ public void start() throws Exception
+ {
+ m_manager.start() ;
+ }
+
+
+ /**
+ * Blocks calling thread until this module gracefully stops.
+ *
+ * @see org.apache.avalon.framework.activity.Startable#stop()
+ */
+ public void stop() throws Exception
+ {
+ m_manager.stop() ;
+ }
+
+
+ /**
+ * @avalon.dependency type="org.apache.eve.EventRouter"
+ * key="event-router" version="1.0"
+ * @see org.apache.avalon.framework.service.Serviceable#service(
+ * org.apache.avalon.framework.service.ServiceManager)
+ */
+ public void service( ServiceManager a_manager )
+ throws ServiceException
+ {
+ m_router = ( EventRouter ) a_manager.lookup( "event-router" ) ;
+ }
+
+
+ /**
+ * @see org.apache.avalon.framework.activity.Initializable#initialize()
+ */
+ public void initialize() throws Exception
+ {
+ m_manager = new DefaultListenerManager( m_router ) ;
+ }
+}
Modified: incubator/directory/ldap/trunk/eve/frontend/listener/spi/src/java/org/apache/eve/listener/ListenerManager.java
==============================================================================
--- incubator/directory/ldap/trunk/eve/frontend/listener/spi/src/java/org/apache/eve/listener/ListenerManager.java (original)
+++ incubator/directory/ldap/trunk/eve/frontend/listener/spi/src/java/org/apache/eve/listener/ListenerManager.java Sat Dec 6 14:55:28 2003
@@ -65,18 +65,17 @@
public interface ListenerManager extends DisconnectSubscriber
{
/**
- * Registers a server listener.
+ * Binds and registers a server listener.
*
- * @param a_listener the listener to register
- * @throws IOException if there is a problem binding a listener
+ * @param a_listener the listener to register and bind
*/
- public void register( ServerListener a_listener ) throws IOException ;
+ public void bind( ServerListener a_listener ) throws IOException ;
/**
- * Unregisters a server listener.
+ * Unbinds and unregisters a server listener.
*
- * @param a_listener the listener to unregister
- * @throws IOException if there is a problem binding a listener
+ * @param a_listener the listener to unregister and unbind
+ * @throws IOException if there is a problem unbinding a listener
*/
- public void unregister( ServerListener a_listener ) throws IOException ;
+ public void unbind( ServerListener a_listener ) throws IOException ;
}
Added: incubator/directory/ldap/trunk/eve/frontend/listener/spi/src/java/org/apache/eve/listener/ListenerManagerMonitor.java
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/eve/frontend/listener/spi/src/java/org/apache/eve/listener/ListenerManagerMonitor.java Sat Dec 6 14:55:28 2003
@@ -0,0 +1,144 @@
+/*
+
+ ============================================================================
+ 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/>.
+
+*/
+package org.apache.eve.listener ;
+
+
+import java.io.IOException ;
+import java.nio.channels.Selector ;
+import java.nio.channels.SelectionKey ;
+
+
+/**
+ * Used to monitor the activities of a ListenerManager.
+ *
+ * @author <a href="mailto:aok123@bellsouth.net">Alex Karasulu</a>
+ * @author $Author$
+ * @version $Revision$
+ */
+public interface ListenerManagerMonitor
+{
+ /**
+ * Monitors when the ListnenerManager starts.
+ */
+ void started() ;
+
+ /**
+ * Monitors when the ListnenerManager stops.
+ */
+ void stopped() ;
+
+ /**
+ * Monitors bind occurences.
+ *
+ * @param a_listener the listener just bound to a port
+ */
+ void bindOccured( ServerListener a_listener ) ;
+
+ /**
+ * Monitors unbind occurences.
+ *
+ * @param a_listener the listener just unbound from a port
+ */
+ void unbindOccured( ServerListener a_listener ) ;
+
+ /**
+ * Monitors the occurrence of successful socket accept attempts
+ *
+ * @param a_key
+ */
+ void acceptOccured( SelectionKey a_key ) ;
+
+ /**
+ * Monitors the occurrence of successful select calls on a selector
+ *
+ * @param a_selector
+ */
+ void selectOccured( Selector a_selector ) ;
+
+ /**
+ * Monitors bind failures.
+ *
+ * @param a_listener the listener whose bind attempt failed
+ * @param a_failure the exception resulting from the failure
+ */
+ void failedToBind( ServerListener a_listener, IOException a_failure ) ;
+
+ /**
+ * Monitors unbind failures.
+ *
+ * @param a_listener the listener whose unbind attempt failed
+ * @param a_failure the exception resulting from the failure
+ */
+ void failedToUnbind( ServerListener a_listener, IOException a_failure ) ;
+
+ /**
+ * Monitors expiration failures on client keys.
+ *
+ * @param a_key the client key that caused the failure
+ * @param a_failure the exception resulting from the failure
+ */
+ void failedToExpire( ClientKey a_key, IOException a_failure ) ;
+
+ /**
+ * Monitors accept failures on socket channels.
+ *
+ * @param a_key the selector key associated with the channel
+ * @param a_failure the exception resulting from the failure
+ */
+ void failedToAccept( SelectionKey a_key, IOException a_failure ) ;
+
+ /**
+ * Monitors select failures on a selector.
+ *
+ * @param a_selector the selector on which the select failed
+ * @param a_failure the exception resulting from the failure
+ */
+ void failedToSelect( Selector a_selector, IOException a_failure ) ;
+}