Пример #1
0
 /// <summary>
 /// Get a ConnectionsPoolsSource given a SiteTable using the factory's default pool source
 /// </summary>
 /// <param name="sources">SiteTable</param>
 /// <returns>ConnectionPoolsSource</returns>
 public override object getPoolSources(object sources)
 {
     if (!(sources is SiteTable))
     {
         throw new ArgumentException("Invalid source. Must supply a SiteTable");
     }
     SiteTable siteTable = (SiteTable)sources;
     Site[] sites = new Site[siteTable.Sites.Count];
     for (int i = 0; i < siteTable.Sites.Count; i++)
     {
         sites[i] = (Site)siteTable.Sites.GetByIndex(i);
     }
     ConnectionPoolsSource result = new ConnectionPoolsSource();
     result.CxnSources = new Dictionary<string, ConnectionPoolSource>();
     foreach (Site site in sites)
     {
         if (site.Sources == null || site.Sources.Length == 0)
         {
             continue;
         }
         for (int i = 0; i < site.Sources.Length; i++)
         {
             if (String.Equals(site.Sources[i].Protocol, "VISTA", StringComparison.CurrentCultureIgnoreCase)
                 || String.Equals(site.Sources[i].Protocol, "PVISTA", StringComparison.CurrentCultureIgnoreCase))
             {
                 result.CxnSources.Add(site.Id, (ConnectionPoolSource)getPoolSource(site.Sources[i]));
                 break;
             }
         }
     }
     return result;
 }
        /// <summary>
        /// Get a ConnectionsPoolsSource given a SiteTable using the factory's default pool source
        /// </summary>
        /// <param name="sources">SiteTable</param>
        /// <returns>ConnectionPoolsSource</returns>
        public override object getPoolSources(object sources)
        {
            if (!(sources is SiteTable))
            {
                throw new ArgumentException("Invalid source. Must supply a SiteTable");
            }
            SiteTable siteTable = (SiteTable)sources;

            Site[] sites = new Site[siteTable.Sites.Count];
            for (int i = 0; i < siteTable.Sites.Count; i++)
            {
                sites[i] = (Site)siteTable.Sites.GetByIndex(i);
            }
            ConnectionPoolsSource result = new ConnectionPoolsSource();

            result.CxnSources = new Dictionary <string, ConnectionPoolSource>();
            foreach (Site site in sites)
            {
                if (site.Sources == null || site.Sources.Length == 0)
                {
                    continue;
                }
                for (int i = 0; i < site.Sources.Length; i++)
                {
                    if (String.Equals(site.Sources[i].Protocol, "VISTA", StringComparison.CurrentCultureIgnoreCase) ||
                        String.Equals(site.Sources[i].Protocol, "PVISTA", StringComparison.CurrentCultureIgnoreCase))
                    {
                        result.CxnSources.Add(site.Id, (ConnectionPoolSource)getPoolSource(site.Sources[i]));
                        break;
                    }
                }
            }
            return(result);
        }
Пример #3
0
        /// <summary>
        /// Start the connection pool. This method is rather slow when run in production (130+ sites). A connection pool is started for
        /// each of the sources. A loop is used to start each pool. Each new pool start waits for the previous pool to come to a reasonable
        /// state before starting. If the previous pool hasn't finished starting after 60 seconds, the current pool will go ahead
        /// and start anyways.
        /// </summary>
        /// <param name="source">The source for all the connection pool configuration information</param>
        void startUp(ConnectionPoolsSource source)
        {
            // first things first - initialize the pool collection based off the connection sources!
            _pools = new Dictionary <string, ConnectionPool>();
            foreach (string siteId in source.CxnSources.Keys)
            {
                _pools.Add(siteId, null);
            }

            if (source.LoadStrategy == LoadingStrategy.Lazy)
            {
                return; // lazy loading? we're all done with startup!
            }

            // the rest of this code starts the pool for each of the connection sources
            string[] allKeys = new string[source.CxnSources.Count];
            source.CxnSources.Keys.CopyTo(allKeys, 0);
            IList <ConnectionPool> allPools = new List <ConnectionPool>(allKeys.Length);

            for (int i = 0; i < allKeys.Length; i++)
            {
                DateTime lastPoolStart = DateTime.Now;

                // starting 130+ connection pool threads takes a lot of system resources - we should try and let the
                // previous pool come up or at least give it a reasonable time to start before moving to the next connection pool
                if (i > 0)
                {
                    while (lastPoolStart.Subtract(DateTime.Now).TotalSeconds < 60 &&
                           allPools[i - 1].TotalResources < allPools[i - 1].PoolSource.MinPoolSize)
                    {
                        System.Threading.Thread.Sleep(500);
                    }
                }

                // go ahead and start the pool now
                startPool(allKeys[i], source.CxnSources[allKeys[i]]);
                allPools.Add(_pools[allKeys[i]]);
                //ConnectionPool cxnPool = (ConnectionPool)ConnectionPoolFactory.getResourcePool(source.CxnSources[allKeys[i]]);
                //allPools.Add(cxnPool);
                //_pools[allKeys[i]] = cxnPool;
            }
        }
Пример #4
0
        internal void run()
        {
            // never let two processes call run!!!
            lock (_locker)
            {
                ConnectionPoolsSource poolSource = (ConnectionPoolsSource)this.PoolSource; // just cast this once
                // startup
                _starting = true;
                startUp(poolSource);
                _starting = false;

                while (!Convert.ToBoolean(SHUTDOWN_FLAG))
                {
                    System.Threading.Thread.Sleep(1000);
                    // babysit pools
                    foreach (string siteId in poolSource.CxnSources.Keys)
                    {
                        if (_pools[siteId] == null)                                   // if pool hasn't been instantiated
                        {
                            if (this.PoolSource.LoadStrategy == LoadingStrategy.Lazy) // and loading lazily then just continue
                            {
                                continue;
                            }
                            else if (this.PoolSource.LoadStrategy == LoadingStrategy.Eager) // and loading eagerly then instantiate pool
                            {
                                _pools[siteId] = (ConnectionPool)ConnectionPoolFactory.getResourcePool(poolSource.CxnSources[siteId]);
                            }
                        }
                        // need to either modify isAlive to recognize idle pool or leave commented out/delete because this is re-starting the pool evert time.
                        //else if (!_pools[siteId].IsAlive && !Convert.ToBoolean(SHUTDOWN_FLAG)) // if the pool is not started for some reason and we're not shutting down
                        //{
                        //    //_pools[siteId].shutdown();
                        //    //startPool(siteId, poolSource.CxnSources[siteId]);
                        //    //_pools[siteId] = (ConnectionPool)ConnectionPoolFactory.getResourcePool(poolSource.CxnSources[siteId]);
                        //}
                    }
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Checkout a connection
        /// </summary>
        /// <param name="obj">The connection identifier (usually the site ID)</param>
        /// <returns>AbstractConnection</returns>
        public override AbstractResource checkOut(object obj)
        {
            while (_starting) // block while startup is occurring
            {
                System.Threading.Thread.Sleep(10);
            }
            if (!(obj is String))
            {
                throw new ArgumentException("Must supply the ID of the connection pool to check out a connection");
            }
            string site = (String)obj;
            // first make sure we have a dictionary key/queue for this site - if lazy loading then create a new pool for site - else exception
            ConnectionPoolsSource source = (ConnectionPoolsSource)this.PoolSource;

            if (!_pools.ContainsKey(site))
            {
                if (!source.CxnSources.ContainsKey(site))
                {
                    throw new ArgumentException("No configuration information available for that connection pool ID ({0}) - unable to start", site);
                }
                _pools.Add(site, null);
            }
            if (_pools[site] == null)
            {
                if (this.PoolSource.LoadStrategy == LoadingStrategy.Lazy)
                {
                    startPool(site, source.CxnSources[site]);
                    //_pools[site] = (ConnectionPool)ConnectionPoolFactory.getResourcePool(source.CxnSources[site]);
                }
                else // treating this as an error case - if we're not lazy loading and the pool hasn't already been initialized then assume pool is being used incorrectly
                {
                    throw new ConfigurationErrorsException("The pools have not been initialized properly to service your request");
                }
            }
            // try and check out a connection from the pool
            return(_pools[site].checkOut(null));
        }
Пример #6
0
        /// <summary>
        /// Start the connection pool. This method is rather slow when run in production (130+ sites). A connection pool is started for
        /// each of the sources. A loop is used to start each pool. Each new pool start waits for the previous pool to come to a reasonable
        /// state before starting. If the previous pool hasn't finished starting after 60 seconds, the current pool will go ahead 
        /// and start anyways. 
        /// </summary>
        /// <param name="source">The source for all the connection pool configuration information</param>
        void startUp(ConnectionPoolsSource source)
        {
            // first things first - initialize the pool collection based off the connection sources!
            _pools = new Dictionary<string, ConnectionPool>();
            foreach (string siteId in source.CxnSources.Keys)
            {
                _pools.Add(siteId, null);
            }

            if (source.LoadStrategy == LoadingStrategy.Lazy)
            {
                return; // lazy loading? we're all done with startup!
            }

            // the rest of this code starts the pool for each of the connection sources
            string[] allKeys = new string[source.CxnSources.Count];
            source.CxnSources.Keys.CopyTo(allKeys, 0);
            IList<ConnectionPool> allPools = new List<ConnectionPool>(allKeys.Length);

            for (int i = 0; i < allKeys.Length; i++)
            {
                DateTime lastPoolStart = DateTime.Now;

                // starting 130+ connection pool threads takes a lot of system resources - we should try and let the
                // previous pool come up or at least give it a reasonable time to start before moving to the next connection pool
                if (i > 0)
                {
                    while (lastPoolStart.Subtract(DateTime.Now).TotalSeconds < 60 &&
                        allPools[i - 1].TotalResources < allPools[i - 1].PoolSource.MinPoolSize)
                    {
                        System.Threading.Thread.Sleep(500);
                    }
                }

                // go ahead and start the pool now
                ConnectionPool cxnPool = (ConnectionPool)ConnectionPoolFactory.getResourcePool(source.CxnSources[allKeys[i]]);
                allPools.Add(cxnPool);
                _pools[allKeys[i]] = cxnPool;
            }
        }