[ 
https://issues.apache.org/jira/browse/DIRMINA-874?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13162793#comment-13162793
 ] 

Christian Schwarz commented on DIRMINA-874:
-------------------------------------------

Some hasty notes on the MINA 2 API..


<T> T getAttribute(String name);         
- its not type safe

<T> T setAttribute(String name, T value);       
- this is not possibe:
Number n = session.setAttribute(“key”,12)

Object removeAttribute(Object name);    
- the type parameter is missing for the return type
- the name is not of type String

boolean containsAttribute(Object name);
- the name should be a String

Set<Object> getAttributeNames();        
- the Set does not contain Strings as the user expects see #setAttribute(..)


Currently a attribute key-value pair can have 3 relevant states in a session 
instance:
the key-value pair is absent
the key has a null value
the key has a non null value


The current Mina 3 API mixup case 1 and 2 in getAttribute(String) the user 
don’t know which case happend if null is returned. Did i forget to set the 
value or is it null? So if null values are supported, the user should know the 
difference of null value and a value that is absent. 
If the precondition is checked with containsAttribute(), who guaranees that no 
datarace can occure ?
                
> Typesafe AttributeKeys
> ----------------------
>
>                 Key: DIRMINA-874
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-874
>             Project: MINA
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 3.0.0-M1
>            Reporter: Christian Schwarz
>
> In Mina 2 we can add attributes to a session and get them as well. Because 
> IoSession#getAttribute(Object key)  returns Object we always have to remember 
> what attribute type is associated with the key and cast the result to the 
> expected type.
> Mina 2 example:
> final static Object KEY = new AttributeKey(SourceClass.class,"myKey");
> ...
> session.set(KEY,"myAttribute");
> String attributeValue= (String)session.get(KEY);
> Instead of using plain Object-keys, the key type should contain information 
> about its attributes. The aim is to get type-safe access to attributes.
> Assume we have the following new AttributeKey-Class:
> /**
> * @parmeter T Type of the referenced Attribute
> */
> class AttributeKey<T> {
>   public TypesafeAttributeKey(Class<T> attributeType, String attributeKey){
>    ...
>   }
> }
> The IoSession should have Attribute related accessors like these:
>  
>  void setAttribute(AttributeKey<T> key, T value);
>  T getAttribute(AttributeKey<T> key);
> So in Mina 3 the example could look like this:
> final static AttributeKey<String> KEY = new 
> AttributeKey<String>(String.class,"myKey");
> ...
> session.set(KEY,"myAttribute");
> String attributeValue=session.get(KEY);
> These 2 cases won't compile:
> session.set(KEY,new Date());
> Integer attributeValue=session.get(KEY);
> This pattern would simplify the use of Attributes, because the programmer 
> don't have to care about the types and can concentrate on more improtant 
> things. In my humble opinion the Objekt keys should be removed at all, i 
> don't see the purpose for such unspecific keys.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira


Reply via email to