directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r151560 - in incubator/directory/apacheds/branches/mina-port/protocol: ./ src/main/java/org/apache/ldap/server/protocol/ src/test/org/apache/ldap/server/protocol/
Date Sun, 06 Feb 2005 09:14:33 GMT
Author: trustin
Date: Sun Feb  6 01:14:30 2005
New Revision: 151560

URL: http://svn.apache.org/viewcvs?view=rev&rev=151560
Log:
Ported APSEDA ProtocolProvider to MINA ProtocolProvider.

Added:
    incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/CommandHandler.java   (with props)
Modified:
    incubator/directory/apacheds/branches/mina-port/protocol/project.xml
    incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/AbandonHandler.java
    incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/AddHandler.java
    incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/BindHandler.java
    incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/CompareHandler.java
    incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/DeleteHandler.java
    incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/ExtendedHandler.java
    incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/LdapProtocolProvider.java
    incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/ModifyDnHandler.java
    incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/ModifyHandler.java
    incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/SearchHandler.java
    incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/SessionRegistry.java
    incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/UnbindHandler.java
    incubator/directory/apacheds/branches/mina-port/protocol/src/test/org/apache/ldap/server/protocol/LdapProtocolProviderTest.java

Modified: incubator/directory/apacheds/branches/mina-port/protocol/project.xml
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/branches/mina-port/protocol/project.xml?view=diff&r1=151559&r2=151560
==============================================================================
--- incubator/directory/apacheds/branches/mina-port/protocol/project.xml (original)
+++ incubator/directory/apacheds/branches/mina-port/protocol/project.xml Sun Feb  6 01:14:30 2005
@@ -51,9 +51,9 @@
     </dependency>
     <dependency>
       <groupId>incubator-directory</groupId>
-      <artifactId>apseda</artifactId>
-      <version>0.3-SNAPSHOT</version>
-      <url>http://incubator.apache.org/directory/subprojects/seda</url>
+      <artifactId>mina</artifactId>
+      <version>0.7-SNAPSHOT</version>
+      <url>http://incubator.apache.org/directory/subprojects/mina</url>
     </dependency>
   </dependencies>
 

Modified: incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/AbandonHandler.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/AbandonHandler.java?view=diff&r1=151559&r2=151560
==============================================================================
--- incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/AbandonHandler.java (original)
+++ incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/AbandonHandler.java Sun Feb  6 01:14:30 2005
@@ -17,10 +17,9 @@
 package org.apache.ldap.server.protocol;
 
 
-import org.apache.apseda.listener.ClientKey;
-import org.apache.apseda.protocol.AbstractNoReplyHandler;
 import org.apache.ldap.common.NotImplementedException;
 import org.apache.ldap.common.message.AbandonRequest;
+import org.apache.mina.protocol.ProtocolSession;
 
 
 /**
@@ -29,9 +28,9 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class AbandonHandler extends AbstractNoReplyHandler
+public class AbandonHandler implements CommandHandler
 {
-    public void handle( ClientKey key, Object request )
+    public void handle( ProtocolSession session, Object request )
     {
         AbandonRequest req = ( AbandonRequest ) request;
         int abandonedId = req.getAbandoned();

Modified: incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/AddHandler.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/AddHandler.java?view=diff&r1=151559&r2=151560
==============================================================================
--- incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/AddHandler.java (original)
+++ incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/AddHandler.java Sun Feb  6 01:14:30 2005
@@ -16,13 +16,10 @@
  */
 package org.apache.ldap.server.protocol;
 
-
 import javax.naming.NamingException;
 import javax.naming.ldap.InitialLdapContext;
 import javax.naming.ldap.LdapContext;
 
-import org.apache.apseda.listener.ClientKey;
-import org.apache.apseda.protocol.AbstractSingleReplyHandler;
 import org.apache.ldap.common.exception.LdapException;
 import org.apache.ldap.common.message.AddRequest;
 import org.apache.ldap.common.message.AddResponse;
@@ -30,7 +27,7 @@
 import org.apache.ldap.common.message.LdapResultImpl;
 import org.apache.ldap.common.message.ResultCodeEnum;
 import org.apache.ldap.common.util.ExceptionUtils;
-
+import org.apache.mina.protocol.ProtocolSession;
 
 /**
  * A single reply handler for {@link org.apache.ldap.common.message.AddRequest}s.
@@ -38,9 +35,9 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class AddHandler extends AbstractSingleReplyHandler
+public class AddHandler implements CommandHandler
 {
-    public Object handle( ClientKey key, Object request )
+    public void handle( ProtocolSession session, Object request )
     {
         AddRequest req = ( AddRequest ) request;
         AddResponse resp = new AddResponseImpl( req.getMessageId() );
@@ -49,19 +46,19 @@
         try
         {
             InitialLdapContext ictx = SessionRegistry.getSingleton()
-                    .getInitialLdapContext( key, null, true );
+                    .getInitialLdapContext( session, null, true );
             LdapContext ctx = ( LdapContext ) ictx.lookup( "" );
             ctx.createSubcontext( req.getName(), req.getEntry() );
         }
-        catch ( NamingException e )
+        catch( NamingException e )
         {
             String msg = "failed to add entry " + req.getName() + ":\n";
             msg += ExceptionUtils.getStackTrace( e );
             ResultCodeEnum code;
 
-            if ( e instanceof LdapException )
+            if( e instanceof LdapException )
             {
-                code = ( ( LdapException ) e ).getResultCode() ;
+                code = ( ( LdapException ) e ).getResultCode();
             }
             else
             {
@@ -71,16 +68,18 @@
             resp.getLdapResult().setResultCode( code );
             resp.getLdapResult().setErrorMessage( msg );
 
-            if ( e.getResolvedName() != null )
+            if( e.getResolvedName() != null )
             {
-                resp.getLdapResult().setMatchedDn( e.getResolvedName().toString() );
+                resp.getLdapResult().setMatchedDn(
+                        e.getResolvedName().toString() );
             }
 
-            return resp;
+            session.write( resp );
+            return;
         }
 
         resp.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
         resp.getLdapResult().setMatchedDn( req.getName() );
-        return resp;
+        session.write( resp );
     }
 }

Modified: incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/BindHandler.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/BindHandler.java?view=diff&r1=151559&r2=151560
==============================================================================
--- incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/BindHandler.java (original)
+++ incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/BindHandler.java Sun Feb  6 01:14:30 2005
@@ -23,8 +23,6 @@
 import javax.naming.NamingException;
 import javax.naming.ldap.InitialLdapContext;
 
-import org.apache.apseda.listener.ClientKey;
-import org.apache.apseda.protocol.AbstractSingleReplyHandler;
 import org.apache.ldap.common.exception.LdapException;
 import org.apache.ldap.common.message.BindRequest;
 import org.apache.ldap.common.message.BindResponse;
@@ -34,6 +32,7 @@
 import org.apache.ldap.common.message.LdapResultImpl;
 import org.apache.ldap.common.message.ResultCodeEnum;
 import org.apache.ldap.common.util.ExceptionUtils;
+import org.apache.mina.protocol.ProtocolSession;
 
 
 /**
@@ -42,15 +41,12 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class BindHandler extends AbstractSingleReplyHandler
+public class BindHandler implements CommandHandler
 {
     private static final Control[] EMPTY = new Control[0];
 
 
-    /**
-     * @see org.apache.apseda.protocol.SingleReplyHandler#handle(ClientKey,Object)
-     */
-    public Object handle( ClientKey key, Object request )
+    public void handle( ProtocolSession session, Object request )
     {
         InitialLdapContext ictx;
         BindRequest req = ( BindRequest ) request;
@@ -64,7 +60,8 @@
         {
             result.setResultCode( ResultCodeEnum.AUTHMETHODNOTSUPPORTED );
             result.setErrorMessage( "Only simple binds currently supported" );
-            return resp;
+            session.write( resp );
+            return;
         }
 
         // clone the environment first then add the required security settings
@@ -96,12 +93,13 @@
             String msg = "Bind failure:\n" + ExceptionUtils.getStackTrace( e );
             msg += "\n\nBindRequest = \n" + req.toString();
             result.setErrorMessage( msg );
-            return resp;
+            session.write( resp );
+            return;
         }
 
-        SessionRegistry.getSingleton().setInitialLdapContext( key, ictx );
+        SessionRegistry.getSingleton().setInitialLdapContext( session, ictx );
         result.setResultCode( ResultCodeEnum.SUCCESS );
         result.setMatchedDn( req.getName() );
-        return resp;
+        session.write( resp );
     }
 }

Added: incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/CommandHandler.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/CommandHandler.java?view=auto&rev=151560
==============================================================================
--- incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/CommandHandler.java (added)
+++ incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/CommandHandler.java Sun Feb  6 01:14:30 2005
@@ -0,0 +1,17 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.ldap.server.protocol;
+
+import org.apache.mina.protocol.ProtocolSession;
+
+/**
+ * TODO Document me.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$, 
+ */
+public interface CommandHandler
+{
+    void handle( ProtocolSession session, Object request );
+}

Propchange: incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/CommandHandler.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/CompareHandler.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/CompareHandler.java?view=diff&r1=151559&r2=151560
==============================================================================
--- incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/CompareHandler.java (original)
+++ incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/CompareHandler.java Sun Feb  6 01:14:30 2005
@@ -22,8 +22,6 @@
 import javax.naming.directory.DirContext;
 import javax.naming.ldap.InitialLdapContext;
 
-import org.apache.apseda.listener.ClientKey;
-import org.apache.apseda.protocol.AbstractSingleReplyHandler;
 import org.apache.ldap.common.exception.LdapException;
 import org.apache.ldap.common.message.CompareRequest;
 import org.apache.ldap.common.message.CompareResponse;
@@ -31,6 +29,7 @@
 import org.apache.ldap.common.message.LdapResultImpl;
 import org.apache.ldap.common.message.ResultCodeEnum;
 import org.apache.ldap.common.util.ExceptionUtils;
+import org.apache.mina.protocol.ProtocolSession;
 
 
 /**
@@ -39,12 +38,9 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class CompareHandler extends AbstractSingleReplyHandler
+public class CompareHandler implements CommandHandler
 {
-    /**
-     * @see org.apache.apseda.protocol.SingleReplyHandler#handle(org.apache.apseda.listener.ClientKey,Object)
-     */
-    public Object handle( ClientKey key, Object request )
+    public void handle( ProtocolSession session, Object request )
     {
         CompareRequest req = ( CompareRequest ) request;
         CompareResponse resp = new CompareResponseImpl( req.getMessageId() );
@@ -53,7 +49,7 @@
         try
         {
             InitialLdapContext ictx = SessionRegistry.getSingleton()
-                    .getInitialLdapContext( key, null, true );
+                    .getInitialLdapContext( session, null, true );
             DirContext ctx = ( DirContext ) ictx.lookup( "" );
             Attribute attr = ctx.getAttributes( req.getName() ).get( req.getAttributeId() );
 
@@ -93,10 +89,11 @@
                 resp.getLdapResult().setMatchedDn( e.getResolvedName().toString() );
             }
 
-            return resp;
+            session.write( resp );
+            return;
         }
 
         resp.getLdapResult().setMatchedDn( req.getName() );
-        return resp;
+        session.write( resp );
     }
 }

Modified: incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/DeleteHandler.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/DeleteHandler.java?view=diff&r1=151559&r2=151560
==============================================================================
--- incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/DeleteHandler.java (original)
+++ incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/DeleteHandler.java Sun Feb  6 01:14:30 2005
@@ -16,13 +16,10 @@
  */
 package org.apache.ldap.server.protocol;
 
-
 import javax.naming.NamingException;
 import javax.naming.directory.DirContext;
 import javax.naming.ldap.InitialLdapContext;
 
-import org.apache.apseda.listener.ClientKey;
-import org.apache.apseda.protocol.AbstractSingleReplyHandler;
 import org.apache.ldap.common.exception.LdapException;
 import org.apache.ldap.common.message.DeleteRequest;
 import org.apache.ldap.common.message.DeleteResponse;
@@ -30,7 +27,7 @@
 import org.apache.ldap.common.message.LdapResultImpl;
 import org.apache.ldap.common.message.ResultCodeEnum;
 import org.apache.ldap.common.util.ExceptionUtils;
-
+import org.apache.mina.protocol.ProtocolSession;
 
 /**
  * A single reply handler for {@link org.apache.ldap.common.message.DeleteRequest}s.
@@ -38,12 +35,9 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class DeleteHandler extends AbstractSingleReplyHandler
+public class DeleteHandler implements CommandHandler
 {
-    /**
-     * @see org.apache.apseda.protocol.SingleReplyHandler#handle(ClientKey,Object)
-     */
-    public Object handle( ClientKey key, Object request )
+    public void handle( ProtocolSession session, Object request )
     {
         DeleteRequest req = ( DeleteRequest ) request;
         DeleteResponse resp = new DeleteResponseImpl( req.getMessageId() );
@@ -52,19 +46,19 @@
         try
         {
             InitialLdapContext ictx = SessionRegistry.getSingleton()
-                    .getInitialLdapContext( key, null, true );
+                    .getInitialLdapContext( session, null, true );
             DirContext ctx = ( DirContext ) ictx.lookup( "" );
             ctx.destroySubcontext( req.getName() );
         }
-        catch ( NamingException e )
+        catch( NamingException e )
         {
             String msg = "failed to add entry " + req.getName() + ":\n";
             msg += ExceptionUtils.getStackTrace( e );
             ResultCodeEnum code;
 
-            if ( e instanceof LdapException )
+            if( e instanceof LdapException )
             {
-                code = ( ( LdapException ) e ).getResultCode() ;
+                code = ( ( LdapException ) e ).getResultCode();
             }
             else
             {
@@ -74,16 +68,18 @@
             resp.getLdapResult().setResultCode( code );
             resp.getLdapResult().setErrorMessage( msg );
 
-            if ( e.getResolvedName() != null )
+            if( e.getResolvedName() != null )
             {
-                resp.getLdapResult().setMatchedDn( e.getResolvedName().toString() );
+                resp.getLdapResult().setMatchedDn(
+                        e.getResolvedName().toString() );
             }
 
-            return resp;
+            session.write( resp );
+            return;
         }
 
         resp.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
         resp.getLdapResult().setMatchedDn( req.getName() );
-        return resp;
+        session.write( resp );
     }
 }

Modified: incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/ExtendedHandler.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/ExtendedHandler.java?view=diff&r1=151559&r2=151560
==============================================================================
--- incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/ExtendedHandler.java (original)
+++ incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/ExtendedHandler.java Sun Feb  6 01:14:30 2005
@@ -17,9 +17,8 @@
 package org.apache.ldap.server.protocol;
 
 
-import org.apache.apseda.listener.ClientKey;
-import org.apache.apseda.protocol.AbstractSingleReplyHandler;
 import org.apache.ldap.common.NotImplementedException;
+import org.apache.mina.protocol.ProtocolSession;
 
 
 /**
@@ -28,12 +27,9 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class ExtendedHandler extends AbstractSingleReplyHandler
+public class ExtendedHandler implements CommandHandler
 {
-    /**
-     * @see org.apache.apseda.protocol.SingleReplyHandler#handle(ClientKey,Object)
-     */
-    public Object handle( ClientKey key, Object request )
+    public void handle( ProtocolSession session, Object request )
     {
         throw new NotImplementedException( "handle in org.apache.ldap.server.protocol.ExtendedHandler not implemented!" );
     }

Modified: incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/LdapProtocolProvider.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/LdapProtocolProvider.java?view=diff&r1=151559&r2=151560
==============================================================================
--- incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/LdapProtocolProvider.java (original)
+++ incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/LdapProtocolProvider.java Sun Feb  6 01:14:30 2005
@@ -16,7 +16,6 @@
  */
 package org.apache.ldap.server.protocol;
 
-
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Hashtable;
@@ -25,14 +24,6 @@
 
 import javax.naming.Context;
 
-import org.apache.apseda.event.EventRouter;
-import org.apache.apseda.listener.ClientKey;
-import org.apache.apseda.protocol.ProtocolProvider;
-import org.apache.apseda.protocol.RequestHandler;
-import org.apache.asn1.codec.stateful.DecoderFactory;
-import org.apache.asn1.codec.stateful.EncoderFactory;
-import org.apache.asn1.codec.stateful.StatefulDecoder;
-import org.apache.asn1.codec.stateful.StatefulEncoder;
 import org.apache.ldap.common.exception.LdapNamingException;
 import org.apache.ldap.common.message.AbandonRequest;
 import org.apache.ldap.common.message.AbandonRequestImpl;
@@ -58,7 +49,15 @@
 import org.apache.ldap.common.message.UnbindRequest;
 import org.apache.ldap.common.message.UnbindRequestImpl;
 import org.apache.ldap.common.message.spi.Provider;
-
+import org.apache.mina.protocol.ProtocolCodecFactory;
+import org.apache.mina.protocol.ProtocolDecoder;
+import org.apache.mina.protocol.ProtocolEncoder;
+import org.apache.mina.protocol.ProtocolHandler;
+import org.apache.mina.protocol.ProtocolHandlerAdapter;
+import org.apache.mina.protocol.ProtocolProvider;
+import org.apache.mina.protocol.ProtocolSession;
+import org.apache.mina.protocol.codec.Asn1CodecDecoder;
+import org.apache.mina.protocol.codec.Asn1CodecEncoder;
 
 /**
  * An LDAP protocol provider implementation which dynamically associates
@@ -71,6 +70,7 @@
 {
     /** the constant service name of this ldap protocol provider **/
     public static final String SERVICE_NAME = "ldap";
+
     /** a map of the default request object class name to the handler class name */
     public static final Map DEFAULT_HANDLERS;
 
@@ -121,52 +121,48 @@
         DEFAULT_HANDLERS = Collections.unmodifiableMap( map );
     }
 
-    /** a handle on the SEDA event router */
-    public final EventRouter router;
-    /** the underlying provider decoder factory */
-    public final DecoderFactory decoderFactory;
-    /** the underlying provider encoder factory */
-    public final EncoderFactory encoderFactory;
-    /** the handlers to use while processing requests */
-    public final Map handlers;
+    /** the underlying provider codec factory */
+    private final ProtocolCodecFactory codecFactory;
+
+    /** the MINA protocol handler */
+    private final LdapProtocolHandler handler = new LdapProtocolHandler();
 
+    /** the handlers to use while processing requests */
+    private final Map commandHandlers;
 
     // ------------------------------------------------------------------------
     // C O N S T R U C T O R S
     // ------------------------------------------------------------------------
 
-
     /**
      * Creates a SEDA LDAP protocol provider.
      *
      * @param env environment properties used to configure the provider and
      * underlying codec providers if any
      */
-    public LdapProtocolProvider( Hashtable env, EventRouter router )
-            throws LdapNamingException
+    public LdapProtocolProvider( Hashtable env ) throws LdapNamingException
     {
-        this.router = router;
         Hashtable copy = ( Hashtable ) env.clone();
-        this.handlers = new HashMap();
+        this.commandHandlers = new HashMap();
 
         copy.put( Context.PROVIDER_URL, "" );
         SessionRegistry.releaseSingleton();
-        new SessionRegistry( copy, router );
+        new SessionRegistry( copy );
 
         Iterator requestTypes = DEFAULT_HANDLERS.keySet().iterator();
-        while ( requestTypes.hasNext() )
+        while( requestTypes.hasNext() )
         {
-            RequestHandler handler = null;
+            CommandHandler handler = null;
             String type = ( String ) requestTypes.next();
             Class clazz = null;
 
-            if ( copy.containsKey( type ) )
+            if( copy.containsKey( type ) )
             {
                 try
                 {
                     clazz = Class.forName( ( String ) copy.get( type ) );
                 }
-                catch ( ClassNotFoundException e )
+                catch( ClassNotFoundException e )
                 {
                     LdapNamingException lne;
                     String msg = "failed to load class " + clazz;
@@ -183,9 +179,9 @@
 
             try
             {
-                handler = ( RequestHandler ) clazz.newInstance();
+                handler = ( CommandHandler ) clazz.newInstance();
             }
-            catch ( Exception e )
+            catch( Exception e )
             {
                 LdapNamingException lne;
                 String msg = "failed to create handler instance of " + clazz;
@@ -195,28 +191,25 @@
                 throw lne;
             }
 
-            this.handlers.put( type, handler );
+            this.commandHandlers.put( type, handler );
         }
 
-        this.decoderFactory = new DecoderFactoryImpl( copy );
-        this.encoderFactory = new EncoderFactoryImpl( copy );
+        this.codecFactory = new ProtocolCodecFactoryImpl( copy );
     }
 
-
     /**
      * Creates a SEDA LDAP protocol provider.
      */
-    public LdapProtocolProvider( EventRouter router ) throws LdapNamingException
+    public LdapProtocolProvider() throws LdapNamingException
     {
-        this.router = router;
-        this.handlers = new HashMap();
+        this.commandHandlers = new HashMap();
         SessionRegistry.releaseSingleton();
-        new SessionRegistry( null, router );
+        new SessionRegistry( null );
 
         Iterator requestTypes = DEFAULT_HANDLERS.keySet().iterator();
-        while ( requestTypes.hasNext() )
+        while( requestTypes.hasNext() )
         {
-            RequestHandler handler = null;
+            CommandHandler handler = null;
             String type = ( String ) requestTypes.next();
             Class clazz = null;
 
@@ -224,9 +217,9 @@
 
             try
             {
-                handler = ( RequestHandler ) clazz.newInstance();
+                handler = ( CommandHandler ) clazz.newInstance();
             }
-            catch ( Exception e )
+            catch( Exception e )
             {
                 LdapNamingException lne;
                 String msg = "failed to create handler instance of " + clazz;
@@ -236,63 +229,46 @@
                 throw lne;
             }
 
-            this.handlers.put( type, handler );
+            this.commandHandlers.put( type, handler );
         }
 
-        this.decoderFactory = new DecoderFactoryImpl();
-        this.encoderFactory = new EncoderFactoryImpl();
+        this.codecFactory = new ProtocolCodecFactoryImpl();
     }
 
-
     // ------------------------------------------------------------------------
     // ProtocolProvider Methods
     // ------------------------------------------------------------------------
 
-
-    /**
-     * @see ProtocolProvider#getName()
-     * @return ldap every time
-     */
     public String getName()
     {
         return SERVICE_NAME;
     }
 
-
-    /**
-     * @see ProtocolProvider#getDecoderFactory()
-     */
-    public DecoderFactory getDecoderFactory()
+    public ProtocolCodecFactory getCodecFactory()
     {
-        return this.decoderFactory;
+        return codecFactory;
     }
 
-
-    /**
-     * @see ProtocolProvider#getEncoderFactory()
-     */
-    public EncoderFactory getEncoderFactory()
+    public ProtocolHandler getHandler()
     {
-        return this.encoderFactory;
+        return handler;
     }
 
-
-    /**
-     * @see ProtocolProvider#getHandler(ClientKey, Object)
-     */
-    public RequestHandler getHandler( ClientKey key, Object request )
+    public CommandHandler getCommandHandler( Object request )
     {
-        if ( this.handlers.containsKey( request.getClass().getName() ) )
+        if( this.commandHandlers.containsKey( request.getClass().getName() ) )
         {
-            return ( RequestHandler ) this.handlers.get( request.getClass().getName() );
+            return ( CommandHandler ) this.commandHandlers.get( request
+                    .getClass().getName() );
         }
 
         Class[] interfaces = request.getClass().getInterfaces();
-        for ( int ii = 0; ii < interfaces.length; ii++ )
+        for( int ii = 0; ii < interfaces.length; ii ++ )
         {
-            if ( this.handlers.containsKey( interfaces[ii].getName() ) )
+            if( this.commandHandlers.containsKey( interfaces[ ii ].getName() ) )
             {
-                return ( RequestHandler ) this.handlers.get( interfaces[ii].getName() );
+                return ( CommandHandler ) this.commandHandlers
+                        .get( interfaces[ ii ].getName() );
             }
         }
 
@@ -300,71 +276,66 @@
         throw new IllegalArgumentException( msg );
     }
 
-
     /**
      * A snickers based BER Decoder factory.
      */
-    private static final class DecoderFactoryImpl implements DecoderFactory
+    private static final class ProtocolCodecFactoryImpl implements
+            ProtocolCodecFactory
     {
         final Hashtable env;
 
-
-        public DecoderFactoryImpl()
+        public ProtocolCodecFactoryImpl()
         {
             this.env = null;
         }
 
-
-        DecoderFactoryImpl( Hashtable env )
+        ProtocolCodecFactoryImpl( Hashtable env )
         {
             this.env = env;
         }
 
+        public ProtocolEncoder newEncoder()
+        {
+            if( env == null || env.get( Provider.BERLIB_PROVIDER ) == null )
+            {
+                return new Asn1CodecEncoder( new MessageEncoder() );
+            }
+            else
+            {
+                return new Asn1CodecEncoder( new MessageEncoder( env ) );
+            }
+        }
 
-        public StatefulDecoder createDecoder()
+        public ProtocolDecoder newDecoder()
         {
-            if ( env == null || env.get( Provider.BERLIB_PROVIDER ) == null )
+            if( env == null || env.get( Provider.BERLIB_PROVIDER ) == null )
             {
-                return new MessageDecoder();
+                return new Asn1CodecDecoder( new MessageDecoder() );
             }
             else
             {
-                return new MessageDecoder( env );
+                return new Asn1CodecDecoder( new MessageDecoder( env ) );
             }
         }
     }
 
-
-    /**
-     * A snickers based BER Encoder factory.
-     */
-    private static final class EncoderFactoryImpl implements EncoderFactory
+    private class LdapProtocolHandler extends ProtocolHandlerAdapter
     {
-        final Hashtable env;
-
 
-        public EncoderFactoryImpl()
+        public void messageReceived( ProtocolSession session, Object request )
         {
-            this.env = null;
+            CommandHandler handler = getCommandHandler( request );
+            handler.handle( session, request );
         }
 
-
-        public EncoderFactoryImpl( Hashtable env )
+        public void sessionClosed( ProtocolSession session )
         {
-            this.env = env;
+            SessionRegistry.getSingleton().remove( session );
         }
 
-
-        public StatefulEncoder createEncoder()
+        public void exceptionCaught( ProtocolSession session, Throwable cause )
         {
-            if ( env == null || env.get( Provider.BERLIB_PROVIDER ) == null )
-            {
-                return new MessageEncoder();
-            }
-            else
-            {
-                return new MessageEncoder( env );
-            }
+            cause.printStackTrace();
         }
     }
 }

Modified: incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/ModifyDnHandler.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/ModifyDnHandler.java?view=diff&r1=151559&r2=151560
==============================================================================
--- incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/ModifyDnHandler.java (original)
+++ incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/ModifyDnHandler.java Sun Feb  6 01:14:30 2005
@@ -21,8 +21,6 @@
 import javax.naming.directory.DirContext;
 import javax.naming.ldap.InitialLdapContext;
 
-import org.apache.apseda.listener.ClientKey;
-import org.apache.apseda.protocol.AbstractSingleReplyHandler;
 import org.apache.ldap.common.exception.LdapException;
 import org.apache.ldap.common.message.LdapResultImpl;
 import org.apache.ldap.common.message.ModifyDnRequest;
@@ -31,6 +29,7 @@
 import org.apache.ldap.common.message.ResultCodeEnum;
 import org.apache.ldap.common.name.LdapName;
 import org.apache.ldap.common.util.ExceptionUtils;
+import org.apache.mina.protocol.ProtocolSession;
 
 
 /**
@@ -39,12 +38,9 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class ModifyDnHandler extends AbstractSingleReplyHandler
+public class ModifyDnHandler implements CommandHandler
 {
-    /**
-     * @see org.apache.apseda.protocol.SingleReplyHandler#handle(ClientKey,Object)
-     */
-    public Object handle( ClientKey key, Object request )
+    public void handle( ProtocolSession session, Object request )
     {
         ModifyDnRequest req = ( ModifyDnRequest ) request;
         ModifyDnResponse resp = new ModifyDnResponseImpl( req.getMessageId() );
@@ -53,7 +49,7 @@
         try
         {
             InitialLdapContext ictx = SessionRegistry.getSingleton()
-                    .getInitialLdapContext( key, null, true );
+                    .getInitialLdapContext( session, null, true );
             DirContext ctx = ( DirContext ) ictx.lookup( "" );
             String deleteRDN = String.valueOf( req.getDeleteOldRdn() );
             ctx.addToEnvironment( "java.naming.ldap.deleteRDN", deleteRDN );
@@ -105,11 +101,12 @@
                 resp.getLdapResult().setMatchedDn( e.getResolvedName().toString() );
             }
 
-            return resp;
+            session.write( resp );
+            return;
         }
 
         resp.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
         resp.getLdapResult().setMatchedDn( req.getName() );
-        return resp;
+        session.write( resp );
     }
 }

Modified: incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/ModifyHandler.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/ModifyHandler.java?view=diff&r1=151559&r2=151560
==============================================================================
--- incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/ModifyHandler.java (original)
+++ incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/ModifyHandler.java Sun Feb  6 01:14:30 2005
@@ -22,8 +22,6 @@
 import javax.naming.directory.ModificationItem;
 import javax.naming.ldap.InitialLdapContext;
 
-import org.apache.apseda.listener.ClientKey;
-import org.apache.apseda.protocol.AbstractSingleReplyHandler;
 import org.apache.ldap.common.exception.LdapException;
 import org.apache.ldap.common.message.LdapResultImpl;
 import org.apache.ldap.common.message.ModifyRequest;
@@ -31,6 +29,7 @@
 import org.apache.ldap.common.message.ModifyResponseImpl;
 import org.apache.ldap.common.message.ResultCodeEnum;
 import org.apache.ldap.common.util.ExceptionUtils;
+import org.apache.mina.protocol.ProtocolSession;
 
 
 /**
@@ -39,13 +38,11 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class ModifyHandler extends AbstractSingleReplyHandler
+public class ModifyHandler implements CommandHandler
 {
     private static final ModificationItem[] EMPTY = new ModificationItem[0];
-    /**
-     * @see org.apache.apseda.protocol.SingleReplyHandler#handle(ClientKey,Object)
-     */
-    public Object handle( ClientKey key, Object request )
+
+    public void handle( ProtocolSession session, Object request )
     {
         ModifyRequest req = ( ModifyRequest ) request;
         ModifyResponse resp = new ModifyResponseImpl( req.getMessageId() );
@@ -54,7 +51,7 @@
         try
         {
             InitialLdapContext ictx = SessionRegistry.getSingleton()
-                    .getInitialLdapContext( key, null, true );
+                    .getInitialLdapContext( session, null, true );
             DirContext ctx = ( DirContext ) ictx.lookup( "" );
             Object[] mods = req.getModificationItems().toArray( EMPTY );
             ctx.modifyAttributes( req.getName(), ( ModificationItem[] ) mods );
@@ -82,11 +79,13 @@
                 resp.getLdapResult().setMatchedDn( e.getResolvedName().toString() );
             }
 
-            return resp;
+            session.write( resp );
+            return;
         }
 
         resp.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
         resp.getLdapResult().setMatchedDn( req.getName() );
-        return resp;
+        session.write( resp );
+        return;
     }
 }

Modified: incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/SearchHandler.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/SearchHandler.java?view=diff&r1=151559&r2=151560
==============================================================================
--- incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/SearchHandler.java (original)
+++ incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/SearchHandler.java Sun Feb  6 01:14:30 2005
@@ -16,7 +16,6 @@
  */
 package org.apache.ldap.server.protocol;
 
-
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
@@ -31,8 +30,6 @@
 import javax.naming.ldap.InitialLdapContext;
 import javax.naming.ldap.LdapContext;
 
-import org.apache.apseda.listener.ClientKey;
-import org.apache.apseda.protocol.AbstractManyReplyHandler;
 import org.apache.ldap.common.exception.LdapException;
 import org.apache.ldap.common.message.LdapResultImpl;
 import org.apache.ldap.common.message.ReferralImpl;
@@ -46,7 +43,7 @@
 import org.apache.ldap.common.message.SearchResponseReferenceImpl;
 import org.apache.ldap.common.util.ArrayUtils;
 import org.apache.ldap.common.util.ExceptionUtils;
-
+import org.apache.mina.protocol.ProtocolSession;
 
 /**
  * A handler for processing search requests.
@@ -54,18 +51,11 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class SearchHandler extends AbstractManyReplyHandler
+public class SearchHandler implements CommandHandler
 {
     private static final String DEREFALIASES_KEY = "java.naming.ldap.derefAliases";
 
-
-    public SearchHandler()
-    {
-        super( true );
-    }
-
-
-    public Iterator handle( ClientKey key, Object request )
+    public void handle( ProtocolSession session, Object request )
     {
         LdapContext ctx;
         SearchRequest req = ( SearchRequest ) request;
@@ -75,14 +65,16 @@
         String[] ids = null;
         Collection retAttrs = new HashSet();
         retAttrs.addAll( req.getAttributes() );
-        if ( retAttrs.size() > 0 && ! retAttrs.contains( "ref" ) )
+        if( retAttrs.size() > 0 && !retAttrs.contains( "ref" ) )
         {
             retAttrs.add( "ref" );
-            ids = ( String [] ) retAttrs.toArray( ArrayUtils.EMPTY_STRING_ARRAY );
+            ids = ( String[] ) retAttrs
+                    .toArray( ArrayUtils.EMPTY_STRING_ARRAY );
         }
-        else if ( retAttrs.size() > 0 )
+        else if( retAttrs.size() > 0 )
         {
-            ids = ( String [] ) retAttrs.toArray( ArrayUtils.EMPTY_STRING_ARRAY );
+            ids = ( String[] ) retAttrs
+                    .toArray( ArrayUtils.EMPTY_STRING_ARRAY );
         }
 
         // prepare all the search controls
@@ -97,9 +89,10 @@
         try
         {
             InitialLdapContext ictx = SessionRegistry.getSingleton()
-                    .getInitialLdapContext( key, null, true );
+                    .getInitialLdapContext( session, null, true );
             ctx = ( LdapContext ) ictx.lookup( "" );
-            ctx.addToEnvironment( DEREFALIASES_KEY, req.getDerefAliases().getName() );
+            ctx.addToEnvironment( DEREFALIASES_KEY, req.getDerefAliases()
+                    .getName() );
 
             /*
              * Eve JNDI Provider Specific Hack!
@@ -121,30 +114,42 @@
             list = ctx.search( req.getBase(), null, controls );
             ctx.removeFromEnvironment( "__filter__" );
 
-            if ( list.hasMore() )
+            if( list.hasMore() )
             {
-                return new SearchResponseIterator( req, list );
+                Iterator it = new SearchResponseIterator( req, list );
+                while( it.hasNext() )
+                {
+                    session.write( it.next() );
+                }
+                return;
             }
             else
             {
                 list.close();
-                SearchResponseDone resp = new SearchResponseDoneImpl( req.getMessageId() );
+                SearchResponseDone resp = new SearchResponseDoneImpl( req
+                        .getMessageId() );
                 resp.setLdapResult( new LdapResultImpl( resp ) );
                 resp.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
                 resp.getLdapResult().setMatchedDn( req.getBase() );
-                return Collections.singleton( resp ).iterator();
+                Iterator it = Collections.singleton( resp ).iterator();
+                while( it.hasNext() )
+                {
+                    session.write( it.next() );
+                }
+                return;
             }
         }
-        catch ( NamingException e )
+        catch( NamingException e )
         {
             String msg = "failed on search operation:\n" + req + "\n";
             msg += ExceptionUtils.getStackTrace( e );
-            SearchResponseDone resp = new SearchResponseDoneImpl( req.getMessageId() );
+            SearchResponseDone resp = new SearchResponseDoneImpl( req
+                    .getMessageId() );
             ResultCodeEnum rc = null;
 
-            if ( e instanceof LdapException )
+            if( e instanceof LdapException )
             {
-                rc = ( ( LdapException ) e ).getResultCode() ;
+                rc = ( ( LdapException ) e ).getResultCode();
             }
             else
             {
@@ -154,30 +159,35 @@
             resp.setLdapResult( new LdapResultImpl( resp ) );
             resp.getLdapResult().setResultCode( rc );
             resp.getLdapResult().setErrorMessage( msg );
-            if ( e.getResolvedName() != null )
+            if( e.getResolvedName() != null )
             {
-                resp.getLdapResult().setMatchedDn( e.getResolvedName().toString() );
+                resp.getLdapResult().setMatchedDn(
+                        e.getResolvedName().toString() );
             }
             else
             {
                 resp.getLdapResult().setMatchedDn( "" );
             }
 
-            return Collections.singleton( resp ).iterator();
+            Iterator it = Collections.singleton( resp ).iterator();
+            while( it.hasNext() )
+            {
+                session.write( it.next() );
+            }
         }
     }
 
-
     SearchResponseDone getResponse( SearchRequest req, NamingException e )
     {
         String msg = "failed on search operation:\n" + req + "\n";
         msg += ExceptionUtils.getStackTrace( e );
-        SearchResponseDone resp = new SearchResponseDoneImpl( req.getMessageId() );
+        SearchResponseDone resp = new SearchResponseDoneImpl( req
+                .getMessageId() );
         ResultCodeEnum rc = null;
 
-        if ( e instanceof LdapException )
+        if( e instanceof LdapException )
         {
-            rc = ( ( LdapException ) e ).getResultCode() ;
+            rc = ( ( LdapException ) e ).getResultCode();
         }
         else
         {
@@ -187,9 +197,10 @@
         resp.setLdapResult( new LdapResultImpl( resp ) );
         resp.getLdapResult().setResultCode( rc );
         resp.getLdapResult().setErrorMessage( msg );
-        if ( e.getResolvedName() != null )
+        if( e.getResolvedName() != null )
         {
-            resp.getLdapResult().setMatchedDn( e.getResolvedName().toString() );
+            resp.getLdapResult()
+                    .setMatchedDn( e.getResolvedName().toString() );
         }
         else
         {
@@ -199,15 +210,17 @@
         return resp;
     }
 
-
     class SearchResponseIterator implements Iterator
     {
         private final SearchRequest req;
+
         private final NamingEnumeration underlying;
+
         private SearchResponseDone respDone;
+
         private boolean done = false;
-        private Object prefetched;
 
+        private Object prefetched;
 
         /**
          * Creates a search response iterator for the resulting enumeration
@@ -216,14 +229,15 @@
          * @param req the search request to generate responses to
          * @param underlying the underlying JNDI enumeration containing SearchResults
          */
-        public SearchResponseIterator( SearchRequest req, NamingEnumeration underlying )
+        public SearchResponseIterator( SearchRequest req,
+                                      NamingEnumeration underlying )
         {
             this.req = req;
             this.underlying = underlying;
 
             try
             {
-                if ( underlying.hasMore() )
+                if( underlying.hasMore() )
                 {
                     SearchResult result = ( SearchResult ) underlying.next();
 
@@ -232,10 +246,11 @@
                      * local variable for the following call to next()
                      */
                     Attribute ref = result.getAttributes().get( "ref" );
-                    if ( ref == null || ref.size() > 0 )
+                    if( ref == null || ref.size() > 0 )
                     {
                         SearchResponseEntry respEntry;
-                        respEntry = new SearchResponseEntryImpl( req.getMessageId() );
+                        respEntry = new SearchResponseEntryImpl( req
+                                .getMessageId() );
                         respEntry.setAttributes( result.getAttributes() );
                         respEntry.setObjectName( result.getName() );
                         prefetched = respEntry;
@@ -243,9 +258,10 @@
                     else
                     {
                         SearchResponseReference respRef;
-                        respRef = new SearchResponseReferenceImpl( req.getMessageId() );
+                        respRef = new SearchResponseReferenceImpl( req
+                                .getMessageId() );
                         respRef.setReferral( new ReferralImpl( respRef ) );
-                        for ( int ii = 0; ii < ref.size(); ii++ )
+                        for( int ii = 0; ii < ref.size(); ii ++ )
                         {
                             String url;
 
@@ -254,9 +270,15 @@
                                 url = ( String ) ref.get( ii );
                                 respRef.getReferral().addLdapUrl( url );
                             }
-                            catch ( NamingException e )
+                            catch( NamingException e )
                             {
-                                try { underlying.close(); } catch( Throwable t ) {}
+                                try
+                                {
+                                    underlying.close();
+                                }
+                                catch( Throwable t )
+                                {
+                                }
                                 prefetched = null;
                                 respDone = getResponse( req, e );
                             }
@@ -265,33 +287,37 @@
                     }
                 }
             }
-            catch ( NamingException e )
+            catch( NamingException e )
             {
-                try { this.underlying.close(); } catch( Exception e2 ) {}
+                try
+                {
+                    this.underlying.close();
+                }
+                catch( Exception e2 )
+                {
+                }
                 respDone = getResponse( req, e );
             }
         }
 
-
         public boolean hasNext()
         {
             return !done;
         }
 
-
         public Object next()
         {
             Object next = prefetched;
             SearchResult result = null;
 
             // if we're done we got nothing to give back
-            if ( done )
+            if( done )
             {
                 throw new NoSuchElementException();
             }
 
             // if respDone has been assembled this is our last object to return
-            if ( respDone != null )
+            if( respDone != null )
             {
                 done = true;
                 return respDone;
@@ -307,24 +333,37 @@
                  * If we have more results from the underlying cursorr then
                  * we just set the result and build the response object below.
                  */
-                if ( underlying.hasMore() )
+                if( underlying.hasMore() )
                 {
                     result = ( SearchResult ) underlying.next();
                 }
                 else
                 {
-                    try { underlying.close(); } catch( Throwable t ) {}
+                    try
+                    {
+                        underlying.close();
+                    }
+                    catch( Throwable t )
+                    {
+                    }
                     respDone = new SearchResponseDoneImpl( req.getMessageId() );
                     respDone.setLdapResult( new LdapResultImpl( respDone ) );
-                    respDone.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
+                    respDone.getLdapResult().setResultCode(
+                            ResultCodeEnum.SUCCESS );
                     respDone.getLdapResult().setMatchedDn( req.getBase() );
                     prefetched = null;
                     return next;
                 }
             }
-            catch ( NamingException e )
+            catch( NamingException e )
             {
-                try { underlying.close(); } catch( Throwable t ) {}
+                try
+                {
+                    underlying.close();
+                }
+                catch( Throwable t )
+                {
+                }
                 prefetched = null;
                 respDone = getResponse( req, e );
                 return next;
@@ -335,18 +374,20 @@
              * local variable for the following call to next()
              */
             Attribute ref = result.getAttributes().get( "ref" );
-            if ( ref == null || ref.size() > 0 )
+            if( ref == null || ref.size() > 0 )
             {
-                SearchResponseEntry respEntry = new SearchResponseEntryImpl( req.getMessageId() );
+                SearchResponseEntry respEntry = new SearchResponseEntryImpl(
+                        req.getMessageId() );
                 respEntry.setAttributes( result.getAttributes() );
                 respEntry.setObjectName( result.getName() );
                 prefetched = respEntry;
             }
             else
             {
-                SearchResponseReference respRef = new SearchResponseReferenceImpl( req.getMessageId() );
+                SearchResponseReference respRef = new SearchResponseReferenceImpl(
+                        req.getMessageId() );
                 respRef.setReferral( new ReferralImpl( respRef ) );
-                for ( int ii = 0; ii < ref.size(); ii++ )
+                for( int ii = 0; ii < ref.size(); ii ++ )
                 {
                     String url;
 
@@ -355,9 +396,15 @@
                         url = ( String ) ref.get( ii );
                         respRef.getReferral().addLdapUrl( url );
                     }
-                    catch ( NamingException e )
+                    catch( NamingException e )
                     {
-                        try { underlying.close(); } catch( Throwable t ) {}
+                        try
+                        {
+                            underlying.close();
+                        }
+                        catch( Throwable t )
+                        {
+                        }
                         prefetched = null;
                         respDone = getResponse( req, e );
                         return next;
@@ -368,7 +415,6 @@
 
             return next;
         }
-
 
         /**
          * Unsupported so it throws an exception.

Modified: incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/SessionRegistry.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/SessionRegistry.java?view=diff&r1=151559&r2=151560
==============================================================================
--- incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/SessionRegistry.java (original)
+++ incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/SessionRegistry.java Sun Feb  6 01:14:30 2005
@@ -20,8 +20,6 @@
 import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Map;
-import java.util.Observable;
-import java.util.Observer;
 
 import javax.naming.Context;
 import javax.naming.NamingException;
@@ -29,10 +27,8 @@
 import javax.naming.ldap.Control;
 import javax.naming.ldap.InitialLdapContext;
 
-import org.apache.apseda.event.DisconnectEvent;
-import org.apache.apseda.event.EventRouter;
-import org.apache.apseda.listener.ClientKey;
 import org.apache.ldap.common.exception.LdapNoPermissionException;
+import org.apache.mina.protocol.ProtocolSession;
 
 
 /**
@@ -44,12 +40,8 @@
 public class SessionRegistry
 {
     private static SessionRegistry s_singleton;
-    /** a handle on the event router */
-    private final EventRouter router;
     /** the set of client contexts */
     private final Map contexts = new HashMap();
-    /** the observer to listen for key expiration */
-    private final Observer keyObserver = new KeyExpirationObserver();
     /** the properties associated with this SessionRegistry */
     private Hashtable env;
 
@@ -77,10 +69,8 @@
      *
      * @param env the properties associated with this SessionRegistry
      */
-    SessionRegistry( Hashtable env, EventRouter router )
+    SessionRegistry( Hashtable env )
     {
-        this.router = router;
-
         if ( s_singleton == null )
         {
             s_singleton = this;
@@ -121,24 +111,22 @@
      * client.  If the context is not present then there was no bind operation
      * that set it.  Hence this operation requesting the IC is anonymous.
      *
-     * @param key the client's key
+     * @param session the client's key
      * @param connCtls connection controls if any to use if creating anon context
      * @param allowAnonymous true if anonymous requests will create anonymous
      * InitialContext if one is not present for the operation
      * @return the InitialContext or null
      */
-    public InitialLdapContext getInitialLdapContext( ClientKey key,
+    public InitialLdapContext getInitialLdapContext( ProtocolSession session,
                                                      Control[] connCtls,
                                                      boolean allowAnonymous )
             throws NamingException
     {
         InitialLdapContext ictx = null;
 
-        key.addObserver( keyObserver );
-
         synchronized( contexts )
         {
-            ictx = ( InitialLdapContext ) contexts.get( key );
+            ictx = ( InitialLdapContext ) contexts.get( session );
         }
 
         if ( ictx == null && allowAnonymous )
@@ -159,16 +147,14 @@
     /**
      * Sets the initial context associated with a newly authenticated client.
      *
-     * @param key the client's key
+     * @param session the client session
      * @param ictx the initial context gotten
      */
-    public void setInitialLdapContext( ClientKey key, InitialDirContext ictx )
+    public void setInitialLdapContext( ProtocolSession session, InitialDirContext ictx )
     {
-        key.deleteObserver( keyObserver );  // remove first just in case
-        key.addObserver( keyObserver );
         synchronized( contexts )
         {
-            contexts.put( key, ictx );
+            contexts.put( session, ictx );
         }
     }
 
@@ -176,39 +162,13 @@
     /**
      * Removes the state mapping a JNDI initial context for the client's key.
      *
-     * @param key the client's key
+     * @param session the client's key
      */
-    public void remove( ClientKey key )
+    public void remove( ProtocolSession session )
     {
-        key.deleteObserver( keyObserver );
         synchronized( contexts )
         {
-            contexts.remove( key );
-        }
-    }
-
-
-    /**
-     * A key expiration observer.
-     */
-    class KeyExpirationObserver implements Observer
-    {
-        /**
-         * This is called whenever the client's key expires. We react by removing
-         * the entry if any of the client's in our InitialContext registry.
-         *
-         * @param o the ClientKey that has expired
-         * @param arg will be null
-         */
-        public void update( Observable o, Object arg )
-        {
-            // cast just to make sure
-            ClientKey key = ( ClientKey ) o;
-            key.deleteObserver( keyObserver );
-            synchronized( contexts )
-            {
-                contexts.remove( key );
-            }
+            contexts.remove( session );
         }
     }
 
@@ -216,11 +176,10 @@
     /**
      * Terminates the session by publishing a disconnect event.
      *
-     * @param key the client key of the client to disconnect
+     * @param session the client key of the client to disconnect
      */
-    public void terminateSession( ClientKey key )
+    public void terminateSession( ProtocolSession session )
     {
-        DisconnectEvent event = new DisconnectEvent( this, key );
-        router.publish( event );
+        session.close();
     }
 }

Modified: incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/UnbindHandler.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/UnbindHandler.java?view=diff&r1=151559&r2=151560
==============================================================================
--- incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/UnbindHandler.java (original)
+++ incubator/directory/apacheds/branches/mina-port/protocol/src/main/java/org/apache/ldap/server/protocol/UnbindHandler.java Sun Feb  6 01:14:30 2005
@@ -20,8 +20,7 @@
 import javax.naming.NamingException;
 import javax.naming.ldap.InitialLdapContext;
 
-import org.apache.apseda.listener.ClientKey;
-import org.apache.apseda.protocol.AbstractNoReplyHandler;
+import org.apache.mina.protocol.ProtocolSession;
 
 
 /**
@@ -31,22 +30,22 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class UnbindHandler extends AbstractNoReplyHandler
+public class UnbindHandler implements CommandHandler
 {
-    public void handle( ClientKey key, Object request )
+    public void handle( ProtocolSession session, Object request )
     {
         SessionRegistry registry = SessionRegistry.getSingleton();
 
         try
         {
             InitialLdapContext ictx = SessionRegistry.getSingleton()
-                    .getInitialLdapContext( key, null, false );
+                    .getInitialLdapContext( session, null, false );
             if ( ictx != null )
             {
                 ictx.close();
             }
-            registry.terminateSession( key );
-            registry.remove( key );
+            registry.terminateSession( session );
+            registry.remove( session );
         }
         catch ( NamingException e )
         {

Modified: incubator/directory/apacheds/branches/mina-port/protocol/src/test/org/apache/ldap/server/protocol/LdapProtocolProviderTest.java
URL: http://svn.apache.org/viewcvs/incubator/directory/apacheds/branches/mina-port/protocol/src/test/org/apache/ldap/server/protocol/LdapProtocolProviderTest.java?view=diff&r1=151559&r2=151560
==============================================================================
--- incubator/directory/apacheds/branches/mina-port/protocol/src/test/org/apache/ldap/server/protocol/LdapProtocolProviderTest.java (original)
+++ incubator/directory/apacheds/branches/mina-port/protocol/src/test/org/apache/ldap/server/protocol/LdapProtocolProviderTest.java Sun Feb  6 01:14:30 2005
@@ -18,17 +18,32 @@
 
 
 import java.util.Properties;
-import java.util.Iterator;
 
 import junit.framework.TestCase;
 
-import org.apache.ldap.common.exception.LdapNamingException;
-import org.apache.ldap.common.message.*;
 import org.apache.ldap.common.NotImplementedException;
-import org.apache.ldap.server.protocol.*;
-import org.apache.apseda.listener.ClientKey;
-import org.apache.apseda.listener.ClientKey;
-import org.apache.apseda.protocol.*;
+import org.apache.ldap.common.exception.LdapNamingException;
+import org.apache.ldap.common.message.AbandonRequest;
+import org.apache.ldap.common.message.AbandonRequestImpl;
+import org.apache.ldap.common.message.AddRequest;
+import org.apache.ldap.common.message.AddRequestImpl;
+import org.apache.ldap.common.message.BindRequest;
+import org.apache.ldap.common.message.BindRequestImpl;
+import org.apache.ldap.common.message.CompareRequest;
+import org.apache.ldap.common.message.CompareRequestImpl;
+import org.apache.ldap.common.message.DeleteRequest;
+import org.apache.ldap.common.message.DeleteRequestImpl;
+import org.apache.ldap.common.message.ExtendedRequest;
+import org.apache.ldap.common.message.ExtendedRequestImpl;
+import org.apache.ldap.common.message.ModifyDnRequest;
+import org.apache.ldap.common.message.ModifyDnRequestImpl;
+import org.apache.ldap.common.message.ModifyRequest;
+import org.apache.ldap.common.message.ModifyRequestImpl;
+import org.apache.ldap.common.message.SearchRequest;
+import org.apache.ldap.common.message.SearchRequestImpl;
+import org.apache.ldap.common.message.UnbindRequest;
+import org.apache.ldap.common.message.UnbindRequestImpl;
+import org.apache.mina.protocol.ProtocolSession;
 
 
 /**
@@ -50,42 +65,41 @@
      */
     public void testDefaultOperation() throws LdapNamingException
     {
-        LdapProtocolProvider provider = new LdapProtocolProvider( null );
-        assertNotNull( provider.getDecoderFactory() );
-        assertNotNull( provider.getEncoderFactory() );
+        LdapProtocolProvider provider = new LdapProtocolProvider();
+        assertNotNull( provider.getCodecFactory() );
         assertTrue( provider.getName() == LdapProtocolProvider.SERVICE_NAME );
 
         Object req = null;
 
         req = new AbandonRequestImpl( 0 );
-        assertTrue( provider.getHandler( null, req ) instanceof AbandonHandler );
+        assertTrue( provider.getCommandHandler( req ) instanceof AbandonHandler );
 
         req = new AddRequestImpl( 0 );
-        assertTrue( provider.getHandler( null, req ) instanceof AddHandler );
+        assertTrue( provider.getCommandHandler( req ) instanceof AddHandler );
 
         req = new BindRequestImpl( 0 );
-        assertTrue( provider.getHandler( null, req ) instanceof BindHandler );
+        assertTrue( provider.getCommandHandler( req ) instanceof BindHandler );
 
         req = new CompareRequestImpl( 0 );
-        assertTrue( provider.getHandler( null, req ) instanceof CompareHandler );
+        assertTrue( provider.getCommandHandler( req ) instanceof CompareHandler );
 
         req = new DeleteRequestImpl( 0 );
-        assertTrue( provider.getHandler( null, req ) instanceof DeleteHandler );
+        assertTrue( provider.getCommandHandler( req ) instanceof DeleteHandler );
 
         req = new ExtendedRequestImpl( 0 );
-        assertTrue( provider.getHandler( null, req ) instanceof ExtendedHandler );
+        assertTrue( provider.getCommandHandler( req ) instanceof ExtendedHandler );
 
         req = new ModifyDnRequestImpl( 0 );
-        assertTrue( provider.getHandler( null, req ) instanceof ModifyDnHandler );
+        assertTrue( provider.getCommandHandler( req ) instanceof ModifyDnHandler );
 
         req = new ModifyRequestImpl( 0 );
-        assertTrue( provider.getHandler( null, req ) instanceof ModifyHandler );
+        assertTrue( provider.getCommandHandler( req ) instanceof ModifyHandler );
 
         req = new SearchRequestImpl( 0 );
-        assertTrue( provider.getHandler( null, req ) instanceof SearchHandler );
+        assertTrue( provider.getCommandHandler( req ) instanceof SearchHandler );
 
         req = new UnbindRequestImpl( 0 );
-        assertTrue( provider.getHandler( null, req ) instanceof UnbindHandler );
+        assertTrue( provider.getCommandHandler( req ) instanceof UnbindHandler );
     }
 
 
@@ -130,155 +144,139 @@
         props.setProperty( UnbindRequest.class.getName(), BogusUnbindHandler.class.getName() );
         props.setProperty( UnbindRequestImpl.class.getName(), BogusUnbindHandler.class.getName() );
 
-        LdapProtocolProvider provider = new LdapProtocolProvider( props, null );
-        assertNotNull( provider.getDecoderFactory() );
-        assertNotNull( provider.getEncoderFactory() );
+        LdapProtocolProvider provider = new LdapProtocolProvider( props );
+        assertNotNull( provider.getCodecFactory() );
         assertTrue( provider.getName() == LdapProtocolProvider.SERVICE_NAME );
 
         Object req = null;
-        RequestHandler handler = null;
+        CommandHandler handler = null;
 
         req = new AbandonRequestImpl( 0 );
-        handler = provider.getHandler( null, req );
-        assertEquals( HandlerTypeEnum.NOREPLY, handler.getHandlerType() );
+        handler = provider.getCommandHandler( req );
         assertTrue( handler instanceof BogusAbandonHandler );
 
         req = new AddRequestImpl( 0 );
-        handler = provider.getHandler( null, req );
-        assertEquals( HandlerTypeEnum.SINGLEREPLY, handler.getHandlerType() );
+        handler = provider.getCommandHandler( req );
         assertTrue( handler instanceof BogusAddHandler );
 
         req = new BindRequestImpl( 0 );
-        handler = provider.getHandler( null, req );
-        assertEquals( HandlerTypeEnum.SINGLEREPLY, handler.getHandlerType() );
+        handler = provider.getCommandHandler( req );
         assertTrue( handler instanceof BogusBindHandler );
 
         req = new CompareRequestImpl( 0 );
-        handler = provider.getHandler( null, req );
-        assertEquals( HandlerTypeEnum.SINGLEREPLY, handler.getHandlerType() );
+        handler = provider.getCommandHandler( req );
         assertTrue( handler instanceof BogusCompareHandler );
 
         req = new DeleteRequestImpl( 0 );
-        handler = provider.getHandler( null, req );
-        assertEquals( HandlerTypeEnum.SINGLEREPLY, handler.getHandlerType() );
+        handler = provider.getCommandHandler( req );
         assertTrue( handler instanceof BogusDeleteHandler );
 
         req = new ExtendedRequestImpl( 0 );
-        handler = provider.getHandler( null, req );
-        assertEquals( HandlerTypeEnum.SINGLEREPLY, handler.getHandlerType() );
+        handler = provider.getCommandHandler( req );
         assertTrue( handler instanceof BogusExtendedHandler );
 
         req = new ModifyDnRequestImpl( 0 );
-        handler = provider.getHandler( null, req );
-        assertEquals( HandlerTypeEnum.SINGLEREPLY, handler.getHandlerType() );
+        handler = provider.getCommandHandler( req );
         assertTrue( handler instanceof BogusModifyDnHandler );
 
         req = new ModifyRequestImpl( 0 );
-        handler = provider.getHandler( null, req );
-        assertEquals( HandlerTypeEnum.SINGLEREPLY, handler.getHandlerType() );
+        handler = provider.getCommandHandler( req );
         assertTrue( handler instanceof BogusModifyHandler );
 
         req = new SearchRequestImpl( 0 );
-        handler = provider.getHandler( null, req );
-        assertEquals( HandlerTypeEnum.MANYREPLY, handler.getHandlerType() );
+        handler = provider.getCommandHandler( req );
         assertTrue( handler instanceof BogusSearchHandler );
 
         req = new UnbindRequestImpl( 0 );
-        handler = provider.getHandler( null, req );
-        assertEquals( HandlerTypeEnum.NOREPLY, handler.getHandlerType() );
+        handler = provider.getCommandHandler( req );
         assertTrue( handler instanceof BogusUnbindHandler );
     }
 
 
-    public static class BogusAbandonHandler extends AbstractNoReplyHandler
+    public static class BogusAbandonHandler implements CommandHandler
     {
-        public void handle( ClientKey key, Object request )
+        public void handle( ProtocolSession session, Object request )
         {
             throw new NotImplementedException( "handler not implemented!" );
         }
     }
 
 
-    public static class BogusUnbindHandler extends AbstractNoReplyHandler
+    public static class BogusUnbindHandler implements CommandHandler
     {
-        public void handle( ClientKey key, Object request )
+        public void handle( ProtocolSession session, Object request )
         {
             throw new NotImplementedException( "handler not implemented!" );
         }
     }
 
 
-    public static class BogusAddHandler extends AbstractSingleReplyHandler
+    public static class BogusAddHandler implements CommandHandler
     {
-        public Object handle( ClientKey key, Object request )
+        public void handle( ProtocolSession session, Object request )
         {
             throw new NotImplementedException( "handler not implemented!" );
         }
     }
 
 
-    public static class BogusBindHandler extends AbstractSingleReplyHandler
+    public static class BogusBindHandler implements CommandHandler
     {
-        public Object handle( ClientKey key, Object request )
+        public void handle( ProtocolSession session, Object request )
         {
             throw new NotImplementedException( "handler not implemented!" );
         }
     }
 
 
-    public static class BogusCompareHandler extends AbstractSingleReplyHandler
+    public static class BogusCompareHandler implements CommandHandler
     {
-        public Object handle( ClientKey key, Object request )
+        public void handle( ProtocolSession session, Object request )
         {
             throw new NotImplementedException( "handler not implemented!" );
         }
     }
 
 
-    public static class BogusDeleteHandler extends AbstractSingleReplyHandler
+    public static class BogusDeleteHandler implements CommandHandler
     {
-        public Object handle( ClientKey key, Object request )
+        public void handle( ProtocolSession session, Object request )
         {
             throw new NotImplementedException( "handler not implemented!" );
         }
     }
 
 
-    public static class BogusExtendedHandler extends AbstractSingleReplyHandler
+    public static class BogusExtendedHandler implements CommandHandler
     {
-        public Object handle( ClientKey key, Object request )
+        public void handle( ProtocolSession session, Object request )
         {
             throw new NotImplementedException( "handler not implemented!" );
         }
     }
 
 
-    public static class BogusModifyDnHandler extends AbstractSingleReplyHandler
+    public static class BogusModifyDnHandler implements CommandHandler
     {
-        public Object handle( ClientKey key, Object request )
+        public void handle( ProtocolSession session, Object request )
         {
             throw new NotImplementedException( "handler not implemented!" );
         }
     }
 
 
-    public static class BogusModifyHandler extends AbstractSingleReplyHandler
+    public static class BogusModifyHandler implements CommandHandler
     {
-        public Object handle( ClientKey key, Object request )
+        public void handle( ProtocolSession session, Object request )
         {
             throw new NotImplementedException( "handler not implemented!" );
         }
     }
 
 
-    public static class BogusSearchHandler extends AbstractManyReplyHandler
+    public static class BogusSearchHandler implements CommandHandler
     {
-        public BogusSearchHandler()
-        {
-            super( true );
-        }
-
-        public Iterator handle( ClientKey key, Object request )
+        public void handle( ProtocolSession session, Object request )
         {
             throw new NotImplementedException( "handler not implemented!" );
         }



Mime
View raw message