Interface Channel
-
- All Known Implementing Classes:
ChannelImpl
public interface ChannelA channel is a way of interleaving data meant for different endpoints over the sameCoreRemotingConnection.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. seePacket.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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclearCommands()clears any commands from the cache that are yet to be confirmed.voidclose()Closes this channel.voidconfirm(Packet packet)sends a confirmation of a packet being received.voidendOfBatch()voidflushConfirmations()flushes any confirmations on to the connection.voidflushConnection()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.intgetConfirmationWindowSize()returns the confirmation window size this channel is using.CoreRemotingConnectiongetConnection()returns theCoreRemotingConnectionbeing used by the channelChannelHandlergetHandler()Gets theChannelHandlerthat this channel should forward received packets to.longgetID()Returns the id of this channel.intgetLastConfirmedCommandID()returns the last confirmed packet command idLockgetLock()returns the channel lockintgetReconnectID()This 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.voidreturnBlocking()forces anysendBlocking(Packet, byte)request to return with an exception.voidreturnBlocking(Throwable cause)forces anysendBlocking(Packet, byte)request to return with an exception.booleansend(Packet packet)Sends a packet on this channel.booleansend(Packet packet, boolean flushConnection)Sends a packet on this channel, but request it to be flushed (along with the un-flushed previous ones) only iffflushConnectionistrue.booleansend(Packet packet, int reconnectID)Sends 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 appropriatePacketsendBlocking(Packet packet, byte expectedPacket)Sends a packet on this channel and then blocks until a response is received or a timeout occurs.PacketsendBlocking(Packet packet, int reconnectID, byte expectedPacket)Sends a packet on this channel and then blocks until a response is received or a timeout occurs.voidsetCommandConfirmationHandler(CommandConfirmationHandler handler)sets 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 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 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
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 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; 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 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) 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 sendexpectedPacket- the packet being expected.- Returns:
- the response
- Throws:
ActiveMQException- if an error occurs during the send
-
setHandler
void setHandler(ChannelHandler handler)
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
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.
-
returnBlocking
void returnBlocking()
forces anysendBlocking(Packet, byte)request to return with an exception.
-
returnBlocking
void returnBlocking(Throwable cause)
forces anysendBlocking(Packet, byte)request to return with an exception.
-
getLock
Lock getLock()
returns the channel lock- Returns:
- the lock
-
getConnection
CoreRemotingConnection getConnection()
returns theCoreRemotingConnectionbeing used by the channel
-
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
-
setResponseHandler
void setResponseHandler(ResponseHandler handler)
-
flushConfirmations
void flushConfirmations()
flushes any confirmations on to the connection.
-
handlePacket
void handlePacket(Packet packet)
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 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
-
-