You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Ben Gollmer <be...@jatosoft.com> on 2007/05/23 22:52:33 UTC

JMX StatCollector & IoSession Attribute

Hi all,

I have an application which reuses IoSessions often. Basically as the  
client sends data, state is built up within the IoSession via a  
series of attributes. When the server recognizes that an event has  
taken place, it processes the session, and clears the attributes for  
the next round of data collection.

To facilitate this, I had written a clearAttrs() method which simply  
iterated through the attribute keys and called  
IoSession.removeAttribute() on each key. Unfortunately when I added  
Mina's JMX statistics collection to my app, I began seeing null  
pointer exceptions in StatCollector$Worker. This was puzzling until I  
looked at the source and found that stats are gathered in sessions,  
using the attribute StatCollector.KEY.

Of course, it probably isn't the best application design to go around  
blasting IoSession attributes willy-nilly. However, I know my code,  
and nothing else was storing attributes on IoSessions until I started  
working with JMX. It would be nice to have a mention of this on the  
Mina+JMX wiki page for future reference.


Thanks,
-- 
Ben



Re: JMX StatCollector & IoSession Attribute

Posted by Niklas Therning <ni...@trillian.se>.
Ben Gollmer wrote:
> On May 24, 2007, at 8:12 AM, Niklas Therning wrote:
>
>> Ben Gollmer wrote:
>>>
>>> Of course, it probably isn't the best application design to go around
>>> blasting IoSession attributes willy-nilly. However, I know my code,
>>> and nothing else was storing attributes on IoSessions until I started
>>> working with JMX. It would be nice to have a mention of this on the
>>> Mina+JMX wiki page for future reference.
>>>
>>
>> There are other stuff in MINA apart from the JMX code which use
>> IoSession attributes to store state (e.g. StreamWriteFilter, SSLFilter).
>> It's not a good idea to clear all attributes. Instead, why don't you put
>> a dedicated Map in the session and store your state in it? Then you
>> could just change your code to iterate over the keys of that map and
>> remove whatever keys you like.
>
> True, but I'm not using any filters except my own. I am planning on
> moving my attributes to a custom 'namespace', as you suggested.
>
> I guess I was just caught off guard by the StatCollector using an
> attribute. Do the docs for StreamWriteFilter and SSLFilter mention
> their use of attributes?
>
SSLFilter does, StreamWriteFilter doesn't IIRC.

The thing is that the MINA code uses session attributes to store a lot
of per session state. It would be a lot of work to document all those
places. Just did a search for calls to IoSession.setAttribute() in the
MINA source code and got over 30 matches. So it's strongly advised that
you don't clear all session attributes, only those that you set
yourself. Maybe this should be stated somewhere in the docs (like in the
Javadocs for IoSession). If you think so please add a JIRA issue:
https://issues.apache.org/jira/browse/DIRMINA

-- 
Niklas Therning
www.spamdrain.net


Re: JMX StatCollector & IoSession Attribute

Posted by Ben Gollmer <be...@jatosoft.com>.
On May 24, 2007, at 8:12 AM, Niklas Therning wrote:

> Ben Gollmer wrote:
>>
>> Of course, it probably isn't the best application design to go around
>> blasting IoSession attributes willy-nilly. However, I know my code,
>> and nothing else was storing attributes on IoSessions until I started
>> working with JMX. It would be nice to have a mention of this on the
>> Mina+JMX wiki page for future reference.
>>
>
> There are other stuff in MINA apart from the JMX code which use
> IoSession attributes to store state (e.g. StreamWriteFilter,  
> SSLFilter).
> It's not a good idea to clear all attributes. Instead, why don't  
> you put
> a dedicated Map in the session and store your state in it? Then you
> could just change your code to iterate over the keys of that map and
> remove whatever keys you like.

True, but I'm not using any filters except my own. I am planning on  
moving my attributes to a custom 'namespace', as you suggested.

I guess I was just caught off guard by the StatCollector using an  
attribute. Do the docs for StreamWriteFilter and SSLFilter mention  
their use of attributes?

-- 
Ben



Re: JMX StatCollector & IoSession Attribute

Posted by Niklas Therning <ni...@trillian.se>.
Ben Gollmer wrote:
> Hi all,
>
> I have an application which reuses IoSessions often. Basically as the
> client sends data, state is built up within the IoSession via a series
> of attributes. When the server recognizes that an event has taken
> place, it processes the session, and clears the attributes for the
> next round of data collection.
>
> To facilitate this, I had written a clearAttrs() method which simply
> iterated through the attribute keys and called
> IoSession.removeAttribute() on each key. Unfortunately when I added
> Mina's JMX statistics collection to my app, I began seeing null
> pointer exceptions in StatCollector$Worker. This was puzzling until I
> looked at the source and found that stats are gathered in sessions,
> using the attribute StatCollector.KEY.
>
> Of course, it probably isn't the best application design to go around
> blasting IoSession attributes willy-nilly. However, I know my code,
> and nothing else was storing attributes on IoSessions until I started
> working with JMX. It would be nice to have a mention of this on the
> Mina+JMX wiki page for future reference.
>

There are other stuff in MINA apart from the JMX code which use
IoSession attributes to store state (e.g. StreamWriteFilter, SSLFilter).
It's not a good idea to clear all attributes. Instead, why don't you put
a dedicated Map in the session and store your state in it? Then you
could just change your code to iterate over the keys of that map and
remove whatever keys you like.

-- 
Niklas Therning
www.spamdrain.net