private static void startConnectionPool() { MySession temp = new MySession(); AbstractPoolSource defaultSrc = new ConnectionPoolSource() { CxnSource = new mdo.DataSource() { Protocol = "PVISTA" }, Credentials = new VistaCredentials(), LoadStrategy = (LoadingStrategy)Enum.Parse(typeof(LoadingStrategy), temp.MdwsConfiguration.AllConfigs[conf.MdwsConfigConstants.CONNECTION_POOL_CONFIG_SECTION][conf.MdwsConfigConstants.CONNECTION_POOL_LOAD_STRATEGY]), MaxPoolSize = Convert.ToInt32(temp.MdwsConfiguration.AllConfigs[conf.MdwsConfigConstants.CONNECTION_POOL_CONFIG_SECTION][conf.MdwsConfigConstants.CONNECTION_POOL_MAX_CXNS]), MinPoolSize = Convert.ToInt32(temp.MdwsConfiguration.AllConfigs[conf.MdwsConfigConstants.CONNECTION_POOL_CONFIG_SECTION][conf.MdwsConfigConstants.CONNECTION_POOL_MIN_CXNS]), PoolExpansionSize = Convert.ToInt32(temp.MdwsConfiguration.AllConfigs[conf.MdwsConfigConstants.CONNECTION_POOL_CONFIG_SECTION][conf.MdwsConfigConstants.CONNECTION_POOL_EXPAND_SIZE]), WaitTime = TimeSpan.Parse(temp.MdwsConfiguration.AllConfigs[conf.MdwsConfigConstants.CONNECTION_POOL_CONFIG_SECTION][conf.MdwsConfigConstants.CONNECTION_POOL_WAIT_TIME]), Timeout = TimeSpan.Parse(temp.MdwsConfiguration.AllConfigs[conf.MdwsConfigConstants.CONNECTION_POOL_CONFIG_SECTION][conf.MdwsConfigConstants.CONNECTION_POOL_CXN_TIMEOUT]) }; IList <AbstractPoolSource> sources = new List <AbstractPoolSource>(); //AbstractPoolSource poolsSource = new ConnectionPoolsSource(); //((ConnectionPoolsSource)poolsSource).CxnSources = new Dictionary<string, ConnectionPoolSource>(); AbstractPoolSourceFactory factory = new ConnectionPoolSourceFactory(defaultSrc); // instantiate the pool source factory AbstractPoolSource result = (ConnectionPoolsSource)factory.getPoolSources(temp.SiteTable); AbstractResourcePool pools = AbstractResourcePoolFactory.getResourcePool(result); // this starts the pool }
public CrudSvc() { if (ConnectionPools.getInstance().PoolSource != null) { return; // already set up the pools! } _mySession = new MySession(); SiteTable sites = _mySession.SiteTable; IList <AbstractPoolSource> sources = new List <AbstractPoolSource>(); ConnectionPoolsSource poolsSource = new ConnectionPoolsSource(); poolsSource.CxnSources = new Dictionary <string, ConnectionPoolSource>(); User user = _mySession.MdwsConfiguration.ApplicationProxy; AbstractCredentials creds = new VistaCredentials(); creds.AccountName = user.UserName; creds.AccountPassword = user.Pwd; creds.AuthenticationSource = new DataSource(); // BSE creds.AuthenticationSource.SiteId = new SiteId(user.LogonSiteId.Id, user.LogonSiteId.Name); creds.AuthenticationToken = user.LogonSiteId.Id + "_" + user.Uid; creds.LocalUid = user.Uid; creds.FederatedUid = user.SSN.toString(); creds.SubjectName = user.Name.getLastNameFirst(); creds.SubjectPhone = user.Phone; creds.SecurityPhrase = _mySession.MdwsConfiguration.AllConfigs [conf.MdwsConfigConstants.MDWS_CONFIG_SECTION][conf.MdwsConfigConstants.SECURITY_PHRASE]; foreach (DataSource source in sites.Sources) { if (!String.Equals(source.Protocol, "VISTA", StringComparison.CurrentCultureIgnoreCase)) { continue; } ConnectionPoolSource newSource = new ConnectionPoolSource() { LoadStrategy = (LoadingStrategy)Enum.Parse(typeof(LoadingStrategy), _mySession.MdwsConfiguration.AllConfigs[conf.MdwsConfigConstants.CONNECTION_POOL_CONFIG_SECTION][conf.MdwsConfigConstants.CONNECTION_POOL_LOAD_STRATEGY]), MaxPoolSize = Convert.ToInt32(_mySession.MdwsConfiguration.AllConfigs[conf.MdwsConfigConstants.CONNECTION_POOL_CONFIG_SECTION][conf.MdwsConfigConstants.CONNECTION_POOL_MAX_CXNS]), MinPoolSize = Convert.ToInt32(_mySession.MdwsConfiguration.AllConfigs[conf.MdwsConfigConstants.CONNECTION_POOL_CONFIG_SECTION][conf.MdwsConfigConstants.CONNECTION_POOL_MIN_CXNS]), PoolExpansionSize = Convert.ToInt32(_mySession.MdwsConfiguration.AllConfigs[conf.MdwsConfigConstants.CONNECTION_POOL_CONFIG_SECTION][conf.MdwsConfigConstants.CONNECTION_POOL_EXPAND_SIZE]), WaitTime = TimeSpan.Parse(_mySession.MdwsConfiguration.AllConfigs[conf.MdwsConfigConstants.CONNECTION_POOL_CONFIG_SECTION][conf.MdwsConfigConstants.CONNECTION_POOL_WAIT_TIME]), Timeout = TimeSpan.Parse(_mySession.MdwsConfiguration.AllConfigs[conf.MdwsConfigConstants.CONNECTION_POOL_CONFIG_SECTION][conf.MdwsConfigConstants.CONNECTION_POOL_CXN_TIMEOUT]), CxnSource = source, Credentials = creds }; newSource.CxnSource.Protocol = "PVISTA"; poolsSource.CxnSources.Add(source.SiteId.Id, newSource); } ConnectionPools pools = (ConnectionPools)AbstractResourcePoolFactory.getResourcePool(poolsSource); }
internal void initializePool() { logging.Log.LOG("Initializing connection pools..."); if (ConnectionPools.getInstance().PoolSource != null) { logging.Log.LOG("Connection pools already initialized"); return; // already set up the pools! } SiteTable sites = new SiteTable(ConfigurationManager.AppSettings[config.AppConfigSettingsConstants.VhaSitesFilePath]); IList <AbstractPoolSource> sources = new List <AbstractPoolSource>(); ConnectionPoolsSource poolsSource = new ConnectionPoolsSource(); poolsSource.CxnSources = new Dictionary <string, ConnectionPoolSource>(); VistaDao trash = new VistaDao(); AbstractCredentials creds = getDownstreamCredentialsFromConfig(getDownstreamUserFromConfig()); foreach (DataSource source in sites.Sources) { if (!String.Equals(source.Protocol, "VISTA", StringComparison.CurrentCultureIgnoreCase)) { continue; } ConnectionPoolSource newSource = new ConnectionPoolSource() { Timeout = TimeSpan.Parse(ConfigurationManager.AppSettings["PoolConnectionTimeout"]), WaitTime = TimeSpan.Parse(ConfigurationManager.AppSettings["PoolWaitTimeout"]), MaxPoolSize = Convert.ToInt32(ConfigurationManager.AppSettings["PoolMaxSize"]), MinPoolSize = Convert.ToInt32(ConfigurationManager.AppSettings["PoolMinSize"]), PoolExpansionSize = Convert.ToInt32(ConfigurationManager.AppSettings["PoolExpansionSize"]), CxnSource = source, Credentials = creds, Permission = new MenuOption(ConfigurationManager.AppSettings["PoolUserPermission"]) }; Int32 recycleCount = 0; if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["PoolRecycleCount"]) && Int32.TryParse(ConfigurationManager.AppSettings["PoolRecycleCount"], out recycleCount)) { newSource.RecycleCount = recycleCount; } newSource.CxnSource.Protocol = "PVISTA"; poolsSource.CxnSources.Add(source.SiteId.Id, newSource); } ConnectionPools pools = (ConnectionPools)AbstractResourcePoolFactory.getResourcePool(poolsSource); logging.Log.LOG("Successfully completed connection pools initialization"); }
public void testEagerStartupCxnTimeouts() { _localSource.LoadStrategy = LoadingStrategy.Eager; _localSource.Timeout = new TimeSpan(0, 0, 4); _pool = AbstractResourcePoolFactory.getResourcePool(_localSource); System.Threading.Thread.Sleep(3000); // wait a few seconds for pool to start but not enough for cxns to timeout Assert.IsTrue(_pool.TotalResources > 0, "Should have resources before asking for them in eager startup model"); AbstractConnection cxn = (AbstractConnection)_pool.checkOut("901"); Assert.IsNotNull(cxn); Assert.IsTrue(cxn.isAlive()); // the checkout function of the pool should ensure we're getting an alive connection but assert anyways to prove _pool.checkIn(cxn); // cleanup System.Threading.Thread.Sleep(5000); }
public void testRunningPool() { _localSource.Timeout = new TimeSpan(0, 0, 1); // set this very low so the test can run quickly _pool = AbstractResourcePoolFactory.getResourcePool(_localSource); System.Threading.Thread.Sleep(5000); // let's increase our connection timeout for this test so we can more easily test the state of things _localSource.Timeout = new TimeSpan(0, 0, 5); // this should affect all newly created connections AbstractConnection cxn = (AbstractConnection)_pool.checkOutAlive("901"); Int32 resourceCountBefore = _pool.TotalResources; // we take this immediately after checkOutAlive which should have found all our timed out connections and begun adding new ones // the pool shouldn't try to restart connections until they're needed - checkOutAlive should be that signal // so, now that checkOutAlive has been called, the pool should have discovered that it doesn't have any alive resources and started adding some back Assert.IsTrue(_pool.TotalResources == 1); Assert.IsNotNull(cxn); Assert.IsTrue(cxn.isAlive()); // the checkout function of the pool should ensure we're getting an alive connection but assert anyways to prove System.Threading.Thread.Sleep(1100); // even though our connection is checked out, it should still timeout _pool.checkIn(cxn); // the pool shouldn't put this item back in its collection (doesn't throw error though) Int32 resourcesAfter = _pool.TotalResources; }