directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r124954 - in incubator/directory/network/trunk/mina/src: examples/org/apache/mina/examples/echoserver examples/org/apache/mina/examples/reverser examples/org/apache/mina/examples/sumup examples/org/apache/mina/examples/tennis java/org/apache/mina/io java/org/apache/mina/io/datagram java/org/apache/mina/io/socket java/org/apache/mina/protocol java/org/apache/mina/protocol/io java/org/apache/mina/protocol/vmpipe java/org/apache/mina/util test/org/apache/mina/examples/echoserver
Date Wed, 12 Jan 2005 08:51:38 GMT
Author: trustin
Date: Wed Jan 12 00:51:34 2005
New Revision: 124954

URL: http://svn.apache.org/viewcvs?view=rev&rev=124954
Log:
 * Renamed Acceptor to IoAcceptor
 * Renamed Connector to IoConnector
 * Added ProtocolAcceptor and ProtocolConnector
 * Added IoProtocolAcceptor and IoProtocolConnector which wraps IoAcceptor and IoConnector
 * connect() method of all connectors now returns IoSession(or ProtocolSession)
Added:
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoAcceptor.java
      - copied, changed from r124951, incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Acceptor.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoConnector.java
      - copied, changed from r124951, incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Connector.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolAcceptor.java   (contents, props changed)
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolConnector.java   (contents, props changed)
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/io/
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/io/IoAdapter.java
      - copied, changed from r124951, incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/io/IoProtocolAcceptor.java   (contents, props changed)
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/io/IoProtocolConnector.java   (contents, props changed)
Removed:
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Acceptor.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Connector.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java
Modified:
   incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/Main.java
   incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/Main.java
   incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/sumup/Client.java
   incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/sumup/Server.java
   incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/tennis/TennisPlayer.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoHandler.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramConnector.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketAcceptor.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketConnector.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolProvider.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolViolationException.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeAcceptor.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeConnector.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java
   incubator/directory/network/trunk/mina/src/test/org/apache/mina/examples/echoserver/Test.java

Modified: incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/Main.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/Main.java?view=diff&rev=124954&p1=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/Main.java&r1=124953&p2=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/Main.java&r2=124954
==============================================================================
--- incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/Main.java	(original)
+++ incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/Main.java	Wed Jan 12 00:51:34 2005
@@ -20,7 +20,7 @@
 
 import java.net.InetSocketAddress;
 
-import org.apache.mina.io.Acceptor;
+import org.apache.mina.io.IoAcceptor;
 import org.apache.mina.io.datagram.DatagramAcceptor;
 import org.apache.mina.io.filter.IoThreadPoolFilter;
 import org.apache.mina.io.socket.SocketAcceptor;
@@ -42,7 +42,7 @@
         threadPoolFilter.start(); // and start it
 
         // Create a TCP/IP acceptor
-        Acceptor acceptor = new SocketAcceptor();
+        IoAcceptor acceptor = new SocketAcceptor();
 
         // Add thread pool filter
         // MINA runs in a single thread if you don't add this filter.
@@ -53,7 +53,7 @@
                        new EchoProtocolHandler() );
 
         // Create a UDP/IP acceptor
-        Acceptor datagramAcceptor = new DatagramAcceptor();
+        IoAcceptor datagramAcceptor = new DatagramAcceptor();
 
         // Add thread pool filter
         datagramAcceptor.addFilter( Integer.MAX_VALUE, threadPoolFilter );

Modified: incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/Main.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/Main.java?view=diff&rev=124954&p1=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/Main.java&r1=124953&p2=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/Main.java&r2=124954
==============================================================================
--- incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/Main.java	(original)
+++ incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/Main.java	Wed Jan 12 00:51:34 2005
@@ -20,11 +20,10 @@
 
 import java.net.InetSocketAddress;
 
-import org.apache.mina.io.Acceptor;
 import org.apache.mina.io.filter.IoThreadPoolFilter;
 import org.apache.mina.io.socket.SocketAcceptor;
-import org.apache.mina.protocol.IoAdapter;
 import org.apache.mina.protocol.filter.ProtocolThreadPoolFilter;
+import org.apache.mina.protocol.io.IoProtocolAcceptor;
 
 /**
  * (<b>Entry point</b>) Reverser server which reverses all text lines from
@@ -49,19 +48,18 @@
         ioThreadPoolFilter.start();
         protocolThreadPoolFilter.start();
 
-        // Create TCP/IP acceptor.
-        Acceptor acceptor = new SocketAcceptor();
-
-        // Create an I/O adapter to adapt ProtocolProvider to IoHandler.
-        IoAdapter ioAdapter = new IoAdapter();
+        // Create a TCP/IP acceptor.
+        IoProtocolAcceptor acceptor = new IoProtocolAcceptor(
+                                                              new SocketAcceptor() );
 
         // Add both thread pool filters.
-        acceptor.addFilter( Integer.MAX_VALUE, ioThreadPoolFilter );
-        ioAdapter.addFilter( Integer.MAX_VALUE, protocolThreadPoolFilter );
+        acceptor.getIoAcceptor().addFilter( Integer.MAX_VALUE,
+                                            ioThreadPoolFilter );
+        acceptor.addFilter( Integer.MAX_VALUE, protocolThreadPoolFilter );
 
         // Bind
-        acceptor.bind( new InetSocketAddress( PORT ), ioAdapter
-                .adapt( new ReverseProtocolProvider() ) );
+        acceptor.bind( new InetSocketAddress( PORT ),
+                       new ReverseProtocolProvider() );
 
         System.out.println( "Listening on port " + PORT );
     }

Modified: incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/sumup/Client.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/sumup/Client.java?view=diff&rev=124954&p1=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/sumup/Client.java&r1=124953&p2=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/sumup/Client.java&r2=124954
==============================================================================
--- incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/sumup/Client.java	(original)
+++ incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/sumup/Client.java	Wed Jan 12 00:51:34 2005
@@ -6,12 +6,12 @@
 import java.io.IOException;
 import java.net.InetSocketAddress;
 
-import org.apache.mina.io.Connector;
 import org.apache.mina.io.filter.IoThreadPoolFilter;
 import org.apache.mina.io.socket.SocketConnector;
-import org.apache.mina.protocol.IoAdapter;
 import org.apache.mina.protocol.ProtocolProvider;
+import org.apache.mina.protocol.ProtocolSession;
 import org.apache.mina.protocol.filter.ProtocolThreadPoolFilter;
+import org.apache.mina.protocol.io.IoProtocolConnector;
 
 /**
  * (<strong>Entry Point</strong>) Starts SumUp client.
@@ -52,20 +52,21 @@
         ioThreadPoolFilter.start();
         protocolThreadPoolFilter.start();
 
-        Connector connector = new SocketConnector();
-        IoAdapter adapter = new IoAdapter();
-
-        connector.addFilter( Integer.MAX_VALUE, ioThreadPoolFilter );
-        adapter.addFilter( Integer.MAX_VALUE, protocolThreadPoolFilter );
+        IoProtocolConnector connector = new IoProtocolConnector(
+                                                                 new SocketConnector() );
+        connector.getIoConnector().addFilter( Integer.MAX_VALUE,
+                                              ioThreadPoolFilter );
+        connector.addFilter( Integer.MAX_VALUE, protocolThreadPoolFilter );
 
         ProtocolProvider protocolProvider = new ClientProtocolProvider( values );
+        ProtocolSession session;
         for( ;; )
         {
             try
             {
-                connector.connect( new InetSocketAddress( HOSTNAME, PORT ),
-                                   CONNECT_TIMEOUT, adapter
-                                           .adapt( protocolProvider ) );
+                session = connector
+                        .connect( new InetSocketAddress( HOSTNAME, PORT ),
+                                  CONNECT_TIMEOUT, protocolProvider );
                 break;
             }
             catch( IOException e )
@@ -77,9 +78,7 @@
         }
 
         // wait until the summation is done
-        ClientSessionHandler sessionHandler = ( ClientSessionHandler ) protocolProvider
-                .getHandler();
-        while( sessionHandler.isFinished() )
+        while( session.isConnected() )
         {
             Thread.sleep( 100 );
         }

Modified: incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/sumup/Server.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/sumup/Server.java?view=diff&rev=124954&p1=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/sumup/Server.java&r1=124953&p2=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/sumup/Server.java&r2=124954
==============================================================================
--- incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/sumup/Server.java	(original)
+++ incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/sumup/Server.java	Wed Jan 12 00:51:34 2005
@@ -5,11 +5,10 @@
 
 import java.net.InetSocketAddress;
 
-import org.apache.mina.io.Acceptor;
 import org.apache.mina.io.filter.IoThreadPoolFilter;
 import org.apache.mina.io.socket.SocketAcceptor;
-import org.apache.mina.protocol.IoAdapter;
 import org.apache.mina.protocol.filter.ProtocolThreadPoolFilter;
+import org.apache.mina.protocol.io.IoProtocolAcceptor;
 
 /**
  * (<strong>Entry Point</strong>) Starts SumUp server.
@@ -33,14 +32,15 @@
         ioThreadPoolFilter.start();
         protocolThreadPoolFilter.start();
 
-        Acceptor acceptor = new SocketAcceptor();
-        IoAdapter adapter = new IoAdapter();
+        IoProtocolAcceptor acceptor = new IoProtocolAcceptor(
+                                                              new SocketAcceptor() );
 
-        acceptor.addFilter( Integer.MAX_VALUE, ioThreadPoolFilter );
-        adapter.addFilter( Integer.MAX_VALUE, protocolThreadPoolFilter );
+        acceptor.getIoAcceptor().addFilter( Integer.MAX_VALUE,
+                                            ioThreadPoolFilter );
+        acceptor.addFilter( Integer.MAX_VALUE, protocolThreadPoolFilter );
 
-        acceptor.bind( new InetSocketAddress( SERVER_PORT ), adapter
-                .adapt( new ServerProtocolProvider() ) );
+        acceptor.bind( new InetSocketAddress( SERVER_PORT ),
+                       new ServerProtocolProvider() );
         System.out.println( "Listening on port " + SERVER_PORT );
     }
 }

Modified: incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/tennis/TennisPlayer.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/tennis/TennisPlayer.java?view=diff&rev=124954&p1=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/tennis/TennisPlayer.java&r1=124953&p2=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/tennis/TennisPlayer.java&r2=124954
==============================================================================
--- incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/tennis/TennisPlayer.java	(original)
+++ incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/tennis/TennisPlayer.java	Wed Jan 12 00:51:34 2005
@@ -3,8 +3,10 @@
  */
 package org.apache.mina.examples.tennis;
 
+import org.apache.mina.protocol.ProtocolCodecFactory;
 import org.apache.mina.protocol.ProtocolHandler;
 import org.apache.mina.protocol.ProtocolHandlerAdapter;
+import org.apache.mina.protocol.ProtocolProvider;
 import org.apache.mina.protocol.ProtocolSession;
 
 /**
@@ -13,47 +15,62 @@
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$
  */
-public class TennisPlayer extends ProtocolHandlerAdapter
+public class TennisPlayer implements ProtocolProvider
 {
-    private static int nextId = 0;
-
-    /** Player ID **/
-    private final int id = nextId++;
-
-    public void sessionOpened( ProtocolSession session )
+    private static final ProtocolHandler HANDLER = new TennisPlayerHandler();
+    
+    public ProtocolCodecFactory getCodecFactory()
     {
-        System.out.println( "Player-" + id + ": READY" );
+        throw new UnsupportedOperationException();
     }
 
-    public void sessionClosed( ProtocolSession session )
+    public ProtocolHandler getHandler()
     {
-        System.out.println( "Player-" + id + ": QUIT" );
+        return HANDLER;
     }
 
-    public void messageReceived( ProtocolSession session, Object message )
+    private static class TennisPlayerHandler extends ProtocolHandlerAdapter
     {
-        System.out.println( "Player-" + id + ": RCVD " + message );
+        private static int nextId = 0;
 
-        TennisBall ball = ( TennisBall ) message;
+        /** Player ID **/
+        private final int id = nextId++;
 
-        // Stroke: TTL decreases and PING/PONG state changes.
-        ball = ball.stroke();
+        public void sessionOpened( ProtocolSession session )
+        {
+            System.out.println( "Player-" + id + ": READY" );
+        }
 
-        if( ball.getTTL() > 0 )
+        public void sessionClosed( ProtocolSession session )
         {
-            // If the ball is still alive, pass it back to peer.
-            session.write( ball );
+            System.out.println( "Player-" + id + ": QUIT" );
         }
-        else
+
+        public void messageReceived( ProtocolSession session, Object message )
         {
-            // If the ball is dead, this player loses.
-            System.out.println( "Player-" + id + ": LOSE" );
-            session.close();
+            System.out.println( "Player-" + id + ": RCVD " + message );
+
+            TennisBall ball = ( TennisBall ) message;
+
+            // Stroke: TTL decreases and PING/PONG state changes.
+            ball = ball.stroke();
+
+            if( ball.getTTL() > 0 )
+            {
+                // If the ball is still alive, pass it back to peer.
+                session.write( ball );
+            }
+            else
+            {
+                // If the ball is dead, this player loses.
+                System.out.println( "Player-" + id + ": LOSE" );
+                session.close();
+            }
         }
-    }
 
-    public void messageSent( ProtocolSession session, Object message )
-    {
-        System.out.println( "Player-" + id + ": SENT " + message );
+        public void messageSent( ProtocolSession session, Object message )
+        {
+            System.out.println( "Player-" + id + ": SENT " + message );
+        }
     }
 }

Deleted: /incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Acceptor.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Acceptor.java?view=auto&rev=124953
==============================================================================

Deleted: /incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Connector.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Connector.java?view=auto&rev=124953
==============================================================================

Copied: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoAcceptor.java (from r124951, incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Acceptor.java)
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoAcceptor.java?view=diff&rev=124954&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Acceptor.java&r1=124951&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoAcceptor.java&r2=124954
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Acceptor.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoAcceptor.java	Wed Jan 12 00:51:34 2005
@@ -47,16 +47,15 @@
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$
  */
-public interface Acceptor
+public interface IoAcceptor
 {
     /**
      * Binds to the specified <code>address</code> and handles incoming
-     * connections with the specified <code>defaultHandler</code>.
+     * connections with the specified <code>handler</code>.
      * 
      * @throws IOException if failed to bind
      */
-    void bind( SocketAddress address, IoHandler defaultHandler )
-            throws IOException;
+    void bind( SocketAddress address, IoHandler handler ) throws IOException;
 
     /**
      * Unbinds from the specified <code>address</code>.

Copied: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoConnector.java (from r124951, incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Connector.java)
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoConnector.java?view=diff&rev=124954&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Connector.java&r1=124951&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoConnector.java&r2=124954
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Connector.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoConnector.java	Wed Jan 12 00:51:34 2005
@@ -47,26 +47,26 @@
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$
  */
-public interface Connector
+public interface IoConnector
 {
     /**
      * Connects to the specified <code>address</code>.  If communication starts
      * successfully, events are fired to the specified
-     * <code>defaultHandler</code>.  This method blocks.
+     * <code>handler</code>.  This method blocks.
      * 
      * @throws IOException if failed to connect
      */
-    void connect( SocketAddress address, IoHandler defaultHandler )
+    IoSession connect( SocketAddress address, IoHandler handler )
             throws IOException;
 
     /**
      * Connects to the specified <code>address</code> with timeout.  If
      * communication starts successfully, events are fired to the specified
-     * <code>defaultHandler</code>.  This method blocks.
+     * <code>handler</code>.  This method blocks.
      * 
      * @throws IOException if failed to connect
      */
-    void connect( SocketAddress address, int timeout, IoHandler defaultHandler )
+    IoSession connect( SocketAddress address, int timeout, IoHandler handler )
             throws IOException;
 
     /**

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoHandler.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoHandler.java?view=diff&rev=124954&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoHandler.java&r1=124953&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoHandler.java&r2=124954
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoHandler.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoHandler.java	Wed Jan 12 00:51:34 2005
@@ -24,7 +24,7 @@
 import org.apache.mina.common.IdleStatus;
 
 /**
- * Handles all I/O events fired by {@link Acceptor} and {@link Connector}.
+ * Handles all I/O events fired by {@link IoAcceptor} and {@link IoConnector}.
  * There are 6 event handler methods, and they are all invoked by MINA
  * automatically.  Most users of MINA I/O package will be OK with this single
  * interface to implement their protocols.

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java?view=diff&rev=124954&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java&r1=124953&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java&r2=124954
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java	Wed Jan 12 00:51:34 2005
@@ -31,7 +31,7 @@
 import java.util.Set;
 
 import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.io.Acceptor;
+import org.apache.mina.io.IoAcceptor;
 import org.apache.mina.io.DefaultExceptionMonitor;
 import org.apache.mina.io.ExceptionMonitor;
 import org.apache.mina.io.IoHandler;
@@ -40,12 +40,12 @@
 import org.apache.mina.util.Queue;
 
 /**
- * {@link Acceptor} for datagram transport (UDP/IP).
+ * {@link IoAcceptor} for datagram transport (UDP/IP).
  * 
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$
  */
-public class DatagramAcceptor extends DatagramProcessor implements Acceptor
+public class DatagramAcceptor extends DatagramProcessor implements IoAcceptor
 {
     private static volatile int nextId = 0;
 
@@ -77,13 +77,13 @@
         selector = Selector.open();
     }
 
-    public void bind( SocketAddress address, IoHandler defaultHandler )
+    public void bind( SocketAddress address, IoHandler handler )
             throws IOException
     {
         if( address == null )
             throw new NullPointerException( "address" );
-        if( defaultHandler == null )
-            throw new NullPointerException( "defaultHandler" );
+        if( handler == null )
+            throw new NullPointerException( "handler" );
 
         if( ! ( address instanceof InetSocketAddress ) )
             throw new IllegalArgumentException( "Unexpected address type: "
@@ -97,8 +97,7 @@
         {
             synchronized( registerQueue )
             {
-                registerQueue.push( new RegistrationRequest( ch,
-                                                             defaultHandler ) );
+                registerQueue.push( new RegistrationRequest( ch, handler ) );
             }
             channels.put( address, ch );
 

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramConnector.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramConnector.java?view=diff&rev=124954&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramConnector.java&r1=124953&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramConnector.java&r2=124954
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramConnector.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramConnector.java	Wed Jan 12 00:51:34 2005
@@ -29,21 +29,23 @@
 import java.util.Set;
 
 import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.io.Connector;
 import org.apache.mina.io.DefaultExceptionMonitor;
 import org.apache.mina.io.ExceptionMonitor;
+import org.apache.mina.io.IoConnector;
 import org.apache.mina.io.IoHandler;
 import org.apache.mina.io.IoHandlerFilter;
+import org.apache.mina.io.IoSession;
 import org.apache.mina.util.IoHandlerFilterManager;
 import org.apache.mina.util.Queue;
 
 /**
- * {@link Connector} for datagram transport (UDP/IP).
+ * {@link IoConnector} for datagram transport (UDP/IP).
  * 
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$
  */
-public class DatagramConnector extends DatagramProcessor implements Connector
+public class DatagramConnector extends DatagramProcessor implements
+                                                        IoConnector
 {
     private static volatile int nextId = 0;
 
@@ -73,13 +75,13 @@
         selector = Selector.open();
     }
 
-    public void connect( SocketAddress address, IoHandler defaultHandler )
+    public IoSession connect( SocketAddress address, IoHandler handler )
             throws IOException
     {
         if( address == null )
             throw new NullPointerException( "address" );
-        if( defaultHandler == null )
-            throw new NullPointerException( "defaultHandler" );
+        if( handler == null )
+            throw new NullPointerException( "handler" );
 
         if( ! ( address instanceof InetSocketAddress ) )
             throw new IllegalArgumentException( "Unexpected address type: "
@@ -89,8 +91,7 @@
         ch.configureBlocking( false );
         ch.socket().connect( address );
 
-        RegistrationRequest request = new RegistrationRequest( ch,
-                                                               defaultHandler );
+        RegistrationRequest request = new RegistrationRequest( ch, handler );
         synchronized( this )
         {
             synchronized( registerQueue )
@@ -120,12 +121,14 @@
                 }
             }
         }
+
+        return request.session;
     }
 
-    public void connect( SocketAddress address, int timeout,
-                        IoHandler defaultHandler ) throws IOException
+    public IoSession connect( SocketAddress address, int timeout,
+                             IoHandler handler ) throws IOException
     {
-        connect( address, defaultHandler );
+        return connect( address, handler );
     }
 
     public void closeSession( DatagramSession session )

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketAcceptor.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketAcceptor.java?view=diff&rev=124954&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketAcceptor.java&r1=124953&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketAcceptor.java&r2=124954
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketAcceptor.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketAcceptor.java	Wed Jan 12 00:51:34 2005
@@ -30,7 +30,7 @@
 import java.util.Iterator;
 import java.util.Map;
 
-import org.apache.mina.io.Acceptor;
+import org.apache.mina.io.IoAcceptor;
 import org.apache.mina.io.DefaultExceptionMonitor;
 import org.apache.mina.io.ExceptionMonitor;
 import org.apache.mina.io.IoHandler;
@@ -39,12 +39,12 @@
 import org.apache.mina.util.Queue;
 
 /**
- * {@link Acceptor} for socket transport (TCP/IP).
+ * {@link IoAcceptor} for socket transport (TCP/IP).
  * 
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$
  */
-public class SocketAcceptor implements Acceptor
+public class SocketAcceptor implements IoAcceptor
 {
     private static volatile int nextId = 0;
 
@@ -74,26 +74,26 @@
         selector = Selector.open();
     }
 
-    public void bind( SocketAddress address, IoHandler defaultHandler )
+    public void bind( SocketAddress address, IoHandler handler )
             throws IOException
     {
-        this.bind( address, 50, defaultHandler );
+        this.bind( address, 50, handler );
     }
 
     /**
      * Binds to the specified <code>address</code> and handles incoming
-     * connections with the specified <code>defaultHandler</code>.
+     * connections with the specified <code>handler</code>.
      *
      * @param backlog the listen backlog length 
      * @throws IOException if failed to bind
      */
-    public void bind( SocketAddress address, int backlog,
-                     IoHandler defaultHandler ) throws IOException
+    public void bind( SocketAddress address, int backlog, IoHandler handler )
+            throws IOException
     {
         if( address == null )
             throw new NullPointerException( "address" );
-        if( defaultHandler == null )
-            throw new NullPointerException( "defaultHandler" );
+        if( handler == null )
+            throw new NullPointerException( "handler" );
 
         if( ! ( address instanceof InetSocketAddress ) )
             throw new IllegalArgumentException( "Unexpected address type: "
@@ -107,8 +107,7 @@
         {
             synchronized( registerQueue )
             {
-                registerQueue.push( new RegistrationRequest( ssc,
-                                                             defaultHandler ) );
+                registerQueue.push( new RegistrationRequest( ssc, handler ) );
             }
             channels.put( address, ssc );
 

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketConnector.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketConnector.java?view=diff&rev=124954&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketConnector.java&r1=124953&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketConnector.java&r2=124954
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketConnector.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketConnector.java	Wed Jan 12 00:51:34 2005
@@ -28,20 +28,21 @@
 import java.util.Iterator;
 import java.util.Set;
 
-import org.apache.mina.io.Connector;
 import org.apache.mina.io.DefaultExceptionMonitor;
 import org.apache.mina.io.ExceptionMonitor;
+import org.apache.mina.io.IoConnector;
 import org.apache.mina.io.IoHandler;
 import org.apache.mina.io.IoHandlerFilter;
+import org.apache.mina.io.IoSession;
 import org.apache.mina.util.IoHandlerFilterManager;
 
 /**
- * {@link Connector} for socket transport (TCP/IP).
+ * {@link IoConnector} for socket transport (TCP/IP).
  * 
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$
  */
-public class SocketConnector implements Connector
+public class SocketConnector implements IoConnector
 {
     private static volatile int nextId = 0;
 
@@ -65,19 +66,19 @@
         selector = Selector.open();
     }
 
-    public void connect( SocketAddress address, IoHandler defaultHandler )
+    public IoSession connect( SocketAddress address, IoHandler handler )
             throws IOException
     {
-        connect( address, Integer.MAX_VALUE, defaultHandler );
+        return connect( address, Integer.MAX_VALUE, handler );
     }
 
-    public void connect( SocketAddress address, int timeout,
-                        IoHandler defaultHandler ) throws IOException
+    public IoSession connect( SocketAddress address, int timeout,
+                             IoHandler handler ) throws IOException
     {
         if( address == null )
             throw new NullPointerException( "address" );
-        if( defaultHandler == null )
-            throw new NullPointerException( "defaultHandler" );
+        if( handler == null )
+            throw new NullPointerException( "handler" );
 
         if( timeout <= 0 )
             throw new IllegalArgumentException( "Illegal timeout: " + timeout );
@@ -89,13 +90,14 @@
         SocketChannel ch = SocketChannel.open();
         ch.configureBlocking( false );
 
+        IoSession session;
         if( ch.connect( address ) )
         {
-            newSession( ch, defaultHandler );
+            session = newSession( ch, handler );
         }
         else
         {
-            ConnectEntry entry = new ConnectEntry( timeout, defaultHandler );
+            ConnectEntry entry = new ConnectEntry( timeout, handler );
 
             synchronized( this )
             {
@@ -124,7 +126,11 @@
 
             if( entry.exception != null )
                 throw entry.exception;
+
+            session = entry.session;
         }
+
+        return session;
     }
 
     private void processSessions( Set keys )
@@ -144,9 +150,8 @@
             try
             {
                 ch.finishConnect();
-                newSession( ch, entry.handler );
-                //                SocketSession session = newSession( ch, entry.handler );
-                //                entry.session = session;
+                SocketSession session = newSession( ch, entry.handler );
+                entry.session = session;
                 entry.done = true;
 
                 synchronized( entry )
@@ -263,7 +268,7 @@
 
         private final IoHandler handler;
 
-        //        private SocketSession session;
+        private SocketSession session;
 
         private boolean done;
 

Deleted: /incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java?view=auto&rev=124953
==============================================================================

Added: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolAcceptor.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolAcceptor.java?view=auto&rev=124954
==============================================================================
--- (empty file)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolAcceptor.java	Wed Jan 12 00:51:34 2005
@@ -0,0 +1,73 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.protocol;
+
+import java.io.IOException;
+import java.net.SocketAddress;
+
+/**
+ * Accepts incoming connection, communicates with clients, and fires events to
+ * {@link ProtocolHandler}s.
+ * <p>
+ * Please refer to
+ * <a href="../../../../../xref-examples/org/apache/mina/examples/reverser/Main.html">Reverser</a>
+ * example. 
+ * <p>
+ * You should bind to the desired socket address to accept incoming
+ * connections, and then events for incoming connections will be sent to
+ * the specified default {@link ProtocolHandler}.
+ * <p>
+ * Threads accepts incoming connections start automatically when
+ * {@link #bind(SocketAddress, ProtocolProvider)} is invoked, and stop when all
+ * addresses are unbound.
+ * <p>
+ * {@link ProtocolHandlerFilter}s can be added and removed at any time to filter
+ * events just like Servlet filters and they are effective immediately.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public interface ProtocolAcceptor
+{
+    /**
+     * Binds to the specified <code>address</code> and handles incoming
+     * connections with the specified <code>protocolProvider</code>.
+     * 
+     * @throws IOException if failed to bind
+     */
+    void bind( SocketAddress address, ProtocolProvider protocolProvider )
+            throws IOException;
+
+    /**
+     * Unbinds from the specified <code>address</code>.
+     */
+    void unbind( SocketAddress address );
+
+    /**
+     * Adds the specified filter with the specified priority.  Greater priority
+     * value, higher priority, and thus evaluated more earlier.  Please note
+     * that priority value must be unique.
+     */
+    void addFilter( int priority, ProtocolHandlerFilter filter );
+
+    /**
+     * Removes the specified filter from the filter list.
+     */
+    void removeFilter( ProtocolHandlerFilter filter );
+}
\ No newline at end of file

Added: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolConnector.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolConnector.java?view=auto&rev=124954
==============================================================================
--- (empty file)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolConnector.java	Wed Jan 12 00:51:34 2005
@@ -0,0 +1,81 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.protocol;
+
+import java.io.IOException;
+import java.net.SocketAddress;
+
+/**
+ * Connects to endpoint, communicates with the server, and fires events to
+ * {@link ProtocolProvider}s.
+ * <p>
+ * Please refer to
+ * <a href="../../../../../xref-examples/org/apache/mina/examples/sumup/Client.html">SumUp client</a>
+ * example. 
+ * <p>
+ * You should connect to the desired socket address to start communication,
+ * and then events for incoming connections will be sent to the
+ * {@link ProtocolHandler} of the specified {@link ProtocolProvider}.
+ * <p>
+ * Threads connects to endpoint start automatically when
+ * {@link #connect(SocketAddress, ProtocolProvider)} is invoked, and stop when
+ * all connection attempts are finished.
+ * <p>
+ * {@link ProtocolHandlerFilter}s can be added and removed at any time to filter
+ * events just like Servlet filters and they are effective immediately.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public interface ProtocolConnector
+{
+    /**
+     * Connects to the specified <code>address</code>.  If communication starts
+     * successfully, events are fired to the specified
+     * <code>protocolProvider</code>.  This method blocks.
+     * 
+     * @throws IOException if failed to connect
+     */
+    ProtocolSession connect( SocketAddress address,
+                            ProtocolProvider protocolProvider )
+            throws IOException;
+
+    /**
+     * Connects to the specified <code>address</code> with timeout.  If
+     * communication starts successfully, events are fired to the specified
+     * <code>protocolProvider</code>.  This method blocks.
+     * 
+     * @throws IOException if failed to connect
+     */
+    ProtocolSession connect( SocketAddress address, int timeout,
+                            ProtocolProvider protocolProvider )
+            throws IOException;
+
+    /**
+     * Adds the specified filter with the specified priority.  Greater priority
+     * value, higher priority, and thus evaluated more earlier.  Please note
+     * that priority value must be unique.
+     */
+    void addFilter( int priority, ProtocolHandlerFilter filter );
+
+    /**
+     * Removes the specified filter from the filter list.
+     */
+    void removeFilter( ProtocolHandlerFilter filter );
+}
\ No newline at end of file

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolProvider.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolProvider.java?view=diff&rev=124954&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolProvider.java&r1=124953&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolProvider.java&r2=124954
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolProvider.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolProvider.java	Wed Jan 12 00:51:34 2005
@@ -18,7 +18,7 @@
  */
 package org.apache.mina.protocol;
 
-import org.apache.mina.io.IoHandler;
+import java.net.SocketAddress;
 
 /**
  * Provides a required information to implement high-level protocols.
@@ -31,8 +31,8 @@
  * </ul>
  * <p>
  * If once you implement {@link ProtocolProvider} for your protocol, you can
- * adapt it into {@link IoHandler} using {@link IoAdapter} to work with I/O
- * layer which does actual I/O operations.
+ * connect to or bind on {@link SocketAddress} using {@link ProtocolAcceptor}
+ * and {@link ProtocolConnector}.
  * <p>
  * Please refer to
  * <a href="../../../../../xref-examples/org/apache/mina/examples/reverser/ReverseProtocolProvider.html"><code>ReverserProtocolProvider</code></a>

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolViolationException.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolViolationException.java?view=diff&rev=124954&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolViolationException.java&r1=124953&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolViolationException.java&r2=124954
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolViolationException.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolViolationException.java	Wed Jan 12 00:51:34 2005
@@ -99,7 +99,7 @@
     /**
      * Sets unknown message part.
      */
-    void setBuffer( ByteBuffer buffer )
+    public void setBuffer( ByteBuffer buffer )
     {
         this.buffer = buffer;
     }

Copied: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/io/IoAdapter.java (from r124951, incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java)
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/io/IoAdapter.java?view=diff&rev=124954&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java&r1=124951&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/io/IoAdapter.java&r2=124954
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/io/IoAdapter.java	Wed Jan 12 00:51:34 2005
@@ -16,7 +16,7 @@
  *   limitations under the License.
  *
  */
-package org.apache.mina.protocol;
+package org.apache.mina.protocol.io;
 
 import java.net.SocketAddress;
 
@@ -24,11 +24,21 @@
 import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.SessionConfig;
 import org.apache.mina.common.TransportType;
-import org.apache.mina.io.Acceptor;
-import org.apache.mina.io.Connector;
+import org.apache.mina.io.IoAcceptor;
+import org.apache.mina.io.IoConnector;
 import org.apache.mina.io.IoHandler;
 import org.apache.mina.io.IoHandlerFilter;
 import org.apache.mina.io.IoSession;
+import org.apache.mina.protocol.ProtocolCodecFactory;
+import org.apache.mina.protocol.ProtocolDecoder;
+import org.apache.mina.protocol.ProtocolDecoderOutput;
+import org.apache.mina.protocol.ProtocolEncoder;
+import org.apache.mina.protocol.ProtocolEncoderOutput;
+import org.apache.mina.protocol.ProtocolHandler;
+import org.apache.mina.protocol.ProtocolHandlerFilter;
+import org.apache.mina.protocol.ProtocolProvider;
+import org.apache.mina.protocol.ProtocolSession;
+import org.apache.mina.protocol.ProtocolViolationException;
 import org.apache.mina.util.ProtocolHandlerFilterManager;
 import org.apache.mina.util.Queue;
 import org.apache.mina.util.ProtocolHandlerFilterManager.WriteCommand;
@@ -51,8 +61,8 @@
  * <a href="../../../../../xref-examples/org/apache/mina/examples/reverser/Main.html">Reverser</a>
  * example.
  * <p>
- * {@link IoAdapter} supports protocol-level filters like {@link Acceptor}s and
- * {@link Connector}s.  It is the same with {@link IoHandlerFilter} and Servlet
+ * {@link IoAdapter} supports protocol-level filters like {@link IoAcceptor}s and
+ * {@link IoConnector}s.  It is the same with {@link IoHandlerFilter} and Servlet
  * filters and effective immediately.
  * 
  * @author Trustin Lee (trustin@apache.org)
@@ -64,7 +74,7 @@
 
     private final ProtocolHandlerFilterManager filterManager = new ProtocolHandlerFilterManager();
 
-    public IoAdapter()
+    IoAdapter()
     {
     }
 
@@ -95,6 +105,23 @@
     public IoHandler adapt( ProtocolProvider protocolProvider )
     {
         return new SessionHandlerAdapter( protocolProvider );
+    }
+
+    /**
+     * Returns {@link ProtocolSession} of the specified {@link IoSession}.
+     */
+    public ProtocolSession toProtocolSession( IoSession session )
+    {
+        IoHandler handler = session.getHandler();
+        if( handler instanceof SessionHandlerAdapter )
+        {
+            SessionHandlerAdapter sha = ( SessionHandlerAdapter ) handler;
+            return sha.getProtocolSession( session );
+        }
+        else
+        {
+            throw new IllegalArgumentException( "Not adapted from IoAdapter." );
+        }
     }
 
     private class SessionHandlerAdapter implements IoHandler

Added: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/io/IoProtocolAcceptor.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/io/IoProtocolAcceptor.java?view=auto&rev=124954
==============================================================================
--- (empty file)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/io/IoProtocolAcceptor.java	Wed Jan 12 00:51:34 2005
@@ -0,0 +1,67 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.protocol.io;
+
+import java.io.IOException;
+import java.net.SocketAddress;
+
+import org.apache.mina.io.IoAcceptor;
+import org.apache.mina.protocol.ProtocolAcceptor;
+import org.apache.mina.protocol.ProtocolHandlerFilter;
+import org.apache.mina.protocol.ProtocolProvider;
+
+/**
+ * A {@link ProtocolAcceptor} which wraps {@link IoAcceptor} to provide
+ * low-level I/O.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public class IoProtocolAcceptor implements ProtocolAcceptor
+{
+    private final IoAcceptor acceptor;
+
+    private final IoAdapter adapter = new IoAdapter();
+
+    /**
+     * Creates a new instance with the specified {@link IoAcceptor}.
+     */
+    public IoProtocolAcceptor( IoAcceptor acceptor )
+    {
+        if( acceptor == null )
+            throw new NullPointerException( "acceptor" );
+
+        this.acceptor = acceptor;
+    }
+
+    /**
+     * Returns a underlying {@link IoAcceptor} instance this acceptor is
+     * wrapping.
+     */
+    public IoAcceptor getIoAcceptor()
+    {
+        return acceptor;
+    }
+
+    public void bind( SocketAddress address, ProtocolProvider provider )
+            throws IOException
+    {
+        acceptor.bind( address, adapter.adapt( provider ) );
+    }
+
+    public void unbind( SocketAddress address )
+    {
+        acceptor.unbind( address );
+    }
+
+    public void addFilter( int priority, ProtocolHandlerFilter filter )
+    {
+        adapter.addFilter( priority, filter );
+    }
+
+    public void removeFilter( ProtocolHandlerFilter filter )
+    {
+        adapter.removeFilter( filter );
+    }
+}
\ No newline at end of file

Added: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/io/IoProtocolConnector.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/io/IoProtocolConnector.java?view=auto&rev=124954
==============================================================================
--- (empty file)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/io/IoProtocolConnector.java	Wed Jan 12 00:51:34 2005
@@ -0,0 +1,76 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.protocol.io;
+
+import java.io.IOException;
+import java.net.SocketAddress;
+
+import org.apache.mina.io.IoConnector;
+import org.apache.mina.io.IoSession;
+import org.apache.mina.protocol.ProtocolConnector;
+import org.apache.mina.protocol.ProtocolHandlerFilter;
+import org.apache.mina.protocol.ProtocolProvider;
+import org.apache.mina.protocol.ProtocolSession;
+
+/**
+ * A {@link ProtocolConnector} which wraps {@link IoConnector} to provide
+ * low-level I/O.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public class IoProtocolConnector implements ProtocolConnector
+{
+    private final IoConnector connector;
+
+    private final IoAdapter adapter = new IoAdapter();
+
+    /**
+     * Creates a new instance with the specified {@link IoConnector}.
+     */
+    public IoProtocolConnector( IoConnector connector )
+    {
+        if( connector == null )
+            throw new NullPointerException( "connector" );
+        this.connector = connector;
+    }
+
+    /**
+     * Returns a underlying {@link IoConnector} instance this acceptor is
+     * wrapping.
+     */
+    public IoConnector getIoConnector()
+    {
+        return connector;
+    }
+
+    public ProtocolSession connect( SocketAddress address,
+                                   ProtocolProvider provider )
+            throws IOException
+    {
+        IoSession session = connector.connect( address, adapter
+                .adapt( provider ) );
+        return adapter.toProtocolSession( session );
+    }
+
+    public ProtocolSession connect( SocketAddress address, int timeout,
+                                   ProtocolProvider provider )
+            throws IOException
+    {
+        IoSession session = connector.connect( address, timeout, adapter
+                .adapt( provider ) );
+        return adapter.toProtocolSession( session );
+    }
+
+    public void addFilter( int priority, ProtocolHandlerFilter filter )
+    {
+        adapter.addFilter( priority, filter );
+    }
+
+    public void removeFilter( ProtocolHandlerFilter filter )
+    {
+        adapter.removeFilter( filter );
+    }
+
+}
\ No newline at end of file

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeAcceptor.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeAcceptor.java?view=diff&rev=124954&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeAcceptor.java&r1=124953&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeAcceptor.java&r2=124954
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeAcceptor.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeAcceptor.java	Wed Jan 12 00:51:34 2005
@@ -4,21 +4,24 @@
 package org.apache.mina.protocol.vmpipe;
 
 import java.io.IOException;
+import java.net.SocketAddress;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.mina.protocol.ProtocolAcceptor;
 import org.apache.mina.protocol.ProtocolHandler;
 import org.apache.mina.protocol.ProtocolHandlerFilter;
+import org.apache.mina.protocol.ProtocolProvider;
 import org.apache.mina.util.ProtocolHandlerFilterManager;
 
 /**
- * Binds the specified {@link ProtocolHandler} to the specified
+ * Binds the specified {@link ProtocolProvider} to the specified
  * {@link VmPipeAddress}.
  * 
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$
  */
-public class VmPipeAcceptor
+public class VmPipeAcceptor implements ProtocolAcceptor
 {
     static final Map boundHandlers = new HashMap();
 
@@ -29,22 +32,19 @@
      */
     public VmPipeAcceptor()
     {
-        filterManager.addFilter( Integer.MIN_VALUE, new VmPipeFilter() );
+        filterManager.addFilter( Integer.MIN_VALUE - 1, new VmPipeFilter() );
     }
 
-    /**
-     * Binds to the specified <code>address</code> and handles incoming
-     * connections with the specified <code>defaultHandler</code>.
-     * 
-     * @throws IOException if failed to bind
-     */
-    public void bind( VmPipeAddress address, ProtocolHandler defaultHandler )
+    public void bind( SocketAddress address, ProtocolProvider protocolProvider )
             throws IOException
     {
         if( address == null )
             throw new NullPointerException( "address" );
-        if( defaultHandler == null )
-            throw new NullPointerException( "defaultHandler" );
+        if( protocolProvider == null )
+            throw new NullPointerException( "protocolProvider" );
+        if( ! ( address instanceof VmPipeAddress ) )
+            throw new IllegalArgumentException(
+                                                "address must be VmPipeAddress." );
 
         synchronized( boundHandlers )
         {
@@ -53,15 +53,14 @@
                 throw new IOException( "Address already bound: " + address );
             }
 
-            boundHandlers.put( address, new Entry( address, filterManager,
-                                                   defaultHandler ) );
+            boundHandlers.put( address, new Entry( ( VmPipeAddress ) address,
+                                                   filterManager,
+                                                   protocolProvider
+                                                           .getHandler() ) );
         }
     }
 
-    /**
-     * Unbinds from the specified <code>address</code>.
-     */
-    public void unbind( VmPipeAddress address )
+    public void unbind( SocketAddress address )
     {
         if( address == null )
             throw new NullPointerException( "address" );
@@ -72,18 +71,11 @@
         }
     }
 
-    /**
-     * Adds the specified filter with the specified priority.  Greater priority
-     * value, higher priority, and thus evaluated more earlier.
-     */
     public void addFilter( int priority, ProtocolHandlerFilter filter )
     {
         filterManager.addFilter( priority, filter );
     }
 
-    /**
-     * Removes the specified filter from the filter list.
-     */
     public void removeFilter( ProtocolHandlerFilter filter )
     {
         filterManager.removeFilter( filter );

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeConnector.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeConnector.java?view=diff&rev=124954&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeConnector.java&r1=124953&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeConnector.java&r2=124954
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeConnector.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeConnector.java	Wed Jan 12 00:51:34 2005
@@ -4,21 +4,23 @@
 package org.apache.mina.protocol.vmpipe;
 
 import java.io.IOException;
+import java.net.SocketAddress;
 
-import org.apache.mina.protocol.ProtocolHandler;
+import org.apache.mina.protocol.ProtocolConnector;
 import org.apache.mina.protocol.ProtocolHandlerFilter;
+import org.apache.mina.protocol.ProtocolProvider;
 import org.apache.mina.protocol.ProtocolSession;
 import org.apache.mina.protocol.vmpipe.VmPipeAcceptor.Entry;
 import org.apache.mina.util.ProtocolHandlerFilterManager;
 
 /**
- * Connects to {@link ProtocolHandler}s which is bound on the specified
+ * Connects to {@link ProtocolProvider}s which is bound on the specified
  * {@link VmPipeAddress}.
  * 
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$
  */
-public class VmPipeConnector
+public class VmPipeConnector implements ProtocolConnector
 {
     private final ProtocolHandlerFilterManager filterManager = new ProtocolHandlerFilterManager();
 
@@ -27,40 +29,30 @@
      */
     public VmPipeConnector()
     {
-        filterManager.addFilter( Integer.MIN_VALUE, new VmPipeFilter() );
+        filterManager.addFilter( Integer.MIN_VALUE - 1, new VmPipeFilter() );
     }
 
-    /**
-     * Adds the specified filter with the specified priority.  Greater priority
-     * value, higher priority, and thus evaluated more earlier.  Please note
-     * that priority value must be unique.
-     */
     public void addFilter( int priority, ProtocolHandlerFilter filter )
     {
         filterManager.addFilter( priority, filter );
     }
 
-    /**
-     * Removes the specified filter from the filter list.
-     */
     public void removeFilter( ProtocolHandlerFilter filter )
     {
         filterManager.removeFilter( filter );
     }
 
-    /**
-     * Connects to the specified <code>address</code>.  If communication starts
-     * successfully, events are fired to the specified
-     * <code>defaultHandler</code>.  This method blocks.
-     */
-    public ProtocolSession connect( VmPipeAddress address,
-                                   ProtocolHandler defaultHandler )
+    public ProtocolSession connect( SocketAddress address,
+                                   ProtocolProvider protocolProvider )
             throws IOException
     {
         if( address == null )
             throw new NullPointerException( "address" );
-        if( defaultHandler == null )
-            throw new NullPointerException( "defaultHandler" );
+        if( protocolProvider == null )
+            throw new NullPointerException( "protocolProvider" );
+        if( ! ( address instanceof VmPipeAddress ) )
+            throw new IllegalArgumentException(
+                                                "address must be VmPipeAddress." );
 
         Entry entry = ( Entry ) VmPipeAcceptor.boundHandlers.get( address );
         if( entry == null )
@@ -71,10 +63,18 @@
                                                    AnonymousVmPipeAddress.INSTANCE,
                                                    entry.address,
                                                    filterManager,
-                                                   defaultHandler,
+                                                   protocolProvider
+                                                           .getHandler(),
                                                    entry.filterManager,
                                                    entry.handler );
         VmPipeIdleStatusChecker.INSTANCE.addSession( session );
         return session;
+    }
+
+    public ProtocolSession connect( SocketAddress address, int timeout,
+                                   ProtocolProvider protocolProvider )
+            throws IOException
+    {
+        return connect( address, protocolProvider );
     }
 }

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java?view=diff&rev=124954&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java&r1=124953&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java&r2=124954
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java	Wed Jan 12 00:51:34 2005
@@ -26,7 +26,7 @@
 import org.apache.mina.io.IoHandler;
 import org.apache.mina.io.IoHandlerFilter;
 import org.apache.mina.io.IoSession;
-import org.apache.mina.protocol.IoAdapter;
+import org.apache.mina.protocol.io.IoAdapter;
 
 /**
  * Manages the list of {@link IoHandlerFilter}s.

Modified: incubator/directory/network/trunk/mina/src/test/org/apache/mina/examples/echoserver/Test.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/test/org/apache/mina/examples/echoserver/Test.java?view=diff&rev=124954&p1=incubator/directory/network/trunk/mina/src/test/org/apache/mina/examples/echoserver/Test.java&r1=124953&p2=incubator/directory/network/trunk/mina/src/test/org/apache/mina/examples/echoserver/Test.java&r2=124954
==============================================================================
--- incubator/directory/network/trunk/mina/src/test/org/apache/mina/examples/echoserver/Test.java	(original)
+++ incubator/directory/network/trunk/mina/src/test/org/apache/mina/examples/echoserver/Test.java	Wed Jan 12 00:51:34 2005
@@ -11,7 +11,7 @@
 
 import org.apache.commons.net.EchoTCPClient;
 import org.apache.commons.net.EchoUDPClient;
-import org.apache.mina.io.Acceptor;
+import org.apache.mina.io.IoAcceptor;
 import org.apache.mina.io.datagram.DatagramAcceptor;
 import org.apache.mina.io.filter.IoThreadPoolFilter;
 import org.apache.mina.io.socket.SocketAcceptor;
@@ -26,9 +26,9 @@
 {
     private static final int PORT = 8080;
 
-    private Acceptor acceptor;
+    private IoAcceptor acceptor;
 
-    private Acceptor datagramAcceptor;
+    private IoAcceptor datagramAcceptor;
 
     private IoThreadPoolFilter threadPoolFilter;
 

Mime
View raw message