To add to Emm's solution, use an ScheduledExecutor to make life more simple.
Or if you wish to hack into the code, there is something similar being done in MINA code. To check for Expiring session, we check the all the current session for last used timestamp. Forgot the class name, but this would be easy to find. It will give you an idea. thanks ashish On Sun, Oct 4, 2009 at 3:51 AM, Emmanuel Lecharny <elecha...@apache.org> wrote: > A naive approach would be to do something like : > > while (true) { > session.write ( <your data to the client> ); > Thread.sleep( 1000L ); > } > > it does the trick *IF* you don't have a lot of clients (and you'll have to > add an Executor filter in the chain, otherwise you wo'nt be able to deal > with more than the number of threads you have defined in the acceptor). > > However, this is not the best solution. The problem is that in order to > process a request, a thread is selected, and released when you quit the > handler (ie, once the message has been processed on the server side). > > A better solution would be, as suggested by mark, to have a separate thread > having a list of all your client's IoSession. When the clock tiks, you get > all the active sessions and you simply write a message into them : > > while ( true ) { > for ( IoSession session : MySessions ) { > if ( session.isConnected() && ! session.isWriteSuspended()) { > session.write( <time to wake up !> ); > } else { > // some cleanup here, as the session has been closed. > } > } > > Thread.sleep( 1000L ); > } > > Hope it helps too. > > Mark Wallsgrove wrote: >> >> Hey.. I haven't been using Mina for long, but what you could do is >> create a new object that runs on a thread that uses the filter chain >> to fire a event every x seconds. Your handler should then do the rest. >> Once the event has been fired the thread should then go back to sleep. >> I guess you could use the connection object to gather the sessions / >> filter chains? Hope this helps.. >> >> Best regards, >> Mark Wallsgrove >> >> On 10/3/09, CoolHedin <coolhe...@yandex.ru> wrote: >> >>> >>> Hi. I develop an application using your excellent library. But I had a >>> difficulty. >>> I need to send messages from server to clients, by timer. >>> and I do not understand how to do it. >>> for example, i send every 1 minutes 'Hi everyone' message to all >>> conection >>> -- >>> Sincerely yours, >>> Sergey Paramonov >>> Adept Team, www.adept-project.com >>> >>> >> >> >> > > > -- > -- > cordialement, regards, > Emmanuel Lécharny > www.iktek.com > directory.apache.org > > > -- thanks ashish Blog: http://www.ashishpaliwal.com/blog My Photo Galleries: http://www.pbase.com/ashishpaliwal