public abstract class TimedEndDecoder extends Object implements org.apache.mina.filter.codec.ProtocolDecoder
ProtocolDecoder
which detects a frame end
based on the absence of new data (timeout).
Some protocol use a timeout to detect a frame end. e.g. Modbus defines a
end-of-frame
as a timeout of x milliseconds in which no data is sent.
This decoder helps to implement such protocols.
In order to use it you will need to derive your class from this one and
implement timeout(IoSession, ProtocolDecoderOutput)
which will be
called in the case of the timeout. The timeout detect will be started by
calling tick(IoSession, ProtocolDecoderOutput)
. It will remember the
output and pass it later on to the
timeout(IoSession, ProtocolDecoderOutput)
call. So when you read
data in your
ProtocolDecoder#decode(IoSession, org.apache.mina.common.ByteBuffer, ProtocolDecoderOutput)
you simply call tick(IoSession, ProtocolDecoderOutput)
and the
timeout is started or pushed back if it was already started.
If you need to clear the timeout use clear(IoSession)
Modifier and Type | Field and Description |
---|---|
protected org.apache.mina.core.filterchain.IoFilter.NextFilter |
nextFilter |
Constructor and Description |
---|
TimedEndDecoder(ScheduledExecutorService scheduler,
long timeout,
TimeUnit timeUnit)
Create a new instance
|
Modifier and Type | Method and Description |
---|---|
void |
clear(org.apache.mina.core.session.IoSession session)
Clear the end-of-frame detection for this session
|
void |
dispose(org.apache.mina.core.session.IoSession session) |
void |
finishDecode(org.apache.mina.core.session.IoSession session,
org.apache.mina.filter.codec.ProtocolDecoderOutput out) |
void |
setNextFilter(org.apache.mina.core.filterchain.IoFilter.NextFilter nextFilter) |
protected void |
tick() |
void |
tick(org.apache.mina.core.session.IoSession session,
org.apache.mina.filter.codec.ProtocolDecoderOutput out)
Start or tick the end-of-frame detection for this session
|
abstract void |
timeout(org.apache.mina.core.session.IoSession session,
org.apache.mina.filter.codec.ProtocolDecoderOutput out)
Handle the timeout situation
|
public TimedEndDecoder(ScheduledExecutorService scheduler, long timeout, TimeUnit timeUnit)
scheduler
- the scheduler to use for cyclic jobstimeout
- the timeout in milliseconds for the end-of-frame detectionprotected void tick()
public void dispose(org.apache.mina.core.session.IoSession session) throws Exception
dispose
in interface org.apache.mina.filter.codec.ProtocolDecoder
Exception
public void finishDecode(org.apache.mina.core.session.IoSession session, org.apache.mina.filter.codec.ProtocolDecoderOutput out) throws Exception
finishDecode
in interface org.apache.mina.filter.codec.ProtocolDecoder
Exception
public abstract void timeout(org.apache.mina.core.session.IoSession session, org.apache.mina.filter.codec.ProtocolDecoderOutput out) throws Exception
session
- the session for which the timeout occurredout
- the outputException
public void tick(org.apache.mina.core.session.IoSession session, org.apache.mina.filter.codec.ProtocolDecoderOutput out)
session
- the sessionout
- the protocol decoder output to use for the finished framepublic void clear(org.apache.mina.core.session.IoSession session)
session
- the sessionpublic void setNextFilter(org.apache.mina.core.filterchain.IoFilter.NextFilter nextFilter)
Copyright © 2016 Eclipse NeoSCADA Project. All rights reserved.