Interface Channel

  • All Known Implementing Classes:
    ChannelImpl

    public interface Channel
    A channel is a way of interleaving data meant for different endpoints over the same CoreRemotingConnection.

    Any packet sent will have its channel id set to the specific channel sending so it can be routed to its correct channel when received by the CoreRemotingConnection. see Packet.setChannelID(long).

    Each Channel should will forward any packets received to its ChannelHandler.

    A Channel *does not* support concurrent access by more than one thread!

    • Method Detail

      • getID

        long getID()
        Returns the id of this channel.
        Returns:
        the id
      • getReconnectID

        int getReconnectID()
        This number increases every time the channel reconnects successfully. This is used to guarantee the integrity of the channel on sequential commands such as large messages.
        Returns:
      • supports

        boolean supports​(byte packetID)
        For protocol check
      • supports

        boolean supports​(byte packetID,
                         int version)
        For protocol check
      • send

        boolean send​(Packet packet)
        Sends a packet on this channel.
        Parameters:
        packet - the packet to send
        Returns:
        false if the packet was rejected by an outgoing interceptor; true if the send was successful
      • send

        boolean send​(Packet packet,
                     int reconnectID)
        Sends a packet on this channel.
        Parameters:
        packet - the packet to send
        Returns:
        false if the packet was rejected by an outgoing interceptor; true if the send was successful
      • sendBatched

        boolean sendBatched​(Packet packet)
        Sends a packet on this channel using batching algorithm if appropriate
        Parameters:
        packet - the packet to send
        Returns:
        false if the packet was rejected by an outgoing interceptor; true if the send was successful
      • flushConnection

        void flushConnection()
        Similarly to flushConnection on send(Packet, boolean), it requests any un-flushed previous sent packets to be flushed to the underlying connection.
        It can be a no-op in case of InVM transports, because they would likely to flush already on each send.
      • send

        boolean send​(Packet packet,
                     boolean flushConnection)
        Sends a packet on this channel, but request it to be flushed (along with the un-flushed previous ones) only iff flushConnection is true.
        Parameters:
        packet - the packet to send
        flushConnection - if true requests this packet and any un-flushed previous sent one to be flushed to the underlying connection
        Returns:
        false if the packet was rejected by an outgoing interceptor; true if the send was successful
      • sendAndFlush

        boolean sendAndFlush​(Packet packet)
        Sends a packet on this channel and then blocks until it has been written to the connection.
        Parameters:
        packet - the packet to send
        Returns:
        false if the packet was rejected by an outgoing interceptor; true if the send was successful
      • sendBlocking

        Packet sendBlocking​(Packet packet,
                            byte expectedPacket)
                     throws ActiveMQException
        Sends a packet on this channel and then blocks until a response is received or a timeout occurs.
        Parameters:
        packet - the packet to send
        expectedPacket - the packet being expected.
        Returns:
        the response
        Throws:
        ActiveMQException - if an error occurs during the send
      • sendBlocking

        Packet sendBlocking​(Packet packet,
                            int reconnectID,
                            byte expectedPacket)
                     throws ActiveMQException
        Sends a packet on this channel and then blocks until a response is received or a timeout occurs.
        Parameters:
        packet - the packet to send
        expectedPacket - the packet being expected.
        Returns:
        the response
        Throws:
        ActiveMQException - if an error occurs during the send
      • setHandler

        void setHandler​(ChannelHandler handler)
        Sets the ChannelHandler that this channel should forward received packets to.
        Parameters:
        handler - the handler
      • getHandler

        ChannelHandler getHandler()
        Gets the ChannelHandler that this channel should forward received packets to.
        Returns:
        the current channel handler
      • endOfBatch

        void endOfBatch()
      • close

        void close()
        Closes this channel.

        once closed no packets can be sent.

      • transferConnection

        void transferConnection​(CoreRemotingConnection newConnection)
        Transfers the connection used by this channel to the one specified.

        All new packets will be sent via this connection.

        Parameters:
        newConnection - the new connection
      • replayCommands

        void replayCommands​(int lastConfirmedCommandID)
        resends any packets that have not received confirmations yet.

        Typically called after a connection has been transferred.

        Parameters:
        lastConfirmedCommandID - the last confirmed packet
      • getLastConfirmedCommandID

        int getLastConfirmedCommandID()
        returns the last confirmed packet command id
        Returns:
        the id
      • isLocked

        boolean isLocked()
        queries if this channel is locked. This method is designed for use in monitoring of the system state, not for synchronization control.
        Returns:
        true it the channel is locked and false otherwise
      • lock

        void lock()
        locks the channel.

        While locked no packets can be sent or received

      • unlock

        void unlock()
        unlocks the channel.
      • getLock

        Lock getLock()
        returns the channel lock
        Returns:
        the lock
      • confirm

        void confirm​(Packet packet)
        sends a confirmation of a packet being received.
        Parameters:
        packet - the packet to confirm
      • setCommandConfirmationHandler

        void setCommandConfirmationHandler​(CommandConfirmationHandler handler)
        sets the handler to use when a confirmation is received.
        Parameters:
        handler - the handler to call
      • flushConfirmations

        void flushConfirmations()
        flushes any confirmations on to the connection.
      • handlePacket

        void handlePacket​(Packet packet)
        Called by CoreRemotingConnection when a packet is received.

        This method should then call its ChannelHandler after appropriate processing of the packet

        Parameters:
        packet - the packet to process.
      • clearCommands

        void clearCommands()
        clears any commands from the cache that are yet to be confirmed.
      • getConfirmationWindowSize

        int getConfirmationWindowSize()
        returns the confirmation window size this channel is using.
        Returns:
        the window size
      • setTransferring

        void setTransferring​(boolean transferring)
        notifies the channel if it is transferring its connection. When true it is illegal to send messages.
        Parameters:
        transferring - whether the channel is transferring