跳到主要内容

三、RabbitMQ-客户端源码之ChannelManager

关于ChannelManager,官方注解:Manages a set of channels, indexed by channel number (1… _channelMax)。

ChannelManager类的代码量不是很多,主要用来管理Channel的,channelNumber=0的除外,应为channelNumber=0是留给Connection的特殊的channelNumber。

下面是ChannelManager的成员变量:

/** Monitor for _channelMap and channelNumberAllocator */
private final Object monitor = new Object();
/** Mapping from 1.._channelMax to {@link ChannelN} instance */
private final Map



_channelMap = new HashMap



();
private final IntAllocator channelNumberAllocator;
private final ConsumerWorkService workService;
private final Set



shutdownSet = new HashSet



();
/** Maximum channel number available on this connection. */
private final int _channelMax;
private final ThreadFactory threadFactory;

这上面的成员变量下面会有涉及。


对于ChannelManager的使用,是AMQConnection中的成员变量:

/** Object that manages a set of channels */
private volatile ChannelManager _channelManager;