directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r188680 - in /directory/network/branches/dirmina-39: ./ src/java/org/apache/mina/common/ src/java/org/apache/mina/filter/ src/java/org/apache/mina/filter/codec/ src/java/org/apache/mina/handler/ src/java/org/apache/mina/transport/socket/nio/ src/test/org/apache/mina/transport/socket/nio/
Date Tue, 07 Jun 2005 03:36:07 GMT
Author: trustin
Date: Mon Jun  6 20:36:04 2005
New Revision: 188680

URL: http://svn.apache.org/viewcvs?rev=188680&view=rev
Log:
Branching to resolve DIRMINA-39


Added:
    directory/network/branches/dirmina-39/
      - copied from r179491, directory/network/trunk/
    directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLFilter.java
      - copied, changed from r188663, directory/network/trunk/src/java/org/apache/mina/filter/SSLFilter.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLHandler.java
      - copied, changed from r188663, directory/network/trunk/src/java/org/apache/mina/filter/SSLHandler.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/handler/DemuxingIoHandler.java
      - copied unchanged from r188659, directory/network/trunk/src/java/org/apache/mina/handler/DemuxingIoHandler.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramAcceptor.java
      - copied unchanged from r188654, directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/DatagramAcceptor.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramConnector.java
      - copied, changed from r188654, directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/DatagramConnector.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java
      - copied unchanged from r188654, directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketConnector.java
      - copied unchanged from r188654, directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/SocketConnector.java
    directory/network/branches/dirmina-39/src/test/org/apache/mina/transport/socket/nio/DatagramBindTest.java
      - copied unchanged from r188654, directory/network/trunk/src/test/org/apache/mina/transport/socket/nio/DatagramBindTest.java
    directory/network/branches/dirmina-39/src/test/org/apache/mina/transport/socket/nio/SocketBindTest.java
      - copied unchanged from r188654, directory/network/trunk/src/test/org/apache/mina/transport/socket/nio/SocketBindTest.java
Modified:
    directory/network/branches/dirmina-39/project.xml
    directory/network/branches/dirmina-39/src/java/org/apache/mina/common/AbstractIoFilterChain.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/common/BaseIoSession.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/common/ByteBuffer.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFilter.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFilterAdapter.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSession.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSessionFilterChain.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSessionManagerFilterChain.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/LoggingFilter.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/ThreadPoolFilter.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/ProtocolEncoderOutput.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/SimpleProtocolEncoderOutput.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/handler/StreamIoHandler.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramSession.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramSessionManagerFilterChain.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketSession.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketSessionManagerFilterChain.java

Modified: directory/network/branches/dirmina-39/project.xml
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/project.xml?rev=188680&r1=179491&r2=188680&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/project.xml (original)
+++ directory/network/branches/dirmina-39/project.xml Mon Jun  6 20:36:04 2005
@@ -71,6 +71,13 @@
 
   <dependencies>
 
+    <dependency>
+      <groupId>concurrent</groupId>
+      <artifactId>concurrent</artifactId>
+      <version>1.3.4</version>
+      <url>http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html</url>
+    </dependency>
+
     <!-- ========================================================= -->
     <!-- Dependencies required for running test cases and examples -->
     <!-- ========================================================= -->

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/AbstractIoFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/common/AbstractIoFilterChain.java?rev=188680&r1=179491&r2=188680&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/common/AbstractIoFilterChain.java
(original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/common/AbstractIoFilterChain.java
Mon Jun  6 20:36:04 2005
@@ -28,6 +28,8 @@
 import org.apache.mina.common.IoFilter.NextFilter;
 import org.apache.mina.util.ByteBufferUtil;
 
+import EDU.oswego.cs.dl.util.concurrent.FutureResult;
+
 /**
  * An abstract implementation of {@link IoFilterChain} that provides
  * common operations for developers to extend protocol layer.
@@ -39,9 +41,10 @@
  *   <li></li>
  * </ul>
  * 
- * The only method a developer should implement is {@link #doWrite(IoSession, Object)}.
- * This method is invoked when filter chain is evaluated for
- * {@link IoFilter#filterWrite(NextFilter, IoSession, Object)} and 
+ * The only method a developer should implement is
+ * {@link #doWrite(IoSession, Object, FutureResult)}.  This method is invoked
+ * when filter chain is evaluated for
+ * {@link IoFilter#filterWrite(NextFilter, IoSession, Object, FutureResult)} and 
  * finally to be written out.
  * 
  * @author The Apache Directory Project
@@ -106,7 +109,7 @@
             }
             
             public void filterWrite( NextFilter nextFilter, IoSession session,
-                                     Object message )
+                                     Object message, FutureResult future )
             {
                 if( message == null )
                 {
@@ -115,7 +118,7 @@
 
                 if( session.getTransportType().getEnvelopeType().isAssignableFrom( message.getClass()
) )
                 {
-                    doWrite( session, message );
+                    doWrite( session, message, future );
                 }
                 else
                 {
@@ -184,9 +187,10 @@
             }
 
             public void filterWrite( NextFilter nextFilter,
-                                     IoSession session, Object message ) throws Exception
+                                     IoSession session, Object message,
+                                     FutureResult future ) throws Exception
             {
-                nextFilter.filterWrite( session, message );
+                nextFilter.filterWrite( session, message, future );
             }
         };
     }
@@ -436,15 +440,15 @@
         }
     }
     
-    public void filterWrite( IoSession session, Object message )
+    public void filterWrite( IoSession session, Object message, FutureResult future )
     {
         Entry tail = this.tail;
-        callPreviousFilterWrite( tail, session, message );
+        callPreviousFilterWrite( tail, session, message, future );
     }
 
     private void callPreviousFilterWrite( Entry entry,
                                           IoSession session,
-                                          Object message )
+                                          Object message, FutureResult future )
     {
         if( message == null )
         {
@@ -453,7 +457,7 @@
         
         try
         {
-            entry.filter.filterWrite( entry.nextFilter, session, message );
+            entry.filter.filterWrite( entry.nextFilter, session, message, future );
         }
         catch( Throwable e )
         {
@@ -486,7 +490,7 @@
         return list;
     }
     
-    protected abstract void doWrite( IoSession session, Object message );
+    protected abstract void doWrite( IoSession session, Object message, FutureResult future
);
 
     private class Entry
     {
@@ -556,10 +560,10 @@
                     callNextMessageSent( nextEntry, session, message );
                 }
                 
-                public void filterWrite( IoSession session, Object message )
+                public void filterWrite( IoSession session, Object message, FutureResult
future )
                 {
                     Entry nextEntry = Entry.this.prevEntry;
-                    callPreviousFilterWrite( nextEntry, session, message );
+                    callPreviousFilterWrite( nextEntry, session, message, future );
                 }
             };
         }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/BaseIoSession.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/common/BaseIoSession.java?rev=188680&r1=179491&r2=188680&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/common/BaseIoSession.java
(original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/common/BaseIoSession.java
Mon Jun  6 20:36:04 2005
@@ -51,11 +51,6 @@
     {
     }
     
-    public void close()
-    {
-        this.close( false );
-    }
-
     public Object getAttachment()
     {
         return attributes.get( "" );

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/ByteBuffer.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/common/ByteBuffer.java?rev=188680&r1=179491&r2=188680&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/common/ByteBuffer.java
(original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/common/ByteBuffer.java
Mon Jun  6 20:36:04 2005
@@ -36,6 +36,8 @@
 import org.apache.mina.filter.codec.ProtocolEncoderOutput;
 import org.apache.mina.util.Stack;
 
+import EDU.oswego.cs.dl.util.concurrent.FutureResult;
+
 /**
  * A pooled byte buffer used by MINA applications.
  * <p>
@@ -74,7 +76,7 @@
  * because MINA will release it automatically when:
  * <ul>
  *   <li>You pass the buffer by calling {@link IoSession#write(Object)}.</li>
- *   <li>You pass the buffer by calling {@link NextFilter#filterWrite(IoSession,Object)}.</li>
+ *   <li>You pass the buffer by calling {@link NextFilter#filterWrite(IoSession,Object,FutureResult)}.</li>
  *   <li>You pass the buffer by calling {@link ProtocolEncoderOutput#write(ByteBuffer)}.</li>
  * </ul>
  * And, you don't need to release any {@link ByteBuffer} which is passed as a parameter

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFilter.java?rev=188680&r1=179491&r2=188680&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFilter.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFilter.java Mon
Jun  6 20:36:04 2005
@@ -18,6 +18,8 @@
  */
 package org.apache.mina.common;
 
+import EDU.oswego.cs.dl.util.concurrent.FutureResult;
+
 
 /**
  * A filter which intercepts {@link IoHandler} events like Servlet
@@ -83,7 +85,7 @@
     /**
      * Filters {@link IoSession#write(Object)} method invocation.
      */
-    void filterWrite( NextFilter nextFilter, IoSession session, Object message ) throws Exception;
+    void filterWrite( NextFilter nextFilter, IoSession session, Object message, FutureResult
future ) throws Exception;
     
     public interface NextFilter
     {
@@ -93,6 +95,6 @@
         void exceptionCaught( IoSession session, Throwable cause );
         void messageReceived( IoSession session, Object message );
         void messageSent( IoSession session, Object message );
-        void filterWrite( IoSession session, Object message );
+        void filterWrite( IoSession session, Object message, FutureResult future );
     }
 }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFilterAdapter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFilterAdapter.java?rev=188680&r1=179491&r2=188680&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFilterAdapter.java
(original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoFilterAdapter.java
Mon Jun  6 20:36:04 2005
@@ -18,6 +18,8 @@
  */
 package org.apache.mina.common;
 
+import EDU.oswego.cs.dl.util.concurrent.FutureResult;
+
 
 /**
  * An abstract adapter class for {@link IoFilter}.  You can extend
@@ -59,8 +61,8 @@
         nextFilter.messageSent( session, message );
     }
 
-    public void filterWrite( NextFilter nextFilter, IoSession session, Object message ) throws
Exception
+    public void filterWrite( NextFilter nextFilter, IoSession session, Object message, FutureResult
future ) throws Exception
     {
-        nextFilter.filterWrite( session, message );
+        nextFilter.filterWrite( session, message, future );
     }
 }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSession.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSession.java?rev=188680&r1=179491&r2=188680&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSession.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSession.java Mon
Jun  6 20:36:04 2005
@@ -21,6 +21,8 @@
 import java.net.SocketAddress;
 import java.util.Set;
 
+import EDU.oswego.cs.dl.util.concurrent.FutureResult;
+
 /**
  * A handle which represents connection between two endpoints regardless of 
  * transport types.
@@ -46,26 +48,21 @@
     IoFilterChain getFilterChain();
 
     /**
-     * Writes the specified <code>message</code> to remote peer.  This operation
-     * is asynchronous; {@link IoHandler#messageSent(IoSession, Object)}
+     * Writes the specified <code>message</code> to remote peer.  This
+     * operation is asynchronous; {@link IoHandler#messageSent(IoSession, Object)}
      * will be invoked when the message is actually sent to remote peer.
+     * You can also ait for the returned {@link FutureResult} if you want
+     * to wait for the session actually closed.
      */
-    void write( Object message );
+    FutureResult write( Object message );
 
     /**
-     * Closes this session immediately.  Calling method is identical with
-     * calling <tt>close( false )</tt>.
+     * Closes this session immediately.  This operation is asynthronous.
+     * Wait for the returned {@link FutureResult} if you want to wait for
+     * the session actually closed.
      */
-    void close();
+    FutureResult close();
 
-    /**
-     * Closes this session immediately.
-     * 
-     * @param wait <tt>true</tt> if you want to wait until closing process is
-     *             complete.
-     */
-    void close( boolean wait );
-    
     /**
      * Returns an attachment of this session.
      * This method is identical with <tt>getAttribute( "" )</tt>.

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSessionFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSessionFilterChain.java?rev=188680&r1=179491&r2=188680&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSessionFilterChain.java
(original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSessionFilterChain.java
Mon Jun  6 20:36:04 2005
@@ -18,6 +18,8 @@
  */
 package org.apache.mina.common;
 
+import EDU.oswego.cs.dl.util.concurrent.FutureResult;
+
 /**
  * An {@link IoFilterChain} that forwards <tt>filterWrite</tt>
  * requests to the specified {@link IoSessionManagerFilterChain}.
@@ -37,8 +39,8 @@
         this.managerChain = managerChain;
     }
     
-    protected void doWrite( IoSession session, Object message )
+    protected void doWrite( IoSession session, Object message, FutureResult future )
     {
-        managerChain.filterWrite( session, message );
+        managerChain.filterWrite( session, message, future );
     }
 }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSessionManagerFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSessionManagerFilterChain.java?rev=188680&r1=179491&r2=188680&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSessionManagerFilterChain.java
(original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/common/IoSessionManagerFilterChain.java
Mon Jun  6 20:36:04 2005
@@ -18,6 +18,8 @@
  */
 package org.apache.mina.common;
 
+import EDU.oswego.cs.dl.util.concurrent.FutureResult;
+
 /**
  * An {@link IoFilterChain} that forwards all events
  * except <tt>filterWrite</tt> to the {@link IoSessionFilterChain}
@@ -82,9 +84,10 @@
             }
 
             public void filterWrite( NextFilter nextFilter,
-                                     IoSession session, Object message )
+                                     IoSession session, Object message,
+                                     FutureResult future )
             {
-                nextFilter.filterWrite( session, message );
+                nextFilter.filterWrite( session, message, future );
             }
         };
     }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/LoggingFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/LoggingFilter.java?rev=188680&r1=179491&r2=188680&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/LoggingFilter.java
(original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/LoggingFilter.java
Mon Jun  6 20:36:04 2005
@@ -26,6 +26,8 @@
 import org.apache.mina.common.IoSession;
 import org.apache.mina.util.SessionLog;
 
+import EDU.oswego.cs.dl.util.concurrent.FutureResult;
+
 /**
  * Logs all MINA protocol events to {@link Logger}.
  * 
@@ -111,9 +113,9 @@
         nextFilter.messageSent( session, message );
     }
 
-    public void filterWrite( NextFilter nextFilter, IoSession session, Object message)
+    public void filterWrite( NextFilter nextFilter, IoSession session, Object message, FutureResult
future )
     {
         SessionLog.log( defaultLevel, session, "WRITE: " + message );
-        nextFilter.filterWrite( session, message );
+        nextFilter.filterWrite( session, message, future );
     }
 }

Copied: directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLFilter.java
(from r188663, directory/network/trunk/src/java/org/apache/mina/filter/SSLFilter.java)
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLFilter.java?p2=directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLFilter.java&p1=directory/network/trunk/src/java/org/apache/mina/filter/SSLFilter.java&r1=188663&r2=188680&rev=188680&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/SSLFilter.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLFilter.java Mon
Jun  6 20:36:04 2005
@@ -33,6 +33,8 @@
 import org.apache.mina.common.IoFilterAdapter;
 import org.apache.mina.common.IoSession;
 
+import EDU.oswego.cs.dl.util.concurrent.FutureResult;
+
 /**
  * An SSL filter that encrypts and decrypts the data exchanged in the session.
  * This filter uses an {@link SSLEngine} which was introduced in Java 5, so 
@@ -285,7 +287,7 @@
         }
     }
 
-    public void filterWrite( NextFilter nextFilter, IoSession session, Object message ) throws
SSLException
+    public void filterWrite( NextFilter nextFilter, IoSession session, Object message, FutureResult
future ) throws SSLException
     {
         ByteBuffer buf = ( ByteBuffer ) message;
 
@@ -304,7 +306,7 @@
                 {
                     log.log( Level.FINEST, session + "   already encrypted: " + buf );
                 }
-                nextFilter.filterWrite( session, buf );
+                nextFilter.filterWrite( session, buf, future );
                 return;
             }
             
@@ -326,7 +328,7 @@
                 {
                     log.log( Level.FINEST, session + " encrypted buf: " + encryptedBuffer);
                 }
-                nextFilter.filterWrite( session, encryptedBuffer );
+                nextFilter.filterWrite( session, encryptedBuffer, future );
                 return;
             }
             else
@@ -344,7 +346,7 @@
                     {
                         log.log( Level.FINEST, session + " Handshaking is not complete yet.
Buffering write request." );
                     }
-                    handler.scheduleWrite( nextFilter, buf );
+                    handler.scheduleWrite( nextFilter, buf, future );
                 }
             }
         }
@@ -419,7 +421,9 @@
                 log.log( Level.FINEST, session + " session write: " + writeBuffer );
             }
             //debug("outNetBuffer (after copy): {0}", sslHandler.getOutNetBuffer());
-            filterWrite( nextFilter, session, writeBuffer );
+            
+            // TODO: FutureResult is not used here. Can we reuse it?
+            filterWrite( nextFilter, session, writeBuffer, new FutureResult() );
 
             // loop while more writes required to complete handshake
             while( sslHandler.needToCompleteInitialHandshake() )

Copied: directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLHandler.java
(from r188663, directory/network/trunk/src/java/org/apache/mina/filter/SSLHandler.java)
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLHandler.java?p2=directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLHandler.java&p1=directory/network/trunk/src/java/org/apache/mina/filter/SSLHandler.java&r1=188663&r2=188680&rev=188680&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/SSLHandler.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLHandler.java
Mon Jun  6 20:36:04 2005
@@ -32,6 +32,8 @@
 import org.apache.mina.common.IoFilter.NextFilter;
 import org.apache.mina.util.Queue;
 
+import EDU.oswego.cs.dl.util.concurrent.FutureResult;
+
 /**
  * A helper class using the SSLEngine API to decrypt/encrypt data.
  * <p>
@@ -51,9 +53,7 @@
 
     private final IoSession session;
     
-    private final Queue nextFilterQueue = new Queue();
-    
-    private final Queue writeBufferQueue = new Queue();
+    private final Queue scheduledWrites = new Queue();
 
     private SSLEngine sslEngine;
 
@@ -185,25 +185,22 @@
         return ( initialHandshakeStatus == SSLEngineResult.HandshakeStatus.NEED_WRAP &&
!closed );
     }
     
-    public synchronized void scheduleWrite( NextFilter nextFilter, org.apache.mina.common.ByteBuffer
buf )
+    public synchronized void scheduleWrite( NextFilter nextFilter, org.apache.mina.common.ByteBuffer
buf, FutureResult future )
     {
-        nextFilterQueue.push( nextFilter );
-        writeBufferQueue.push( buf );
+        scheduledWrites.push( new ScheduledWrite( nextFilter, buf, future ) );
     }
     
     public synchronized void flushScheduledWrites() throws SSLException
     {
-        NextFilter nextFilter;
-        org.apache.mina.common.ByteBuffer scheduledBuf;
+        ScheduledWrite scheduledWrite;
         
-        while( ( scheduledBuf = ( org.apache.mina.common.ByteBuffer ) writeBufferQueue.pop()
) != null )
+        while( ( scheduledWrite = ( ScheduledWrite ) scheduledWrites.pop() ) != null )
         {
             if( log.isLoggable( Level.FINEST ) )
             {
-                log.log( Level.FINEST, session + " Flushing buffered write request: " + scheduledBuf
);
+                log.log( Level.FINEST, session + " Flushing buffered write request: " + scheduledWrite.buf
);
             }
-            nextFilter = ( NextFilter ) nextFilterQueue.pop();
-            parent.filterWrite( nextFilter, session, scheduledBuf );
+            parent.filterWrite( scheduledWrite.nextFilter, session, scheduledWrite.buf, scheduledWrite.future
);
         }
     }
 
@@ -667,5 +664,19 @@
             throw new SSLException( "Improper close state: " + result );
         }
         outNetBuffer.flip();
+    }
+    
+    private static class ScheduledWrite
+    {
+        private final NextFilter nextFilter;
+        private final org.apache.mina.common.ByteBuffer buf;
+        private final FutureResult future; 
+        
+        public ScheduledWrite( NextFilter nextFilter, org.apache.mina.common.ByteBuffer buf,
FutureResult future )
+        {
+            this.nextFilter = nextFilter;
+            this.buf = buf;
+            this.future = future;
+        }
     }
 }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/ThreadPoolFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/ThreadPoolFilter.java?rev=188680&r1=179491&r2=188680&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/ThreadPoolFilter.java
(original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/ThreadPoolFilter.java
Mon Jun  6 20:36:04 2005
@@ -27,6 +27,8 @@
 import org.apache.mina.util.EventType;
 import org.apache.mina.util.ThreadPool;
 
+import EDU.oswego.cs.dl.util.concurrent.FutureResult;
+
 /**
  * A Thread-pooling filter.  This filter forwards {@link IoHandler} events
  * to its thread pool.
@@ -118,8 +120,8 @@
         }
     }
 
-    public void filterWrite( NextFilter nextFilter, IoSession session, Object message )
+    public void filterWrite( NextFilter nextFilter, IoSession session, Object message, FutureResult
future )
     {
-        nextFilter.filterWrite( session, message );
+        nextFilter.filterWrite( session, message, future );
     }
 }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java?rev=188680&r1=179491&r2=188680&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
(original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
Mon Jun  6 20:36:04 2005
@@ -6,6 +6,8 @@
 import org.apache.mina.common.IoSession;
 import org.apache.mina.util.Queue;
 
+import EDU.oswego.cs.dl.util.concurrent.FutureResult;
+
 public class ProtocolCodecFilter extends IoFilterAdapter
 {
     public static final String ENCODER = ProtocolCodecFilter.class.getName() + ".encoder";
@@ -74,7 +76,7 @@
         }
     }
     
-    public void filterWrite( NextFilter nextFilter, IoSession session, Object message ) throws
Exception
+    public void filterWrite( NextFilter nextFilter, IoSession session, Object message, FutureResult
future ) throws Exception
     {
         ProtocolEncoder encoder = getEncoder( session );
         if( message == null )
@@ -82,17 +84,13 @@
             throw new NullPointerException( "message" );
         }
 
-        SimpleProtocolEncoderOutput encoderOut = getEncoderOut( session );
-        Queue queue = encoderOut.getBufferQueue();
+        ProtocolEncoderOutputImpl encoderOut = getEncoderOut( session );
+        encoderOut.nextFilter = nextFilter;
+        encoderOut.message = message;
+        encoderOut.future = future;
+        
         encoder.encode( session, message, encoderOut );
-        for( ;; )
-        {
-            ByteBuffer buf = ( ByteBuffer ) queue.pop();
-            if( buf == null )
-                break;
-            
-            nextFilter.filterWrite( session, new MessageByteBuffer( buf, message ) );
-        }
+        encoderOut.flush();
     }
     
     private ProtocolEncoder getEncoder( IoSession session )
@@ -106,12 +104,12 @@
         return encoder;
     }
     
-    private SimpleProtocolEncoderOutput getEncoderOut( IoSession session )
+    private ProtocolEncoderOutputImpl getEncoderOut( IoSession session )
     {
-        SimpleProtocolEncoderOutput out = ( SimpleProtocolEncoderOutput ) session.getAttribute(
ENCODER_OUT );
+        ProtocolEncoderOutputImpl out = ( ProtocolEncoderOutputImpl ) session.getAttribute(
ENCODER_OUT );
         if( out == null )
         {
-            out = new SimpleProtocolEncoderOutput();
+            out = new ProtocolEncoderOutputImpl( session );
             session.setAttribute( ENCODER_OUT, out );
         }
         return out;
@@ -147,6 +145,25 @@
         {
             super( buf );
             this.message = message;
+        }
+    }
+    
+    private static class ProtocolEncoderOutputImpl extends SimpleProtocolEncoderOutput
+    {
+        private final IoSession session;
+        private NextFilter nextFilter;
+        private Object message;
+        private FutureResult future;
+        
+        public ProtocolEncoderOutputImpl( IoSession session )
+        {
+            this.session = session;
+        }
+
+        protected FutureResult doFlush( ByteBuffer buf )
+        {
+            nextFilter.filterWrite( session, new MessageByteBuffer( buf, message ), future
);
+            return null;
         }
     }
 }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/ProtocolEncoderOutput.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/ProtocolEncoderOutput.java?rev=188680&r1=179491&r2=188680&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/ProtocolEncoderOutput.java
(original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/ProtocolEncoderOutput.java
Mon Jun  6 20:36:04 2005
@@ -20,6 +20,8 @@
 
 import org.apache.mina.common.ByteBuffer;
 
+import EDU.oswego.cs.dl.util.concurrent.FutureResult;
+
 /**
  * Callback for {@link ProtocolEncoder} to generate encoded {@link ByteBuffer}s.
  * {@link ProtocolEncoder} must call {@link #write(ByteBuffer)} for each decoded
@@ -46,4 +48,12 @@
      * network packets.
      */
     void mergeAll();
+    
+    /**
+     * Flushes all buffers you wrote via {@link #write(ByteBuffer)} to
+     * the session.  This operation is asynchronous; please wait for
+     * the returned {@link FutureResult} if you want to wait for
+     * the buffers flushed.
+     */
+    FutureResult flush();
 }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/SimpleProtocolEncoderOutput.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/SimpleProtocolEncoderOutput.java?rev=188680&r1=179491&r2=188680&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/SimpleProtocolEncoderOutput.java
(original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/codec/SimpleProtocolEncoderOutput.java
Mon Jun  6 20:36:04 2005
@@ -6,6 +6,8 @@
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.util.Queue;
 
+import EDU.oswego.cs.dl.util.concurrent.FutureResult;
+
 /**
  * A {@link ProtocolEncoderOutput} based on queue.
  *
@@ -13,9 +15,8 @@
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$
  */
-public class SimpleProtocolEncoderOutput implements ProtocolEncoderOutput
+public abstract class SimpleProtocolEncoderOutput implements ProtocolEncoderOutput
 {
-
     private final Queue bufferQueue = new Queue();
     
     public SimpleProtocolEncoderOutput()
@@ -69,4 +70,31 @@
         newBuf.flip();
         bufferQueue.push(newBuf);
     }
+    
+    public FutureResult flush()
+    {
+        Queue bufferQueue = this.bufferQueue;
+        FutureResult future = null;
+        for( ;; )
+        {
+            ByteBuffer buf = ( ByteBuffer ) bufferQueue.pop();
+            if( buf == null )
+            {
+                break;
+            }
+            
+            future = doFlush( buf );
+        }
+        
+        if( future == null )
+        {
+            // Nothing is written; future is now.
+            future = new FutureResult();
+            future.set( Boolean.FALSE );
+        }
+        
+        return future;
+    }
+    
+    protected abstract FutureResult doFlush( ByteBuffer buf );
 }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/handler/StreamIoHandler.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/handler/StreamIoHandler.java?rev=188680&r1=179491&r2=188680&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/handler/StreamIoHandler.java
(original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/handler/StreamIoHandler.java
Mon Jun  6 20:36:04 2005
@@ -250,7 +250,7 @@
 
         public void close()
         {
-            session.close( true );
+            session.close();
         }
 
         public void flush()

Copied: directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramConnector.java
(from r188654, directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/DatagramConnector.java)
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramConnector.java?p2=directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramConnector.java&p1=directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/DatagramConnector.java&r1=188654&r2=188680&rev=188680&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/DatagramConnector.java
(original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramConnector.java
Mon Jun  6 20:36:04 2005
@@ -491,6 +491,7 @@
                 {
                     exceptionMonitor.exceptionCaught( this, e );
                 }
+                // FIXME: call closeFuture.set( Boolean.TRUE ) here
                 key.cancel();
                 selector.wakeup(); // wake up again to trigger thread death
             }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramSession.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramSession.java?rev=188680&r1=179491&r2=188680&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramSession.java
(original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramSession.java
Mon Jun  6 20:36:04 2005
@@ -33,6 +33,8 @@
 import org.apache.mina.common.TransportType;
 import org.apache.mina.util.Queue;
 
+import EDU.oswego.cs.dl.util.concurrent.FutureResult;
+
 /**
  * An {@link IoSession} for datagram transport (UDP/IP).
  * 
@@ -59,7 +61,7 @@
 
     private SelectionKey key;
     
-    private boolean disposed;
+    private final FutureResult closeFuture = new FutureResult();
 
     /**
      * Creates a new instance.
@@ -107,40 +109,21 @@
         return handler;
     }
     
-    synchronized void notifyClose()
-    {
-        if( !disposed )
-        {
-            disposed = true;
-            notify();
-        }
-    }
-
-    public synchronized void close( boolean wait )
+    public synchronized FutureResult close()
     {
-        if( disposed )
+        if( !closeFuture.isReady() )
         {
-            return;
-        }
-
-        IoSessionManager manager = managerFilterChain.getManager();
-        if( manager instanceof DatagramConnector )
-        {
-            ( ( DatagramConnector ) manager ).closeSession( this );
-            if( wait )
+            IoSessionManager manager = managerFilterChain.getManager();
+            if( manager instanceof DatagramConnector )
+            {
+                ( ( DatagramConnector ) manager ).closeSession( this );
+            }
+            else
             {
-                while( disposed )
-                {
-                    try
-                    {
-                        wait();
-                    }
-                    catch( InterruptedException e )
-                    {
-                    }
-                }
+                closeFuture.set( Boolean.TRUE );
             }
         }
+        return closeFuture;
     }
 
     Queue getWriteBufferQueue()
@@ -148,9 +131,11 @@
         return writeBufferQueue;
     }
 
-    public void write( Object message )
+    public FutureResult write( Object message )
     {
-        filterChain.filterWrite( this, message );
+        FutureResult future = new FutureResult();
+        filterChain.filterWrite( this, message, future );
+        return future;
     }
 
     public TransportType getTransportType()

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramSessionManagerFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramSessionManagerFilterChain.java?rev=188680&r1=179491&r2=188680&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramSessionManagerFilterChain.java
(original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/DatagramSessionManagerFilterChain.java
Mon Jun  6 20:36:04 2005
@@ -5,6 +5,8 @@
 import org.apache.mina.common.IoSessionManagerFilterChain;
 import org.apache.mina.util.Queue;
 
+import EDU.oswego.cs.dl.util.concurrent.FutureResult;
+
 /**
  * An {@link IoFilterChain} for datagram transport (UDP/IP).
  * 
@@ -17,7 +19,7 @@
         super( processor );
     }
     
-    protected void doWrite( IoSession session, Object message )
+    protected void doWrite( IoSession session, Object message, FutureResult future )
     {
         DatagramSession s = ( DatagramSession ) session;
         Queue writeBufferQueue = s.getWriteBufferQueue();
@@ -27,6 +29,6 @@
             writeBufferQueue.push( message );
         }
 
-        ( ( DatagramSessionManager ) getManager() ).flushSession( s );
+        ( ( DatagramSessionManager ) getManager() ).flushSession( s, future );
     }
 }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketSession.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketSession.java?rev=188680&r1=179491&r2=188680&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketSession.java
(original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketSession.java
Mon Jun  6 20:36:04 2005
@@ -32,6 +32,8 @@
 import org.apache.mina.common.TransportType;
 import org.apache.mina.util.Queue;
 
+import EDU.oswego.cs.dl.util.concurrent.FutureResult;
+
 /**
  * An {@link IoSession} for socket transport (TCP/IP).
  * 
@@ -58,7 +60,7 @@
 
     private SelectionKey key;
     
-    private boolean disposed;
+    private FutureResult closeFuture = new FutureResult();
 
     /**
      * Creates a new instance.
@@ -106,37 +108,14 @@
         return handler;
     }
     
-    synchronized void notifyClose()
+    public synchronized FutureResult close( boolean wait )
     {
-        if( !disposed )
+        if( !closeFuture.isReady() )
         {
-            disposed = true;
-            notify();
+            SocketIoProcessor.getInstance().removeSession( this );
         }
-    }
-    
 
-    public synchronized void close( boolean wait )
-    {
-        if( disposed )
-        {
-            return;
-        }
-
-        SocketIoProcessor.getInstance().removeSession( this );
-        if( wait )
-        {
-            while( disposed )
-            {
-                try
-                {
-                    wait();
-                }
-                catch( InterruptedException e )
-                {
-                }
-            }
-        }
+        return closeFuture;
     }
 
     Queue getWriteBufferQueue()

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketSessionManagerFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketSessionManagerFilterChain.java?rev=188680&r1=179491&r2=188680&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketSessionManagerFilterChain.java
(original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/transport/socket/nio/SocketSessionManagerFilterChain.java
Mon Jun  6 20:36:04 2005
@@ -19,7 +19,7 @@
         super( manager );
     }
 
-    protected void doWrite( IoSession session, Object message )
+    protected void doWrite( IoSession session, Object message, FutureResult future )
     {
         SocketSession s = ( SocketSession ) session;
         Queue writeBufferQueue = s.getWriteBufferQueue();
@@ -30,6 +30,6 @@
             writeBufferQueue.push( message );
         }
 
-        SocketIoProcessor.getInstance().flushSession( s );
+        SocketIoProcessor.getInstance().flushSession( s, future );
     }
 }



Mime
View raw message