Package jadex.bridge.component.streams
Class OutputConnectionHandler
- java.lang.Object
-
- jadex.bridge.component.streams.AbstractConnectionHandler
-
- jadex.bridge.component.streams.OutputConnectionHandler
-
- All Implemented Interfaces:
IAbstractConnectionHandler
,IOutputConnectionHandler
public class OutputConnectionHandler extends AbstractConnectionHandler implements IOutputConnectionHandler
The output connection handler.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
OutputConnectionHandler.DataSendInfo
Info about a sent but not yet acknowledged data message.-
Nested classes/interfaces inherited from class jadex.bridge.component.streams.AbstractConnectionHandler
AbstractConnectionHandler.SendInfo
-
-
Field Summary
Fields Modifier and Type Field Description protected int
ackcnt
The number of received elements after which an ack is sent.protected java.util.TimerTask
acktimer
The acknowledgement timer.protected boolean
closereqflag
Close request flag (when a closereq message was received).protected boolean
closesent
Flag if close was already sent.protected int
maxqueued
The max number of messages that can be sending concurrently (i.e. passed to message service but sending not yet completed).protected int
maxsend
The max number of packets that can be sent without an ack is received.protected Future<java.lang.Void>
mpfut
The current multipacket future (shared by all write requests that put data in the same multi packet).protected int
mpmaxsize
The packet size to collect (in bytes).protected long
mpsendtimeout
The max delay before a multipacket is sent (even if not full).protected java.util.TimerTask
mpsendtimer
The multipacket send timer.protected int
mpsize
The current multipacket size.protected java.util.List<byte[]>
multipacket
The collected data for a packet.protected boolean
multipackets
Flag if multipackets should be used.protected int
queuecnt
The number of sending messages (i.e. passed to message service but sending not yet completed).protected Future<java.lang.Integer>
readyfuture
Future used in waitForReady().protected java.util.Map<java.lang.Integer,OutputConnectionHandler.DataSendInfo>
sent
The data sent (not acknowledged).protected int
seqnumber
The current sequence number.protected Tuple2<java.lang.Boolean,java.lang.Integer>
stopflag
Stop flag (is sent in ack from input side) to signal that the rceiver is flooded with data).protected java.util.List<Tuple2<StreamPacket,Future<java.lang.Void>>>
tosend
The data to send.-
Fields inherited from class jadex.bridge.component.streams.AbstractConnectionHandler
ACKCLOSE, ACKCLOSE_INPUT_INITIATOR, ACKCLOSE_OUTPUT_PARTICIPANT, ACKCLOSEREQ, ACKCLOSEREQ_INPUT_PARTICIPANT, ACKCLOSEREQ_OUTPUT_INITIATOR, ACKDATA, ACKDATA_INPUT_INITIATOR, ACKDATA_OUTPUT_PARTICIPANT, ACKINIT, ACKINIT_INPUT_PARTICIPANT, ACKINIT_OUTPUT_PARTICIPANT, acktimeout, ALIVE, ALIVE_INITIATOR, ALIVE_PARTICIPANT, alivetime, CLOSE, CLOSE_INPUT_PARTICIPANT, CLOSE_OUTPUT_INITIATOR, CLOSEREQ, CLOSEREQ_INPUT_INITIATOR, CLOSEREQ_OUTPUT_PARTICIPANT, component, con, DATA, DATA_INPUT_PARTICIPANT, DATA_OUTPUT_INITIATOR, EMPTY_BYTE_ARRAY, INIT, INIT_INPUT_INITIATOR, INIT_OUTPUT_INITIATOR, leasetime, maxresends, MESSAGE_TYPE_STREAM, MESSAGETYPES, nonfunc, timer, unacked
-
-
Constructor Summary
Constructors Constructor Description OutputConnectionHandler(IInternalAccess component, java.util.Map<java.lang.String,java.lang.Object> nonfunc)
Create a new handler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
ackDataReceived(AckInfo ackinfo)
Called from message service.protected IFuture<java.lang.Void>
addMultipacket(byte[] data)
Called internally.protected IFuture<java.lang.Void>
addMultiPacketChunk(byte[] data)
Called internally.protected void
checkClose()
void
checkResend()
Check resending of unacknowledged messages.protected void
checkWaitForReady()
void
closeRequestReceived()
Received a request to close the connection.protected java.util.TimerTask
createBulkAckTimer(java.lang.Object id)
Triggers resends of packets if no ack has been received in acktimeout.protected void
createMultipacketSendTimer(int seqno)
This timer automatically sends non-full multipackets after mpsendtimeout has occurred.IFuture<java.lang.Void>
doClose()
Called from connection.protected IFuture<java.lang.Void>
doSendData(StreamPacket task)
void
flush()
Flush the data.int
getNextSequenceNumber()
Get The next seqnumber.OutputConnection
getOutputConnection()
Get the output connection.int
getSequenceNumber()
Get the seqnumber.boolean
isCloseRequested()
Get the closereq.protected boolean
isDataAckFinished()
Tests if the data processing of the connection is finished.protected boolean
isDataSendFinished()
Tests if the data processing of the connection is finished.protected boolean
isSendAllowed()
protected boolean
isStop()
void
notifyInited()
IFuture<java.lang.Void>
send(byte[] dat)
Called from connection.protected IFuture<java.lang.Void>
sendAcknowledgedMultiPacket()
Called internally.IFuture<java.lang.Void>
sendData(StreamPacket task)
Send or resend a data message.protected void
sendStored()
Called internally.void
setClosed()
Set the connection closed.IFuture<java.lang.Integer>
waitForReady()
Wait until the connection is ready for the next write.-
Methods inherited from class jadex.bridge.component.streams.AbstractConnectionHandler
ackReceived, close, createAckTimer, createTask, createTask, getComponent, getConnection, getConnectionId, getExecutionFeature, getLeasetime, getMessageFeature, getMessageType, getMessageType, getNonFunctionalProperties, initReceived, isClosed, isConnectionAlive, scheduleStep, sendAcknowledgedMessage, sendAlive, sendInit, sendTask, setAliveTime, setConnection, setNonFunctionalProperties, waitForRealDelay
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jadex.bridge.component.streams.IAbstractConnectionHandler
getNonFunctionalProperties, sendInit, setConnection
-
-
-
-
Field Detail
-
sent
protected java.util.Map<java.lang.Integer,OutputConnectionHandler.DataSendInfo> sent
The data sent (not acknowledged).
-
tosend
protected java.util.List<Tuple2<StreamPacket,Future<java.lang.Void>>> tosend
The data to send.
-
seqnumber
protected int seqnumber
The current sequence number.
-
maxsend
protected int maxsend
The max number of packets that can be sent without an ack is received.
-
maxqueued
protected int maxqueued
The max number of messages that can be sending concurrently (i.e. passed to message service but sending not yet completed).
-
ackcnt
protected int ackcnt
The number of received elements after which an ack is sent.
-
queuecnt
protected int queuecnt
The number of sending messages (i.e. passed to message service but sending not yet completed).
-
acktimer
protected java.util.TimerTask acktimer
The acknowledgement timer.
-
multipackets
protected boolean multipackets
Flag if multipackets should be used.
-
mpmaxsize
protected int mpmaxsize
The packet size to collect (in bytes).
-
multipacket
protected java.util.List<byte[]> multipacket
The collected data for a packet.
-
mpsize
protected int mpsize
The current multipacket size.
-
mpfut
protected Future<java.lang.Void> mpfut
The current multipacket future (shared by all write requests that put data in the same multi packet).
-
mpsendtimeout
protected long mpsendtimeout
The max delay before a multipacket is sent (even if not full).
-
mpsendtimer
protected java.util.TimerTask mpsendtimer
The multipacket send timer.
-
closereqflag
protected boolean closereqflag
Close request flag (when a closereq message was received).
-
stopflag
protected Tuple2<java.lang.Boolean,java.lang.Integer> stopflag
Stop flag (is sent in ack from input side) to signal that the rceiver is flooded with data).
-
closesent
protected boolean closesent
Flag if close was already sent.
-
readyfuture
protected Future<java.lang.Integer> readyfuture
Future used in waitForReady().
-
-
Constructor Detail
-
OutputConnectionHandler
public OutputConnectionHandler(IInternalAccess component, java.util.Map<java.lang.String,java.lang.Object> nonfunc)
Create a new handler.
-
-
Method Detail
-
closeRequestReceived
public void closeRequestReceived()
Received a request to close the connection.
-
ackDataReceived
public void ackDataReceived(AckInfo ackinfo)
Called from message service. Uses: sent, lastack
-
notifyInited
public void notifyInited()
- Specified by:
notifyInited
in interfaceIAbstractConnectionHandler
- Overrides:
notifyInited
in classAbstractConnectionHandler
-
doClose
public IFuture<java.lang.Void> doClose()
Called from connection. Initiates closing procedure (is different for initiator and participant).- Specified by:
doClose
in interfaceIAbstractConnectionHandler
- Overrides:
doClose
in classAbstractConnectionHandler
-
send
public IFuture<java.lang.Void> send(byte[] dat)
Called from connection. Uses: sent, tosend- Specified by:
send
in interfaceIOutputConnectionHandler
-
flush
public void flush()
Flush the data.- Specified by:
flush
in interfaceIOutputConnectionHandler
-
waitForReady
public IFuture<java.lang.Integer> waitForReady()
Wait until the connection is ready for the next write.- Specified by:
waitForReady
in interfaceIOutputConnectionHandler
- Returns:
- Calls future when next data can be written. Provides a value of how much data should be given to the connection for best performance.
-
checkWaitForReady
protected void checkWaitForReady()
-
doSendData
protected IFuture<java.lang.Void> doSendData(StreamPacket task)
-
sendStored
protected void sendStored()
Called internally. Uses: sent, tosend
-
addMultipacket
protected IFuture<java.lang.Void> addMultipacket(byte[] data)
Called internally. Add data to a multi packet.
-
addMultiPacketChunk
protected IFuture<java.lang.Void> addMultiPacketChunk(byte[] data)
Called internally. Add data chunk.- Parameters:
data
- The data.
-
sendAcknowledgedMultiPacket
protected IFuture<java.lang.Void> sendAcknowledgedMultiPacket()
Called internally. Send a multi packet.
-
sendData
public IFuture<java.lang.Void> sendData(StreamPacket task)
Send or resend a data message.
-
createBulkAckTimer
protected java.util.TimerTask createBulkAckTimer(java.lang.Object id)
Triggers resends of packets if no ack has been received in acktimeout.- Parameters:
id
- The message id.- Returns:
- The timer.
-
isSendAllowed
protected boolean isSendAllowed()
-
isStop
protected boolean isStop()
-
isCloseRequested
public boolean isCloseRequested()
Get the closereq.- Returns:
- The closereq.
-
isDataSendFinished
protected boolean isDataSendFinished()
Tests if the data processing of the connection is finished.
-
isDataAckFinished
protected boolean isDataAckFinished()
Tests if the data processing of the connection is finished.
-
setClosed
public void setClosed()
Set the connection closed.
-
getOutputConnection
public OutputConnection getOutputConnection()
Get the output connection.- Returns:
- The connection.
-
getSequenceNumber
public int getSequenceNumber()
Get the seqnumber.- Returns:
- the seqnumber.
-
getNextSequenceNumber
public int getNextSequenceNumber()
Get The next seqnumber.- Returns:
- The next seqnumber.
-
createMultipacketSendTimer
protected void createMultipacketSendTimer(int seqno)
This timer automatically sends non-full multipackets after mpsendtimeout has occurred.
-
checkClose
protected void checkClose()
-
checkResend
public void checkResend()
Check resending of unacknowledged messages.
-
-