Package jadex.bridge.component.streams
Class AbstractConnectionHandler
- java.lang.Object
- 
- jadex.bridge.component.streams.AbstractConnectionHandler
 
- 
- All Implemented Interfaces:
- IAbstractConnectionHandler
 - Direct Known Subclasses:
- InputConnectionHandler,- OutputConnectionHandler
 
 public class AbstractConnectionHandler extends java.lang.Object implements IAbstractConnectionHandler Abstract base class for connection handlers. Is called from the message service and the connection. Ensures that all calls from threads other than the message service component are scheduled on this thread to avoid multithreading issues in this class.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classAbstractConnectionHandler.SendInfoStruct class that holds send information.
 - 
Field SummaryFields Modifier and Type Field Description static java.lang.StringACKCLOSEAcknowledge the close message.static byteACKCLOSE_INPUT_INITIATORAck for close - from initiator .static byteACKCLOSE_OUTPUT_PARTICIPANTAck data/close - from participant .static java.lang.StringACKCLOSEREQAcknowledge the close request.static byteACKCLOSEREQ_INPUT_PARTICIPANTAck for close request - from initiator .static byteACKCLOSEREQ_OUTPUT_INITIATORAck for close request - from initiator .static java.lang.StringACKDATAAcknowledge data message.static byteACKDATA_INPUT_INITIATORAck data - from participant .static byteACKDATA_OUTPUT_PARTICIPANTAck data/close - from participant .static java.lang.StringACKINITAcknowledge init.static byteACKINIT_INPUT_PARTICIPANTAck the init - from participant.static byteACKINIT_OUTPUT_PARTICIPANTAck the init - from initiator.protected longacktimeoutThe max delay before an acknowledgement is received.static java.lang.StringALIVEThe alive message.static byteALIVE_INITIATORAlive message - from initiator.static byteALIVE_PARTICIPANTAlive message - from participant.protected longalivetimeThe latest alive time.static java.lang.StringCLOSEClose the connection.static byteCLOSE_INPUT_PARTICIPANTClose connection - from participant.static byteCLOSE_OUTPUT_INITIATORClose connection - from initiator.static java.lang.StringCLOSEREQClose request (from participant which cannot close itself).static byteCLOSEREQ_INPUT_INITIATORClose request connection - from initiator.static byteCLOSEREQ_OUTPUT_PARTICIPANTRequest close connection - from participant.protected IInternalAccesscomponentThe message service.protected AbstractConnectionconThe connection.static java.lang.StringDATASend data message.static byteDATA_INPUT_PARTICIPANTSend data - from participant.static byteDATA_OUTPUT_INITIATORSend data - from initiator.static byte[]EMPTY_BYTE_ARRAYstatic java.lang.StringINITInit a connection.static byteINIT_INPUT_INITIATORCreate virtual input connection - from initiator.static byteINIT_OUTPUT_INITIATORCreate virtual output connection - from initiator.protected longleasetimeThe lease time.protected intmaxresendsThe maximum number of resends.static byteMESSAGE_TYPE_STREAMThe message type for streams.static java.util.Map<Tuple,java.lang.Byte>MESSAGETYPESString type, boolean input, boolean initiator.protected java.util.Map<java.lang.String,java.lang.Object>nonfuncThe non-functional properties.protected java.util.TimertimerThe timer.protected java.util.Map<java.lang.Object,AbstractConnectionHandler.SendInfo>unackedThe unacknowledged messages.
 - 
Constructor SummaryConstructors Constructor Description AbstractConnectionHandler(IInternalAccess component, java.util.Map<java.lang.String,java.lang.Object> nonfunc)Create a new connection handler.AbstractConnectionHandler(IInternalAccess component, java.util.Map<java.lang.String,java.lang.Object> nonfunc, int maxresends, long acktimeout, long leasetime)Create a new connection handler.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidackReceived(java.lang.Object id, java.lang.Object content)Called when an ack was received.voidclose()Close the connection.protected java.util.TimerTaskcreateAckTimer(java.lang.Object id)Triggers resends of packets if no ack has been received in acktimeout.protected StreamPacketcreateTask(java.lang.String type, byte[] content, java.lang.Integer seqnumber, java.util.Map<java.lang.String,java.lang.Object> nonfunc)Create a new task.protected StreamPacketcreateTask(java.lang.String type, java.lang.Object content, boolean useserializer, java.lang.Integer seqnumber, java.util.Map<java.lang.String,java.lang.Object> nonfunc)Create a new task.IFuture<java.lang.Void>doClose()Called from connection.IInternalAccessgetComponent()Get the component.protected AbstractConnectiongetConnection()Get the connection.intgetConnectionId()Get the id.IExecutionFeaturegetExecutionFeature()Get the execution feature.protected longgetLeasetime()Get the leasetime.IMessageFeaturegetMessageFeature()Get the message feature.protected bytegetMessageType(java.lang.String type)Get the message type for a given type, e.g.static bytegetMessageType(java.lang.String type, boolean input, boolean initiator)Get the message type.java.util.Map<java.lang.String,java.lang.Object>getNonFunctionalProperties()Get the non-functional properties.voidinitReceived()Received the init message.booleanisClosed()Get the closed.booleanisConnectionAlive()Test if the connection is alive.voidnotifyInited()protected <E> IFuture<E>scheduleStep(IComponentStep<E> step)Schedule a step on the message service component.protected IFuture<java.lang.Object>sendAcknowledgedMessage(StreamPacket task, java.lang.Object id)Send a message and wait for an ack.IFuture<java.lang.Void>sendAlive()Send alive message.IFuture<java.lang.Void>sendInit()Send init message.protected IFuture<java.lang.Void>sendTask(StreamPacket task)Send a task.voidsetAliveTime(long alivetime)Set the alive time of the other connection side.voidsetConnection(AbstractConnection con)Set the connection (needed as connection and handler need each other).voidsetNonFunctionalProperties(java.util.Map<java.lang.String,java.lang.Object> nonfunc)Set the non-functional properties.java.util.TimerTaskwaitForRealDelay(long delay, IComponentStep<?> step)Wait for a time delay on the (real) system clock.
 
- 
- 
- 
Field Detail- 
MESSAGE_TYPE_STREAMpublic static final byte MESSAGE_TYPE_STREAM The message type for streams.- See Also:
- Constant Field Values
 
 - 
INITpublic static final java.lang.String INIT Init a connection.- See Also:
- Constant Field Values
 
 - 
ACKINITpublic static final java.lang.String ACKINIT Acknowledge init.- See Also:
- Constant Field Values
 
 - 
DATApublic static final java.lang.String DATA Send data message.- See Also:
- Constant Field Values
 
 - 
ACKDATApublic static final java.lang.String ACKDATA Acknowledge data message.- See Also:
- Constant Field Values
 
 - 
CLOSEpublic static final java.lang.String CLOSE Close the connection.- See Also:
- Constant Field Values
 
 - 
ACKCLOSEpublic static final java.lang.String ACKCLOSE Acknowledge the close message.- See Also:
- Constant Field Values
 
 - 
CLOSEREQpublic static final java.lang.String CLOSEREQ Close request (from participant which cannot close itself).- See Also:
- Constant Field Values
 
 - 
ACKCLOSEREQpublic static final java.lang.String ACKCLOSEREQ Acknowledge the close request.- See Also:
- Constant Field Values
 
 - 
ALIVEpublic static final java.lang.String ALIVE The alive message.- See Also:
- Constant Field Values
 
 - 
INIT_OUTPUT_INITIATORpublic static final byte INIT_OUTPUT_INITIATOR Create virtual output connection - from initiator.- See Also:
- Constant Field Values
 
 - 
ACKINIT_OUTPUT_PARTICIPANTpublic static final byte ACKINIT_OUTPUT_PARTICIPANT Ack the init - from initiator.- See Also:
- Constant Field Values
 
 - 
DATA_OUTPUT_INITIATORpublic static final byte DATA_OUTPUT_INITIATOR Send data - from initiator.- See Also:
- Constant Field Values
 
 - 
ACKDATA_OUTPUT_PARTICIPANTpublic static final byte ACKDATA_OUTPUT_PARTICIPANT Ack data/close - from participant .- See Also:
- Constant Field Values
 
 - 
CLOSEREQ_OUTPUT_PARTICIPANTpublic static final byte CLOSEREQ_OUTPUT_PARTICIPANT Request close connection - from participant.- See Also:
- Constant Field Values
 
 - 
ACKCLOSEREQ_OUTPUT_INITIATORpublic static final byte ACKCLOSEREQ_OUTPUT_INITIATOR Ack for close request - from initiator .- See Also:
- Constant Field Values
 
 - 
CLOSE_OUTPUT_INITIATORpublic static final byte CLOSE_OUTPUT_INITIATOR Close connection - from initiator.- See Also:
- Constant Field Values
 
 - 
ACKCLOSE_OUTPUT_PARTICIPANTpublic static final byte ACKCLOSE_OUTPUT_PARTICIPANT Ack data/close - from participant .- See Also:
- Constant Field Values
 
 - 
INIT_INPUT_INITIATORpublic static final byte INIT_INPUT_INITIATOR Create virtual input connection - from initiator.- See Also:
- Constant Field Values
 
 - 
ACKINIT_INPUT_PARTICIPANTpublic static final byte ACKINIT_INPUT_PARTICIPANT Ack the init - from participant.- See Also:
- Constant Field Values
 
 - 
DATA_INPUT_PARTICIPANTpublic static final byte DATA_INPUT_PARTICIPANT Send data - from participant.- See Also:
- Constant Field Values
 
 - 
ACKDATA_INPUT_INITIATORpublic static final byte ACKDATA_INPUT_INITIATOR Ack data - from participant .- See Also:
- Constant Field Values
 
 - 
CLOSEREQ_INPUT_INITIATORpublic static final byte CLOSEREQ_INPUT_INITIATOR Close request connection - from initiator.- See Also:
- Constant Field Values
 
 - 
ACKCLOSEREQ_INPUT_PARTICIPANTpublic static final byte ACKCLOSEREQ_INPUT_PARTICIPANT Ack for close request - from initiator .- See Also:
- Constant Field Values
 
 - 
CLOSE_INPUT_PARTICIPANTpublic static final byte CLOSE_INPUT_PARTICIPANT Close connection - from participant.- See Also:
- Constant Field Values
 
 - 
ACKCLOSE_INPUT_INITIATORpublic static final byte ACKCLOSE_INPUT_INITIATOR Ack for close - from initiator .- See Also:
- Constant Field Values
 
 - 
ALIVE_INITIATORpublic static final byte ALIVE_INITIATOR Alive message - from initiator.- See Also:
- Constant Field Values
 
 - 
ALIVE_PARTICIPANTpublic static final byte ALIVE_PARTICIPANT Alive message - from participant.- See Also:
- Constant Field Values
 
 - 
MESSAGETYPESpublic static final java.util.Map<Tuple,java.lang.Byte> MESSAGETYPES String type, boolean input, boolean initiator.
 - 
EMPTY_BYTE_ARRAYpublic static final byte[] EMPTY_BYTE_ARRAY 
 - 
componentprotected IInternalAccess component The message service.
 - 
conprotected AbstractConnection con The connection.
 - 
alivetimeprotected long alivetime The latest alive time.
 - 
leasetimeprotected long leasetime The lease time.
 - 
unackedprotected java.util.Map<java.lang.Object,AbstractConnectionHandler.SendInfo> unacked The unacknowledged messages.
 - 
maxresendsprotected int maxresends The maximum number of resends.
 - 
acktimeoutprotected long acktimeout The max delay before an acknowledgement is received.
 - 
nonfuncprotected java.util.Map<java.lang.String,java.lang.Object> nonfunc The non-functional properties.
 - 
timerprotected java.util.Timer timer The timer.
 
- 
 - 
Constructor Detail- 
AbstractConnectionHandlerpublic AbstractConnectionHandler(IInternalAccess component, java.util.Map<java.lang.String,java.lang.Object> nonfunc) Create a new connection handler.
 - 
AbstractConnectionHandlerpublic AbstractConnectionHandler(IInternalAccess component, java.util.Map<java.lang.String,java.lang.Object> nonfunc, int maxresends, long acktimeout, long leasetime) Create a new connection handler.
 
- 
 - 
Method Detail- 
getMessageTypepublic static byte getMessageType(java.lang.String type, boolean input, boolean initiator)Get the message type.- Parameters:
- type- The type.
- input- Flag if in input connection.
- initiator- Flag if is initiator side.
 
 - 
setConnectionpublic void setConnection(AbstractConnection con) Set the connection (needed as connection and handler need each other). The connections uses this method to set itself as connection in their constructor.- Specified by:
- setConnectionin interface- IAbstractConnectionHandler
 
 - 
initReceivedpublic void initReceived() Received the init message.
 - 
ackReceivedpublic void ackReceived(java.lang.Object id, java.lang.Object content)Called when an ack was received. The id is used to identify the original message task. This will cancel the timer (resending) task and call the future of sendAcknowledgedMessage().
 - 
closepublic void close() Close the connection. Notifies the other side that the connection has been closed.
 - 
setAliveTimepublic void setAliveTime(long alivetime) Set the alive time of the other connection side.- Parameters:
- alivetime- The alive time.
 
 - 
isConnectionAlivepublic boolean isConnectionAlive() Test if the connection is alive.- Returns:
- True, if is alive.
 
 - 
isClosedpublic boolean isClosed() Get the closed.- Returns:
- The closed.
 
 - 
getConnectionIdpublic int getConnectionId() Get the id.- Returns:
- the id.
 
 - 
doClosepublic IFuture<java.lang.Void> doClose() Called from connection. Initiates closing procedure (is different for initiator and participant).- Specified by:
- doClosein interface- IAbstractConnectionHandler
 
 - 
sendInitpublic IFuture<java.lang.Void> sendInit() Send init message.- Specified by:
- sendInitin interface- IAbstractConnectionHandler
 
 - 
sendAlivepublic IFuture<java.lang.Void> sendAlive() Send alive message.
 - 
notifyInitedpublic void notifyInited() - Specified by:
- notifyInitedin interface- IAbstractConnectionHandler
 
 - 
getConnectionprotected AbstractConnection getConnection() Get the connection.- Returns:
- The connection.
 
 - 
getNonFunctionalPropertiespublic java.util.Map<java.lang.String,java.lang.Object> getNonFunctionalProperties() Get the non-functional properties.- Specified by:
- getNonFunctionalPropertiesin interface- IAbstractConnectionHandler
- Returns:
- The non-functional properties.
 
 - 
setNonFunctionalPropertiespublic void setNonFunctionalProperties(java.util.Map<java.lang.String,java.lang.Object> nonfunc) Set the non-functional properties.- Parameters:
- nonfunc- The non-functional properties.
 
 - 
getMessageTypeprotected byte getMessageType(java.lang.String type) Get the message type for a given type, e.g. init, close (defined in StreamSendTask).- Parameters:
- type- The message type.
- Returns:
- The message type for message sending.
 
 - 
createTaskprotected StreamPacket createTask(java.lang.String type, byte[] content, java.lang.Integer seqnumber, java.util.Map<java.lang.String,java.lang.Object> nonfunc) Create a new task.- Parameters:
- type- The message type.
- content- The content.
- seqnumber- The sequence number.
- Returns:
- The task for sending the message.
 
 - 
createTaskprotected StreamPacket createTask(java.lang.String type, java.lang.Object content, boolean useserializer, java.lang.Integer seqnumber, java.util.Map<java.lang.String,java.lang.Object> nonfunc) Create a new task.- Parameters:
- type- The message type.
- content- The content.
- usecodecs- Flag if codecs should be used to encode the content.
- seqnumber- The sequence number.
- Returns:
- The task for sending the message.
 
 - 
sendTaskprotected IFuture<java.lang.Void> sendTask(StreamPacket task) Send a task.- Parameters:
- task- The task.
 
 - 
sendAcknowledgedMessageprotected IFuture<java.lang.Object> sendAcknowledgedMessage(StreamPacket task, java.lang.Object id) Send a message and wait for an ack. Automatically resends messages () if not is ack is received within acktimeout.- Parameters:
- task- The send task.
- id- The id of the call (e.g. sequence number).
- Returns:
- Exception if sending and resending failed.
 
 - 
getLeasetimeprotected long getLeasetime() Get the leasetime.- Returns:
- the leasetime.
 
 - 
scheduleStepprotected <E> IFuture<E> scheduleStep(IComponentStep<E> step) Schedule a step on the message service component.
 - 
createAckTimerprotected java.util.TimerTask createAckTimer(java.lang.Object id) Triggers resends of packets if no ack has been received in acktimeout.- Parameters:
- id- The message id.
- Returns:
- The timer.
 
 - 
waitForRealDelaypublic java.util.TimerTask waitForRealDelay(long delay, IComponentStep<?> step)Wait for a time delay on the (real) system clock.
 - 
getComponentpublic IInternalAccess getComponent() Get the component.- Returns:
- the component
 
 - 
getMessageFeaturepublic IMessageFeature getMessageFeature() Get the message feature.
 - 
getExecutionFeaturepublic IExecutionFeature getExecutionFeature() Get the execution feature.
 
- 
 
-