Class AbstractConnectionHandler

    • Field Detail

      • MESSAGE_TYPE_STREAM

        public static final byte MESSAGE_TYPE_STREAM
        The message type for streams.
        See Also:
        Constant Field Values
      • ACKINIT

        public static final java.lang.String ACKINIT
        Acknowledge init.
        See Also:
        Constant Field Values
      • ACKDATA

        public static final java.lang.String ACKDATA
        Acknowledge data message.
        See Also:
        Constant Field Values
      • CLOSE

        public static final java.lang.String CLOSE
        Close the connection.
        See Also:
        Constant Field Values
      • ACKCLOSE

        public static final java.lang.String ACKCLOSE
        Acknowledge the close message.
        See Also:
        Constant Field Values
      • CLOSEREQ

        public static final java.lang.String CLOSEREQ
        Close request (from participant which cannot close itself).
        See Also:
        Constant Field Values
      • ACKCLOSEREQ

        public static final java.lang.String ACKCLOSEREQ
        Acknowledge the close request.
        See Also:
        Constant Field Values
      • INIT_OUTPUT_INITIATOR

        public static final byte INIT_OUTPUT_INITIATOR
        Create virtual output connection - from initiator.
        See Also:
        Constant Field Values
      • ACKINIT_OUTPUT_PARTICIPANT

        public static final byte ACKINIT_OUTPUT_PARTICIPANT
        Ack the init - from initiator.
        See Also:
        Constant Field Values
      • DATA_OUTPUT_INITIATOR

        public static final byte DATA_OUTPUT_INITIATOR
        Send data - from initiator.
        See Also:
        Constant Field Values
      • ACKDATA_OUTPUT_PARTICIPANT

        public static final byte ACKDATA_OUTPUT_PARTICIPANT
        Ack data/close - from participant .
        See Also:
        Constant Field Values
      • CLOSEREQ_OUTPUT_PARTICIPANT

        public static final byte CLOSEREQ_OUTPUT_PARTICIPANT
        Request close connection - from participant.
        See Also:
        Constant Field Values
      • ACKCLOSEREQ_OUTPUT_INITIATOR

        public static final byte ACKCLOSEREQ_OUTPUT_INITIATOR
        Ack for close request - from initiator .
        See Also:
        Constant Field Values
      • CLOSE_OUTPUT_INITIATOR

        public static final byte CLOSE_OUTPUT_INITIATOR
        Close connection - from initiator.
        See Also:
        Constant Field Values
      • ACKCLOSE_OUTPUT_PARTICIPANT

        public static final byte ACKCLOSE_OUTPUT_PARTICIPANT
        Ack data/close - from participant .
        See Also:
        Constant Field Values
      • INIT_INPUT_INITIATOR

        public static final byte INIT_INPUT_INITIATOR
        Create virtual input connection - from initiator.
        See Also:
        Constant Field Values
      • ACKINIT_INPUT_PARTICIPANT

        public static final byte ACKINIT_INPUT_PARTICIPANT
        Ack the init - from participant.
        See Also:
        Constant Field Values
      • DATA_INPUT_PARTICIPANT

        public static final byte DATA_INPUT_PARTICIPANT
        Send data - from participant.
        See Also:
        Constant Field Values
      • ACKDATA_INPUT_INITIATOR

        public static final byte ACKDATA_INPUT_INITIATOR
        Ack data - from participant .
        See Also:
        Constant Field Values
      • CLOSEREQ_INPUT_INITIATOR

        public static final byte CLOSEREQ_INPUT_INITIATOR
        Close request connection - from initiator.
        See Also:
        Constant Field Values
      • ACKCLOSEREQ_INPUT_PARTICIPANT

        public static final byte ACKCLOSEREQ_INPUT_PARTICIPANT
        Ack for close request - from initiator .
        See Also:
        Constant Field Values
      • CLOSE_INPUT_PARTICIPANT

        public static final byte CLOSE_INPUT_PARTICIPANT
        Close connection - from participant.
        See Also:
        Constant Field Values
      • ACKCLOSE_INPUT_INITIATOR

        public static final byte ACKCLOSE_INPUT_INITIATOR
        Ack for close - from initiator .
        See Also:
        Constant Field Values
      • ALIVE_INITIATOR

        public static final byte ALIVE_INITIATOR
        Alive message - from initiator.
        See Also:
        Constant Field Values
      • ALIVE_PARTICIPANT

        public static final byte ALIVE_PARTICIPANT
        Alive message - from participant.
        See Also:
        Constant Field Values
      • MESSAGETYPES

        public static final java.util.Map<Tuple,​java.lang.Byte> MESSAGETYPES
        String type, boolean input, boolean initiator.
      • EMPTY_BYTE_ARRAY

        public static final byte[] EMPTY_BYTE_ARRAY
      • alivetime

        protected long alivetime
        The latest alive time.
      • leasetime

        protected long leasetime
        The lease time.
      • maxresends

        protected int maxresends
        The maximum number of resends.
      • acktimeout

        protected long acktimeout
        The max delay before an acknowledgement is received.
      • nonfunc

        protected java.util.Map<java.lang.String,​java.lang.Object> nonfunc
        The non-functional properties.
      • timer

        protected java.util.Timer timer
        The timer.
    • Constructor Detail

      • AbstractConnectionHandler

        public AbstractConnectionHandler​(IInternalAccess component,
                                         java.util.Map<java.lang.String,​java.lang.Object> nonfunc)
        Create a new connection handler.
      • AbstractConnectionHandler

        public 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

      • getMessageType

        public 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.
      • setConnection

        public 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:
        setConnection in interface IAbstractConnectionHandler
      • initReceived

        public void initReceived()
        Received the init message.
      • ackReceived

        public 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().
      • close

        public void close()
        Close the connection. Notifies the other side that the connection has been closed.
      • setAliveTime

        public void setAliveTime​(long alivetime)
        Set the alive time of the other connection side.
        Parameters:
        alivetime - The alive time.
      • isConnectionAlive

        public boolean isConnectionAlive()
        Test if the connection is alive.
        Returns:
        True, if is alive.
      • isClosed

        public boolean isClosed()
        Get the closed.
        Returns:
        The closed.
      • getConnectionId

        public int getConnectionId()
        Get the id.
        Returns:
        the id.
      • doClose

        public IFuture<java.lang.Void> doClose()
        Called from connection. Initiates closing procedure (is different for initiator and participant).
        Specified by:
        doClose in interface IAbstractConnectionHandler
      • sendAlive

        public IFuture<java.lang.Void> sendAlive()
        Send alive message.
      • getConnection

        protected AbstractConnection getConnection()
        Get the connection.
        Returns:
        The connection.
      • getNonFunctionalProperties

        public java.util.Map<java.lang.String,​java.lang.Object> getNonFunctionalProperties()
        Get the non-functional properties.
        Specified by:
        getNonFunctionalProperties in interface IAbstractConnectionHandler
        Returns:
        The non-functional properties.
      • setNonFunctionalProperties

        public void setNonFunctionalProperties​(java.util.Map<java.lang.String,​java.lang.Object> nonfunc)
        Set the non-functional properties.
        Parameters:
        nonfunc - The non-functional properties.
      • getMessageType

        protected 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.
      • createTask

        protected 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.
      • createTask

        protected 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.
      • sendTask

        protected IFuture<java.lang.Void> sendTask​(StreamPacket task)
        Send a task.
        Parameters:
        task - The task.
      • sendAcknowledgedMessage

        protected 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.
      • getLeasetime

        protected long getLeasetime()
        Get the leasetime.
        Returns:
        the leasetime.
      • scheduleStep

        protected <E> IFuture<E> scheduleStep​(IComponentStep<E> step)
        Schedule a step on the message service component.
      • createAckTimer

        protected 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.
      • waitForRealDelay

        public java.util.TimerTask waitForRealDelay​(long delay,
                                                    IComponentStep<?> step)
        Wait for a time delay on the (real) system clock.
      • getComponent

        public IInternalAccess getComponent()
        Get the component.
        Returns:
        the component
      • getMessageFeature

        public IMessageFeature getMessageFeature()
        Get the message feature.
      • getExecutionFeature

        public IExecutionFeature getExecutionFeature()
        Get the execution feature.