Author: trustin
Date: Thu Dec 6 02:13:21 2007
New Revision: 601679
URL: http://svn.apache.org/viewvc?rev=601679&view=rev
Log:
Reduced the number of methods to implement for IoSessionAttributeMap
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoSession.java
mina/trunk/core/src/main/java/org/apache/mina/common/DefaultIoSessionDataStructureFactory.java
mina/trunk/core/src/main/java/org/apache/mina/common/IoSession.java
mina/trunk/core/src/main/java/org/apache/mina/common/IoSessionAttributeMap.java
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoSession.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoSession.java?rev=601679&r1=601678&r2=601679&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoSession.java
(original)
+++ mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoSession.java
Thu Dec 6 02:13:21 2007
@@ -336,7 +336,7 @@
}
public final Object getAttribute(Object key) {
- return attributes.getAttribute(this, key);
+ return getAttribute(key, null);
}
public final Object getAttribute(Object key, Object defaultValue) {
@@ -348,11 +348,15 @@
}
public final Object setAttribute(Object key) {
- return attributes.setAttribute(this, key);
+ return setAttribute(key, Boolean.TRUE);
}
public final Object setAttributeIfAbsent(Object key, Object value) {
return attributes.setAttributeIfAbsent(this, key, value);
+ }
+
+ public final Object setAttributeIfAbsent(Object key) {
+ return setAttributeIfAbsent(key, Boolean.TRUE);
}
public final Object removeAttribute(Object key) {
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/DefaultIoSessionDataStructureFactory.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/DefaultIoSessionDataStructureFactory.java?rev=601679&r1=601678&r2=601679&view=diff
==============================================================================
---
mina/trunk/core/src/main/java/org/apache/mina/common/DefaultIoSessionDataStructureFactory.java
(original)
+++
mina/trunk/core/src/main/java/org/apache/mina/common/DefaultIoSessionDataStructureFactory.java
Thu Dec 6 02:13:21 2007
@@ -55,21 +55,10 @@
private final Map<Object, Object> attributes =
Collections.synchronizedMap(new HashMap<Object, Object>(4));
- public Object getAttribute(IoSession session, Object key) {
- if (key == null) {
- throw new NullPointerException("key");
- }
-
- return attributes.get(key);
- }
-
public Object getAttribute(IoSession session, Object key, Object
defaultValue) {
if (key == null) {
throw new NullPointerException("key");
}
- if (defaultValue == null) {
- return attributes.get(key);
- }
Object answer = attributes.get(key);
if (answer == null) {
@@ -89,10 +78,6 @@
} else {
return attributes.put(key, value);
}
- }
-
- public Object setAttribute(IoSession session, Object key) {
- return setAttribute(session, key, Boolean.TRUE);
}
public Object setAttributeIfAbsent(IoSession session, Object key,
Object value) {
Modified: mina/trunk/core/src/main/java/org/apache/mina/common/IoSession.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/IoSession.java?rev=601679&r1=601678&r2=601679&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/common/IoSession.java
(original)
+++ mina/trunk/core/src/main/java/org/apache/mina/common/IoSession.java Thu Dec
6 02:13:21 2007
@@ -235,6 +235,22 @@
Object setAttributeIfAbsent(Object key, 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 [EMAIL PROTECTED]
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.
*
* @return The old value of the attribute. <tt>null</tt> if not found.
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/IoSessionAttributeMap.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/IoSessionAttributeMap.java?rev=601679&r1=601678&r2=601679&view=diff
==============================================================================
---
mina/trunk/core/src/main/java/org/apache/mina/common/IoSessionAttributeMap.java
(original)
+++
mina/trunk/core/src/main/java/org/apache/mina/common/IoSessionAttributeMap.java
Thu Dec 6 02:13:21 2007
@@ -32,14 +32,6 @@
public interface IoSessionAttributeMap {
/**
- * Returns the value of the user-defined attribute.
- * @param key the key of the attribute
- *
- * @return <tt>null</tt> if there is no attribute with the specified key
- */
- Object getAttribute(IoSession session, 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
@@ -64,16 +56,6 @@
* @return The old value of the attribute. <tt>null</tt> if it is new.
*/
Object setAttribute(IoSession session, 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
- * [EMAIL PROTECTED] 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(IoSession session, Object key);
/**
* Sets a user defined attribute if the attribute with the specified key