Package com.rabbitmq.client.impl
Class ChannelManager
- java.lang.Object
-
- com.rabbitmq.client.impl.ChannelManager
-
- Direct Known Subclasses:
RecoveryAwareChannelManager
public class ChannelManager extends java.lang.Object
Manages a set of channels, indexed by channel number (1.._channelMax
).
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.Integer,ChannelN>
_channelMap
Mapping from1.._channelMax
toChannelN
instanceprivate int
_channelMax
Maximum channel number available on this connection.private IntAllocator
channelNumberAllocator
private int
channelShutdownTimeout
private static org.slf4j.Logger
LOGGER
protected MetricsCollector
metricsCollector
private java.lang.Object
monitor
Monitor for_channelMap
andchannelNumberAllocator
protected ObservationCollector
observationCollector
private java.util.concurrent.ExecutorService
shutdownExecutor
private java.util.Set<java.util.concurrent.CountDownLatch>
shutdownSet
private java.util.concurrent.ThreadFactory
threadFactory
private ConsumerWorkService
workService
-
Constructor Summary
Constructors Constructor Description ChannelManager(ConsumerWorkService workService, int channelMax)
ChannelManager(ConsumerWorkService workService, int channelMax, java.util.concurrent.ThreadFactory threadFactory)
ChannelManager(ConsumerWorkService workService, int channelMax, java.util.concurrent.ThreadFactory threadFactory, MetricsCollector metricsCollector, ObservationCollector observationCollector)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private ChannelN
addNewChannel(AMQConnection connection, int channelNumber)
ChannelN
createChannel(AMQConnection connection)
ChannelN
createChannel(AMQConnection connection, int channelNumber)
ChannelN
getChannel(int channelNumber)
Looks up a channel on this connection.int
getChannelMax()
java.util.concurrent.ExecutorService
getShutdownExecutor()
void
handleSignal(ShutdownSignalException signal)
Handle shutdown.protected ChannelN
instantiateChannel(AMQConnection connection, int channelNumber, ConsumerWorkService workService)
void
releaseChannelNumber(ChannelN channel)
Remove the channel from the channel map and free the number for re-use.private void
scheduleShutdownProcessing()
void
setChannelShutdownTimeout(int channelShutdownTimeout)
Set the shutdown timeout for channels.void
setShutdownExecutor(java.util.concurrent.ExecutorService shutdownExecutor)
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
monitor
private final java.lang.Object monitor
Monitor for_channelMap
andchannelNumberAllocator
-
_channelMap
private final java.util.Map<java.lang.Integer,ChannelN> _channelMap
Mapping from1.._channelMax
toChannelN
instance
-
channelNumberAllocator
private final IntAllocator channelNumberAllocator
-
workService
private final ConsumerWorkService workService
-
shutdownSet
private final java.util.Set<java.util.concurrent.CountDownLatch> shutdownSet
-
_channelMax
private final int _channelMax
Maximum channel number available on this connection.
-
shutdownExecutor
private java.util.concurrent.ExecutorService shutdownExecutor
-
threadFactory
private final java.util.concurrent.ThreadFactory threadFactory
-
channelShutdownTimeout
private int channelShutdownTimeout
-
metricsCollector
protected final MetricsCollector metricsCollector
-
observationCollector
protected final ObservationCollector observationCollector
-
-
Constructor Detail
-
ChannelManager
public ChannelManager(ConsumerWorkService workService, int channelMax)
-
ChannelManager
public ChannelManager(ConsumerWorkService workService, int channelMax, java.util.concurrent.ThreadFactory threadFactory)
-
ChannelManager
public ChannelManager(ConsumerWorkService workService, int channelMax, java.util.concurrent.ThreadFactory threadFactory, MetricsCollector metricsCollector, ObservationCollector observationCollector)
-
-
Method Detail
-
getChannelMax
public int getChannelMax()
-
getChannel
public ChannelN getChannel(int channelNumber)
Looks up a channel on this connection.- Parameters:
channelNumber
- the number of the required channel- Returns:
- the channel on this connection with number
channelNumber
- Throws:
UnknownChannelException
- if there is no channel with numberchannelNumber
on this connection
-
handleSignal
public void handleSignal(ShutdownSignalException signal)
Handle shutdown. All the managedChannel
s are shutdown.- Parameters:
signal
- reason for shutdown
-
scheduleShutdownProcessing
private void scheduleShutdownProcessing()
-
createChannel
public ChannelN createChannel(AMQConnection connection) throws java.io.IOException
- Throws:
java.io.IOException
-
createChannel
public ChannelN createChannel(AMQConnection connection, int channelNumber) throws java.io.IOException
- Throws:
java.io.IOException
-
addNewChannel
private ChannelN addNewChannel(AMQConnection connection, int channelNumber)
-
instantiateChannel
protected ChannelN instantiateChannel(AMQConnection connection, int channelNumber, ConsumerWorkService workService)
-
releaseChannelNumber
public void releaseChannelNumber(ChannelN channel)
Remove the channel from the channel map and free the number for re-use. This method must be safe to call multiple times on the same channel. If it is not then things go badly wrong.
-
getShutdownExecutor
public java.util.concurrent.ExecutorService getShutdownExecutor()
-
setShutdownExecutor
public void setShutdownExecutor(java.util.concurrent.ExecutorService shutdownExecutor)
-
setChannelShutdownTimeout
public void setChannelShutdownTimeout(int channelShutdownTimeout)
Set the shutdown timeout for channels. This is the amount of time the manager waits for a channel to shutdown before giving up. Works only when theshutdownExecutor
property is set. Default toConnectionFactory.DEFAULT_HEARTBEAT
+ 5 % seconds- Parameters:
channelShutdownTimeout
- shutdown timeout in milliseconds
-
-