You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ni...@apache.org on 2006/02/15 16:30:20 UTC
svn commit: r378022 - in
/directory/sandbox/trustin/dirmina-158/core/src/main/java/org/apache/mina/common:
IoSessionConfig.java support/BaseIoSessionConfig.java
Author: niklas
Date: Wed Feb 15 07:30:18 2006
New Revision: 378022
URL: http://svn.apache.org/viewcvs?rev=378022&view=rev
Log:
Added attributes to IoSessionConfig
Modified:
directory/sandbox/trustin/dirmina-158/core/src/main/java/org/apache/mina/common/IoSessionConfig.java
directory/sandbox/trustin/dirmina-158/core/src/main/java/org/apache/mina/common/support/BaseIoSessionConfig.java
Modified: directory/sandbox/trustin/dirmina-158/core/src/main/java/org/apache/mina/common/IoSessionConfig.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/dirmina-158/core/src/main/java/org/apache/mina/common/IoSessionConfig.java?rev=378022&r1=378021&r2=378022&view=diff
==============================================================================
--- directory/sandbox/trustin/dirmina-158/core/src/main/java/org/apache/mina/common/IoSessionConfig.java (original)
+++ directory/sandbox/trustin/dirmina-158/core/src/main/java/org/apache/mina/common/IoSessionConfig.java Wed Feb 15 07:30:18 2006
@@ -18,6 +18,8 @@
*/
package org.apache.mina.common;
+import java.util.Set;
+
/**
* The configuration of {@link IoSession}.
*
@@ -30,4 +32,49 @@
* Returns a deep clone of this configuration.
*/
Object clone();
+
+ /**
+ * 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 );
+
+ /**
+ * 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( String key );
+
+ /**
+ * Removes a user-defined attribute with the specified key.
+ *
+ * @return The old value of the attribute. <tt>null</tt> if not found.
+ */
+ Object removeAttribute( String key );
+
+ /**
+ * Returns <tt>true</tt> if this session contains the attribute with
+ * the specified <tt>key</tt>.
+ */
+ boolean containsAttribute( String key );
+
+ /**
+ * Returns the set of keys of all user-defined attributes.
+ */
+ Set getAttributeKeys();
}
Modified: directory/sandbox/trustin/dirmina-158/core/src/main/java/org/apache/mina/common/support/BaseIoSessionConfig.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/dirmina-158/core/src/main/java/org/apache/mina/common/support/BaseIoSessionConfig.java?rev=378022&r1=378021&r2=378022&view=diff
==============================================================================
--- directory/sandbox/trustin/dirmina-158/core/src/main/java/org/apache/mina/common/support/BaseIoSessionConfig.java (original)
+++ directory/sandbox/trustin/dirmina-158/core/src/main/java/org/apache/mina/common/support/BaseIoSessionConfig.java Wed Feb 15 07:30:18 2006
@@ -18,6 +18,11 @@
*/
package org.apache.mina.common.support;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
import org.apache.mina.common.IoSessionConfig;
/**
@@ -28,6 +33,8 @@
*/
public abstract class BaseIoSessionConfig implements IoSessionConfig, Cloneable
{
+ private Map attributes = new HashMap();
+
protected BaseIoSessionConfig()
{
}
@@ -38,6 +45,8 @@
try
{
ret = ( BaseIoSessionConfig ) super.clone();
+ ret.attributes = new HashMap();
+ ret.attributes.putAll( attributes );
}
catch( CloneNotSupportedException e )
{
@@ -46,4 +55,62 @@
return ret;
}
+
+ public Object getAttachment()
+ {
+ synchronized( attributes )
+ {
+ return attributes.get( "" );
+ }
+ }
+
+ public Object setAttachment( Object attachment )
+ {
+ synchronized( attributes )
+ {
+ return attributes.put( "", attachment );
+ }
+ }
+
+ public Object getAttribute( String key )
+ {
+ synchronized( attributes )
+ {
+ return attributes.get( key );
+ }
+ }
+
+ public Object setAttribute( String key, Object value )
+ {
+ synchronized( attributes )
+ {
+ return attributes.put( key, value );
+ }
+ }
+
+ public Object setAttribute( String key )
+ {
+ return setAttribute( key, Boolean.TRUE );
+ }
+
+ public Object removeAttribute( String key )
+ {
+ synchronized( attributes )
+ {
+ return attributes.remove( key );
+ }
+ }
+
+ public boolean containsAttribute( String key )
+ {
+ return getAttribute( key ) != null;
+ }
+
+ public Set getAttributeKeys()
+ {
+ synchronized( attributes )
+ {
+ return new HashSet( attributes.keySet() );
+ }
+ }
}