You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by jv...@apache.org on 2009/10/26 15:23:47 UTC

svn commit: r829811 - in /mina/branches/3.0/core/src/main/java/org/apache/mina: IoSession.java session/AbstractIoSession.java

Author: jvermillard
Date: Mon Oct 26 14:23:47 2009
New Revision: 829811

URL: http://svn.apache.org/viewvc?rev=829811&view=rev
Log:
session attribute management (simplified)

Modified:
    mina/branches/3.0/core/src/main/java/org/apache/mina/IoSession.java
    mina/branches/3.0/core/src/main/java/org/apache/mina/session/AbstractIoSession.java

Modified: mina/branches/3.0/core/src/main/java/org/apache/mina/IoSession.java
URL: http://svn.apache.org/viewvc/mina/branches/3.0/core/src/main/java/org/apache/mina/IoSession.java?rev=829811&r1=829810&r2=829811&view=diff
==============================================================================
--- mina/branches/3.0/core/src/main/java/org/apache/mina/IoSession.java (original)
+++ mina/branches/3.0/core/src/main/java/org/apache/mina/IoSession.java Mon Oct 26 14:23:47 2009
@@ -179,124 +179,35 @@
     /**
      * Returns the value of the 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
+     * @param name the name of the attribute
+     * @return <tt>null</tt> if there is no attribute with the specified name
      */
-    Object getAttribute(Object key);
-
-    /**
-     * Returns the value of user defined attribute associated with the
-     * specified key.  If there's no such attribute, the specified default
-     * value is associated with the specified key, and the default value is
-     * returned.  This method is same with the following code except that the
-     * operation is performed atomically.
-     * <pre>
-     * if (containsAttribute(key)) {
-     *     return getAttribute(key);
-     * } else {
-     *     setAttribute(key, defaultValue);
-     *     return defaultValue;
-     * }
-     * </pre>
-     */
-    Object getAttribute(Object key, Object defaultValue);
+    Object getAttribute(Object name);
 
     /**
      * Sets a user-defined attribute.
      *
-     * @param key   the key of the attribute
+     * @param name   the name 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(Object key, Object value);
-
-    /**
-     * Sets a user defined attribute without a value.  This is useful when
-     * you just want to put a 'mark' attribute.  Its value is set to
-     * {@link Boolean#TRUE}.
-     *
-     * @param key the key of the attribute
-     * @return The old value of the attribute.  <tt>null</tt> if it is new.
-     */
-    Object setAttribute(Object key);
-    
-    /**
-     * Sets a user defined attribute if the attribute with the specified key
-     * is not set yet.  This method is same with the following code except
-     * that the operation is performed atomically.
-     * <pre>
-     * if (containsAttribute(key)) {
-     *     return getAttribute(key);
-     * } else {
-     *     return setAttribute(key, value);
-     * }
-     * </pre>
-     */
-    Object setAttributeIfAbsent(Object key, Object value);
+    Object setAttribute(Object name, Object value);
 
     /**
-     * Sets a user defined attribute without a value if the attribute with
-     * the specified key is not set yet.  This is useful when you just want to
-     * put a 'mark' attribute.  Its value is set to {@link Boolean#TRUE}.
-     * This method is same with the following code except that the operation
-     * is performed atomically.
-     * <pre>
-     * if (containsAttribute(key)) {
-     *     return getAttribute(key);  // might not always be Boolean.TRUE.
-     * } else {
-     *     return setAttribute(key);
-     * }
-     * </pre>
-     */
-    Object setAttributeIfAbsent(Object key);
-
-    /**
-     * Removes a user-defined attribute with the specified key.
-     *
+     * Removes a user-defined attribute with the specified name.
+     * @param name the name of the attribute
      * @return The old value of the attribute.  <tt>null</tt> if not found.
      */
-    Object removeAttribute(Object key);
-
-    /**
-     * Removes a user defined attribute with the specified key if the current
-     * attribute value is equal to the specified value.  This method is same
-     * with the following code except that the operation is performed
-     * atomically.
-     * <pre>
-     * if (containsAttribute(key) && getAttribute(key).equals(value)) {
-     *     removeAttribute(key);
-     *     return true;
-     * } else {
-     *     return false;
-     * }
-     * </pre>
-     */
-    boolean removeAttribute(Object key, Object value);
-
-    /**
-     * Replaces a user defined attribute with the specified key if the
-     * value of the attribute is equals to the specified old value.
-     * This method is same with the following code except that the operation
-     * is performed atomically.
-     * <pre>
-     * if (containsAttribute(key) && getAttribute(key).equals(oldValue)) {
-     *     setAttribute(key, newValue);
-     *     return true;
-     * } else {
-     *     return false;
-     * }
-     * </pre>
-     */
-    boolean replaceAttribute(Object key, Object oldValue, Object newValue);
+    Object removeAttribute(Object name);
 
     /**
      * Returns <tt>true</tt> if this session contains the attribute with
-     * the specified <tt>key</tt>.
+     * the specified <tt>name</tt>.
      */
-    boolean containsAttribute(Object key);
+    boolean containsAttribute(Object name);
 
     /**
-     * Returns the set of keys of all user-defined attributes.
+     * Returns the set of names of all user-defined attributes.
      */
-    Set<Object> getAttributeKeys();
+    Set<Object> getAttributeNames();
 }
\ No newline at end of file

Modified: mina/branches/3.0/core/src/main/java/org/apache/mina/session/AbstractIoSession.java
URL: http://svn.apache.org/viewvc/mina/branches/3.0/core/src/main/java/org/apache/mina/session/AbstractIoSession.java?rev=829811&r1=829810&r2=829811&view=diff
==============================================================================
--- mina/branches/3.0/core/src/main/java/org/apache/mina/session/AbstractIoSession.java (original)
+++ mina/branches/3.0/core/src/main/java/org/apache/mina/session/AbstractIoSession.java Mon Oct 26 14:23:47 2009
@@ -22,6 +22,7 @@
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.mina.IoService;
@@ -106,4 +107,33 @@
         return Math.max(lastReadTime, lastWriteTime);
     }
     
+    @Override
+    public IoService getService() {
+        return service;
+    }
+    
+    @Override
+    public Object getAttribute(Object name) {
+        return attributes.get(name);
+    }
+    
+    @Override
+    public Object setAttribute(Object name, Object value) {
+        return attributes.put(name, value);
+    }
+    
+    @Override
+    public boolean containsAttribute(Object name) {
+        return attributes.containsKey(name);
+    }
+    
+    @Override
+    public Object removeAttribute(Object name) {
+        return attributes.remove(name);
+    }
+    
+    @Override
+    public Set<Object> getAttributeNames() {
+        return attributes.keySet();
+    }
 }