Le 02/07/15 14:55, Luan Muniz a écrit :
> Hello,
>
> I am a developer and I'm using mine (nio socket) to talk with to a variety
> of hardware.
>
> Now I have to send commands to a specific hardware and do not know how to
> catch the session that hardware.
>
> *Question:* How do I get a session from a specific attribute?
Not exactly sure I get what you want to do, so I will try to infer from
what I understand.
Let's assume you have hardwares connected to your MINA server : all of
them have created a session when connecting, and I assume they have
identified themselves by adding some Attribute in their session.
from MINA PoV, nothing distinguishes a session from another one. So the
only way for your server to send a message to an opened session is to
fetch a specific Attribute that is supposed to be present in the
sessions. First step : grab the active sessions, something you can do
using the instance of your Nio(Socket|Datagram)Acceptor, using the
getManagedSessions() method.
Then, for each session, fetch the attribute you are expecting to be
present, and that has a value that is associated with the hardware you
are targetting, using this method :
public final Object getAttribute(Object key) {
return getAttribute(key, null);
}
The Object stored in the session is a String if you put a String into
it, an Integer if you stored an Integer, etc.
That should do the trick.
Hope it helps.