public void SetFactory(IKeyedPoolableObjectFactory <K, V> factory) { var oldFactory = this.factory; var idleObjs = new Dictionary <K, List <V> >(); lock (this) { AssertOpen(); if (GetActiveCount() > 0) { throw new InvalidOperationException("Cannot change factory with active object in the pool."); } else { foreach (var key in idle.Keys) { idleObjs.Add(key, new List <V>()); idleObjs[key].AddRange(idle[key]); idle[key].Clear(); } idle.Clear(); } this.factory = factory; } foreach (var entry in idleObjs) { foreach (var obj in entry.Value) { oldFactory.Destroy(entry.Key, obj); } } }
public IKeyedObjectPool <Endpoint, ICassandraClient> Create(IKeyedPoolableObjectFactory <Endpoint, ICassandraClient> factory) { if (pool == null) { pool = new KeyedObjectPool <Endpoint, ICassandraClient>(null, new KeyedObjectPool <Endpoint, ICassandraClient> .Configuration { MaxSize = 25, MinSize = 4, Timeout = 20 }); pool.SetFactory(factory); } return(pool); }
public KeyedObjectPool(IKeyedPoolableObjectFactory <K, V> factory, KeyedObjectPool <K, V> .Configuration config) { IsClosed = false; this.factory = factory; if (config != null) { MinSize = config.MinSize; MaxSize = config.MaxSize; Timeout = config.Timeout; } if (MinSize > MaxSize) { MinSize = MaxSize; } // populate the idle pool to the minimum size reset.Set(); }