directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r385252 - in /directory/trunks/mina/core/src: main/java/org/apache/mina/common/support/ main/java/org/apache/mina/transport/socket/nio/support/ main/java/org/apache/mina/transport/vmpipe/support/ test/java/org/apache/mina/common/
Date Sun, 12 Mar 2006 05:36:34 GMT
Author: trustin
Date: Sat Mar 11 21:36:32 2006
New Revision: 385252

URL: http://svn.apache.org/viewcvs?rev=385252&view=rev
Log:
* AbstractIoFilterChain.messageSent() calls WriteFuture.setWritten(true) to remove code duplication.
* AbstractIoFilterChain.messageNotSent() calls WriteFuture.setWritten(false) to remove code
duplication.
* The ByteBuffer passed via messageSent now has a correct position.

Modified:
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/AbstractIoFilterChain.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramFilterChain.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketFilterChain.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketIoProcessor.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/support/VmPipeFilterChain.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/common/IoFilterChainTest.java

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/AbstractIoFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/AbstractIoFilterChain.java?rev=385252&r1=385251&r2=385252&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/AbstractIoFilterChain.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/AbstractIoFilterChain.java
Sat Mar 11 21:36:32 2006
@@ -509,10 +509,30 @@
         }
     }
 
-    public void messageSent( IoSession session, Object message )
+    public void messageNotSent( IoSession session, WriteRequest request )
     {
+        try
+        {
+            request.getFuture().setWritten( false );
+        }
+        catch( Throwable t )
+        {
+            exceptionCaught( session, t );
+        }
+    }
+
+    public void messageSent( IoSession session, WriteRequest request )
+    {
+        try
+        {
+            request.getFuture().setWritten( true );
+        }
+        catch( Throwable t )
+        {
+            exceptionCaught( session, t );
+        }
         Entry head = this.head;
-        callNextMessageSent(head, session, message);
+        callNextMessageSent( head, session, request.getMessage() );
     }
 
     private void callNextMessageSent( Entry entry,

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java?rev=385252&r1=385251&r2=385252&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
Sat Mar 11 21:36:32 2006
@@ -465,9 +465,9 @@
                     writeRequestQueue.pop();
                 }
 
-                req.getFuture().setWritten( true );
                 session.increaseWrittenWriteRequests();
-                ( ( DatagramFilterChain ) session.getFilterChain() ).messageSent( session,
buf );
+                buf.reset();
+                ( ( DatagramFilterChain ) session.getFilterChain() ).messageSent( session,
req );
                 continue;
             }
 
@@ -482,7 +482,6 @@
                 continue;
             }
 
-            int pos = buf.position();
             int writtenBytes = ch
                     .send( buf.buf(), session.getRemoteAddress() );
 
@@ -503,9 +502,9 @@
                 }
 
                 session.increaseWrittenBytes( writtenBytes );
-                req.getFuture().setWritten( true );
                 session.increaseWrittenWriteRequests();
-                ( ( DatagramFilterChain ) session.getFilterChain() ).messageSent( session,
buf.position( pos ) );
+                buf.reset();
+                ( ( DatagramFilterChain ) session.getFilterChain() ).messageSent( session,
req );
             }
         }
     }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java?rev=385252&r1=385251&r2=385252&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
Sat Mar 11 21:36:32 2006
@@ -481,9 +481,9 @@
                     writeRequestQueue.pop();
                 }
 
-                req.getFuture().setWritten( true );
                 session.increaseWrittenWriteRequests();
-                ( ( DatagramFilterChain ) session.getFilterChain() ).messageSent( session,
buf );
+                buf.reset();
+                ( ( DatagramFilterChain ) session.getFilterChain() ).messageSent( session,
req );
                 continue;
             }
 
@@ -498,7 +498,6 @@
                 continue;
             }
 
-            int pos = buf.position();
             int writtenBytes = ch.write( buf.buf() );
 
             if( writtenBytes == 0 )
@@ -518,9 +517,9 @@
                 }
 
                 session.increaseWrittenBytes( writtenBytes );
-                req.getFuture().setWritten( true );
                 session.increaseWrittenWriteRequests();
-                ( ( DatagramFilterChain ) session.getFilterChain() ).messageSent( session,
buf.position( pos ) );
+                buf.reset();
+                ( ( DatagramFilterChain ) session.getFilterChain() ).messageSent( session,
req );
             }
         }
     }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramFilterChain.java?rev=385252&r1=385251&r2=385252&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramFilterChain.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramFilterChain.java
Sat Mar 11 21:36:32 2006
@@ -18,6 +18,7 @@
  */
 package org.apache.mina.transport.socket.nio.support;
 
+import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoFilter.WriteRequest;
@@ -41,6 +42,9 @@
         DatagramSessionImpl s = ( DatagramSessionImpl ) session;
         Queue writeRequestQueue = s.getWriteRequestQueue();
         
+        // SocketIoProcessor.doFlush() will reset it after write is finished
+        // because the buffer will be passed with messageSent event. 
+        ( ( ByteBuffer ) writeRequest.getMessage() ).mark();
         synchronized( writeRequestQueue )
         {
             writeRequestQueue.push( writeRequest );

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketFilterChain.java?rev=385252&r1=385251&r2=385252&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketFilterChain.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketFilterChain.java
Sat Mar 11 21:36:32 2006
@@ -26,6 +26,8 @@
         SocketSessionImpl s = ( SocketSessionImpl ) session;
         Queue writeRequestQueue = s.getWriteRequestQueue();
         
+        // SocketIoProcessor.doFlush() will reset it after write is finished
+        // because the buffer will be passed with messageSent event. 
         ( ( ByteBuffer ) writeRequest.getMessage() ).mark();
         synchronized( writeRequestQueue )
         {

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketIoProcessor.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketIoProcessor.java?rev=385252&r1=385251&r2=385252&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketIoProcessor.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketIoProcessor.java
Sat Mar 11 21:36:32 2006
@@ -459,7 +459,7 @@
             }
             finally
             {
-                req.getFuture().setWritten( false );
+                ( ( SocketFilterChain ) session.getFilterChain() ).messageNotSent( session,
req );
             }
         }
     }
@@ -492,9 +492,10 @@
                     writeRequestQueue.pop();
                 }
                 
-                req.getFuture().setWritten( true );
                 session.increaseWrittenWriteRequests();
-                ( ( SocketFilterChain ) session.getFilterChain() ).messageSent( session,
buf.reset() );
+                
+                buf.reset();
+                ( ( SocketFilterChain ) session.getFilterChain() ).messageSent( session,
req );
                 continue;
             }
 

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/support/VmPipeFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/support/VmPipeFilterChain.java?rev=385252&r1=385251&r2=385252&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/support/VmPipeFilterChain.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/support/VmPipeFilterChain.java
Sat Mar 11 21:36:32 2006
@@ -64,26 +64,26 @@
                     if( message instanceof ByteBuffer )
                     {
                         ByteBuffer rb = ( ByteBuffer ) message;
+                        rb.mark();
                         byteCount = rb.remaining();
                         ByteBuffer wb = ByteBuffer.allocate( rb.remaining() );
                         wb.put( rb );
                         wb.flip();
+                        rb.reset();
                         messageCopy = wb;
                     }
                     
                     s.increaseWrittenBytes( byteCount );
                     s.increaseWrittenWriteRequests();
     
-                    ( ( VmPipeFilterChain ) s.getFilterChain() ).messageSent( s, message
);
+                    ( ( VmPipeFilterChain ) s.getFilterChain() ).messageSent( s, writeRequest
);
                     ( ( VmPipeFilterChain ) s.remoteSession.getFilterChain() )
                                 .messageReceived( s.remoteSession, messageCopy );
-                    
-                    writeRequest.getFuture().setWritten( true );
                 }
             }
             else 
             {
-                writeRequest.getFuture().setWritten( false );
+                ( ( VmPipeFilterChain ) s.getFilterChain() ).messageNotSent( s, writeRequest
);
             }
         }
     }

Modified: directory/trunks/mina/core/src/test/java/org/apache/mina/common/IoFilterChainTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/test/java/org/apache/mina/common/IoFilterChainTest.java?rev=385252&r1=385251&r2=385252&view=diff
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/common/IoFilterChainTest.java
(original)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/common/IoFilterChainTest.java
Sat Mar 11 21:36:32 2006
@@ -438,7 +438,7 @@
 
         protected void doWrite( IoSession session, WriteRequest writeRequest )
         {
-            messageSent( session, writeRequest.getMessage() );
+            messageSent( session, writeRequest );
         }
 
         protected void doClose( IoSession session )



Mime
View raw message