private DisposableBeanstalkdClientLabel GetProducer(string tube) { lock (_pool) { BeanstalkdClientLabel client = null; if (_pool.Count == 0) { client = new BeanstalkdClientLabel { Client = ManagedBeanstalkdClientFactory.Create(_host, _port), CurrentTube = "default", WatchList = new List <string> { "default" } }; } else { var it = _pool.First; while (true) { if (it == null) { break; } if (it.Value.CurrentTube == tube) { client = it.Value; break; } if (it == _pool.Last) { break; } it = it.Next; } if (client == null) { client = _pool.First.Value; } _pool.Remove(client); } client.CurrentTube = client.Client.Use(tube); if (client.CurrentTube != tube) { client.Client.Dispose(); throw new BeanstalkdException(BeanstalkdExceptionCode.UnexpectedResponse); } return(new DisposableBeanstalkdClientLabel(client, _pool)); } }
private DisposableBeanstalkdClientLabel GetBeanstalkdClient() { lock (_pool) { BeanstalkdClientLabel client; if (_pool.Count == 0) { client = new BeanstalkdClientLabel { Client = ManagedBeanstalkdClientFactory.Create(_host, _port), CurrentTube = "default", WatchList = new List <string> { "default" } }; } else { client = _pool.First.Value; _pool.RemoveFirst(); } return(new DisposableBeanstalkdClientLabel(client, _pool)); } }
private DisposableBeanstalkdClientLabel GetConcumer(IList <string> watchList) { lock (_pool) { BeanstalkdClientLabel client = null; if (_pool.Count == 0) { client = new BeanstalkdClientLabel { Client = ManagedBeanstalkdClientFactory.Create(_host, _port), CurrentTube = "default", WatchList = new List <string> { "default" } }; } else { var it = _pool.First; while (true) { if (it == null) { break; } if (AreWatchListsEqual(watchList, it.Value.WatchList)) { client = it.Value; break; } if (it == _pool.Last) { break; } it = it.Next; } if (client == null) { client = _pool.First.Value; } _pool.Remove(client); } if (!AreWatchListsEqual(client.WatchList, WatchList)) { WatchList.ForEach(tube => { if (!client.WatchList.Contains(tube)) { client.Client.Watch(tube); } }); client.WatchList.ForEach(tube => { if (!WatchList.Contains(tube)) { client.Client.Ignore(tube); } }); client.WatchList = WatchList; } return(new DisposableBeanstalkdClientLabel(client, _pool)); } }