directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r344376 - in /directory/network/trunk/src: java/org/apache/mina/common/ java/org/apache/mina/common/support/ java/org/apache/mina/transport/socket/nio/support/ java/org/apache/mina/transport/vmpipe/support/ test/org/apache/mina/common/
Date Tue, 15 Nov 2005 15:23:06 GMT
Author: trustin
Date: Tue Nov 15 07:22:54 2005
New Revision: 344376

URL: http://svn.apache.org/viewcvs?rev=344376&view=rev
Log:
* Removed a parameter from CloseFuture.setClosed() because it is always closed
* Pulled up common code in IoSession implementations to BaseIoSession

Modified:
    directory/network/trunk/src/java/org/apache/mina/common/CloseFuture.java
    directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoSession.java
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramSessionManagerFilterChain.java
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java
    directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java
    directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionManagerFilterChain.java
    directory/network/trunk/src/test/org/apache/mina/common/FutureTest.java

Modified: directory/network/trunk/src/java/org/apache/mina/common/CloseFuture.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/CloseFuture.java?rev=344376&r1=344375&r2=344376&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/CloseFuture.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/common/CloseFuture.java Tue Nov 15 07:22:54
2005
@@ -55,8 +55,8 @@
      * This method is invoked by MINA internally.  Please do not call this method
      * directly.
      */
-    public void setClosed( boolean closed )
+    public void setClosed()
     {
-        setValue( closed? Boolean.TRUE : Boolean.FALSE );
+        setValue( Boolean.TRUE );
     }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoSession.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoSession.java?rev=344376&r1=344375&r2=344376&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoSession.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/common/support/BaseIoSession.java Tue
Nov 15 07:22:54 2005
@@ -22,10 +22,13 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.mina.common.CloseFuture;
 import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoSessionManager;
 import org.apache.mina.common.TrafficMask;
+import org.apache.mina.common.WriteFuture;
+import org.apache.mina.common.IoFilter.WriteRequest;
 
 /**
  * Base implementation of {@link IoSession}.
@@ -38,6 +41,18 @@
     private final Map attributes = new HashMap();
     private final long creationTime;
 
+    /**
+     * A lock object which is acquired when {@link IoSession#close()},
+     * {@link #isClosing()}, or {@link IoSession#write(Object)} is invoked.
+     */
+    protected final Object ioLock = new Object();
+    
+    /** 
+     * A future that will be set 'closed' when the connection is closed.
+     */
+    protected final CloseFuture closeFuture = new CloseFuture();
+    private boolean closing;
+
     // Configuration variables
     private int idleTimeForRead;
     private int idleTimeForWrite;
@@ -68,6 +83,71 @@
             lastIdleTimeForBoth = lastIdleTimeForRead = lastIdleTimeForWrite =
                 System.currentTimeMillis();
     }
+    
+    public boolean isConnected()
+    {
+        return !closeFuture.isClosed();
+    }
+    
+    public boolean isClosing()
+    {
+        synchronized( ioLock )
+        {
+            return closing;
+        }
+    }
+    
+    public CloseFuture close()
+    {
+        synchronized( ioLock )
+        {
+            if( !closing )
+            {
+                closing = true;
+                close0( closeFuture );
+            }
+        }
+
+        return closeFuture;
+
+    }
+
+    /**
+     * Implement this method to perform real close operation.
+     * 
+     * @param closeFuture a future that should be set to 'closed'
+     */
+    protected void close0( CloseFuture closeFuture )
+    {
+        closeFuture.setClosed();
+    }
+    
+    public WriteFuture write( Object message )
+    {
+        WriteFuture future = new WriteFuture();
+        synchronized( ioLock )
+        {
+            if( isClosing() )
+            {
+                future.setWritten( false );
+            }
+            else
+            {
+                write0( new WriteRequest( message, future ) );
+            }
+        }
+        return future;
+    }
+    
+    /**
+     * Implement this method to perform real write operation with
+     * the specified <code>writeRequest</code>.
+     */
+    protected void write0( WriteRequest writeRequest )
+    {
+        writeRequest.getFuture().setWritten( false );
+    }
+
     
     public Object getAttachment()
     {

Modified: directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java?rev=344376&r1=344375&r2=344376&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java
Tue Nov 15 07:22:54 2005
@@ -28,7 +28,6 @@
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.TransportType;
-import org.apache.mina.common.WriteFuture;
 import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.common.support.BaseIoSession;
 import org.apache.mina.common.support.IoSessionFilterChain;
@@ -50,11 +49,8 @@
     private final Queue writeRequestQueue;
     private final IoHandler handler;
     private final SocketAddress localAddress;
-    private final Object ioLock = new Object();
     private SocketAddress remoteAddress;
     private SelectionKey key;
-    private final CloseFuture closeFuture = new CloseFuture();
-    private boolean closing;
 
     /**
      * Creates a new instance.
@@ -103,28 +99,12 @@
     
     void notifyClose()
     {
-        closeFuture.setClosed( true );
+        closeFuture.setClosed();
     }
     
-    public CloseFuture close()
+    protected void close0( CloseFuture closeFuture )
     {
-        synchronized( ioLock )
-        {
-            if( !closing )
-            {
-                closing = true;
-                managerFilterChain.filterClose( this, closeFuture );
-            }
-        }
-        return closeFuture;
-    }
-    
-    public boolean isClosing()
-    {
-        synchronized( ioLock )
-        {
-            return closing;
-        }
+        managerFilterChain.filterClose( this, closeFuture );
     }
 
     Queue getWriteRequestQueue()
@@ -132,23 +112,11 @@
         return writeRequestQueue;
     }
 
-    public WriteFuture write( Object message )
+    protected void write0( WriteRequest writeRequest )
     {
-        WriteFuture future = new WriteFuture();
-        synchronized( ioLock )
-        {
-            if( isClosing() )
-            {
-                future.setWritten( false );
-            }
-            else
-            {
-                filterChain.filterWrite( this, new WriteRequest( message, future ) );
-            }
-        }
-        return future;
+        filterChain.filterWrite( this, writeRequest );
     }
-    
+
     public int getScheduledWriteRequests()
     {
         synchronized( writeRequestQueue )

Modified: directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramSessionManagerFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramSessionManagerFilterChain.java?rev=344376&r1=344375&r2=344376&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramSessionManagerFilterChain.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramSessionManagerFilterChain.java
Tue Nov 15 07:22:54 2005
@@ -45,7 +45,7 @@
         }
         else
         {
-            closeFuture.setClosed( true );
+            closeFuture.setClosed();
         }
     }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java?rev=344376&r1=344375&r2=344376&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java
Tue Nov 15 07:22:54 2005
@@ -28,7 +28,6 @@
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.TransportType;
-import org.apache.mina.common.WriteFuture;
 import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.common.support.BaseIoSession;
 import org.apache.mina.common.support.IoSessionFilterChain;
@@ -54,10 +53,7 @@
     private final IoHandler handler;
     private final SocketAddress remoteAddress;
     private final SocketAddress localAddress;
-    private final Object ioLock = new Object();
     private SelectionKey key;
-    private CloseFuture closeFuture = new CloseFuture();
-    private boolean closing;
     private int readBufferSize = DEFAULT_READ_BUFFER_SIZE;
 
     /**
@@ -115,31 +111,14 @@
     
     void notifyClose()
     {
-        closeFuture.setClosed( true );
+        closeFuture.setClosed();
     }
     
-    public CloseFuture close()
+    protected void close0( CloseFuture closeFuture )
     {
-        synchronized( ioLock )
-        {
-            if( !closing )
-            {
-                closing = true;
-                filterChain.filterClose( this, closeFuture );
-            }
-        }
-
-        return closeFuture;
+        filterChain.filterClose( this, closeFuture );
     }
     
-    public boolean isClosing()
-    {
-        synchronized( ioLock )
-        {
-            return closing;
-        }
-    }
-
     Queue getWriteRequestQueue()
     {
         return writeRequestQueue;
@@ -153,21 +132,9 @@
         }
     }
 
-    public WriteFuture write( Object message )
+    protected void write0( WriteRequest writeRequest )
     {
-        WriteFuture future = new WriteFuture();
-        synchronized( ioLock )
-        {
-            if( isClosing() )
-            {
-                future.setWritten( false );
-            }
-            else
-            {
-                filterChain.filterWrite( this, new WriteRequest( message, future ) );
-            }
-        }
-        return future;
+        filterChain.filterWrite( this, writeRequest );
     }
 
     public TransportType getTransportType()

Modified: directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java?rev=344376&r1=344375&r2=344376&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionImpl.java
Tue Nov 15 07:22:54 2005
@@ -11,7 +11,6 @@
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.TransportType;
-import org.apache.mina.common.WriteFuture;
 import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.common.support.BaseIoSession;
 import org.apache.mina.common.support.IoSessionFilterChain;
@@ -33,11 +32,8 @@
     private final IoHandler handler;
     private final IoSessionFilterChain filterChain;
     private final VmPipeSessionManagerFilterChain managerFilterChain;
-    private final Object ioLock = new Object();
     final VmPipeSessionImpl remoteSession;
     final Object lock;
-    private boolean closing;
-    CloseFuture closeFuture = new CloseFuture();
 
     /**
      * Constructor for client-side session.
@@ -121,44 +117,20 @@
     {
         return null;
     }
-
-    public CloseFuture close()
+    
+    CloseFuture getCloseFuture()
     {
-        synchronized( ioLock )
-        {
-            if( !closing )
-            {
-                closing = true;
-                managerFilterChain.filterClose( this, closeFuture );
-            }
-        }
         return closeFuture;
     }
-    
-    public boolean isClosing()
+
+    protected void close0( CloseFuture closeFuture )
     {
-        synchronized( ioLock )
-        {
-            return closing;
-        }
+        managerFilterChain.filterClose( this, closeFuture );
     }
     
-
-    public WriteFuture write( Object message )
+    protected void write0( WriteRequest writeRequest )
     {
-        WriteFuture future = new WriteFuture();
-        synchronized( ioLock )
-        {
-            if( isClosing() )
-            {
-                future.setWritten( false );
-            }
-            else
-            {
-                this.filterChain.filterWrite( this, new WriteRequest( message, future ) );
-            }
-        }
-        return future;
+        this.filterChain.filterWrite( this, writeRequest );
     }
 
     public int getScheduledWriteRequests()
@@ -169,11 +141,6 @@
     public TransportType getTransportType()
     {
         return TransportType.VM_PIPE;
-    }
-
-    public boolean isConnected()
-    {
-        return !closeFuture.isClosed();
     }
 
     public SocketAddress getRemoteAddress()

Modified: directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionManagerFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionManagerFilterChain.java?rev=344376&r1=344375&r2=344376&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionManagerFilterChain.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/vmpipe/support/VmPipeSessionManagerFilterChain.java
Tue Nov 15 07:22:54 2005
@@ -35,14 +35,14 @@
         VmPipeSessionImpl s = ( VmPipeSessionImpl ) session;
         synchronized( s.lock )
         {
-            if( !s.closeFuture.isClosed() )
+            if( s.getCloseFuture().isClosed() )
             {
-                s.remoteSession.closeFuture.setClosed( true );
+                s.remoteSession.getCloseFuture().setClosed();
                 s.getManagerFilterChain().sessionClosed( session );
                 s.remoteSession.getManagerFilterChain().sessionClosed( s.remoteSession );
             }
         }
         
-        closeFuture.setClosed( true );
+        closeFuture.setClosed();
     }
 }

Modified: directory/network/trunk/src/test/org/apache/mina/common/FutureTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/common/FutureTest.java?rev=344376&r1=344375&r2=344376&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/common/FutureTest.java (original)
+++ directory/network/trunk/src/test/org/apache/mina/common/FutureTest.java Tue Nov 15 07:22:54
2005
@@ -43,22 +43,12 @@
         TestThread thread = new TestThread( future );
         thread.start();
         
-        future.setClosed( true );
+        future.setClosed();
         thread.join();
         
         assertTrue( thread.success );
         assertTrue( future.isReady() );
         assertTrue( future.isClosed() );
-        
-        thread = new TestThread( future );
-        thread.start();
-        
-        future.setClosed( false );
-        thread.join();
-        
-        assertTrue( thread.success );
-        assertTrue( future.isReady() );
-        assertFalse( future.isClosed() );
     }
     
     public void testConnectFuture() throws Exception



Mime
View raw message