org.apache.mina.filter.util
Class SessionAttributeInitializingFilter

java.lang.Object
  extended by org.apache.mina.common.IoFilterAdapter
      extended by org.apache.mina.filter.util.SessionAttributeInitializingFilter
All Implemented Interfaces:
IoFilter

public class SessionAttributeInitializingFilter
extends IoFilterAdapter

An IoFilter that sets initial attributes when a new IoSession is created. By default, the attribute map is empty when an IoSession is newly created. Inserting this filter will make the pre-configured attributes available after this filter executes the sessionCreated event.

Version:
$Rev: 576217 $, $Date: 2007-09-17 01:55:27 +0200 (Mon, 17 Sep 2007) $
Author:
The Apache MINA Project (dev@mina.apache.org)

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.mina.common.IoFilter
IoFilter.NextFilter
 
Constructor Summary
SessionAttributeInitializingFilter()
          Creates a new instance with no default attributes.
SessionAttributeInitializingFilter(Map<String,? extends Object> attributes)
          Creates a new instance with the specified default attributes.
 
Method Summary
 Object getAttribute(String key)
          Returns the value of user-defined attribute.
 Set<String> getAttributeKeys()
          Returns the set of keys of all user-defined attributes.
 Object removeAttribute(String key)
          Removes a user-defined attribute with the specified key.
 void sessionCreated(IoFilter.NextFilter nextFilter, IoSession session)
          Puts all pre-configured attributes into the actual session attribute map and forward the event to the next filter.
 Object setAttribute(String key)
          Sets a user defined attribute without a value.
 Object setAttribute(String key, Object value)
          Sets a user-defined attribute.
 void setAttributes(Map<String,? extends Object> attributes)
          Sets the attribute map.
 
Methods inherited from class org.apache.mina.common.IoFilterAdapter
destroy, exceptionCaught, filterClose, filterSetTrafficMask, filterWrite, init, messageReceived, messageSent, onPostAdd, onPostRemove, onPreAdd, onPreRemove, sessionClosed, sessionIdle, sessionOpened
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionAttributeInitializingFilter

public SessionAttributeInitializingFilter()
Creates a new instance with no default attributes. You can set the additional attributes by calling methods such as setAttribute(String, Object) and setAttributes(Map).


SessionAttributeInitializingFilter

public SessionAttributeInitializingFilter(Map<String,? extends Object> attributes)
Creates a new instance with the specified default attributes. You can set the additional attributes by calling methods such as setAttribute(String, Object) and setAttributes(Map).

Method Detail

getAttribute

public Object getAttribute(String key)
Returns the value of user-defined attribute.

Parameters:
key - the key of the attribute
Returns:
null if there is no attribute with the specified key

setAttribute

public Object setAttribute(String key,
                           Object value)
Sets a user-defined attribute.

Parameters:
key - the key of the attribute
value - the value of the attribute
Returns:
The old value of the attribute. null if it is new.

setAttribute

public Object setAttribute(String key)
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 Boolean.TRUE.

Parameters:
key - the key of the attribute
Returns:
The old value of the attribute. null if it is new.

removeAttribute

public Object removeAttribute(String key)
Removes a user-defined attribute with the specified key.

Returns:
The old value of the attribute. null if not found.

getAttributeKeys

public Set<String> getAttributeKeys()
Returns the set of keys of all user-defined attributes.


setAttributes

public void setAttributes(Map<String,? extends Object> attributes)
Sets the attribute map. The specified attributes are copied into the underlying map, so modifying the specified attributes parameter after the call won't change the internal state.


sessionCreated

public void sessionCreated(IoFilter.NextFilter nextFilter,
                           IoSession session)
                    throws Exception
Puts all pre-configured attributes into the actual session attribute map and forward the event to the next filter.

Specified by:
sessionCreated in interface IoFilter
Overrides:
sessionCreated in class IoFilterAdapter
Throws:
Exception


Copyright © 2004-2009 Apache MINA Project. All Rights Reserved.