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

Reply via email to