/// <summary> /// CheckoutConnection handles the process of pulling a driver /// from the idle pool, possibly resetting its state, /// and adding it to the in use pool. We assume that this method is only /// called inside an active lock so there is no need to acquire a new lock. /// </summary> /// <returns>An idle driver object</returns> /// <summary> /// It is assumed that this method is only called from inside an active lock. /// </summary> private Driver GetPooledConnection() { // check if an idle connection exists // if yes, take it // if not, create one and add it to the "inuse" connection list Driver d = null; lock (lockObject) { if (idlePool.Count > 0) { d = (Driver)idlePool.Dequeue(); } } if (d == null) { d = Driver.Create(settings); d.Pool = this; } else { if (settings.ConnectionReset) { d.Reset(); } } lock (lockObject) { inUsePool.Add(d); } return(d); }
/* private int CheckConnections() * { * int freed = 0; * lock (inUsePool.SyncRoot) * { * for (int i=inUsePool.Count-1; i >= 0; i--) * { * Driver d = (inUsePool[i] as Driver); * if (! d.Ping()) * { * inUsePool.RemoveAt(i); * freed++; * } * } * } * return freed; * } */ private Driver CheckoutConnection() { lock (idlePool.SyncRoot) { if (idlePool.Count == 0) { return(null); } Driver driver = (Driver)idlePool.Dequeue(); // if the user asks us to ping/reset pooled connections // do so now if (settings.ResetPooledConnections) { if (!driver.Ping()) { driver.Close(); return(null); } driver.Reset(); } lock (inUsePool.SyncRoot) { inUsePool.Add(driver); } return(driver); } }
/// <summary> /// It is assumed that this method is only called from inside an active lock. /// </summary> private Driver GetPooledConnection() { Driver driver = null; // if we don't have an idle connection but we have room for a new // one, then create it here. lock ((idlePool as ICollection).SyncRoot) { if (HasIdleConnections) { driver = idlePool.Dequeue(); } } // Obey the connection timeout if (driver != null) { try { driver.ResetTimeout((int)Settings.ConnectionTimeout * 1000); } catch (Exception) { driver.Close(); driver = null; } } if (driver != null) { // first check to see that the server is still alive if (!driver.Ping()) { driver.Close(); driver = null; } else if (settings.ConnectionReset) { // if the user asks us to ping/reset pooled connections // do so now driver.Reset(); } } if (driver == null) { driver = CreateNewPooledConnection(); } Debug.Assert(driver != null); lock ((inUsePool as ICollection).SyncRoot) { inUsePool.Add(driver); int currentlyInUse = inUsePool.Count; if (currentlyInUse > maxUsedConnections) { maxUsedConnections = currentlyInUse; } } return(driver); }
private Driver GetPooledConnection() { Driver driver = null; lock (((ICollection)this.idlePool).SyncRoot) { if (this.HasIdleConnections) { driver = this.idlePool.Dequeue(); } } if (driver != null) { try { driver.ResetTimeout((int)(this.Settings.ConnectionTimeout * 1000u)); } catch (Exception) { driver.Close(); driver = null; } } if (driver != null) { if (!driver.Ping()) { driver.Close(); driver = null; } else { if (this.settings.ConnectionReset) { driver.Reset(); } } } if (driver == null) { driver = this.CreateNewPooledConnection(); } lock (((ICollection)this.inUsePool).SyncRoot) { this.inUsePool.Add(driver); } return(driver); }
private Driver CheckoutConnection() { Driver driver = (Driver)this.idlePool.Dequeue(); if (!driver.Ping()) { driver.Close(); return(null); } if (this.settings.ResetPooledConnections) { driver.Reset(); } this.inUsePool.Add(driver); return(driver); }
/// <summary> /// CheckoutConnection handles the process of pulling a driver /// from the idle pool, possibly resetting its state, /// and adding it to the in use pool. We assume that this method is only /// called inside an active lock so there is no need to acquire a new lock. /// </summary> /// <returns>An idle driver object</returns> private Driver CheckoutConnection() { Driver driver = (Driver)idlePool.Dequeue(); // first check to see that the server is still alive if (!driver.Ping()) { driver.Close(); driver = CreateNewPooledConnection(); } // if the user asks us to ping/reset pooled connections // do so now if (settings.ConnectionReset) { driver.Reset(); } return(driver); }
/// <summary> /// It is assumed that this method is only called from inside an active lock. /// </summary> private Driver GetPooledConnection() { Driver driver = null; // if we don't have an idle connection but we have room for a new // one, then create it here. lock ((idlePool as ICollection).SyncRoot) { if (HasIdleConnections) { driver = (Driver)idlePool.Dequeue(); } } if (driver != null) { // first check to see that the server is still alive if (!driver.Ping()) { driver.Close(); driver = null; } else if (settings.ConnectionReset) { // if the user asks us to ping/reset pooled connections // do so now driver.Reset(); } } if (driver == null) { driver = CreateNewPooledConnection(); } Debug.Assert(driver != null); lock ((inUsePool as ICollection).SyncRoot) { inUsePool.Add(driver); } return(driver); }