java.lang.Object
org.apache.activemq.artemis.core.protocol.core.impl.ChannelImpl
All Implemented Interfaces:
Channel

public final class ChannelImpl extends Object implements Channel
  • Constructor Details

  • Method Details

    • 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
    • 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
    • requireSpecialVotingHandling

      public boolean requireSpecialVotingHandling()
      Specified by:
      requireSpecialVotingHandling 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 of this channel
    • getLastConfirmedCommandID

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

      public Lock getLock()
      Description copied from interface: Channel
      Returns the channel lock.
      Specified by:
      getLock in interface Channel
      Returns:
      the channel 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 confirmation window size this channel is using
    • returnBlocking

      public void returnBlocking()
      Description copied from interface: Channel
      forces any Channel.sendBlocking(Packet, byte) request to return with an exception.
      Specified by:
      returnBlocking in interface Channel
    • returnBlocking

      public void returnBlocking(Throwable cause)
      Description copied from interface: Channel
      forces any Channel.sendBlocking(Packet, byte) request to return with an exception.
      Specified by:
      returnBlocking in interface Channel
    • 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
    • getCache

      protected ResponseCache getCache()
    • 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
      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, long timeout, boolean failOnTimeout) 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
      Throws:
      ActiveMQException
    • invokeInterceptors

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

      public void setCommandConfirmationHandler(CommandConfirmationHandler handler)
      Description copied from interface: Channel
      sets the handler to use when a confirmation is received.
      Specified by:
      setCommandConfirmationHandler in interface Channel
      Parameters:
      handler - the handler to call
    • setResponseHandler

      public void setResponseHandler(ResponseHandler responseHandler)
      Specified by:
      setResponseHandler in interface Channel
    • 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
    • getHandler

      public ChannelHandler getHandler()
      Description copied from interface: Channel
      Gets the ChannelHandler that this channel should forward received packets to.
      Specified by:
      getHandler in interface Channel
      Returns:
      the current channel 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
    • getConnection

      public CoreRemotingConnection getConnection()
      Description copied from interface: Channel
      Returns the CoreRemotingConnection being used by the channel.
      Specified by:
      getConnection in interface Channel
      Returns:
      the CoreRemotingConnection being used by the 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.
    • toString

      public String toString()
      Overrides:
      toString in class Object