public void BeginBind(SmppBindResHandler Callback, object State) { if ((_InternalConnection != null) && _InternalConnection.Connected) { throw new SmppException("Error Connecting: The connection is already Open."); } switch (_Settings.Recycling.Method) { case SmppSettings.RecyclingMethod.Pooling: _InternalConnection = SmppPoolManager.GetConnection(_Settings); break; case SmppSettings.RecyclingMethod.Sharing: _InternalConnection = SmppShareManager.GetConnection(_Settings); break; default: _InternalConnection = new SmppInternalConnection(_Settings); break; } SetEvents(); if ((_InternalConnection.Connected && (_InternalConnection.LastBindRes != null)) && ((_InternalConnection.LastBindRes.Header != null) && (_InternalConnection.LastBindRes.Header.CommandStatus == 0))) { Callback(this, new SmppAsyncBindResEventArgs(_InternalConnection.LastBindRes)); } else { _InternalConnection.BeginBind(Callback, State); } }
SmppInternalConnection GetPooledConnection() { SmppInternalConnection connection = null; lock (idlePool.SyncRoot) { lock (inUsePool.SyncRoot) { if ((idlePool.Count == 0) && (inUsePool.Count == _Settings.Recycling.MaxSize)) { return(null); } if (idlePool.Count > 0) { int index = idlePool.Count - 1; while (index >= 0) { connection = idlePool[index] as SmppInternalConnection; inUsePool.Add(connection); idlePool.RemoveAt(index); return(connection); } return(connection); } connection = new SmppInternalConnection(_Settings); inUsePool.Add(connection); return(connection); } } return(connection); }
public SmppBindRes Bind() { if ((_InternalConnection != null) && _InternalConnection.Connected) { throw new SmppException("Error Connecting: The connection is already Open."); } switch (_Settings.Recycling.Method) { case SmppSettings.RecyclingMethod.Pooling: _InternalConnection = SmppPoolManager.GetConnection(_Settings); break; case SmppSettings.RecyclingMethod.Sharing: _InternalConnection = SmppShareManager.GetConnection(_Settings); break; default: _InternalConnection = new SmppInternalConnection(_Settings); break; } SetEvents(); SmppBindRes res = null; if ((_InternalConnection.Connected && (_InternalConnection.LastBindRes != null)) && ((_InternalConnection.LastBindRes.Header != null) && (_InternalConnection.LastBindRes.Header.CommandStatus == 0))) { return(_InternalConnection.LastBindRes); } res = _InternalConnection.Bind(); _InternalConnection.LastBindRes = res; return(res); }
public SmppShare(SmppSettings Settings) { this.Settings = Settings; availablePool = new SmppInternalConnection[Settings.Recycling.MaxSize]; for (int i = 0; i < availablePool.Length; i++) availablePool[i] = new SmppInternalConnection(Settings); tmCheckIdleConn.AutoReset = false; tmCheckIdleConn.Enabled = true; tmCheckIdleConn.Elapsed += tmCheckIdleConn_Elapsed; }
internal static void ReleaseConnection(SmppInternalConnection connection) { SmppPool pool = null; lock (Pools.SyncRoot) { string connectionString = connection.Settings.ConnectionString; pool = (SmppPool) Pools[connectionString]; if (pool == null) throw new SmppException("Pooling exception: Unable to find original pool for connection"); } pool.ReleaseConnection(connection); }
public void ReleaseConnection(SmppInternalConnection connection) { if (connection != null) lock (idlePool.SyncRoot) { lock (inUsePool.SyncRoot) { connection.ReleasedDateTime = DateTime.Now; inUsePool.Remove(connection); idlePool.Add(connection); } } }
public SmppShare(SmppSettings Settings) { this.Settings = Settings; availablePool = new SmppInternalConnection[Settings.Recycling.MaxSize]; for (int i = 0; i < availablePool.Length; i++) { availablePool[i] = new SmppInternalConnection(Settings); } tmCheckIdleConn.AutoReset = false; tmCheckIdleConn.Enabled = true; tmCheckIdleConn.Elapsed += tmCheckIdleConn_Elapsed; }
public void ReleaseConnection(SmppInternalConnection connection) { if (connection != null) { lock (idlePool.SyncRoot) { lock (inUsePool.SyncRoot) { connection.ReleasedDateTime = DateTime.Now; inUsePool.Remove(connection); idlePool.Add(connection); } } } }
internal static void ReleaseConnection(SmppInternalConnection connection) { SmppPool pool = null; lock (Pools.SyncRoot) { string connectionString = connection.Settings.ConnectionString; pool = (SmppPool)Pools[connectionString]; if (pool == null) { throw new SmppException("Pooling exception: Unable to find original pool for connection"); } } pool.ReleaseConnection(connection); }
public SmppPool(SmppSettings Settings) { _Settings = Settings; inUsePool = new ArrayList(); idlePool = new ArrayList(Settings.Recycling.MinSize); lock (idlePool.SyncRoot) { lock (inUsePool.SyncRoot) { for (int i = 0; i < Settings.Recycling.MinSize; i++) { var connection = new SmppInternalConnection(Settings); idlePool.Add(connection); } } } tmCheckIdleConn.AutoReset = false; tmCheckIdleConn.Enabled = true; tmCheckIdleConn.Elapsed += tmCheckIdleConn_Elapsed; }
public SmppInternalConnection GetConnection() { SmppInternalConnection pooledConnection = null; int tickCount = Environment.TickCount; int timeout = _Settings.Timeout; while ((pooledConnection == null) && ((Environment.TickCount - tickCount) < timeout)) { pooledConnection = GetPooledConnection(); if (pooledConnection == null) { Thread.Sleep(new TimeSpan(0x2710L)); } } if (pooledConnection == null) { throw new Exception( "error connecting: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached."); } return(pooledConnection); }
SmppInternalConnection GetPooledConnection() { SmppInternalConnection connection = null; lock (idlePool.SyncRoot) { lock (inUsePool.SyncRoot) { if ((idlePool.Count == 0) && (inUsePool.Count == _Settings.Recycling.MaxSize)) return null; if (idlePool.Count > 0) { int index = idlePool.Count - 1; while (index >= 0) { connection = idlePool[index] as SmppInternalConnection; inUsePool.Add(connection); idlePool.RemoveAt(index); return connection; } return connection; } connection = new SmppInternalConnection(_Settings); inUsePool.Add(connection); return connection; } } return connection; }
public void BeginBind(SmppBindResHandler Callback, object State) { if ((_InternalConnection != null) && _InternalConnection.Connected) throw new SmppException("Error Connecting: The connection is already Open."); switch (_Settings.Recycling.Method) { case SmppSettings.RecyclingMethod.Pooling: _InternalConnection = SmppPoolManager.GetConnection(_Settings); break; case SmppSettings.RecyclingMethod.Sharing: _InternalConnection = SmppShareManager.GetConnection(_Settings); break; default: _InternalConnection = new SmppInternalConnection(_Settings); break; } SetEvents(); if ((_InternalConnection.Connected && (_InternalConnection.LastBindRes != null)) && ((_InternalConnection.LastBindRes.Header != null) && (_InternalConnection.LastBindRes.Header.CommandStatus == 0))) Callback(this, new SmppAsyncBindResEventArgs(_InternalConnection.LastBindRes)); else _InternalConnection.BeginBind(Callback, State); }
public SmppBindRes Bind() { if ((_InternalConnection != null) && _InternalConnection.Connected) throw new SmppException("Error Connecting: The connection is already Open."); switch (_Settings.Recycling.Method) { case SmppSettings.RecyclingMethod.Pooling: _InternalConnection = SmppPoolManager.GetConnection(_Settings); break; case SmppSettings.RecyclingMethod.Sharing: _InternalConnection = SmppShareManager.GetConnection(_Settings); break; default: _InternalConnection = new SmppInternalConnection(_Settings); break; } SetEvents(); SmppBindRes res = null; if ((_InternalConnection.Connected && (_InternalConnection.LastBindRes != null)) && ((_InternalConnection.LastBindRes.Header != null) && (_InternalConnection.LastBindRes.Header.CommandStatus == 0))) return _InternalConnection.LastBindRes; res = _InternalConnection.Bind(); _InternalConnection.LastBindRes = res; return res; }
void CheckOutConnection(SmppInternalConnection conn) { }
void CheckOutConnection(SmppInternalConnection conn) {}