directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r164009 - in /directory/network/trunk/src: java/org/apache/mina/common/ java/org/apache/mina/io/ java/org/apache/mina/io/datagram/ java/org/apache/mina/io/socket/ java/org/apache/mina/protocol/ java/org/apache/mina/protocol/io/ java/org/apache/mina/protocol/vmpipe/ java/org/apache/mina/util/ test/org/apache/mina/io/ test/org/apache/mina/protocol/ test/org/apache/mina/protocol/codec/
Date Thu, 21 Apr 2005 07:40:00 GMT
Author: trustin
Date: Thu Apr 21 00:39:58 2005
New Revision: 164009

URL: http://svn.apache.org/viewcvs?rev=164009&view=rev
Log:
* Extracted common methods of IoSession and ProtocolSession to Session
* Added BaseSession that implements Session and made most of Sessions extend it
* Renamed BasicSessionConfig to BaseSessionConfig
* Added user-defined attributes to Session and made attachment a user-defined attribute whose
key is "" (empty string)

Added:
    directory/network/trunk/src/java/org/apache/mina/common/Session.java   (with props)
    directory/network/trunk/src/java/org/apache/mina/util/BaseSession.java   (with props)
    directory/network/trunk/src/java/org/apache/mina/util/BaseSessionConfig.java   (with props)
Removed:
    directory/network/trunk/src/java/org/apache/mina/util/BasicSessionConfig.java
Modified:
    directory/network/trunk/src/java/org/apache/mina/io/IoSession.java
    directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramSession.java
    directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramSessionConfig.java
    directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java
    directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSessionConfig.java
    directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolSession.java
    directory/network/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java
    directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeFilter.java
    directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeIdleStatusChecker.java
    directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java
    directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSessionConfig.java
    directory/network/trunk/src/test/org/apache/mina/io/IoHandlerFilterChainTest.java
    directory/network/trunk/src/test/org/apache/mina/protocol/ProtocolHandlerFilterChainTest.java
    directory/network/trunk/src/test/org/apache/mina/protocol/codec/CumulativeProtocolDecoderTest.java

Added: directory/network/trunk/src/java/org/apache/mina/common/Session.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/Session.java?rev=164009&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/Session.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/common/Session.java Thu Apr 21 00:39:58
2005
@@ -0,0 +1,135 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.common;
+
+import java.net.SocketAddress;
+import java.util.Set;
+
+/**
+ * A handle which represents connection between two endpoints regardless of 
+ * transport types.
+ * <p>
+ * Session provides user-defined attributes.  User-defined attributes are
+ * application-specific data which is associated with a session.
+ * It often contains objects that represents the state of a higher-level protocol
+ * and becomes a way to exchange data between filters and handlers.
+ *   
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public interface Session {
+
+    /**
+     * Closes this session immediately.
+     */
+    void close();
+    
+    /**
+     * Returns an attachment of this session.
+     * This method is identical with <tt>getAttribute( "" )</tt>.
+     */
+    Object getAttachment();
+
+    /**
+     * Sets an attachment of this session.
+     * This method is identical with <tt>setAttribute( "", attachment )</tt>.
+     * 
+     * @return Old attachment.  <tt>null</tt> if it is new.
+     */
+    Object setAttachment( Object attachment );
+    
+    /**
+     * Returns the value of user-defined attribute of this session.
+     * 
+     * @param key the key of the attribute
+     * @return <tt>null</tt> if there is no attribute with the specified key
+     */
+    Object getAttribute( String key );
+    
+    /**
+     * Sets a user-defined attribute.
+     * 
+     * @param key the key of the attribute
+     * @param value the value of the attribute
+     * @return The old value of the attribute.  <tt>null</tt> if it is new.
+     */
+    Object setAttribute( String key, Object value );
+    
+    /**
+     * Returns the set of keys of all user-defined attributes.
+     */
+    Set getAttributeKeys();
+    
+    /**
+     * Returns transport type of this session.
+     */
+    TransportType getTransportType();
+
+    /**
+     * Returns <code>true</code> if this session is connected with remote peer.
+     */
+    boolean isConnected();
+
+    /**
+     * Returns the configuration of this session.
+     */
+    SessionConfig getConfig();
+
+    /**
+     * Returns the socket address of remote peer. 
+     */
+    SocketAddress getRemoteAddress();
+
+    /**
+     * Returns the socket address of local machine which is associated with this
+     * session.
+     */
+    SocketAddress getLocalAddress();
+
+    /**
+     * Returns the total number of bytes which were read from this session.
+     */
+    long getReadBytes();
+
+    /**
+     * Returns the total number of bytes which were written to this session.
+     */
+    long getWrittenBytes();
+
+    /**
+     * Returns the time in millis when I/O occurred lastly.
+     */
+    long getLastIoTime();
+
+    /**
+     * Returns the time in millis when read operation occurred lastly.
+     */
+    long getLastReadTime();
+
+    /**
+     * Returns the time in millis when write operation occurred lastly.
+     */
+    long getLastWriteTime();
+
+    /**
+     * Returns <code>true</code> if this session is idle for the specified 
+     * {@link IdleStatus}.
+     */
+    boolean isIdle( IdleStatus status );
+}

Propchange: directory/network/trunk/src/java/org/apache/mina/common/Session.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/network/trunk/src/java/org/apache/mina/io/IoSession.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/IoSession.java?rev=164009&r1=164008&r2=164009&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/IoSession.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/IoSession.java Thu Apr 21 00:39:58
2005
@@ -18,26 +18,19 @@
  */
 package org.apache.mina.io;
 
-import java.net.SocketAddress;
-
 import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.IdleStatus;
-import org.apache.mina.common.SessionConfig;
-import org.apache.mina.common.TransportType;
+import org.apache.mina.common.Session;
 
 /**
- * A handle which represents connection between two endpoints regardless of 
- * transport types (UDP/IP and TCP/IP).
- * <p>
- * Session provides an attachment per session ({@link #getAttachment()} and
- * {@link #setAttachment(Object)}).  Attachment is an application-specific data
- * which is associated with a session.  It is often an object that represents
- * the state of a higher-level protocol.
+ * A {@link Session} that represents low-level I/O connection between two
+ * endpoints regardless of underlying transport types.
  *   
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$
+ * 
+ * @see Session
  */
-public interface IoSession
+public interface IoSession extends Session
 {
     /**
      * Returns the event handler for this session.
@@ -45,82 +38,10 @@
     IoHandler getHandler();
 
     /**
-     * Closes this session immediately.
-     */
-    void close();
-
-    /**
      * Writes the content of the specified <code>buf</code>.
      * This operation is asynchronous, and you'll get notified by
      * {@link IoHandler#dataWritten(IoSession, Object)} event.
      * The specified <code>marker</code> will be passes as a parameter.
      */
     void write( ByteBuffer buf, Object marker );
-
-    /**
-     * Returns an attachment of this session.
-     */
-    Object getAttachment();
-
-    /**
-     * Sets an attachment of this session.
-     */
-    void setAttachment( Object attachment );
-
-    /**
-     * Returns transport type of this session.
-     */
-    TransportType getTransportType();
-
-    /**
-     * Returns <code>true</code> if this session is connected with remote peer.
-     */
-    boolean isConnected();
-
-    /**
-     * Returns the configuration of this session.
-     */
-    SessionConfig getConfig();
-
-    /**
-     * Returns the socket address of remote peer. 
-     */
-    SocketAddress getRemoteAddress();
-
-    /**
-     * Returns the socket address of local machine which is associated with this
-     * session.
-     */
-    SocketAddress getLocalAddress();
-
-    /**
-     * Returns the total number of bytes which were read from this session.
-     */
-    long getReadBytes();
-
-    /**
-     * Returns the total number of bytes which were written to this session.
-     */
-    long getWrittenBytes();
-
-    /**
-     * Returns the time in millis when I/O occurred lastly.
-     */
-    long getLastIoTime();
-
-    /**
-     * Returns the time in millis when read operation occurred lastly.
-     */
-    long getLastReadTime();
-
-    /**
-     * Returns the time in millis when write operation occurred lastly.
-     */
-    long getLastWriteTime();
-
-    /**
-     * Returns <code>true</code> if this session is idle for the specified 
-     * {@link IdleStatus}.
-     */
-    boolean isIdle( IdleStatus status );
 }

Modified: directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramSession.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramSession.java?rev=164009&r1=164008&r2=164009&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramSession.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramSession.java Thu
Apr 21 00:39:58 2005
@@ -23,11 +23,11 @@
 import java.nio.channels.SelectionKey;
 
 import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.SessionConfig;
 import org.apache.mina.common.TransportType;
 import org.apache.mina.io.IoHandler;
 import org.apache.mina.io.IoSession;
+import org.apache.mina.util.BaseSession;
 import org.apache.mina.util.Queue;
 
 /**
@@ -36,7 +36,7 @@
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$
  */
-class DatagramSession implements IoSession
+class DatagramSession extends BaseSession implements IoSession
 {
     private final DatagramFilterChain filters;
 
@@ -56,22 +56,6 @@
 
     private SelectionKey key;
 
-    private Object attachment;
-
-    private long readBytes;
-
-    private long writtenBytes;
-
-    private long lastReadTime;
-
-    private long lastWriteTime;
-
-    private boolean idleForBoth;
-
-    private boolean idleForRead;
-
-    private boolean idleForWrite;
-
     /**
      * Creates a new instance.
      */
@@ -117,16 +101,6 @@
     {
     }
 
-    public Object getAttachment()
-    {
-        return attachment;
-    }
-
-    public void setAttachment( Object attachment )
-    {
-        this.attachment = attachment;
-    }
-
     Queue getWriteBufferQueue()
     {
         return writeBufferQueue;
@@ -170,69 +144,5 @@
     public SocketAddress getLocalAddress()
     {
         return localAddress;
-    }
-
-    public long getReadBytes()
-    {
-        return readBytes;
-    }
-
-    public long getWrittenBytes()
-    {
-        return writtenBytes;
-    }
-
-    void increaseReadBytes( int increment )
-    {
-        readBytes += increment;
-        lastReadTime = System.currentTimeMillis();
-    }
-
-    void increaseWrittenBytes( int increment )
-    {
-        writtenBytes += increment;
-        lastWriteTime = System.currentTimeMillis();
-    }
-
-    public long getLastIoTime()
-    {
-        return Math.max( lastReadTime, lastWriteTime );
-    }
-
-    public long getLastReadTime()
-    {
-        return lastReadTime;
-    }
-
-    public long getLastWriteTime()
-    {
-        return lastWriteTime;
-    }
-
-    public boolean isIdle( IdleStatus status )
-    {
-        if( status == IdleStatus.BOTH_IDLE )
-            return idleForBoth;
-
-        if( status == IdleStatus.READER_IDLE )
-            return idleForRead;
-
-        if( status == IdleStatus.WRITER_IDLE )
-            return idleForWrite;
-
-        throw new IllegalArgumentException( "Unknown idle status: " + status );
-    }
-
-    void setIdle( IdleStatus status )
-    {
-        if( status == IdleStatus.BOTH_IDLE )
-            idleForBoth = true;
-        else if( status == IdleStatus.READER_IDLE )
-            idleForRead = true;
-        else if( status == IdleStatus.WRITER_IDLE )
-            idleForWrite = true;
-        else
-            throw new IllegalArgumentException( "Unknown idle status: "
-                                                + status );
     }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramSessionConfig.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramSessionConfig.java?rev=164009&r1=164008&r2=164009&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramSessionConfig.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramSessionConfig.java
Thu Apr 21 00:39:58 2005
@@ -24,7 +24,7 @@
 import org.apache.mina.common.SessionConfig;
 import org.apache.mina.io.IoSession;
 import org.apache.mina.protocol.ProtocolSession;
-import org.apache.mina.util.BasicSessionConfig;
+import org.apache.mina.util.BaseSessionConfig;
 
 /**
  * A {@link SessionConfig} for datagram transport (UDP/IP).
@@ -36,7 +36,7 @@
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$,
  */
-public class DatagramSessionConfig extends BasicSessionConfig
+public class DatagramSessionConfig extends BaseSessionConfig
 {
     private final DatagramChannel ch;
 

Modified: directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java?rev=164009&r1=164008&r2=164009&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java Thu Apr
21 00:39:58 2005
@@ -23,11 +23,11 @@
 import java.nio.channels.SocketChannel;
 
 import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.SessionConfig;
 import org.apache.mina.common.TransportType;
 import org.apache.mina.io.IoHandler;
 import org.apache.mina.io.IoSession;
+import org.apache.mina.util.BaseSession;
 import org.apache.mina.util.Queue;
 
 /**
@@ -36,7 +36,7 @@
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$
  */
-class SocketSession implements IoSession
+class SocketSession extends BaseSession implements IoSession
 {
     private final SocketFilterChain filters;
 
@@ -56,22 +56,6 @@
 
     private SelectionKey key;
 
-    private Object attachment;
-
-    private long readBytes;
-
-    private long writtenBytes;
-
-    private long lastReadTime;
-
-    private long lastWriteTime;
-
-    private boolean idleForBoth;
-
-    private boolean idleForRead;
-
-    private boolean idleForWrite;
-
     /**
      * Creates a new instance.
      */
@@ -118,16 +102,6 @@
         SocketIoProcessor.getInstance().removeSession( this );
     }
 
-    public Object getAttachment()
-    {
-        return attachment;
-    }
-
-    public void setAttachment( Object attachment )
-    {
-        this.attachment = attachment;
-    }
-
     Queue getWriteBufferQueue()
     {
         return writeBufferQueue;
@@ -166,69 +140,5 @@
     public SocketAddress getLocalAddress()
     {
         return localAddress;
-    }
-
-    public long getReadBytes()
-    {
-        return readBytes;
-    }
-
-    public long getWrittenBytes()
-    {
-        return writtenBytes;
-    }
-
-    void increaseReadBytes( int increment )
-    {
-        readBytes += increment;
-        lastReadTime = System.currentTimeMillis();
-    }
-
-    void increaseWrittenBytes( int increment )
-    {
-        writtenBytes += increment;
-        lastWriteTime = System.currentTimeMillis();
-    }
-
-    public long getLastIoTime()
-    {
-        return Math.max( lastReadTime, lastWriteTime );
-    }
-
-    public long getLastReadTime()
-    {
-        return lastReadTime;
-    }
-
-    public long getLastWriteTime()
-    {
-        return lastWriteTime;
-    }
-
-    public boolean isIdle( IdleStatus status )
-    {
-        if( status == IdleStatus.BOTH_IDLE )
-            return idleForBoth;
-
-        if( status == IdleStatus.READER_IDLE )
-            return idleForRead;
-
-        if( status == IdleStatus.WRITER_IDLE )
-            return idleForWrite;
-
-        throw new IllegalArgumentException( "Unknown idle status: " + status );
-    }
-
-    void setIdle( IdleStatus status, boolean value )
-    {
-        if( status == IdleStatus.BOTH_IDLE )
-            idleForBoth = value;
-        else if( status == IdleStatus.READER_IDLE )
-            idleForRead = value;
-        else if( status == IdleStatus.WRITER_IDLE )
-            idleForWrite = value;
-        else
-            throw new IllegalArgumentException( "Unknown idle status: "
-                                                + status );
     }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSessionConfig.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSessionConfig.java?rev=164009&r1=164008&r2=164009&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSessionConfig.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSessionConfig.java Thu
Apr 21 00:39:58 2005
@@ -23,7 +23,7 @@
 import org.apache.mina.common.SessionConfig;
 import org.apache.mina.io.IoSession;
 import org.apache.mina.protocol.ProtocolSession;
-import org.apache.mina.util.BasicSessionConfig;
+import org.apache.mina.util.BaseSessionConfig;
 
 /**
  * A {@link SessionConfig} for socket transport (TCP/IP).
@@ -35,7 +35,7 @@
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$,
  */
-public class SocketSessionConfig extends BasicSessionConfig
+public class SocketSessionConfig extends BaseSessionConfig
 {
     private static final int DEFAULT_READ_BUFFER_SIZE = 1024;
 

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolSession.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolSession.java?rev=164009&r1=164008&r2=164009&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolSession.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolSession.java Thu Apr
21 00:39:58 2005
@@ -18,25 +18,18 @@
  */
 package org.apache.mina.protocol;
 
-import java.net.SocketAddress;
-
-import org.apache.mina.common.IdleStatus;
-import org.apache.mina.common.SessionConfig;
-import org.apache.mina.common.TransportType;
+import org.apache.mina.common.Session;
 
 /**
- * A handle which represents high-level protocol connection between two
+ * A {@link Session} which represents high-level protocol connection between two
  * endpoints regardless of underlying transport types.
- * <p>
- * Session provides an attachment per session ({@link #getAttachment()} and
- * {@link #setAttachment(Object)}).  Attachment is an application-specific data
- * which is associated with a session.  It is often an object that represents
- * the state of a higher-level protocol.
  * 
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$
+ * 
+ * @see Session
  */
-public interface ProtocolSession
+public interface ProtocolSession extends Session
 {
     /**
      * Returns the {@link ProtocolHandler} which handles this session.
@@ -54,81 +47,9 @@
     ProtocolDecoder getDecoder();
 
     /**
-     * Closes the connection immediately.
-     */
-    void close();
-
-    /**
-     * Returns an attachment of this session.
-     */
-    Object getAttachment();
-
-    /**
-     * Sets an attachment of this session.
-     */
-    void setAttachment( Object attachment );
-
-    /**
      * Writes the specified <code>message</code> to remote peer.  This operation
      * is asynchronous; {@link ProtocolHandler#messageSent(ProtocolSession, Object)}
      * will be invoked when the message is actually sent to remote peer.
      */
     void write( Object message );
-
-    /**
-     * Returns transport type of this session.
-     */
-    TransportType getTransportType();
-
-    /**
-     * Returns <code>true</code> if this session is connected with remote peer.
-     */
-    boolean isConnected();
-
-    /**
-     * Returns the configuration of this session.
-     */
-    SessionConfig getConfig();
-
-    /**
-     * Returns the socket address of remote peer. 
-     */
-    SocketAddress getRemoteAddress();
-
-    /**
-     * Returns the socket address of local machine which is associated with this
-     * session.
-     */
-    SocketAddress getLocalAddress();
-
-    /**
-     * Returns the total number of bytes which were read from this session.
-     */
-    long getReadBytes();
-
-    /**
-     * Returns the total number of bytes which were written to this session.
-     */
-    long getWrittenBytes();
-
-    /**
-     * Returns the time in millis when I/O occurred lastly.
-     */
-    long getLastIoTime();
-
-    /**
-     * Returns the time in millis when read operation occurred lastly.
-     */
-    long getLastReadTime();
-
-    /**
-     * Returns the time in millis when write operation occurred lastly.
-     */
-    long getLastWriteTime();
-
-    /**
-     * Returns <code>true</code> if this session is idle for the specified 
-     * {@link IdleStatus}.
-     */
-    boolean isIdle( IdleStatus status );
 }

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java?rev=164009&r1=164008&r2=164009&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java Thu Apr 21
00:39:58 2005
@@ -19,6 +19,7 @@
 package org.apache.mina.protocol.io;
 
 import java.net.SocketAddress;
+import java.util.Set;
 
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IdleStatus;
@@ -245,8 +246,6 @@
 
         private final ProtocolDecoderOutputImpl decOut;
 
-        private Object attachment;
-
         private ProtocolSessionImpl( IoSession session,
                                     SessionHandlerAdapter adapter )
         {
@@ -280,12 +279,27 @@
 
         public Object getAttachment()
         {
-            return attachment;
+            return session.getAttachment();
+        }
+
+        public Object setAttachment( Object attachment )
+        {
+            return session.setAttachment( attachment );
+        }
+
+        public Object getAttribute( String key )
+        {
+            return session.getAttribute( key );
+        }
+
+        public Object setAttribute( String key, Object value )
+        {
+            return session.setAttribute( key, value );
         }
 
-        public void setAttachment( Object attachment )
+        public Set getAttributeKeys()
         {
-            this.attachment = attachment;
+            return session.getAttributeKeys();
         }
 
         public void write( Object message )

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeFilter.java?rev=164009&r1=164008&r2=164009&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeFilter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeFilter.java Thu
Apr 21 00:39:58 2005
@@ -3,6 +3,7 @@
  */
 package org.apache.mina.protocol.vmpipe;
 
+import org.apache.mina.common.IdleStatus;
 import org.apache.mina.protocol.ProtocolHandler;
 import org.apache.mina.protocol.ProtocolHandlerFilterAdapter;
 import org.apache.mina.protocol.ProtocolSession;
@@ -20,8 +21,9 @@
     {
         VmPipeSession vps = ( VmPipeSession ) session;
 
-        vps.bothIdle = vps.readerIdle = false;
-        vps.lastReadTime = System.currentTimeMillis();
+        vps.setIdle( IdleStatus.BOTH_IDLE, false );
+        vps.setIdle( IdleStatus.READER_IDLE, false );
+        vps.increaseReadBytes( 0 );
 
         // fire messageSent event first
         vps.remoteFilters.messageSent( vps.remoteSession, message );
@@ -34,8 +36,9 @@
                             ProtocolSession session, Object message )
     {
         VmPipeSession vps = ( VmPipeSession ) session;
-        vps.bothIdle = vps.writerIdle = false;
-        vps.lastWriteTime = System.currentTimeMillis();
+        vps.setIdle( IdleStatus.BOTH_IDLE, false );
+        vps.setIdle( IdleStatus.WRITER_IDLE, false );
+        vps.increaseWrittenBytes( 0 );
 
         nextHandler.messageSent( session, message );
     }

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeIdleStatusChecker.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeIdleStatusChecker.java?rev=164009&r1=164008&r2=164009&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeIdleStatusChecker.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeIdleStatusChecker.java
Thu Apr 21 00:39:58 2005
@@ -74,37 +74,40 @@
                             long idleTime;
                             SessionConfig config = session.getConfig();
 
-                            if( !session.bothIdle )
+                            if( !session.isIdle( IdleStatus.BOTH_IDLE ) )
                             {
                                 idleTime = config
                                         .getIdleTimeInMillis( IdleStatus.BOTH_IDLE );
-                                session.bothIdle = idleTime > 0L
-                                                   && ( currentTime - session.lastReadTime
) > idleTime;
-                                if( session.bothIdle )
+                                session.setIdle( IdleStatus.BOTH_IDLE,
+                                                 idleTime > 0L
+                                                 && ( currentTime - session.getLastIoTime()
) > idleTime );
+                                if( session.isIdle( IdleStatus.BOTH_IDLE ) )
                                     session.localFilters
                                             .sessionIdle( session,
                                                           IdleStatus.BOTH_IDLE );
                             }
 
-                            if( !session.readerIdle )
+                            if( !session.isIdle( IdleStatus.READER_IDLE ) )
                             {
                                 idleTime = config
                                         .getIdleTimeInMillis( IdleStatus.READER_IDLE );
-                                session.readerIdle = idleTime > 0L
-                                                     && ( currentTime - session.lastReadTime
) > idleTime;
-                                if( session.readerIdle )
+                                session.setIdle( IdleStatus.READER_IDLE,
+                                                 idleTime > 0L
+                                                 && ( currentTime - session.getLastReadTime()
) > idleTime );
+                                if( session.isIdle( IdleStatus.READER_IDLE ) )
                                     session.localFilters
                                             .sessionIdle( session,
                                                           IdleStatus.READER_IDLE );
                             }
 
-                            if( !session.writerIdle )
+                            if( !session.isIdle( IdleStatus.WRITER_IDLE ) )
                             {
                                 idleTime = config
                                         .getIdleTimeInMillis( IdleStatus.WRITER_IDLE );
-                                session.writerIdle = idleTime > 0L
-                                                     && ( currentTime - session.lastReadTime
) > idleTime;
-                                if( session.writerIdle )
+                                session.setIdle( IdleStatus.WRITER_IDLE,
+                                                 idleTime > 0L
+                                                 && ( currentTime - session.getLastWriteTime()
) > idleTime );
+                                if( session.isIdle( IdleStatus.WRITER_IDLE ) )
                                     session.localFilters
                                             .sessionIdle( session,
                                                           IdleStatus.WRITER_IDLE );

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java?rev=164009&r1=164008&r2=164009&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java Thu
Apr 21 00:39:58 2005
@@ -5,13 +5,13 @@
 
 import java.net.SocketAddress;
 
-import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.SessionConfig;
 import org.apache.mina.common.TransportType;
 import org.apache.mina.protocol.ProtocolDecoder;
 import org.apache.mina.protocol.ProtocolEncoder;
 import org.apache.mina.protocol.ProtocolHandler;
 import org.apache.mina.protocol.ProtocolSession;
+import org.apache.mina.util.BaseSession;
 
 /**
  * TODO Document me.
@@ -19,7 +19,7 @@
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$
  */
-class VmPipeSession implements ProtocolSession
+class VmPipeSession extends BaseSession implements ProtocolSession
 {
     private final SocketAddress localAddress;
 
@@ -35,22 +35,10 @@
 
     final VmPipeSession remoteSession;
 
-    private Object attachment;
-
     final Object lock;
 
     boolean closed;
 
-    long lastReadTime;
-
-    long lastWriteTime;
-
-    boolean bothIdle;
-
-    boolean readerIdle;
-
-    boolean writerIdle;
-
     /**
      * Constructor for client-side session.
      */
@@ -117,16 +105,6 @@
         }
     }
 
-    public Object getAttachment()
-    {
-        return attachment;
-    }
-
-    public void setAttachment( Object attachment )
-    {
-        this.attachment = attachment;
-    }
-
     public void write( Object message )
     {
         localFilters.filterWrite( this, message );
@@ -155,45 +133,5 @@
     public SocketAddress getLocalAddress()
     {
         return localAddress;
-    }
-
-    public long getReadBytes()
-    {
-        return 0;
-    }
-
-    public long getWrittenBytes()
-    {
-        return 0;
-    }
-
-    public long getLastIoTime()
-    {
-        return Math.max( lastReadTime, lastWriteTime );
-    }
-
-    public long getLastReadTime()
-    {
-        return lastReadTime;
-    }
-
-    public long getLastWriteTime()
-    {
-        return lastWriteTime;
-    }
-
-    public boolean isIdle( IdleStatus status )
-    {
-        if( status == null )
-            throw new NullPointerException( "status" );
-
-        if( status == IdleStatus.BOTH_IDLE )
-            return bothIdle;
-        if( status == IdleStatus.READER_IDLE )
-            return readerIdle;
-        if( status == IdleStatus.WRITER_IDLE )
-            return writerIdle;
-
-        throw new IllegalArgumentException( "Illegal statue: " + status );
     }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSessionConfig.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSessionConfig.java?rev=164009&r1=164008&r2=164009&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSessionConfig.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSessionConfig.java
Thu Apr 21 00:39:58 2005
@@ -4,7 +4,7 @@
 package org.apache.mina.protocol.vmpipe;
 
 import org.apache.mina.common.SessionConfig;
-import org.apache.mina.util.BasicSessionConfig;
+import org.apache.mina.util.BaseSessionConfig;
 
 /**
  * A {@link SessionConfig} for in-VM pipe transport.
@@ -12,6 +12,6 @@
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$
  */
-public class VmPipeSessionConfig extends BasicSessionConfig
+public class VmPipeSessionConfig extends BaseSessionConfig
 {
 }

Added: directory/network/trunk/src/java/org/apache/mina/util/BaseSession.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/util/BaseSession.java?rev=164009&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/util/BaseSession.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/util/BaseSession.java Thu Apr 21 00:39:58
2005
@@ -0,0 +1,153 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.util;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.Session;
+
+/**
+ * Base implementation of {@link Session}.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public abstract class BaseSession implements Session
+{
+    private final Map attributes = new HashMap();
+
+    private long readBytes;
+    
+    private long writtenBytes;
+    
+    private long lastReadTime;
+    
+    private long lastWriteTime;
+
+    private boolean idleForBoth;
+
+    private boolean idleForRead;
+
+    private boolean idleForWrite;
+
+
+    protected BaseSession()
+    {
+    }
+
+    public Object getAttachment()
+    {
+        return attributes.get( "" );
+    }
+
+    public Object setAttachment( Object attachment )
+    {
+        synchronized( attributes )
+        {
+            return attributes.put( "", attachment );
+        }
+    }
+
+    public Object getAttribute( String key )
+    {
+        return attributes.get( key );
+    }
+
+    public Object setAttribute( String key, Object value )
+    {
+        synchronized( attributes )
+        {
+            return attributes.put( key, value );
+        }
+    }
+
+    public Set getAttributeKeys() {
+        synchronized( attributes )
+        {
+            return attributes.keySet();
+        }
+    }
+
+    public long getReadBytes()
+    {
+        return readBytes;
+    }
+
+    public long getWrittenBytes()
+    {
+        return writtenBytes;
+    }
+
+    public void increaseReadBytes( int increment )
+    {
+        readBytes += increment;
+        lastReadTime = System.currentTimeMillis();
+    }
+
+    public void increaseWrittenBytes( int increment )
+    {
+        writtenBytes += increment;
+        lastWriteTime = System.currentTimeMillis();
+    }
+
+    public long getLastIoTime()
+    {
+        return Math.max( lastReadTime, lastWriteTime );
+    }
+
+    public long getLastReadTime()
+    {
+        return lastReadTime;
+    }
+
+    public long getLastWriteTime()
+    {
+        return lastWriteTime;
+    }
+
+    public boolean isIdle( IdleStatus status )
+    {
+        if( status == IdleStatus.BOTH_IDLE )
+            return idleForBoth;
+
+        if( status == IdleStatus.READER_IDLE )
+            return idleForRead;
+
+        if( status == IdleStatus.WRITER_IDLE )
+            return idleForWrite;
+
+        throw new IllegalArgumentException( "Unknown idle status: " + status );
+    }
+
+    public void setIdle( IdleStatus status, boolean value )
+    {
+        if( status == IdleStatus.BOTH_IDLE )
+            idleForBoth = value;
+        else if( status == IdleStatus.READER_IDLE )
+            idleForRead = value;
+        else if( status == IdleStatus.WRITER_IDLE )
+            idleForWrite = value;
+        else
+            throw new IllegalArgumentException( "Unknown idle status: "
+                                                + status );
+    }
+}

Propchange: directory/network/trunk/src/java/org/apache/mina/util/BaseSession.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/java/org/apache/mina/util/BaseSessionConfig.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/util/BaseSessionConfig.java?rev=164009&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/util/BaseSessionConfig.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/util/BaseSessionConfig.java Thu Apr 21
00:39:58 2005
@@ -0,0 +1,97 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.util;
+
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.SessionConfig;
+
+/**
+ * Base implementation of {@link SessionConfig}s.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public abstract class BaseSessionConfig implements SessionConfig
+{
+    private int idleTimeForRead;
+
+    private int idleTimeForWrite;
+
+    private int idleTimeForBoth;
+
+    private int writeTimeout;
+
+    protected BaseSessionConfig()
+    {
+    }
+
+    public int getIdleTime( IdleStatus status )
+    {
+        if( status == IdleStatus.BOTH_IDLE )
+            return idleTimeForBoth;
+
+        if( status == IdleStatus.READER_IDLE )
+            return idleTimeForRead;
+
+        if( status == IdleStatus.WRITER_IDLE )
+            return idleTimeForWrite;
+
+        throw new IllegalArgumentException( "Unknown idle status: " + status );
+    }
+
+    public long getIdleTimeInMillis( IdleStatus status )
+    {
+        return getIdleTime( status ) * 1000L;
+    }
+
+    public void setIdleTime( IdleStatus status, int idleTime )
+    {
+        if( idleTime < 0 )
+            throw new IllegalArgumentException( "Illegal idle time: "
+                                                + idleTime );
+
+        if( status == IdleStatus.BOTH_IDLE )
+            idleTimeForBoth = idleTime;
+        else if( status == IdleStatus.READER_IDLE )
+            idleTimeForRead = idleTime;
+        else if( status == IdleStatus.WRITER_IDLE )
+            idleTimeForWrite = idleTime;
+        else
+            throw new IllegalArgumentException( "Unknown idle status: "
+                                                + status );
+    }
+
+    public int getWriteTimeout()
+    {
+        return writeTimeout;
+    }
+
+    public long getWriteTimeoutInMillis()
+    {
+        return writeTimeout * 1000L;
+    }
+
+    public void setWriteTimeout( int writeTimeout )
+    {
+        if( writeTimeout < 0 )
+            throw new IllegalArgumentException( "Illegal write timeout: "
+                                                + writeTimeout );
+        this.writeTimeout = writeTimeout;
+    }
+}
\ No newline at end of file

Propchange: directory/network/trunk/src/java/org/apache/mina/util/BaseSessionConfig.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/network/trunk/src/test/org/apache/mina/io/IoHandlerFilterChainTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/io/IoHandlerFilterChainTest.java?rev=164009&r1=164008&r2=164009&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/io/IoHandlerFilterChainTest.java (original)
+++ directory/network/trunk/src/test/org/apache/mina/io/IoHandlerFilterChainTest.java Thu
Apr 21 00:39:58 2005
@@ -27,6 +27,7 @@
 import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.SessionConfig;
 import org.apache.mina.common.TransportType;
+import org.apache.mina.util.BaseSession;
 
 /**
  * Tests {@link AbstractIoHandlerFilterChain}.
@@ -101,7 +102,7 @@
         return buf.toString();
     }
 
-    private class TestSession implements IoSession
+    private class TestSession extends BaseSession implements IoSession
     {
         private IoHandler handler = new IoHandler()
         {
@@ -147,15 +148,6 @@
         {
         }
 
-        public Object getAttachment()
-        {
-            return null;
-        }
-
-        public void setAttachment(Object attachment)
-        {
-        }
-
         public TransportType getTransportType()
         {
             return null;
@@ -179,36 +171,6 @@
         public SocketAddress getLocalAddress()
         {
             return null;
-        }
-
-        public long getReadBytes()
-        {
-            return 0;
-        }
-
-        public long getWrittenBytes()
-        {
-            return 0;
-        }
-
-        public long getLastIoTime()
-        {
-            return 0;
-        }
-
-        public long getLastReadTime()
-        {
-            return 0;
-        }
-
-        public long getLastWriteTime()
-        {
-            return 0;
-        }
-
-        public boolean isIdle(IdleStatus status)
-        {
-            return false;
         }
     }
 

Modified: directory/network/trunk/src/test/org/apache/mina/protocol/ProtocolHandlerFilterChainTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/protocol/ProtocolHandlerFilterChainTest.java?rev=164009&r1=164008&r2=164009&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/protocol/ProtocolHandlerFilterChainTest.java
(original)
+++ directory/network/trunk/src/test/org/apache/mina/protocol/ProtocolHandlerFilterChainTest.java
Thu Apr 21 00:39:58 2005
@@ -26,6 +26,7 @@
 import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.SessionConfig;
 import org.apache.mina.common.TransportType;
+import org.apache.mina.util.BaseSession;
 
 /**
  * Tests {@link AbstractProtocolHandlerFilterChain}.
@@ -100,7 +101,7 @@
         return buf.toString();
     }
 
-    private class TestSession implements ProtocolSession
+    private class TestSession extends BaseSession implements ProtocolSession
     {
         private ProtocolHandler handler = new ProtocolHandler()
         {
@@ -148,13 +149,6 @@
         public void close() {
         }
 
-        public Object getAttachment() {
-            return null;
-        }
-
-        public void setAttachment(Object attachment) {
-        }
-
         public void write(Object message) {
         }
 
@@ -176,30 +170,6 @@
 
         public SocketAddress getLocalAddress() {
             return null;
-        }
-
-        public long getReadBytes() {
-            return 0;
-        }
-
-        public long getWrittenBytes() {
-            return 0;
-        }
-
-        public long getLastIoTime() {
-            return 0;
-        }
-
-        public long getLastReadTime() {
-            return 0;
-        }
-
-        public long getLastWriteTime() {
-            return 0;
-        }
-
-        public boolean isIdle(IdleStatus status) {
-            return false;
         }
     }
 

Modified: directory/network/trunk/src/test/org/apache/mina/protocol/codec/CumulativeProtocolDecoderTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/protocol/codec/CumulativeProtocolDecoderTest.java?rev=164009&r1=164008&r2=164009&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/protocol/codec/CumulativeProtocolDecoderTest.java
(original)
+++ directory/network/trunk/src/test/org/apache/mina/protocol/codec/CumulativeProtocolDecoderTest.java
Thu Apr 21 00:39:58 2005
@@ -26,7 +26,6 @@
 import junit.framework.TestCase;
 
 import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.SessionConfig;
 import org.apache.mina.common.TransportType;
 import org.apache.mina.protocol.ProtocolDecoder;
@@ -35,6 +34,7 @@
 import org.apache.mina.protocol.ProtocolHandler;
 import org.apache.mina.protocol.ProtocolSession;
 import org.apache.mina.protocol.ProtocolViolationException;
+import org.apache.mina.util.BaseSession;
 
 /**
  * Tests {@link CumulativeProtocolDecoder}.
@@ -171,7 +171,7 @@
         }
     }
     
-    private static class ProtocolSessionImpl implements ProtocolSession
+    private static class ProtocolSessionImpl extends BaseSession implements ProtocolSession
     {
 
         public ProtocolHandler getHandler() {
@@ -189,13 +189,6 @@
         public void close() {
         }
 
-        public Object getAttachment() {
-            return null;
-        }
-
-        public void setAttachment(Object attachment) {
-        }
-
         public void write(Object message) {
         }
 
@@ -218,30 +211,5 @@
         public SocketAddress getLocalAddress() {
             return null;
         }
-
-        public long getReadBytes() {
-            return 0;
-        }
-
-        public long getWrittenBytes() {
-            return 0;
-        }
-
-        public long getLastIoTime() {
-            return 0;
-        }
-
-        public long getLastReadTime() {
-            return 0;
-        }
-
-        public long getLastWriteTime() {
-            return 0;
-        }
-
-        public boolean isIdle(IdleStatus status) {
-            return false;
-        }
-        
     }
 }



Mime
View raw message