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 Summary
Modifier and TypeMethodDescriptionvoidclears any commands from the cache that are yet to be confirmed.voidclose()Closes this channel.voidsends a confirmation of a packet being received.voidvoidflushes any confirmations on to the connection.voidSimilarly toflushConnectiononsend(Packet, boolean), it requests any un-flushed previous sent packets to be flushed to the underlying connection.intReturns the confirmation window size this channel is using.Returns theCoreRemotingConnectionbeing used by the channel.Gets theChannelHandlerthat this channel should forward received packets to.longgetID()Returns the id of this channel.intReturns the last confirmed packet command id.getLock()Returns the channel lock.intThis number increases every time the channel reconnects successfully.voidhandlePacket(Packet packet) Called byCoreRemotingConnectionwhen a packet is received.booleanisLocked()queries if this channel is locked.voidlock()locks the channel.voidreplayCommands(int lastConfirmedCommandID) resends any packets that have not received confirmations yet.default booleanvoidforces anysendBlocking(Packet, byte)request to return with an exception.voidreturnBlocking(Throwable cause) forces anysendBlocking(Packet, byte)request to return with an exception.booleanSends a packet on this channel.booleanSends a packet on this channel, but request it to be flushed (along with the un-flushed previous ones) only iffflushConnectionistrue.booleanSends a packet on this channel.booleansendAndFlush(Packet packet) Sends a packet on this channel and then blocks until it has been written to the connection.booleansendBatched(Packet packet) Sends a packet on this channel using batching algorithm if appropriatesendBlocking(Packet packet, byte expectedPacket) Sends a packet on this channel and then blocks until a response is received or a timeout occurs.sendBlocking(Packet packet, int reconnectID, byte expectedPacket) Sends a packet on this channel and then blocks until a response is received or a timeout occurs.sendBlocking(Packet packet, int reconnectID, byte expectedPacket, long timeout, boolean failOnTimeout) voidsets the handler to use when a confirmation is received.voidsetHandler(ChannelHandler handler) Sets theChannelHandlerthat this channel should forward received packets to.voidsetResponseHandler(ResponseHandler handler) voidsetTransferring(boolean transferring) notifies the channel if it is transferring its connection.booleansupports(byte packetID) For protocol checkbooleansupports(byte packetID, int version) For protocol checkvoidtransferConnection(CoreRemotingConnection newConnection) Transfers the connection used by this channel to the one specified.voidunlock()unlocks the channel.
-
Method Details
-
getID
long getID()Returns the id of this channel.- Returns:
- the id of this channel
-
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. -
supports
boolean supports(byte packetID) For protocol check -
supports
boolean supports(byte packetID, int version) For protocol check -
requireSpecialVotingHandling
default boolean requireSpecialVotingHandling() -
send
Sends a packet on this channel.- Parameters:
packet- the packet to send- Returns:
- false if the packet was rejected by an outgoing interceptor;
trueif the send was successful
-
send
Sends a packet on this channel.- Parameters:
packet- the packet to send- Returns:
- false if the packet was rejected by an outgoing interceptor;
trueif the send was successful
-
sendBatched
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;
trueif the send was successful
-
flushConnection
void flushConnection()Similarly toflushConnectiononsend(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
Sends a packet on this channel, but request it to be flushed (along with the un-flushed previous ones) only iffflushConnectionistrue.- Parameters:
packet- the packet to sendflushConnection- iftruerequests thispacketand any un-flushed previous sent one to be flushed to the underlying connection- Returns:
- false if the packet was rejected by an outgoing interceptor;
trueif the send was successful
-
sendAndFlush
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;
trueif the send was successful
-
sendBlocking
Sends a packet on this channel and then blocks until a response is received or a timeout occurs.- Parameters:
packet- the packet to sendexpectedPacket- the packet being expected.- Returns:
- the response
- Throws:
ActiveMQException- if an error occurs during the send
-
sendBlocking
Sends a packet on this channel and then blocks until a response is received or a timeout occurs.- Parameters:
packet- the packet to sendexpectedPacket- 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, long timeout, boolean failOnTimeout) throws ActiveMQException - Throws:
ActiveMQException
-
setHandler
Sets theChannelHandlerthat this channel should forward received packets to.- Parameters:
handler- the handler
-
getHandler
ChannelHandler getHandler()Gets theChannelHandlerthat 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
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 last confirmed packet command 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:
trueit 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. -
returnBlocking
void returnBlocking()forces anysendBlocking(Packet, byte)request to return with an exception. -
returnBlocking
forces anysendBlocking(Packet, byte)request to return with an exception. -
getLock
Lock getLock()Returns the channel lock.- Returns:
- the channel lock
-
getConnection
CoreRemotingConnection getConnection()Returns theCoreRemotingConnectionbeing used by the channel.- Returns:
- the
CoreRemotingConnectionbeing used by the channel
-
confirm
sends a confirmation of a packet being received.- Parameters:
packet- the packet to confirm
-
setCommandConfirmationHandler
sets the handler to use when a confirmation is received.- Parameters:
handler- the handler to call
-
setResponseHandler
-
flushConfirmations
void flushConfirmations()flushes any confirmations on to the connection. -
handlePacket
Called byCoreRemotingConnectionwhen a packet is received.This method should then call its
ChannelHandlerafter 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 confirmation window size this channel is using
-
setTransferring
void setTransferring(boolean transferring) notifies the channel if it is transferring its connection. Whentrueit is illegal to send messages.- Parameters:
transferring- whether the channel is transferring
-