Class ChannelImpl
- java.lang.Object
-
- org.apache.activemq.artemis.core.protocol.core.impl.ChannelImpl
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classChannelImpl.CHANNEL_ID
-
Constructor Summary
Constructors Constructor Description ChannelImpl(CoreRemotingConnection connection, long id, int confWindowSize, List<Interceptor> interceptors)
-
Method Summary
All Methods Static Methods Instance Methods Concrete 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 toflushConnectiononChannel.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.protected ResponseCachegetCache()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.voidhandleAsyncResponse(Packet packet)voidhandlePacket(Packet packet)Called byCoreRemotingConnectionwhen a packet is received.static StringinvokeInterceptors(Packet packet, List<Interceptor> interceptors, RemotingConnection connection)booleanisLocked()queries if this channel is locked.voidlock()locks the channel.voidreplayCommands(int otherLastConfirmedCommandID)resends any packets that have not received confirmations yet.voidreturnBlocking()forces anyChannel.sendBlocking(Packet, byte)request to return with an exception.voidreturnBlocking(Throwable cause)forces anyChannel.sendBlocking(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)Due to networking issues or server issues the server may take longer to answer than expected..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 responseHandler)voidsetTransferring(boolean transferring)notifies the channel if it is transferring its connection.booleansupports(byte packetType)For protocol checkbooleansupports(byte packetType, int version)For protocol checkStringtoString()voidtransferConnection(CoreRemotingConnection newConnection)Transfers the connection used by this channel to the one specified.voidunlock()unlocks the channel.
-
-
-
Constructor Detail
-
ChannelImpl
public ChannelImpl(CoreRemotingConnection connection, long id, int confWindowSize, List<Interceptor> interceptors)
-
-
Method Detail
-
getReconnectID
public int getReconnectID()
Description copied from interface:ChannelThis 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:
getReconnectIDin interfaceChannel- Returns:
-
supports
public boolean supports(byte packetType)
Description copied from interface:ChannelFor protocol check
-
supports
public boolean supports(byte packetType, int version)Description copied from interface:ChannelFor protocol check
-
getID
public long getID()
Description copied from interface:ChannelReturns the id of this channel.
-
getLastConfirmedCommandID
public int getLastConfirmedCommandID()
Description copied from interface:Channelreturns the last confirmed packet command id- Specified by:
getLastConfirmedCommandIDin interfaceChannel- Returns:
- the id
-
getConfirmationWindowSize
public int getConfirmationWindowSize()
Description copied from interface:Channelreturns the confirmation window size this channel is using.- Specified by:
getConfirmationWindowSizein interfaceChannel- Returns:
- the window size
-
returnBlocking
public void returnBlocking()
Description copied from interface:Channelforces anyChannel.sendBlocking(Packet, byte)request to return with an exception.- Specified by:
returnBlockingin interfaceChannel
-
returnBlocking
public void returnBlocking(Throwable cause)
Description copied from interface:Channelforces anyChannel.sendBlocking(Packet, byte)request to return with an exception.- Specified by:
returnBlockingin interfaceChannel
-
flushConnection
public void flushConnection()
Description copied from interface:ChannelSimilarly toflushConnectiononChannel.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:
flushConnectionin interfaceChannel
-
send
public boolean send(Packet packet, boolean flushConnection)
Description copied from interface:ChannelSends a packet on this channel, but request it to be flushed (along with the un-flushed previous ones) only iffflushConnectionistrue.- Specified by:
sendin interfaceChannel- 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
public boolean sendAndFlush(Packet packet)
Description copied from interface:ChannelSends a packet on this channel and then blocks until it has been written to the connection.- Specified by:
sendAndFlushin interfaceChannel- 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:ChannelSends a packet on this channel.
-
send
public boolean send(Packet packet, int reconnectID)
Description copied from interface:ChannelSends a packet on this channel.
-
sendBatched
public boolean sendBatched(Packet packet)
Description copied from interface:ChannelSends a packet on this channel using batching algorithm if appropriate- Specified by:
sendBatchedin interfaceChannel- 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:Channelnotifies the channel if it is transferring its connection. When true it is illegal to send messages.- Specified by:
setTransferringin interfaceChannel- 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:ChannelSends a packet on this channel and then blocks until a response is received or a timeout occurs.- Specified by:
sendBlockingin interfaceChannel- Parameters:
packet- the packet to sendexpectedPacket- 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:
sendBlockingin interfaceChannel- Parameters:
packet- the packet to sendexpectedPacket- 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
falseornullif no interceptors returnedfalse.
-
setCommandConfirmationHandler
public void setCommandConfirmationHandler(CommandConfirmationHandler handler)
Description copied from interface:Channelsets the handler to use when a confirmation is received.- Specified by:
setCommandConfirmationHandlerin interfaceChannel- Parameters:
handler- the handler to call
-
setResponseHandler
public void setResponseHandler(ResponseHandler responseHandler)
- Specified by:
setResponseHandlerin interfaceChannel
-
setHandler
public void setHandler(ChannelHandler handler)
Description copied from interface:ChannelSets theChannelHandlerthat this channel should forward received packets to.- Specified by:
setHandlerin interfaceChannel- Parameters:
handler- the handler
-
getHandler
public ChannelHandler getHandler()
Description copied from interface:ChannelGets theChannelHandlerthat this channel should forward received packets to.- Specified by:
getHandlerin interfaceChannel- Returns:
- the current channel handler
-
endOfBatch
public void endOfBatch()
- Specified by:
endOfBatchin interfaceChannel
-
close
public void close()
Description copied from interface:ChannelCloses this channel.once closed no packets can be sent.
-
transferConnection
public void transferConnection(CoreRemotingConnection newConnection)
Description copied from interface:ChannelTransfers the connection used by this channel to the one specified.All new packets will be sent via this connection.
- Specified by:
transferConnectionin interfaceChannel- Parameters:
newConnection- the new connection
-
replayCommands
public void replayCommands(int otherLastConfirmedCommandID)
Description copied from interface:Channelresends any packets that have not received confirmations yet.Typically called after a connection has been transferred.
- Specified by:
replayCommandsin interfaceChannel- Parameters:
otherLastConfirmedCommandID- the last confirmed packet
-
isLocked
public boolean isLocked()
Description copied from interface:Channelqueries if this channel is locked. This method is designed for use in monitoring of the system state, not for synchronization control.
-
lock
public void lock()
Description copied from interface:Channellocks the channel.While locked no packets can be sent or received
-
unlock
public void unlock()
Description copied from interface:Channelunlocks the channel.
-
getConnection
public CoreRemotingConnection getConnection()
Description copied from interface:Channelreturns theCoreRemotingConnectionbeing used by the channel- Specified by:
getConnectionin interfaceChannel
-
flushConfirmations
public void flushConfirmations()
Description copied from interface:Channelflushes any confirmations on to the connection.- Specified by:
flushConfirmationsin interfaceChannel
-
handleAsyncResponse
public void handleAsyncResponse(Packet packet)
-
confirm
public void confirm(Packet packet)
Description copied from interface:Channelsends a confirmation of a packet being received.
-
clearCommands
public void clearCommands()
Description copied from interface:Channelclears any commands from the cache that are yet to be confirmed.- Specified by:
clearCommandsin interfaceChannel
-
handlePacket
public void handlePacket(Packet packet)
Description copied from interface:ChannelCalled byCoreRemotingConnectionwhen a packet is received.This method should then call its
ChannelHandlerafter appropriate processing of the packet- Specified by:
handlePacketin interfaceChannel- Parameters:
packet- the packet to process.
-
-