Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 5
0
 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);
 }
Ejemplo n.º 6
0
 public void ReleaseConnection(SmppInternalConnection connection) {
   if (connection != null)
     lock (idlePool.SyncRoot) {
       lock (inUsePool.SyncRoot) {
         connection.ReleasedDateTime = DateTime.Now;
         inUsePool.Remove(connection);
         idlePool.Add(connection);
       }
     }
 }
Ejemplo n.º 7
0
 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;
 }
Ejemplo n.º 8
0
 public void ReleaseConnection(SmppInternalConnection connection)
 {
     if (connection != null)
     {
         lock (idlePool.SyncRoot) {
             lock (inUsePool.SyncRoot) {
                 connection.ReleasedDateTime = DateTime.Now;
                 inUsePool.Remove(connection);
                 idlePool.Add(connection);
             }
         }
     }
 }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
 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;
 }
Ejemplo n.º 11
0
 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;
 }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
 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;
 }
Ejemplo n.º 14
0
    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);
    }
Ejemplo n.º 15
0
    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;
    }
Ejemplo n.º 16
0
 void CheckOutConnection(SmppInternalConnection conn)
 {
 }
Ejemplo n.º 17
0
 void CheckOutConnection(SmppInternalConnection conn) {}