On 11/10/10 9:27 PM, Jason Weinstein wrote:
Is the method
public void messageReceived(final IoSession session, final Object
message) throws Exception {
threadsafe per IoSession?
yes.
That is can the same IoSession under any circumstance receive messages
at the same time?
No. Not while a message is being processed by a thread. Unless you added
an ExecutorFilter in the chain.
Note although that if you have a split message, you may have some
discontinuity in the processing.
If it is threadsafe, then i am curious if this should work for
accessing EM in a threadsafe way?
Give it a try :)
And if it is assured to close? And/or under what circumstances
sessionDestroyed might not be called?
It is assured to close, yes, as soon as the client safely close the
session, or if you handle the idle time to close the session after a
timeout occured.
ie OutOfMemoryError, etc
It's up to you to handle such an exception in the ExceptionCaught handler.
public void sessionCreated(final IoSession session) throws Exception {
session.setAttribute("EM",
entityManagerFactory.createEntityManager());
public void sessionDestroyed(final IoSession session) throws
Exception {
final EntityManager entityManager = (EntityManager)
session.getAttribute("EM");
entityManager.close();
public void messageReceived(final IoSession session, final Object
message) throws Exception {
final EntityManager entityManager = (EntityManager)
session.getAttribute("EM");
// do something with EM
I am also wondering, bar Spring, etc, thoughts on whether this would
be considered a good practice?
Why not ?
Again, give it a try...
--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com