public IModel GetChannel(ConnectionPooling pool, PoolingSettings settings, CancellationToken token = default(CancellationToken)) { var random = new Random(); int rIndex = random.Next(pool.TotalCount); int index = rIndex; IModel channel; do { var connection = pool.Get(index); if (connection.TryGetChannel(out channel)) { return(channel); } index++; } while (index < pool.TotalCount); for (var i = 0; i < rIndex; i++) { var connection = pool.Get(i); if (connection.TryGetChannel(out channel)) { return(channel); } } if (pool.TotalCount < settings.MaxConnections) { ChannelPooling channels; if (pool.TryCreate(out channels)) { return(channels.GetChannel(token)); } } return(pool.Get(rIndex).GetChannel(token)); }
public ChannelPool(IConnectionFactory factory, PoolingSettings settings, IChannelTakingStrategy takingStrategy = null) { this.factory = factory; this.settings = settings; this.strategy = takingStrategy ?? new RandomChannelTakingStrategy(); this.pooling = new ConnectionPooling(factory, settings); }
public ChannelPooling(IConnection connection, PoolingSettings settings) { this.currentConnection = connection; this.settings = settings; this.channelsQueue = new BlockingCollection <IModel>(new ConcurrentBag <IModel>(), Math.Max(1, settings.MaxChannelPerConnection)); channels = new List <IModel>(Math.Max(1, settings.MaxChannelPerConnection)); }
public ConnectionPooling(IConnectionFactory factory, PoolingSettings settings) { this.factory = factory; this.settings = settings; this.connections = new ChannelPooling[Math.Max(1, settings.MinConnections)]; for (int i = 0; i < connections.Length; i++) { connections[i] = new ChannelPooling(factory.CreateConnection(), settings); } totalCount = connections.Length; }