directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r123602 - in incubator/directory/network/trunk/mina/src: examples/org/apache/mina/examples/echoserver examples/org/apache/mina/examples/netcat examples/org/apache/mina/examples/reverser examples/org/apache/mina/examples/vmpipe java/org/apache/mina/common 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/vmpipe java/org/apache/mina/registry
Date Wed, 29 Dec 2004 07:55:12 GMT
Author: trustin
Date: Tue Dec 28 23:55:11 2004
New Revision: 123602

URL: http://svn.apache.org/viewcvs?view=rev&rev=123602
Log:
 * Added: in-VM pipe transport type support
 * Fixed: writtenBytes and readBytes properties were not updated.
 * Fixed: idle status of SocketSessions are not cleared.
 * Reformatted source code
Added:
   incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/vmpipe/
   incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/vmpipe/Main.java   (contents, props changed)
   incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/vmpipe/TennisBall.java   (contents, props changed)
   incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/vmpipe/TennisPlayer.java   (contents, props changed)
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/AnonymousVmPipeAddress.java   (contents, props changed)
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeAcceptor.java   (contents, props changed)
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeAddress.java   (contents, props changed)
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeConnector.java   (contents, props changed)
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeFilter.java   (contents, props changed)
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeIdleStatusChecker.java   (contents, props changed)
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java   (contents, props changed)
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeSessionConfig.java   (contents, props changed)
Modified:
   incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/EchoProtocolHandler.java
   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/netcat/Main.java
   incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/netcat/NetCatProtocolHandler.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/reverser/ReverseProtocolHandler.java
   incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/ReverseProtocolProvider.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/TransportType.java
   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/io/DefaultExceptionMonitor.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/ExceptionMonitor.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/socket/SocketIoProcessor.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketSession.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolDecoderOutput.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolEncoderOutput.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolSession.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/registry/ServiceRegistry.java

Modified: incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/EchoProtocolHandler.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/EchoProtocolHandler.java?view=diff&rev=123602&p1=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/EchoProtocolHandler.java&r1=123601&p2=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/EchoProtocolHandler.java&r2=123602
==============================================================================
--- incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/EchoProtocolHandler.java	(original)
+++ incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/EchoProtocolHandler.java	Tue Dec 28 23:55:11 2004
@@ -59,7 +59,7 @@
 
     public void dataRead( IoSession session, ByteBuffer rb )
     {
-    	// Write the received data back to remote peer
+        // Write the received data back to remote peer
         ByteBuffer wb = ByteBuffer.allocate( rb.remaining() );
         wb.put( rb );
         wb.flip();

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=123602&p1=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/Main.java&r1=123601&p2=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/Main.java&r2=123602
==============================================================================
--- 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	Tue Dec 28 23:55:11 2004
@@ -40,8 +40,8 @@
         // Create a I/O thread pool filter 
         IoThreadPoolFilter threadPoolFilter = new IoThreadPoolFilter();
         threadPoolFilter.start(); // and start it
-        
-    	// Create a TCP/IP acceptor
+
+        // Create a TCP/IP acceptor
         Acceptor acceptor = new SocketAcceptor();
 
         // Add thread pool filter
@@ -54,10 +54,10 @@
 
         // Create a UDP/IP acceptor
         Acceptor datagramAcceptor = new DatagramAcceptor();
-        
+
         // Add thread pool filter
         datagramAcceptor.addFilter( Integer.MAX_VALUE, threadPoolFilter );
-        
+
         // Bind
         datagramAcceptor.bind( new InetSocketAddress( PORT ),
                                new EchoProtocolHandler() );

Modified: incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/netcat/Main.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/netcat/Main.java?view=diff&rev=123602&p1=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/netcat/Main.java&r1=123601&p2=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/netcat/Main.java&r2=123602
==============================================================================
--- incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/netcat/Main.java	(original)
+++ incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/netcat/Main.java	Tue Dec 28 23:55:11 2004
@@ -43,11 +43,11 @@
 
         // Create TCP/IP connector.
         SocketConnector connector = new SocketConnector();
-        
+
         // Add I/O thread pool filter.
         // MINA runs in a single thread if you don't add this filter.
         connector.addFilter( Integer.MAX_VALUE, new IoThreadPoolFilter() );
-        
+
         // Start communication.
         connector.connect( new InetSocketAddress( args[ 0 ], Integer
                 .parseInt( args[ 1 ] ) ), 60, new NetCatProtocolHandler() );

Modified: incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/netcat/NetCatProtocolHandler.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/netcat/NetCatProtocolHandler.java?view=diff&rev=123602&p1=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/netcat/NetCatProtocolHandler.java&r1=123601&p2=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/netcat/NetCatProtocolHandler.java&r2=123602
==============================================================================
--- incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/netcat/NetCatProtocolHandler.java	(original)
+++ incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/netcat/NetCatProtocolHandler.java	Tue Dec 28 23:55:11 2004
@@ -50,8 +50,8 @@
     public void sessionIdle( IoSession session, IdleStatus status )
     {
         // Close the connection if reader is idle.
-        if ( status == IdleStatus.READER_IDLE )
-    	    session.close();
+        if( status == IdleStatus.READER_IDLE )
+            session.close();
     }
 
     public void dataRead( IoSession session, ByteBuffer buf )

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=123602&p1=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/Main.java&r1=123601&p2=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/Main.java&r2=123602
==============================================================================
--- 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	Tue Dec 28 23:55:11 2004
@@ -39,19 +39,19 @@
 
     public static void main( String[] args ) throws Exception
     {
-    	// Create I/O and Protocol thread pool filter.
-    	// I/O thread pool performs encoding and decoding of messages.
-    	// Protocol thread pool performs actual protocol flow.
+        // Create I/O and Protocol thread pool filter.
+        // I/O thread pool performs encoding and decoding of messages.
+        // Protocol thread pool performs actual protocol flow.
         IoThreadPoolFilter ioThreadPoolFilter = new IoThreadPoolFilter();
         ProtocolThreadPoolFilter protocolThreadPoolFilter = new ProtocolThreadPoolFilter();
-        
+
         // and start both.
         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();
 

Modified: incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/ReverseProtocolHandler.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/ReverseProtocolHandler.java?view=diff&rev=123602&p1=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/ReverseProtocolHandler.java&r1=123601&p2=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/ReverseProtocolHandler.java&r2=123602
==============================================================================
--- incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/ReverseProtocolHandler.java	(original)
+++ incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/ReverseProtocolHandler.java	Tue Dec 28 23:55:11 2004
@@ -51,7 +51,7 @@
     {
         System.out.println( session.getRemoteAddress() + " EXCEPTION" );
         cause.printStackTrace( System.out );
-        
+
         // Close connection when unexpected exception is caught.
         session.close();
     }
@@ -74,7 +74,7 @@
 
     public void messageSent( ProtocolSession session, Object message )
     {
-    	// Invoked the reversed string is actually written to socket channel.
+        // Invoked the reversed string is actually written to socket channel.
         System.out.println( session.getRemoteAddress() + " SENT: " + message );
     }
 }

Modified: incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/ReverseProtocolProvider.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/ReverseProtocolProvider.java?view=diff&rev=123602&p1=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/ReverseProtocolProvider.java&r1=123601&p2=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/ReverseProtocolProvider.java&r2=123602
==============================================================================
--- incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/ReverseProtocolProvider.java	(original)
+++ incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/ReverseProtocolProvider.java	Tue Dec 28 23:55:11 2004
@@ -41,13 +41,13 @@
     {
         public ProtocolEncoder newEncoder()
         {
-        	// Create a new encoder.
+            // Create a new encoder.
             return new TextLineEncoder();
         }
 
         public ProtocolDecoder newDecoder()
         {
-        	// Create a new decoder.
+            // Create a new decoder.
             return new TextLineDecoder();
         }
     };

Added: incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/vmpipe/Main.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/vmpipe/Main.java?view=auto&rev=123602
==============================================================================
--- (empty file)
+++ incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/vmpipe/Main.java	Tue Dec 28 23:55:11 2004
@@ -0,0 +1,43 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.examples.vmpipe;
+
+import java.io.IOException;
+
+import org.apache.mina.protocol.ProtocolSession;
+import org.apache.mina.protocol.filter.ProtocolThreadPoolFilter;
+import org.apache.mina.protocol.vmpipe.VmPipeAcceptor;
+import org.apache.mina.protocol.vmpipe.VmPipeAddress;
+import org.apache.mina.protocol.vmpipe.VmPipeConnector;
+
+/**
+ * TODO Document me.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public class Main
+{
+
+    public static void main( String[] args ) throws IOException
+    {
+        VmPipeAddress address = new VmPipeAddress( 8080 );
+
+        // Prepare thread pool
+        ProtocolThreadPoolFilter threadPool = new ProtocolThreadPoolFilter();
+        threadPool.start();
+
+        // set up server
+        VmPipeAcceptor acceptor = new VmPipeAcceptor();
+        acceptor.bind( address, new TennisPlayer() );
+        acceptor.addFilter( 0, threadPool );
+
+        // send ping message
+        VmPipeConnector connector = new VmPipeConnector();
+        ProtocolSession session = connector.connect( address,
+                                                     new TennisPlayer() );
+
+        session.write( new TennisBall( 10 ) );
+    }
+}
\ No newline at end of file

Added: incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/vmpipe/TennisBall.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/vmpipe/TennisBall.java?view=auto&rev=123602
==============================================================================
--- (empty file)
+++ incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/vmpipe/TennisBall.java	Tue Dec 28 23:55:11 2004
@@ -0,0 +1,50 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.examples.vmpipe;
+
+/**
+ * TODO Document me.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public class TennisBall
+{
+    private final boolean ping;
+
+    private final int ttl;
+
+    public TennisBall( int ttl )
+    {
+        this( ttl, true );
+    }
+
+    private TennisBall( int ttl, boolean ping )
+    {
+        this.ttl = ttl;
+        this.ping = ping;
+    }
+
+    public int getTTL()
+    {
+        return ttl;
+    }
+
+    public TennisBall stroke()
+    {
+        return new TennisBall( ttl - 1, !ping );
+    }
+
+    public String toString()
+    {
+        if( ping )
+        {
+            return "PING (" + ttl + ")";
+        }
+        else
+        {
+            return "PONG (" + ttl + ")";
+        }
+    }
+}
\ No newline at end of file

Added: incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/vmpipe/TennisPlayer.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/vmpipe/TennisPlayer.java?view=auto&rev=123602
==============================================================================
--- (empty file)
+++ incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/vmpipe/TennisPlayer.java	Tue Dec 28 23:55:11 2004
@@ -0,0 +1,52 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.examples.vmpipe;
+
+import org.apache.mina.protocol.ProtocolHandlerAdapter;
+import org.apache.mina.protocol.ProtocolSession;
+
+/**
+ * TODO Document me.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public class TennisPlayer extends ProtocolHandlerAdapter
+{
+    private static int nextId = 0;
+
+    private final int id = nextId++;
+
+    public void sessionOpened( ProtocolSession session )
+    {
+        System.out.println( "Player-" + id + ": READY" );
+    }
+
+    public void sessionClosed( ProtocolSession session )
+    {
+        System.out.println( "Player-" + id + ": QUIT" );
+    }
+
+    public void messageReceived( ProtocolSession session, Object message )
+    {
+        System.out.println( "Player-" + id + ": RCVD " + message );
+
+        TennisBall ball = ( TennisBall ) message;
+        ball = ball.stroke();
+        if( ball.getTTL() > 0 )
+        {
+            session.write( ball );
+        }
+        else
+        {
+            System.out.println( "Player-" + id + ": LOSE" );
+            session.close();
+        }
+    }
+
+    public void messageSent( ProtocolSession session, Object message )
+    {
+        System.out.println( "Player-" + id + ": SENT " + message );
+    }
+}
\ No newline at end of file

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java?view=diff&rev=123602&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java&r1=123601&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java&r2=123602
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java	Tue Dec 28 23:55:11 2004
@@ -491,12 +491,12 @@
     {
         return buf.asDoubleBuffer();
     }
-    
+
     /**
      * Returns hexdump of this buffer.
      */
     public String getHexDump()
     {
-        return ByteBufferHexDumper.getHexdump(this);
+        return ByteBufferHexDumper.getHexdump( this );
     }
 }

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/TransportType.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/TransportType.java?view=diff&rev=123602&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/TransportType.java&r1=123601&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/TransportType.java&r2=123602
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/TransportType.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/TransportType.java	Tue Dec 28 23:55:11 2004
@@ -26,20 +26,27 @@
  */
 public class TransportType
 {
-	/**
-	 * Transport type: TCP/IP (<code>SocketChannel</code>)
-	 */
+    /**
+     * Transport type: TCP/IP (<code>SocketChannel</code>)
+     */
     public static final TransportType SOCKET = new TransportType( "SOCKET",
                                                                   false );
 
-	/**
-	 * Transport type: UDP/IP (<code>DatagramChannel</code>)
-	 */
-    public static final TransportType DATAGRAM = new TransportType( "DATAGRAM",
+    /**
+     * Transport type: UDP/IP (<code>DatagramChannel</code>)
+     */
+    public static final TransportType DATAGRAM = new TransportType(
+                                                                    "DATAGRAM",
                                                                     true );
 
+    /**
+     * Transport type: VM pipe (direct message exchange)
+     */
+    public static final TransportType VM_PIPE = new TransportType( "VM_PIPE",
+                                                                   false );
+
     private final String strVal;
-    
+
     private final boolean stateless;
 
     /**
@@ -57,9 +64,9 @@
      */
     public boolean isStateless()
     {
-    	return stateless;
+        return stateless;
     }
-    
+
     public String toString()
     {
         return strVal;

Modified: 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=diff&rev=123602&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Acceptor.java&r1=123601&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Acceptor.java&r2=123602
==============================================================================
--- 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/Acceptor.java	Tue Dec 28 23:55:11 2004
@@ -21,7 +21,6 @@
 import java.io.IOException;
 import java.net.SocketAddress;
 
-
 /**
  * Accepts incoming connection, communicates with clients, and fires events to
  * {@link IoHandler}s.

Modified: 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=diff&rev=123602&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Connector.java&r1=123601&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Connector.java&r2=123602
==============================================================================
--- 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/Connector.java	Tue Dec 28 23:55:11 2004
@@ -21,7 +21,6 @@
 import java.io.IOException;
 import java.net.SocketAddress;
 
-
 /**
  * Connects to endpoint, communicates with the server, and fires events to
  * {@link IoHandler}s.

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/DefaultExceptionMonitor.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/DefaultExceptionMonitor.java?view=diff&rev=123602&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/DefaultExceptionMonitor.java&r1=123601&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/DefaultExceptionMonitor.java&r2=123602
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/DefaultExceptionMonitor.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/DefaultExceptionMonitor.java	Tue Dec 28 23:55:11 2004
@@ -22,7 +22,6 @@
 import java.text.DateFormat;
 import java.util.Date;
 
-
 /**
  * A default {@link ExceptionMonitor} implementation.  It logs uncaught
  * exceptions using <a href="http://jakarta.apache.org/commons/logging/">Apache

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/ExceptionMonitor.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/ExceptionMonitor.java?view=diff&rev=123602&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/ExceptionMonitor.java&r1=123601&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/ExceptionMonitor.java&r2=123602
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/ExceptionMonitor.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/ExceptionMonitor.java	Tue Dec 28 23:55:11 2004
@@ -18,7 +18,6 @@
  */
 package org.apache.mina.io;
 
-
 /**
  * Monitors uncaught exceptions.  {@link #exceptionCaught(Object, Throwable)} is
  * invoked when there are any uncaught exceptions.

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=123602&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java&r1=123601&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java&r2=123602
==============================================================================
--- 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	Tue Dec 28 23:55:11 2004
@@ -258,6 +258,7 @@
                 newBuf.put( readBuf );
                 newBuf.flip();
 
+                session.increaseReadBytes( newBuf.remaining() );
                 filterManager.fireDataRead( session, newBuf );
             }
         }
@@ -353,6 +354,8 @@
                     writeBufferQueue.pop();
                     writeMarkerQueue.pop();
                 }
+
+                session.increaseWrittenBytes( writtenBytes );
                 session.getFilterManager().fireDataWritten( session, marker );
             }
         }

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java?view=diff&rev=123602&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java&r1=123601&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java&r2=123602
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketIoProcessor.java	Tue Dec 28 23:55:11 2004
@@ -250,7 +250,8 @@
             }
 
             session.increaseReadBytes( readBytes );
-
+            session.setIdle( IdleStatus.BOTH_IDLE, false );
+            session.setIdle( IdleStatus.READER_IDLE, false );
             if( ret >= 0 )
             {
                 if( readBytes > 0 )
@@ -337,7 +338,7 @@
         if( idleTime > 0 && !session.isIdle( status )
             && ( currentTime - lastIoTime ) >= idleTime )
         {
-            session.setIdle( status );
+            session.setIdle( status, true );
             session.getFilterManager().fireSessionIdle( session, status );
         }
     }
@@ -419,9 +420,10 @@
                 continue;
             }
 
+            int writtenBytes = 0;
             try
             {
-                ch.write( buf.buf() );
+                writtenBytes = ch.write( buf.buf() );
             }
             finally
             {
@@ -437,6 +439,13 @@
                 {
                     key.interestOps( key.interestOps()
                                      & ( ~SelectionKey.OP_WRITE ) );
+                }
+
+                if( writtenBytes > 0 )
+                {
+                    session.increaseWrittenBytes( writtenBytes );
+                    session.setIdle( IdleStatus.BOTH_IDLE, false );
+                    session.setIdle( IdleStatus.WRITER_IDLE, false );
                 }
             }
         }

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketSession.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketSession.java?view=diff&rev=123602&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketSession.java&r1=123601&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketSession.java&r2=123602
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketSession.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/SocketSession.java	Tue Dec 28 23:55:11 2004
@@ -240,14 +240,14 @@
         throw new IllegalArgumentException( "Unknown idle status: " + status );
     }
 
-    void setIdle( IdleStatus status )
+    void setIdle( IdleStatus status, boolean value )
     {
         if( status == IdleStatus.BOTH_IDLE )
-            idleForBoth = true;
+            idleForBoth = value;
         else if( status == IdleStatus.READER_IDLE )
-            idleForRead = true;
+            idleForRead = value;
         else if( status == IdleStatus.WRITER_IDLE )
-            idleForWrite = true;
+            idleForWrite = value;
         else
             throw new IllegalArgumentException( "Unknown idle status: "
                                                 + status );

Modified: 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=diff&rev=123602&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java&r1=123601&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java&r2=123602
==============================================================================
--- 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/IoAdapter.java	Tue Dec 28 23:55:11 2004
@@ -167,10 +167,10 @@
                 }
             }
             catch( ProtocolViolationException pve )
-			{
-            	pve.setBuffer(in);
-            	filterManager.fireExceptionCaught( psession, pve );
-			}
+            {
+                pve.setBuffer( in );
+                filterManager.fireExceptionCaught( psession, pve );
+            }
             catch( Throwable t )
             {
                 filterManager.fireExceptionCaught( psession, t );
@@ -338,15 +338,15 @@
         {
             return session.getLocalAddress();
         }
-        
+
         public long getReadBytes()
         {
-        	return session.getReadBytes();
+            return session.getReadBytes();
         }
 
         public long getWrittenBytes()
         {
-        	return session.getWrittenBytes();
+            return session.getWrittenBytes();
         }
 
         public long getLastIoTime()

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolDecoderOutput.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolDecoderOutput.java?view=diff&rev=123602&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolDecoderOutput.java&r1=123601&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolDecoderOutput.java&r2=123602
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolDecoderOutput.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolDecoderOutput.java	Tue Dec 28 23:55:11 2004
@@ -28,12 +28,12 @@
  */
 public interface ProtocolDecoderOutput
 {
-	/**
+    /**
      * Callback for {@link ProtocolDecoder} to generate decoded messages.
      * {@link ProtocolDecoder} must call {@link #write(Object)} for each
      * decoded messages.
      * 
      * @param message the decoded message
-	 */
+     */
     void write( Object message );
 }

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolEncoderOutput.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolEncoderOutput.java?view=diff&rev=123602&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolEncoderOutput.java&r1=123601&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolEncoderOutput.java&r2=123602
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolEncoderOutput.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolEncoderOutput.java	Tue Dec 28 23:55:11 2004
@@ -30,12 +30,12 @@
  */
 public interface ProtocolEncoderOutput
 {
-	/**
-	 * Callback for {@link ProtocolEncoder} to generate encoded
-	 * {@link ByteBuffer}s. {@link ProtocolEncoder} must call
-	 * {@link #write(ByteBuffer)} for each decoded messages.
-	 * 
-	 * @param buf the buffer which contains encoded data
-	 */
+    /**
+     * Callback for {@link ProtocolEncoder} to generate encoded
+     * {@link ByteBuffer}s. {@link ProtocolEncoder} must call
+     * {@link #write(ByteBuffer)} for each decoded messages.
+     * 
+     * @param buf the buffer which contains encoded data
+     */
     void write( ByteBuffer buf );
 }

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolSession.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolSession.java?view=diff&rev=123602&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolSession.java&r1=123601&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolSession.java&r2=123602
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolSession.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolSession.java	Tue Dec 28 23:55:11 2004
@@ -38,9 +38,9 @@
  */
 public interface ProtocolSession
 {
-	/**
-	 * Returns the {@link ProtocolHandler} which handles this session.
-	 */
+    /**
+     * Returns the {@link ProtocolHandler} which handles this session.
+     */
     ProtocolHandler getHandler();
 
     /**

Added: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/AnonymousVmPipeAddress.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/AnonymousVmPipeAddress.java?view=auto&rev=123602
==============================================================================
--- (empty file)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/AnonymousVmPipeAddress.java	Tue Dec 28 23:55:11 2004
@@ -0,0 +1,48 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.protocol.vmpipe;
+
+import java.net.SocketAddress;
+
+/**
+ * A {@link SocketAddress} which represents anonymous in-VM pipe port.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+class AnonymousVmPipeAddress extends SocketAddress implements Comparable
+{
+    static final AnonymousVmPipeAddress INSTANCE = new AnonymousVmPipeAddress();
+
+    /**
+     * Creates a new instance with the specifid port number.
+     */
+    private AnonymousVmPipeAddress()
+    {
+    }
+
+    public int hashCode()
+    {
+        return 1432482932;
+    }
+
+    public boolean equals( Object o )
+    {
+        if( o == null )
+            return false;
+        if( this == o )
+            return true;
+        return o instanceof AnonymousVmPipeAddress;
+    }
+
+    public int compareTo( Object o )
+    {
+        return this.hashCode() - ( ( AnonymousVmPipeAddress ) o ).hashCode();
+    }
+
+    public String toString()
+    {
+        return "vm:anonymous";
+    }
+}
\ No newline at end of file

Added: 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=auto&rev=123602
==============================================================================
--- (empty file)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeAcceptor.java	Tue Dec 28 23:55:11 2004
@@ -0,0 +1,97 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.protocol.vmpipe;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.mina.protocol.ProtocolHandler;
+import org.apache.mina.protocol.ProtocolHandlerFilter;
+import org.apache.mina.util.ProtocolHandlerFilterManager;
+
+/**
+ * Binds the specified {@link ProtocolHandler} to the specified
+ * {@link VmPipeAddress}.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public class VmPipeAcceptor
+{
+    static final Map boundHandlers = new HashMap();
+
+    private final ProtocolHandlerFilterManager filterManager = new ProtocolHandlerFilterManager();
+
+    public VmPipeAcceptor()
+    {
+        filterManager.addFilter( Integer.MIN_VALUE, new VmPipeFilter() );
+    }
+
+    public void bind( VmPipeAddress address, ProtocolHandler defaultHandler )
+            throws IOException
+    {
+        if( address == null )
+            throw new NullPointerException( "address" );
+        if( defaultHandler == null )
+            throw new NullPointerException( "defaultHandler" );
+
+        synchronized( boundHandlers )
+        {
+            if( boundHandlers.containsKey( address ) )
+            {
+                throw new IOException( "Address already bound: " + address );
+            }
+
+            boundHandlers.put( address, new Entry( address, filterManager,
+                                                   defaultHandler ) );
+        }
+    }
+
+    public void unbind( VmPipeAddress address )
+    {
+        if( address == null )
+            throw new NullPointerException( "address" );
+
+        synchronized( boundHandlers )
+        {
+            boundHandlers.remove( address );
+        }
+    }
+
+    /**
+     * 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 );
+    }
+
+    static class Entry
+    {
+        final VmPipeAddress address;
+
+        final ProtocolHandlerFilterManager filterManager;
+
+        final ProtocolHandler handler;
+
+        private Entry( VmPipeAddress address,
+                      ProtocolHandlerFilterManager filterManager,
+                      ProtocolHandler handler )
+        {
+            this.address = address;
+            this.filterManager = filterManager;
+            this.handler = handler;
+        }
+    }
+}
\ No newline at end of file

Added: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeAddress.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeAddress.java?view=auto&rev=123602
==============================================================================
--- (empty file)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeAddress.java	Tue Dec 28 23:55:11 2004
@@ -0,0 +1,63 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.protocol.vmpipe;
+
+import java.net.SocketAddress;
+
+/**
+ * A {@link SocketAddress} which represents in-VM pipe port number.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public class VmPipeAddress extends SocketAddress implements Comparable
+{
+    private final int port;
+
+    /**
+     * Creates a new instance with the specifid port number.
+     */
+    public VmPipeAddress( int port )
+    {
+        this.port = port;
+    }
+
+    /**
+     * Returns the port number.
+     */
+    public int getPort()
+    {
+        return port;
+    }
+
+    public int hashCode()
+    {
+        return port;
+    }
+
+    public boolean equals( Object o )
+    {
+        if( o == null )
+            return false;
+        if( this == o )
+            return true;
+        if( o instanceof VmPipeAddress )
+        {
+            VmPipeAddress that = ( VmPipeAddress ) o;
+            return this.port == that.port;
+        }
+
+        return false;
+    }
+
+    public int compareTo( Object o )
+    {
+        return this.port - ( ( VmPipeAddress ) o ).port;
+    }
+
+    public String toString()
+    {
+        return "vm:" + port;
+    }
+}
\ No newline at end of file

Added: 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=auto&rev=123602
==============================================================================
--- (empty file)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeConnector.java	Tue Dec 28 23:55:11 2004
@@ -0,0 +1,53 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.protocol.vmpipe;
+
+import java.io.IOException;
+
+import org.apache.mina.protocol.ProtocolHandler;
+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
+ * {@link VmPipeAddress}.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public class VmPipeConnector
+{
+    private final ProtocolHandlerFilterManager filterManager = new ProtocolHandlerFilterManager();
+
+    public VmPipeConnector()
+    {
+        filterManager.addFilter( Integer.MIN_VALUE, new VmPipeFilter() );
+    }
+
+    public ProtocolSession connect( VmPipeAddress address,
+                                   ProtocolHandler defaultHandler )
+            throws IOException
+    {
+        if( address == null )
+            throw new NullPointerException( "address" );
+        if( defaultHandler == null )
+            throw new NullPointerException( "defaultHandler" );
+
+        Entry entry = ( Entry ) VmPipeAcceptor.boundHandlers.get( address );
+        if( entry == null )
+            throw new IOException( "Endpoint unavailable: " + address );
+
+        VmPipeSession session = new VmPipeSession(
+                                                   new Object(), // lock
+                                                   AnonymousVmPipeAddress.INSTANCE,
+                                                   entry.address,
+                                                   filterManager,
+                                                   defaultHandler,
+                                                   entry.filterManager,
+                                                   entry.handler );
+        VmPipeIdleStatusChecker.INSTANCE.addSession( session );
+        return session;
+    }
+}
\ No newline at end of file

Added: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeFilter.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeFilter.java?view=auto&rev=123602
==============================================================================
--- (empty file)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeFilter.java	Tue Dec 28 23:55:11 2004
@@ -0,0 +1,52 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.protocol.vmpipe;
+
+import org.apache.mina.protocol.ProtocolHandler;
+import org.apache.mina.protocol.ProtocolHandlerFilterAdapter;
+import org.apache.mina.protocol.ProtocolSession;
+
+/**
+ * Sets last(Read|Write)Time for {@link VmPipeSession}s. 
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+class VmPipeFilter extends ProtocolHandlerFilterAdapter
+{
+    public void messageReceived( ProtocolHandler nextHandler,
+                                ProtocolSession session, Object message )
+    {
+        VmPipeSession vps = ( VmPipeSession ) session;
+
+        vps.bothIdle = vps.readerIdle = false;
+        vps.lastReadTime = System.currentTimeMillis();
+
+        // fire messageSent event first
+        vps.remoteFilterManager.fireMessageSent( vps.remoteSession, message );
+
+        // and then messageReceived
+        nextHandler.messageReceived( session, message );
+    }
+
+    public void messageSent( ProtocolHandler nextHandler,
+                            ProtocolSession session, Object message )
+    {
+        VmPipeSession vps = ( VmPipeSession ) session;
+        vps.bothIdle = vps.writerIdle = false;
+        vps.lastWriteTime = System.currentTimeMillis();
+
+        nextHandler.messageSent( session, message );
+    }
+
+    public void sessionClosed( ProtocolHandler nextHandler,
+                              ProtocolSession session )
+    {
+        VmPipeSession vps = ( VmPipeSession ) session;
+        nextHandler.sessionClosed( session );
+
+        if( vps.remoteSession.isConnected() )
+            vps.remoteFilterManager.fireSessionClosed( vps.remoteSession );
+    }
+}
\ No newline at end of file

Added: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeIdleStatusChecker.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeIdleStatusChecker.java?view=auto&rev=123602
==============================================================================
--- (empty file)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeIdleStatusChecker.java	Tue Dec 28 23:55:11 2004
@@ -0,0 +1,116 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.protocol.vmpipe;
+
+import java.util.IdentityHashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.SessionConfig;
+
+/**
+ * TODO Document me.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+class VmPipeIdleStatusChecker
+{
+    static final VmPipeIdleStatusChecker INSTANCE = new VmPipeIdleStatusChecker();
+
+    private final Map sessions = new IdentityHashMap(); // will use as a set
+
+    private final Worker worker = new Worker();
+
+    private VmPipeIdleStatusChecker()
+    {
+        worker.start();
+    }
+
+    void addSession( VmPipeSession session )
+    {
+        synchronized( sessions )
+        {
+            sessions.put( session, session );
+        }
+    }
+
+    private class Worker extends Thread
+    {
+
+        public void run()
+        {
+            for( ;; )
+            {
+                try
+                {
+                    Thread.sleep( 1000 );
+                }
+                catch( InterruptedException e )
+                {
+                }
+
+                long currentTime = System.currentTimeMillis();
+
+                synchronized( sessions )
+                {
+                    Iterator it = sessions.keySet().iterator();
+                    while( it.hasNext() )
+                    {
+                        VmPipeSession session = ( VmPipeSession ) it.next();
+                        if( !session.isConnected() )
+                        {
+                            it.remove();
+                        }
+                        else
+                        {
+                            long idleTime;
+                            SessionConfig config = session.getConfig();
+
+                            if( !session.bothIdle )
+                            {
+                                idleTime = config
+                                        .getIdleTimeInMillis( IdleStatus.BOTH_IDLE );
+                                session.bothIdle = idleTime > 0L
+                                                   && ( currentTime - session.lastReadTime ) > idleTime;
+                                if( session.bothIdle )
+                                    session.localFilterManager
+                                            .fireSessionIdle(
+                                                              session,
+                                                              IdleStatus.BOTH_IDLE );
+                            }
+
+                            if( !session.readerIdle )
+                            {
+                                idleTime = config
+                                        .getIdleTimeInMillis( IdleStatus.READER_IDLE );
+                                session.readerIdle = idleTime > 0L
+                                                     && ( currentTime - session.lastReadTime ) > idleTime;
+                                if( session.readerIdle )
+                                    session.localFilterManager
+                                            .fireSessionIdle(
+                                                              session,
+                                                              IdleStatus.READER_IDLE );
+                            }
+
+                            if( !session.writerIdle )
+                            {
+                                idleTime = config
+                                        .getIdleTimeInMillis( IdleStatus.WRITER_IDLE );
+                                session.writerIdle = idleTime > 0L
+                                                     && ( currentTime - session.lastReadTime ) > idleTime;
+                                if( session.writerIdle )
+                                    session.localFilterManager
+                                            .fireSessionIdle(
+                                                              session,
+                                                              IdleStatus.WRITER_IDLE );
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
\ No newline at end of file

Added: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java?view=auto&rev=123602
==============================================================================
--- (empty file)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java	Tue Dec 28 23:55:11 2004
@@ -0,0 +1,203 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.protocol.vmpipe;
+
+import java.net.SocketAddress;
+
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.SessionConfig;
+import org.apache.mina.common.TransportType;
+import org.apache.mina.protocol.ProtocolDecoder;
+import org.apache.mina.protocol.ProtocolEncoder;
+import org.apache.mina.protocol.ProtocolHandler;
+import org.apache.mina.protocol.ProtocolSession;
+import org.apache.mina.util.ProtocolHandlerFilterManager;
+
+/**
+ * TODO Document me.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+class VmPipeSession implements ProtocolSession
+{
+    private final Object lock;
+
+    private final SocketAddress localAddress;
+
+    private final SocketAddress remoteAddress;
+
+    private final ProtocolHandler localHandler;
+
+    final ProtocolHandlerFilterManager localFilterManager;
+
+    final ProtocolHandlerFilterManager remoteFilterManager;
+
+    final VmPipeSession remoteSession;
+
+    private final VmPipeSessionConfig config = new VmPipeSessionConfig();
+
+    private Object attachment;
+
+    boolean closed;
+
+    long lastReadTime;
+
+    long lastWriteTime;
+
+    boolean bothIdle;
+
+    boolean readerIdle;
+
+    boolean writerIdle;
+
+    /**
+     * Constructor for client-side session.
+     */
+    VmPipeSession( Object lock, SocketAddress localAddress,
+                  SocketAddress remoteAddress,
+                  ProtocolHandlerFilterManager localFilterManager,
+                  ProtocolHandler localHandler,
+                  ProtocolHandlerFilterManager remoteFilterManager,
+                  ProtocolHandler remoteHandler )
+    {
+        this.lock = lock;
+        this.localAddress = localAddress;
+        this.localHandler = localHandler;
+        this.localFilterManager = localFilterManager;
+        this.remoteAddress = remoteAddress;
+        this.remoteFilterManager = remoteFilterManager;
+
+        remoteSession = new VmPipeSession( this, remoteHandler );
+
+        remoteFilterManager.fireSessionOpened( remoteSession );
+        localFilterManager.fireSessionOpened( this );
+    }
+
+    /**
+     * Constructor for server-side session.
+     */
+    VmPipeSession( VmPipeSession remoteSession, ProtocolHandler localHandler )
+    {
+        this.lock = remoteSession.lock;
+        this.localAddress = remoteSession.remoteAddress;
+        this.localHandler = localHandler;
+        this.localFilterManager = remoteSession.remoteFilterManager;
+        this.remoteAddress = remoteSession.localAddress;
+        this.remoteFilterManager = remoteSession.localFilterManager;
+
+        this.remoteSession = remoteSession;
+    }
+
+    public ProtocolHandler getHandler()
+    {
+        return localHandler;
+    }
+
+    public ProtocolEncoder getEncoder()
+    {
+        return null;
+    }
+
+    public ProtocolDecoder getDecoder()
+    {
+        return null;
+    }
+
+    public void close()
+    {
+        synchronized( lock )
+        {
+            if( remoteSession.closed )
+                return;
+            remoteSession.closed = true;
+            remoteFilterManager.fireSessionClosed( remoteSession );
+        }
+    }
+
+    public Object getAttachment()
+    {
+        return attachment;
+    }
+
+    public void setAttachment( Object attachment )
+    {
+        this.attachment = attachment;
+    }
+
+    public void write( Object message )
+    {
+        synchronized( lock )
+        {
+            if( closed )
+                throw new IllegalStateException( "Session is closed." );
+            remoteFilterManager.fireMessageReceived( remoteSession, message );
+        }
+    }
+
+    public TransportType getTransportType()
+    {
+        return TransportType.VM_PIPE;
+    }
+
+    public boolean isConnected()
+    {
+        return !closed;
+    }
+
+    public SessionConfig getConfig()
+    {
+        return config;
+    }
+
+    public SocketAddress getRemoteAddress()
+    {
+        return remoteAddress;
+    }
+
+    public SocketAddress getLocalAddress()
+    {
+        return localAddress;
+    }
+
+    public long getReadBytes()
+    {
+        return 0;
+    }
+
+    public long getWrittenBytes()
+    {
+        return 0;
+    }
+
+    public long getLastIoTime()
+    {
+        return Math.max( lastReadTime, lastWriteTime );
+    }
+
+    public long getLastReadTime()
+    {
+        return lastReadTime;
+    }
+
+    public long getLastWriteTime()
+    {
+        return lastWriteTime;
+    }
+
+    public boolean isIdle( IdleStatus status )
+    {
+        if( status == null )
+            throw new NullPointerException( "status" );
+
+        if( status == IdleStatus.BOTH_IDLE )
+            return bothIdle;
+        if( status == IdleStatus.READER_IDLE )
+            return readerIdle;
+        if( status == IdleStatus.WRITER_IDLE )
+            return writerIdle;
+
+        throw new IllegalArgumentException( "Illegal statue: " + status );
+    }
+}
\ No newline at end of file

Added: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeSessionConfig.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeSessionConfig.java?view=auto&rev=123602
==============================================================================
--- (empty file)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/vmpipe/VmPipeSessionConfig.java	Tue Dec 28 23:55:11 2004
@@ -0,0 +1,17 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.protocol.vmpipe;
+
+import org.apache.mina.common.SessionConfig;
+import org.apache.mina.util.BasicSessionConfig;
+
+/**
+ * A {@link SessionConfig} for in-VM pipe transport.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public class VmPipeSessionConfig extends BasicSessionConfig
+{
+}
\ No newline at end of file

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/registry/ServiceRegistry.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/registry/ServiceRegistry.java?view=diff&rev=123602&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/registry/ServiceRegistry.java&r1=123601&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/registry/ServiceRegistry.java&r2=123602
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/registry/ServiceRegistry.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/registry/ServiceRegistry.java	Tue Dec 28 23:55:11 2004
@@ -43,18 +43,17 @@
             throws IOException;
 
     void unbind( Service service );
-    
+
     void addFilter( int priority, IoHandlerFilter filter );
-    
+
     void addFilter( int priority, ProtocolHandlerFilter filter );
-    
+
     void addFilter( Service service, int priority, IoHandlerFilter filter );
 
-    void addFilter( Service service, int priority,
-                   ProtocolHandlerFilter filter );
-    
+    void addFilter( Service service, int priority, ProtocolHandlerFilter filter );
+
     void removeFilter( IoHandlerFilter filter );
-    
+
     void removeFilter( ProtocolHandlerFilter filter );
 
     Service getByName( String name, TransportType transportType );

Mime
View raw message