Class ChannelImpl

  • All Implemented Interfaces:
    Channel

    public final class ChannelImpl
    extends Object
    implements Channel
    • Method Detail

      • getReconnectID

        public int getReconnectID()
        Description copied from interface: Channel
        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.
        Specified by:
        getReconnectID in interface Channel
        Returns:
      • supports

        public boolean supports​(byte packetType)
        Description copied from interface: Channel
        For protocol check
        Specified by:
        supports in interface Channel
      • supports

        public boolean supports​(byte packetType,
                                int version)
        Description copied from interface: Channel
        For protocol check
        Specified by:
        supports in interface Channel
      • getID

        public long getID()
        Description copied from interface: Channel
        Returns the id of this channel.
        Specified by:
        getID in interface Channel
        Returns:
        the id
      • getLastConfirmedCommandID

        public int getLastConfirmedCommandID()
        Description copied from interface: Channel
        returns the last confirmed packet command id
        Specified by:
        getLastConfirmedCommandID in interface Channel
        Returns:
        the id
      • getLock

        public Lock getLock()
        Description copied from interface: Channel
        returns the channel lock
        Specified by:
        getLock in interface Channel
        Returns:
        the lock
      • getConfirmationWindowSize

        public int getConfirmationWindowSize()
        Description copied from interface: Channel
        returns the confirmation window size this channel is using.
        Specified by:
        getConfirmationWindowSize in interface Channel
        Returns:
        the window size
      • flushConnection

        public void flushConnection()
        Description copied from interface: Channel
        Similarly to flushConnection on Channel.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.
        Specified by:
        flushConnection in interface Channel
      • send

        public boolean send​(Packet packet,
                            boolean flushConnection)
        Description copied from interface: Channel
        Sends a packet on this channel, but request it to be flushed (along with the un-flushed previous ones) only iff flushConnection is true.
        Specified by:
        send in interface Channel
        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

        public boolean sendAndFlush​(Packet packet)
        Description copied from interface: Channel
        Sends a packet on this channel and then blocks until it has been written to the connection.
        Specified by:
        sendAndFlush in interface 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

        public boolean send​(Packet packet)
        Description copied from interface: Channel
        Sends a packet on this channel.
        Specified by:
        send in interface 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

        public boolean send​(Packet packet,
                            int reconnectID)
        Description copied from interface: Channel
        Sends a packet on this channel.
        Specified by:
        send in interface 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

        public boolean sendBatched​(Packet packet)
        Description copied from interface: Channel
        Sends a packet on this channel using batching algorithm if appropriate
        Specified by:
        sendBatched in interface Channel
        Parameters:
        packet - the packet to send
        Returns:
        false if the packet was rejected by an outgoing interceptor; true if the send was successful
      • setTransferring

        public void setTransferring​(boolean transferring)
        Description copied from interface: Channel
        notifies the channel if it is transferring its connection. When true it is illegal to send messages.
        Specified by:
        setTransferring in interface Channel
        Parameters:
        transferring - whether the channel is transferring
      • sendBlocking

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

        public Packet sendBlocking​(Packet packet,
                                   int reconnectID,
                                   byte expectedPacket)
                            throws ActiveMQException
        Due to networking issues or server issues the server may take longer to answer than expected.. the client may timeout the call throwing an exception and the client could eventually retry another call, but the server could then answer a previous command issuing a class-cast-exception. The expectedPacket will be used to filter out undesirable packets that would belong to previous calls.
        Specified by:
        sendBlocking in interface Channel
        Parameters:
        packet - the packet to send
        expectedPacket - the packet being expected.
        Returns:
        the response
        Throws:
        ActiveMQException - if an error occurs during the send
      • invokeInterceptors

        public static String invokeInterceptors​(Packet packet,
                                                List<Interceptor> interceptors,
                                                RemotingConnection connection)
        Parameters:
        packet - the packet to intercept
        Returns:
        the name of the interceptor that returned false or null if no interceptors returned false.
      • setHandler

        public void setHandler​(ChannelHandler handler)
        Description copied from interface: Channel
        Sets the ChannelHandler that this channel should forward received packets to.
        Specified by:
        setHandler in interface Channel
        Parameters:
        handler - the handler
      • endOfBatch

        public void endOfBatch()
        Specified by:
        endOfBatch in interface Channel
      • close

        public void close()
        Description copied from interface: Channel
        Closes this channel.

        once closed no packets can be sent.

        Specified by:
        close in interface Channel
      • transferConnection

        public void transferConnection​(CoreRemotingConnection newConnection)
        Description copied from interface: Channel
        Transfers the connection used by this channel to the one specified.

        All new packets will be sent via this connection.

        Specified by:
        transferConnection in interface Channel
        Parameters:
        newConnection - the new connection
      • replayCommands

        public void replayCommands​(int otherLastConfirmedCommandID)
        Description copied from interface: Channel
        resends any packets that have not received confirmations yet.

        Typically called after a connection has been transferred.

        Specified by:
        replayCommands in interface Channel
        Parameters:
        otherLastConfirmedCommandID - the last confirmed packet
      • isLocked

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

        public void lock()
        Description copied from interface: Channel
        locks the channel.

        While locked no packets can be sent or received

        Specified by:
        lock in interface Channel
      • unlock

        public void unlock()
        Description copied from interface: Channel
        unlocks the channel.
        Specified by:
        unlock in interface Channel
      • flushConfirmations

        public void flushConfirmations()
        Description copied from interface: Channel
        flushes any confirmations on to the connection.
        Specified by:
        flushConfirmations in interface Channel
      • handleAsyncResponse

        public void handleAsyncResponse​(Packet packet)
      • confirm

        public void confirm​(Packet packet)
        Description copied from interface: Channel
        sends a confirmation of a packet being received.
        Specified by:
        confirm in interface Channel
        Parameters:
        packet - the packet to confirm
      • clearCommands

        public void clearCommands()
        Description copied from interface: Channel
        clears any commands from the cache that are yet to be confirmed.
        Specified by:
        clearCommands in interface Channel
      • handlePacket

        public void handlePacket​(Packet packet)
        Description copied from interface: Channel
        Called by CoreRemotingConnection when a packet is received.

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

        Specified by:
        handlePacket in interface Channel
        Parameters:
        packet - the packet to process.