unsubscribe On Sun, Feb 12, 2017 at 4:50 AM, Richards Peter <[email protected]> wrote:
> Thanks Emmanuel. > > Is there any problem if I try to unbind/dispose the ioAcceptor from its > ioHandler callback methods? I found that the thread is not returning > from the method call(unbind/dispose). I haven't configured any executor > filters in my test code. I am not sure whether that is causing the > issue. However if I spawn a separate thread in the messageReceived() and > try to unbind/dispose the acceptor from the threads, the thread does the > operation without any issues. > > Thanks, > Richards Peter. > > > On Mon, Dec 26, 2016 at 7:30 PM, Emmanuel Lécharny <[email protected]> > wrote: > > > > > > > Le 26/12/2016 à 23:53, Richards Peter a écrit : > > > Hi, > > > > > > Thank you for sharing your thoughts regarding this issue. I am using > Mina > > > to develop a TCP client-server program. I experienced a similar issue > > while > > > I was trying to perform the following operation: > > > > > > I would like to shutdown the NioSocketAcceptor instance when it > receives > > a > > > special message from a client (admin client). Upon receiving the > message > > I > > > would like the program to notify all the active IoSessions about the > > server > > > shutdown by broadcasting a SHUTDOWN message and then dispose the > > > NioSocketAcceptor instance. I would like to dispose the acceptor > instance > > > only after the message has been sent successfully. > > > > > > messageReceived(){ > > > - write SHUTDOWN message to all managed ioSessions , wait for the > > write > > > operation to complete. > > > - close the ioSessions and wait for the close operation to complete. > > > - unbind and dispose the acceptor. > > > } > > > > > > What would be the recommended approach to perform this type of a task? > > > > This is not simple. > > > > You need to call session.getService() to get the service instance, and > > cast it to IoAcceptor. > > > > Then you can iterate on all the existing sessions. The > > IoService.getManagedSessions() will return the map of all the existing > > sessions for this service. > > > > Having all the sessions, you can set an Attribute for each of them, and > > close the session. The sessionClosed() method in your IoHandler must > > check if the Attribute is set, and act accordingly. > > > > At the end, you can dispose the acceptor. > > > > Something like that... > > > > > > > > How can I prevent the IO processor thread from DEAD LOCK? Could you > also > > > explain about the threading model that is recommended in this case? Can > > > ExecutorFilter be used to solve this type of problem? > > > > Simply exit the messageReceived() method, settig a current status in the > > session context, and manage the idling. Every second, your session will > > be waken up (IoHandler.sessionIdle()) and you'll be able to check the > > other's session status. Doing so release the IoProcessor that was > > processing your admin command, leaving it for other sessions associated > > with the IoProcessor. > > > > Again, this is not simple, and this is how I would implement it. But > > there may be other ways... > > > > -- > > Emmanuel Lecharny > > > > Symas.com > > directory.apache.org > > > > >
