directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r123187 - 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 java/org/apache/mina/io java/org/apache/mina/io/filter java/org/apache/mina/io/socket java/org/apache/mina/protocol java/org/apache/mina/protocol/filter java/org/apache/mina/registry java/org/apache/mina/util
Date Thu, 23 Dec 2004 11:18:15 GMT
Author: trustin
Date: Thu Dec 23 03:18:13 2004
New Revision: 123187

URL: http://svn.apache.org/viewcvs?view=rev&rev=123187
Log:
 * Added ThreadPoolFilter fo Protocol layer
 * Added init() and destroy() lifecycle methods to ProtocolHandlerFilter.
Added:
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/filter/
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/filter/ThreadPoolFilter.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/ReverseProtocolProvider.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/IoHandlerAdapter.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoHandlerFilter.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoSession.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/WriteBuffer.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/filter/ThreadPoolFilter.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpReadBuffer.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpSession.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpSessionConfig.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpWriteBuffer.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/ProtocolCodecFactory.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolHandlerAdapter.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolHandlerFilter.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolHandlerFilterAdapter.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
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/AbstractWriteBuffer.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ProtocolHandlerFilterManager.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Queue.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Stack.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=123187&p1=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/EchoProtocolHandler.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/EchoProtocolHandler.java&r2=123187
==============================================================================
--- 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	Thu Dec 23 03:18:13 2004
@@ -34,22 +34,26 @@
 {
     public void sessionOpened( IoSession IoSession )
     {
-        System.out.println( Thread.currentThread().getName() + ' ' + IoSession.getRemoteAddress() + ": OPEN" );
+        System.out.println( Thread.currentThread().getName() + ' '
+                            + IoSession.getRemoteAddress() + ": OPEN" );
     }
 
     public void sessionClosed( IoSession IoSession )
     {
-        System.out.println( Thread.currentThread().getName() + ' ' + IoSession.getRemoteAddress() + ": CLOSED" );
+        System.out.println( Thread.currentThread().getName() + ' '
+                            + IoSession.getRemoteAddress() + ": CLOSED" );
     }
 
     public void sessionIdle( IoSession IoSession, IdleStatus status )
     {
-        System.out.println( Thread.currentThread().getName() + ' ' + IoSession.getRemoteAddress() + ": IDLE" );
+        System.out.println( Thread.currentThread().getName() + ' '
+                            + IoSession.getRemoteAddress() + ": IDLE" );
     }
 
     public void exceptionCaught( IoSession IoSession, Throwable cause )
     {
-        System.out.println( Thread.currentThread().getName() + ' ' + IoSession.getRemoteAddress() + ": EXCEPTION" );
+        System.out.println( Thread.currentThread().getName() + ' '
+                            + IoSession.getRemoteAddress() + ": EXCEPTION" );
         cause.printStackTrace( System.out );
     }
 
@@ -58,11 +62,16 @@
         ReadBuffer rb = IoSession.getReadBuffer();
         WriteBuffer wb = IoSession.getWriteBuffer();
 
-        synchronized (rb) {
-            synchronized (wb) {
-                int nBytes = wb.putAsPossible(rb);
-                if (nBytes > 0) {
-                    System.out.println( Thread.currentThread().getName() + ' ' + IoSession.getRemoteAddress() + ": READ (" + nBytes + "B)");
+        synchronized( rb )
+        {
+            synchronized( wb )
+            {
+                int nBytes = wb.putAsPossible( rb );
+                if( nBytes > 0 )
+                {
+                    System.out.println( Thread.currentThread().getName() + ' '
+                                        + IoSession.getRemoteAddress()
+                                        + ": READ (" + nBytes + "B)" );
                     rb.signal();
                     wb.flush();
                 }
@@ -75,11 +84,16 @@
         ReadBuffer rb = IoSession.getReadBuffer();
         WriteBuffer wb = IoSession.getWriteBuffer();
 
-        synchronized (rb) {
-            synchronized (wb) {
-                int nBytes = wb.putAsPossible(rb);
-                if (nBytes > 0) {
-                    System.out.println( Thread.currentThread().getName() + ' ' + IoSession.getRemoteAddress() + ": WRITTEN (" + nBytes + "B)");
+        synchronized( rb )
+        {
+            synchronized( wb )
+            {
+                int nBytes = wb.putAsPossible( rb );
+                if( nBytes > 0 )
+                {
+                    System.out.println( Thread.currentThread().getName() + ' '
+                                        + IoSession.getRemoteAddress()
+                                        + ": WRITTEN (" + nBytes + "B)" );
                     rb.signal();
                     wb.flush();
                 }

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=123187&p1=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/Main.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/echoserver/Main.java&r2=123187
==============================================================================
--- 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	Thu Dec 23 03:18:13 2004
@@ -37,9 +37,9 @@
     public static void main( String[] args ) throws Exception
     {
         Acceptor acceptor = new TcpAcceptor();
+        acceptor.addFilter( Integer.MAX_VALUE, new ThreadPoolFilter() );
         acceptor.bind( new InetSocketAddress( PORT ),
                        new EchoProtocolHandler() );
-        acceptor.addFilter(Integer.MAX_VALUE, new ThreadPoolFilter());
         System.out.println( "Listening on port " + PORT );
     }
 }

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=123187&p1=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/netcat/Main.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/netcat/Main.java&r2=123187
==============================================================================
--- 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	Thu Dec 23 03:18:13 2004
@@ -20,6 +20,7 @@
 
 import java.net.InetSocketAddress;
 
+import org.apache.mina.io.filter.ThreadPoolFilter;
 import org.apache.mina.io.socket.TcpConnector;
 
 /**
@@ -39,10 +40,8 @@
         }
 
         TcpConnector connector = new TcpConnector();
-        connector
-                 .connect(
-                           new InetSocketAddress( args[ 0 ],
-                                                  Integer.parseInt( args[ 1 ] ) ),
-                           60, new NetCatProtocolHandler() );
+        connector.addFilter( Integer.MAX_VALUE, new ThreadPoolFilter() );
+        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=123187&p1=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/netcat/NetCatProtocolHandler.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/netcat/NetCatProtocolHandler.java&r2=123187
==============================================================================
--- 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	Thu Dec 23 03:18:13 2004
@@ -50,11 +50,14 @@
     {
         ReadBuffer buf = session.getReadBuffer();
 
-        while( buf.hasRemaining() )
+        synchronized( buf )
         {
-            System.out.print( ( char ) buf.get() );
+            while( buf.hasRemaining() )
+            {
+                System.out.print( ( char ) buf.get() );
+            }
+            buf.signal();
         }
-        buf.signal();
         System.out.flush();
     }
 }

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=123187&p1=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/Main.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/Main.java&r2=123187
==============================================================================
--- 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	Thu Dec 23 03:18:13 2004
@@ -37,8 +37,18 @@
     public static void main( String[] args ) throws Exception
     {
         Acceptor acceptor = new TcpAcceptor();
-        acceptor.bind( new InetSocketAddress( PORT ),
-                       new IoAdapter().adapt( new ReverseProtocolProvider() ) );
+        IoAdapter ioAdapter = new IoAdapter();
+
+        acceptor.addFilter( Integer.MAX_VALUE,
+                            new org.apache.mina.io.filter.ThreadPoolFilter() );
+        ioAdapter
+                .addFilter(
+                            Integer.MAX_VALUE,
+                            new org.apache.mina.protocol.filter.ThreadPoolFilter() );
+
+        acceptor.bind( new InetSocketAddress( PORT ), ioAdapter
+                .adapt( new ReverseProtocolProvider() ) );
+
         System.out.println( "Listening on port " + PORT );
     }
 }

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=123187&p1=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/ReverseProtocolProvider.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/examples/org/apache/mina/examples/reverser/ReverseProtocolProvider.java&r2=123187
==============================================================================
--- 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	Thu Dec 23 03:18:13 2004
@@ -34,14 +34,14 @@
 {
 
     private static ProtocolHandler HANDLER = new ReverseProtocolHandler();
-    
+
     private static ProtocolCodecFactory CODEC_FACTORY = new ProtocolCodecFactory()
     {
         public ProtocolEncoder newEncoder()
         {
             return new TextLineEncoder();
         }
-        
+
         public ProtocolDecoder newDecoder()
         {
             return new TextLineDecoder();

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=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Acceptor.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Acceptor.java&r2=123187
==============================================================================
--- 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	Thu Dec 23 03:18:13 2004
@@ -19,7 +19,6 @@
 package org.apache.mina.io;
 
 import java.io.IOException;
-
 import java.net.SocketAddress;
 
 /**
@@ -34,8 +33,8 @@
             throws IOException;
 
     void unbind( SocketAddress address );
-    
-    void addFilter(int priority, IoHandlerFilter filter);
-    
-    void removeFilter(IoHandlerFilter filter);
+
+    void addFilter( int priority, IoHandlerFilter filter );
+
+    void removeFilter( IoHandlerFilter filter );
 }

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=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Connector.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/Connector.java&r2=123187
==============================================================================
--- 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	Thu Dec 23 03:18:13 2004
@@ -19,7 +19,6 @@
 package org.apache.mina.io;
 
 import java.io.IOException;
-
 import java.net.SocketAddress;
 
 /**

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoHandlerAdapter.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoHandlerAdapter.java?view=diff&rev=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoHandlerAdapter.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoHandlerAdapter.java&r2=123187
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoHandlerAdapter.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoHandlerAdapter.java	Thu Dec 23 03:18:13 2004
@@ -41,4 +41,4 @@
     public void markerReleased( IoSession session, Object marker )
     {
     }
-}
+}
\ No newline at end of file

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoHandlerFilter.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoHandlerFilter.java?view=diff&rev=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoHandlerFilter.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoHandlerFilter.java&r2=123187
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoHandlerFilter.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoHandlerFilter.java	Thu Dec 23 03:18:13 2004
@@ -36,13 +36,16 @@
 
     void sessionClosed( IoHandler nextHandler, IoSession session );
 
-    void sessionIdle( IoHandler nextHandler, IoSession session, IdleStatus status );
+    void sessionIdle( IoHandler nextHandler, IoSession session,
+                     IdleStatus status );
 
-    void exceptionCaught( IoHandler nextHandler, IoSession session, Throwable cause );
+    void exceptionCaught( IoHandler nextHandler, IoSession session,
+                         Throwable cause );
 
     void dataRead( IoHandler nextHandler, IoSession session );
 
     void dataWritten( IoHandler nextHandler, IoSession session );
 
-    void markerReleased( IoHandler nextHandler, IoSession session, Object marker );
+    void markerReleased( IoHandler nextHandler, IoSession session,
+                        Object marker );
 }

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoSession.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoSession.java?view=diff&rev=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoSession.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoSession.java&r2=123187
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoSession.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/IoSession.java	Thu Dec 23 03:18:13 2004
@@ -32,7 +32,7 @@
 public interface IoSession
 {
     IoHandler getHandler();
-    
+
     void close();
 
     Object getAttachment();

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/WriteBuffer.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/WriteBuffer.java?view=diff&rev=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/WriteBuffer.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/WriteBuffer.java&r2=123187
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/WriteBuffer.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/WriteBuffer.java	Thu Dec 23 03:18:13 2004
@@ -94,4 +94,4 @@
     WriteBuffer flush();
 
     WriteBuffer putMarker( Object marker );
-}
+}
\ No newline at end of file

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/filter/ThreadPoolFilter.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/filter/ThreadPoolFilter.java?view=diff&rev=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/filter/ThreadPoolFilter.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/filter/ThreadPoolFilter.java&r2=123187
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/filter/ThreadPoolFilter.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/filter/ThreadPoolFilter.java	Thu Dec 23 03:18:13 2004
@@ -309,7 +309,8 @@
                     }
 
                     Iterator it = readySessionBuffers.iterator();
-                    if (!it.hasNext()) {
+                    if( !it.hasNext() )
+                    {
                         // exceeded keepAliveTime
                         break;
                     }

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java?view=diff&rev=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java&r2=123187
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java	Thu Dec 23 03:18:13 2004
@@ -185,7 +185,8 @@
                 break;
 
             SelectionKey key = session.getSelectionKey();
-            if ((key.interestOps() & SelectionKey.OP_READ) == 0) {
+            if( ( key.interestOps() & SelectionKey.OP_READ ) == 0 )
+            {
                 key.interestOps( key.interestOps() | SelectionKey.OP_READ );
             }
         }

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpReadBuffer.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpReadBuffer.java?view=diff&rev=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpReadBuffer.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpReadBuffer.java&r2=123187
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpReadBuffer.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpReadBuffer.java	Thu Dec 23 03:18:13 2004
@@ -35,7 +35,7 @@
 
     TcpReadBuffer( TcpSession parent, ByteBuffer buf )
     {
-        super(buf);
+        super( buf );
         this.parent = parent;
     }
 
@@ -44,8 +44,7 @@
         TcpIoProcessor.getInstance().addReadableSession( parent );
         return this;
     }
-    
-    
+
     protected ByteBuffer buf()
     {
         return super.buf();

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpSession.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpSession.java?view=diff&rev=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpSession.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpSession.java&r2=123187
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpSession.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpSession.java	Thu Dec 23 03:18:13 2004
@@ -51,9 +51,9 @@
     private final TcpWriteBuffer writeBuf;
 
     private final IoHandler handler;
-    
+
     private final SocketAddress remoteAddress;
-    
+
     private final SocketAddress localAddress;
 
     private SelectionKey key;
@@ -77,24 +77,22 @@
     /**
      * Creates a new instance.
      */
-    TcpSession( IoHandlerFilterManager filterManager, SocketChannel ch, IoHandler defaultHandler )
+    TcpSession( IoHandlerFilterManager filterManager, SocketChannel ch,
+               IoHandler defaultHandler )
     {
         this.filterManager = filterManager;
         this.ch = ch;
         this.config = new TcpSessionConfig( ch );
-        this.readBuf = new TcpReadBuffer(
-                                          this,
-                                          ( ByteBuffer ) ByteBufferPool
-                                                                       .open()
-                                                                       .limit(
-                                                                               0 ) );
+        this.readBuf = new TcpReadBuffer( this, ( ByteBuffer ) ByteBufferPool
+                .open().limit( 0 ) );
         this.writeBuf = new TcpWriteBuffer( this, ByteBufferPool.open() );
         this.handler = defaultHandler;
         this.remoteAddress = ch.socket().getRemoteSocketAddress();
         this.localAddress = ch.socket().getLocalSocketAddress();
     }
-    
-    IoHandlerFilterManager getFilterManager() {
+
+    IoHandlerFilterManager getFilterManager()
+    {
         return filterManager;
     }
 

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpSessionConfig.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpSessionConfig.java?view=diff&rev=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpSessionConfig.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpSessionConfig.java&r2=123187
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpSessionConfig.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpSessionConfig.java	Thu Dec 23 03:18:13 2004
@@ -19,7 +19,6 @@
 package org.apache.mina.io.socket;
 
 import java.net.SocketException;
-
 import java.nio.channels.SocketChannel;
 
 import org.apache.mina.util.BasicSessionConfig;

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpWriteBuffer.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpWriteBuffer.java?view=diff&rev=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpWriteBuffer.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpWriteBuffer.java&r2=123187
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpWriteBuffer.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpWriteBuffer.java	Thu Dec 23 03:18:13 2004
@@ -36,7 +36,7 @@
 
     TcpWriteBuffer( TcpSession session, ByteBuffer buf )
     {
-        super(buf);
+        super( buf );
         this.session = session;
     }
 
@@ -45,17 +45,17 @@
         session.flush();
         return this;
     }
-    
+
     protected ByteBuffer buf()
     {
         return super.buf();
     }
-    
+
     protected Queue getMarkers()
     {
         return super.getMarkers();
     }
-    
+
     protected void markBaseIndex()
     {
         super.markBaseIndex();

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=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/IoAdapter.java&r2=123187
==============================================================================
--- 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	Thu Dec 23 03:18:13 2004
@@ -41,6 +41,12 @@
 
     public IoAdapter()
     {
+        filterManager.start();
+    }
+
+    public void shutdown()
+    {
+        filterManager.stop();
     }
 
     public void addFilter( int priority, ProtocolHandlerFilter filter )
@@ -174,7 +180,10 @@
                 {
                     synchronized( out )
                     {
-                        if( encoder.encode( psession, writeQueue.first(), out ) )
+                        Object message = writeQueue.first();
+                        if( message == null )
+                            break;
+                        if( encoder.encode( psession, message, out ) )
                         {
                             out.putMarker( writeQueue.pop() );
                             out.flush();
@@ -214,12 +223,12 @@
         {
             return adapter.handler;
         }
-        
+
         public ProtocolEncoder getEncoder()
         {
             return adapter.encoder;
         }
-        
+
         public ProtocolDecoder getDecoder()
         {
             return adapter.decoder;

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolCodecFactory.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolCodecFactory.java?view=diff&rev=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolCodecFactory.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolCodecFactory.java&r2=123187
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolCodecFactory.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolCodecFactory.java	Thu Dec 23 03:18:13 2004
@@ -27,6 +27,6 @@
 public interface ProtocolCodecFactory
 {
     ProtocolEncoder newEncoder();
-    
+
     ProtocolDecoder newDecoder();
 }

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolHandlerAdapter.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolHandlerAdapter.java?view=diff&rev=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolHandlerAdapter.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolHandlerAdapter.java&r2=123187
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolHandlerAdapter.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolHandlerAdapter.java	Thu Dec 23 03:18:13 2004
@@ -37,4 +37,4 @@
     public void messageSent( ProtocolSession session, Object message )
     {
     }
-}
+}
\ No newline at end of file

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolHandlerFilter.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolHandlerFilter.java?view=diff&rev=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolHandlerFilter.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolHandlerFilter.java&r2=123187
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolHandlerFilter.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolHandlerFilter.java	Thu Dec 23 03:18:13 2004
@@ -28,15 +28,23 @@
  */
 public interface ProtocolHandlerFilter
 {
+    void init();
+
+    void destroy();
+
     void sessionOpened( ProtocolHandler nextHandler, ProtocolSession session );
 
     void sessionClosed( ProtocolHandler nextHandler, ProtocolSession session );
 
-    void sessionIdle( ProtocolHandler nextHandler, ProtocolSession session, IdleStatus status );
+    void sessionIdle( ProtocolHandler nextHandler, ProtocolSession session,
+                     IdleStatus status );
 
-    void exceptionCaught( ProtocolHandler nextHandler, ProtocolSession session, Throwable cause );
+    void exceptionCaught( ProtocolHandler nextHandler,
+                         ProtocolSession session, Throwable cause );
 
-    void messageReceived( ProtocolHandler nextHandler, ProtocolSession session, Object message );
+    void messageReceived( ProtocolHandler nextHandler,
+                         ProtocolSession session, Object message );
 
-    void messageSent( ProtocolHandler nextHandler, ProtocolSession session, Object message );
+    void messageSent( ProtocolHandler nextHandler, ProtocolSession session,
+                     Object message );
 }

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolHandlerFilterAdapter.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolHandlerFilterAdapter.java?view=diff&rev=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolHandlerFilterAdapter.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolHandlerFilterAdapter.java&r2=123187
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolHandlerFilterAdapter.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolHandlerFilterAdapter.java	Thu Dec 23 03:18:13 2004
@@ -13,6 +13,13 @@
  */
 public class ProtocolHandlerFilterAdapter implements ProtocolHandlerFilter
 {
+    public void init()
+    {
+    }
+
+    public void destroy()
+    {
+    }
 
     public void sessionOpened( ProtocolHandler nextHandler,
                               ProtocolSession session )

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=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolSession.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/ProtocolSession.java&r2=123187
==============================================================================
--- 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	Thu Dec 23 03:18:13 2004
@@ -32,11 +32,11 @@
 public interface ProtocolSession
 {
     ProtocolHandler getHandler();
-    
+
     ProtocolEncoder getEncoder();
-    
+
     ProtocolDecoder getDecoder();
-   
+
     void close();
 
     Object getAttachment();

Added: incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/filter/ThreadPoolFilter.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/filter/ThreadPoolFilter.java?view=auto&rev=123187
==============================================================================
--- (empty file)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/protocol/filter/ThreadPoolFilter.java	Thu Dec 23 03:18:13 2004
@@ -0,0 +1,466 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.protocol.filter;
+
+import java.util.HashSet;
+import java.util.IdentityHashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.protocol.ProtocolHandler;
+import org.apache.mina.protocol.ProtocolHandlerFilter;
+import org.apache.mina.protocol.ProtocolSession;
+import org.apache.mina.util.BlockingSet;
+import org.apache.mina.util.Queue;
+import org.apache.mina.util.Stack;
+
+/**
+ * TODO Document me.
+ * 
+ * A Leader/Followers thread pool.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public class ThreadPoolFilter implements ProtocolHandlerFilter
+{
+    public static final int DEFAULT_MAXIMUM_POOL_SIZE = Integer.MAX_VALUE;
+
+    public static final int DEFAULT_KEEP_ALIVE_TIME = 60 * 1000;
+
+    private static volatile int threadId = 0;
+
+    private Map buffers = new IdentityHashMap();
+
+    private Stack followers = new Stack();
+
+    private Worker leader;
+
+    private BlockingSet readySessionBuffers = new BlockingSet();
+
+    private Set busySessionBuffers = new HashSet();
+
+    private int maximumPoolSize = DEFAULT_MAXIMUM_POOL_SIZE;
+
+    private int keepAliveTime = DEFAULT_KEEP_ALIVE_TIME;
+
+    private boolean shuttingDown;
+
+    private int poolSize;
+
+    public ThreadPoolFilter()
+    {
+    }
+
+    public synchronized int getPoolSize()
+    {
+        return poolSize;
+    }
+
+    public int getMaximumPoolSize()
+    {
+        return maximumPoolSize;
+    }
+
+    public int getKeepAliveTime()
+    {
+        return keepAliveTime;
+    }
+
+    public void setMaximumPoolSize( int maximumPoolSize )
+    {
+        if( maximumPoolSize <= 0 )
+            throw new IllegalArgumentException();
+        this.maximumPoolSize = maximumPoolSize;
+    }
+
+    public void setKeepAliveTime( int keepAliveTime )
+    {
+        this.keepAliveTime = keepAliveTime;
+    }
+
+    public void init()
+    {
+        shuttingDown = false;
+
+        leader = new Worker();
+        leader.start();
+        leader.lead();
+    }
+
+    public void destroy()
+    {
+        shuttingDown = true;
+        Worker lastLeader = null;
+        for( ;; )
+        {
+            Worker leader = this.leader;
+            if( lastLeader == leader )
+                break;
+
+            while( leader.isAlive() )
+            {
+                leader.interrupt();
+                try
+                {
+                    leader.join();
+                }
+                catch( InterruptedException e )
+                {
+                }
+            }
+
+            lastLeader = leader;
+        }
+    }
+
+    private synchronized void increasePoolSize()
+    {
+        poolSize++;
+    }
+
+    private synchronized void decreasePoolSize()
+    {
+        poolSize--;
+    }
+
+    public void sessionOpened( ProtocolHandler nextHandler,
+                              ProtocolSession session )
+    {
+        fireEvent( nextHandler, session, EventType.OPENED, null );
+    }
+
+    public void sessionClosed( ProtocolHandler nextHandler,
+                              ProtocolSession session )
+    {
+        fireEvent( nextHandler, session, EventType.CLOSED, null );
+    }
+
+    public void sessionIdle( ProtocolHandler nextHandler,
+                            ProtocolSession session, IdleStatus status )
+    {
+        fireEvent( nextHandler, session, EventType.IDLE, status );
+    }
+
+    public void exceptionCaught( ProtocolHandler nextHandler,
+                                ProtocolSession session, Throwable cause )
+    {
+        fireEvent( nextHandler, session, EventType.EXCEPTION, cause );
+    }
+
+    public void messageReceived( ProtocolHandler nextHandler,
+                                ProtocolSession session, Object message )
+    {
+        fireEvent( nextHandler, session, EventType.RECEIVED, message );
+    }
+
+    public void messageSent( ProtocolHandler nextHandler,
+                            ProtocolSession session, Object message )
+    {
+        fireEvent( nextHandler, session, EventType.SENT, message );
+    }
+
+    private void fireEvent( ProtocolHandler nextHandler,
+                           ProtocolSession session, EventType type, Object data )
+    {
+        SessionBuffer buf = getSessionBuffer( session );
+        synchronized( buf )
+        {
+            buf.nextHandlers.push( nextHandler );
+            buf.eventTypes.push( type );
+            buf.eventDatum.push( data );
+        }
+
+        synchronized( readySessionBuffers )
+        {
+            if( !busySessionBuffers.contains( buf ) )
+            {
+                busySessionBuffers.add( buf );
+                readySessionBuffers.add( buf );
+            }
+        }
+    }
+
+    private SessionBuffer getSessionBuffer( ProtocolSession session )
+    {
+        SessionBuffer buf = ( SessionBuffer ) buffers.get( session );
+        if( buf == null )
+        {
+            synchronized( buffers )
+            {
+                buf = ( SessionBuffer ) buffers.get( session );
+                if( buf == null )
+                {
+                    buf = new SessionBuffer( session );
+                    buffers.put( session, buf );
+                }
+            }
+        }
+        return buf;
+    }
+
+    private void removeSessionBuffer( SessionBuffer buf )
+    {
+        synchronized( buffers )
+        {
+            buffers.remove( buf.session );
+        }
+    }
+
+    private static class SessionBuffer
+    {
+
+        private final ProtocolSession session;
+
+        private final Queue nextHandlers = new Queue();
+
+        private final Queue eventTypes = new Queue();
+
+        private final Queue eventDatum = new Queue();
+
+        private SessionBuffer( ProtocolSession session )
+        {
+            this.session = session;
+        }
+    }
+
+    private static class EventType
+    {
+        private static final EventType OPENED = new EventType();
+
+        private static final EventType CLOSED = new EventType();
+
+        private static final EventType RECEIVED = new EventType();
+
+        private static final EventType SENT = new EventType();
+
+        private static final EventType IDLE = new EventType();
+
+        private static final EventType EXCEPTION = new EventType();
+
+        private EventType()
+        {
+        }
+    }
+
+    private class Worker extends Thread
+    {
+        private final Object promotionLock = new Object();
+
+        private Worker()
+        {
+            super( ThreadPoolFilter.class.getName() + '-' + ( threadId++ ) );
+            increasePoolSize();
+        }
+
+        public void lead()
+        {
+            synchronized( promotionLock )
+            {
+                leader = this;
+                promotionLock.notify();
+            }
+        }
+
+        public void run()
+        {
+            for( ;; )
+            {
+                if( !waitForPromotion() )
+                    break;
+
+                SessionBuffer buf = fetchBuffer();
+                giveUpLead();
+
+                if( buf == null )
+                    break;
+
+                processEvents( buf );
+                follow();
+                releaseBuffer( buf );
+            }
+
+            decreasePoolSize();
+        }
+
+        private SessionBuffer fetchBuffer()
+        {
+            SessionBuffer buf = null;
+            synchronized( readySessionBuffers )
+            {
+                do
+                {
+                    buf = null;
+                    try
+                    {
+                        readySessionBuffers.waitForNewItem();
+                    }
+                    catch( InterruptedException e )
+                    {
+                        break;
+                    }
+
+                    Iterator it = readySessionBuffers.iterator();
+                    if( !it.hasNext() )
+                    {
+                        // exceeded keepAliveTime
+                        break;
+                    }
+
+                    do
+                    {
+                        buf = null;
+                        buf = ( SessionBuffer ) it.next();
+                        it.remove();
+                    }
+                    while( buf != null && buf.nextHandlers.isEmpty()
+                           && it.hasNext() );
+                }
+                while( buf != null && buf.nextHandlers.isEmpty() );
+            }
+
+            return buf;
+        }
+
+        private void processEvents( SessionBuffer buf )
+        {
+            ProtocolSession session = buf.session;
+            for( ;; )
+            {
+                ProtocolHandler nextHandler;
+                EventType type;
+                Object data;
+                synchronized( buf )
+                {
+                    nextHandler = ( ProtocolHandler ) buf.nextHandlers.pop();
+                    if( nextHandler == null )
+                        break;
+
+                    type = ( EventType ) buf.eventTypes.pop();
+                    data = buf.eventDatum.pop();
+                }
+                processEvent( nextHandler, session, type, data );
+            }
+        }
+
+        private void processEvent( ProtocolHandler nextHandler,
+                                  ProtocolSession session, EventType type,
+                                  Object data )
+        {
+            if( type == EventType.RECEIVED )
+            {
+                nextHandler.messageReceived( session, data );
+            }
+            else if( type == EventType.SENT )
+            {
+                nextHandler.messageSent( session, data );
+            }
+            else if( type == EventType.EXCEPTION )
+            {
+                nextHandler.exceptionCaught( session, ( Throwable ) data );
+            }
+            else if( type == EventType.IDLE )
+            {
+                nextHandler.sessionIdle( session, ( IdleStatus ) data );
+            }
+            else if( type == EventType.OPENED )
+            {
+                nextHandler.sessionOpened( session );
+            }
+            else if( type == EventType.CLOSED )
+            {
+                nextHandler.sessionClosed( session );
+            }
+        }
+
+        private void follow()
+        {
+            synchronized( promotionLock )
+            {
+                if( this != leader )
+                {
+                    synchronized( followers )
+                    {
+                        followers.push( this );
+                    }
+                }
+            }
+        }
+
+        private void releaseBuffer( SessionBuffer buf )
+        {
+            synchronized( readySessionBuffers )
+            {
+                busySessionBuffers.remove( buf );
+                if( buf.nextHandlers.isEmpty() )
+                {
+                    removeSessionBuffer( buf );
+                }
+                else
+                {
+                    readySessionBuffers.add( buf );
+                }
+            }
+        }
+
+        private boolean waitForPromotion()
+        {
+            synchronized( promotionLock )
+            {
+                if( this != leader )
+                {
+                    try
+                    {
+                        int keepAliveTime = getKeepAliveTime();
+                        if( keepAliveTime > 0 )
+                        {
+                            promotionLock.wait( keepAliveTime );
+                        }
+                        else
+                        {
+                            promotionLock.wait();
+                        }
+                    }
+                    catch( InterruptedException e )
+                    {
+                    }
+                }
+
+                return this == leader;
+            }
+        }
+
+        private void giveUpLead()
+        {
+            Worker worker;
+            synchronized( followers )
+            {
+                worker = ( Worker ) followers.pop();
+            }
+
+            if( worker != null )
+            {
+                worker.lead();
+            }
+            else
+            {
+                if( !shuttingDown )
+                {
+                    synchronized( ThreadPoolFilter.this )
+                    {
+                        if( !shuttingDown
+                            && getPoolSize() < getMaximumPoolSize() )
+                        {
+                            worker = new Worker();
+                            worker.start();
+                            worker.lead();
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
\ 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=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/registry/ServiceRegistry.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/registry/ServiceRegistry.java&r2=123187
==============================================================================
--- 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	Thu Dec 23 03:18:13 2004
@@ -33,8 +33,7 @@
  */
 public interface ServiceRegistry
 {
-    void bind( Service service, IoHandler sessionHandler )
-            throws IOException;
+    void bind( Service service, IoHandler sessionHandler ) throws IOException;
 
     void unbind( Service service );
 

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/AbstractWriteBuffer.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/AbstractWriteBuffer.java?view=diff&rev=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/AbstractWriteBuffer.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/AbstractWriteBuffer.java&r2=123187
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/AbstractWriteBuffer.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/AbstractWriteBuffer.java	Thu Dec 23 03:18:13 2004
@@ -23,7 +23,6 @@
 
 import org.apache.mina.io.ReadBuffer;
 import org.apache.mina.io.WriteBuffer;
-import org.apache.mina.util.Queue;
 
 /**
  * TODO Document me.

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=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/IoHandlerFilterManager.java&r2=123187
==============================================================================
--- 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	Thu Dec 23 03:18:13 2004
@@ -105,7 +105,8 @@
 
     public synchronized void addFilter( int priority, IoHandlerFilter filter )
     {
-        if (started) {
+        if( started )
+        {
             filter.init();
         }
 
@@ -165,8 +166,9 @@
                 {
                     prevEntry.nextEntry = e.nextEntry;
                 }
-                
-                if (started) {
+
+                if( started )
+                {
                     filter.destroy();
                 }
                 break;

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ProtocolHandlerFilterManager.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ProtocolHandlerFilterManager.java?view=diff&rev=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ProtocolHandlerFilterManager.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ProtocolHandlerFilterManager.java&r2=123187
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ProtocolHandlerFilterManager.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/ProtocolHandlerFilterManager.java	Thu Dec 23 03:18:13 2004
@@ -54,16 +54,61 @@
         {
             session.getHandler().messageSent( session, message );
         }
+
+        public void init()
+        {
+        }
+
+        public void destroy()
+        {
+        }
     };
 
     private Entry head = new Entry( null, Integer.MIN_VALUE, FINAL_FILTER );
 
+    private boolean started;
+
     public ProtocolHandlerFilterManager()
     {
     }
 
-    public synchronized void addFilter( int priority, ProtocolHandlerFilter filter )
+    public synchronized void start()
+    {
+        if( started )
+            return;
+
+        Entry e = head;
+        do
+        {
+            e.filter.init();
+            e = e.nextEntry;
+        }
+        while( e != null );
+        started = true;
+    }
+
+    public synchronized void stop()
     {
+        if( !started )
+            return;
+
+        Entry e = head;
+        do
+        {
+            e.filter.destroy();
+            e = e.nextEntry;
+        }
+        while( e != null );
+    }
+
+    public synchronized void addFilter( int priority,
+                                       ProtocolHandlerFilter filter )
+    {
+        if( started )
+        {
+            filter.init();
+        }
+
         Entry e = head;
         Entry prevEntry = null;
         for( ;; )
@@ -120,6 +165,11 @@
                 {
                     prevEntry.nextEntry = e.nextEntry;
                 }
+
+                if( started )
+                {
+                    filter.destroy();
+                }
                 break;
             }
             prevEntry = e;
@@ -215,7 +265,8 @@
 
         private final ProtocolHandler nextHandler;
 
-        private Entry( Entry nextEntry, int priority, ProtocolHandlerFilter filter )
+        private Entry( Entry nextEntry, int priority,
+                      ProtocolHandlerFilter filter )
         {
             if( filter == null )
                 throw new NullPointerException( "filter" );
@@ -255,7 +306,8 @@
                     }
                 }
 
-                public void sessionIdle( ProtocolSession session, IdleStatus status )
+                public void sessionIdle( ProtocolSession session,
+                                        IdleStatus status )
                 {
                     try
                     {
@@ -270,7 +322,8 @@
                     }
                 }
 
-                public void exceptionCaught( ProtocolSession session, Throwable cause )
+                public void exceptionCaught( ProtocolSession session,
+                                            Throwable cause )
                 {
                     try
                     {
@@ -285,14 +338,15 @@
                     }
                 }
 
-                public void messageReceived( ProtocolSession session, Object message )
+                public void messageReceived( ProtocolSession session,
+                                            Object message )
                 {
                     try
                     {
                         Entry.this.nextEntry.filter
                                 .messageReceived(
-                                              Entry.this.nextEntry.nextHandler,
-                                              session, message );
+                                                  Entry.this.nextEntry.nextHandler,
+                                                  session, message );
                     }
                     catch( Throwable e )
                     {
@@ -300,7 +354,8 @@
                     }
                 }
 
-                public void messageSent( ProtocolSession session, Object message )
+                public void messageSent( ProtocolSession session,
+                                        Object message )
                 {
                     try
                     {

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Queue.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Queue.java?view=diff&rev=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Queue.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Queue.java&r2=123187
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Queue.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Queue.java	Thu Dec 23 03:18:13 2004
@@ -19,7 +19,6 @@
 package org.apache.mina.util;
 
 import java.io.Serializable;
-
 import java.util.Arrays;
 
 /**
@@ -33,7 +32,7 @@
 public class Queue implements Serializable
 {
     private Object[] items;
-    
+
     private int mask;
 
     private int first = 0;

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Stack.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Stack.java?view=diff&rev=123187&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Stack.java&r1=123186&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Stack.java&r2=123187
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Stack.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/Stack.java	Thu Dec 23 03:18:13 2004
@@ -19,7 +19,6 @@
 package org.apache.mina.util;
 
 import java.io.Serializable;
-
 import java.util.Arrays;
 
 /**
@@ -33,7 +32,7 @@
 public class Stack implements Serializable
 {
     private Object[] items;
-    
+
     private int size = 0;
 
     /**
@@ -85,7 +84,7 @@
             // expand queue
             final int oldLen = items.length;
             Object[] tmp = new Object[ oldLen * 2 ];
-            System.arraycopy( items, 0, tmp, 0, size);
+            System.arraycopy( items, 0, tmp, 0, size );
             items = tmp;
         }
 

Mime
View raw message