I am using Apache Camel in conjunction with Apache Mina to have a TCP Server. I am using a specific protocol decoder in my code. In this decoder, I am waiting to get X amount of bytes before I send them downstream to the route.
I would like to implement something that is able to understand that the session got idle or closed and then send the bytes that we have already got downstream to the route (it doesn't matter if we didn't get the total X bytes). I have already tried implementing an IoFilterAdapter
overriding the method sessionIdle()
but I am not sure how to use it.
Overriding sessionIdle()
method is basically for closing (or configuring as you want) your session when the session idle time has been reached.
You can set idle time inside your handler class (or by extending IoFilterAdapter
) by overriding sessionOpened()
method.
Something like this should do the work:
@Override
public void sessionOpened(final IoSession session) throws Exception
{
session.getConfig().setIdleTime(IdleStatus.BOTH_IDLE, this.idleTimeOut);
}
You can also use other idle states which are defined in IdleStatus
class. There are essentially there states:
public static final IdleStatus READER_IDLE = new IdleStatus("reader idle");
public static final IdleStatus WRITER_IDLE = new IdleStatus("writer idle");
public static final IdleStatus BOTH_IDLE = new IdleStatus("both idle");