public override IEngine <TModel> GetClient <TModel>() { var pool = ConnectionPools.PoolFor(this); var requestContextFactory = new PooledConnectionRequestContextFactory(pool); return(new RemoteEngineClient <TModel>(requestContextFactory, Host, Port)); }
public override void tearDownQuery(MySession session) { foreach (AbstractConnection cxn in session.ConnectionSet.Connections.Values) { ConnectionPools.getInstance().checkIn(cxn); } }
internal void shutdownPool() { try { ConnectionPools.getInstance().shutdown(); } catch (Exception) { } }
internal void setConnections(MySession session, IList <string> sites) { //Dictionary<string, AbstractConnection> cxns = new Dictionary<string, AbstractConnection>(); foreach (string site in sites) { AbstractConnection cxn = (AbstractConnection)ConnectionPools.getInstance().checkOut(site); cxn.setState(session.Sessions.States[site].State as Dictionary <string, object>); //cxns.Add(site, cxn); session.ConnectionSet.Add(cxn); } }
static void Main() { var connectionPools = new ConnectionPools { "SqlServer", "Oracle", "Postgress" }; foreach (var pool in connectionPools) { Console.WriteLine(pool); } Console.ReadLine(); }
public override void setUpQuery(MySession session) { if (base.QuerySites == null || base.QuerySites.Count == 0) { throw new ArgumentException("No sites specified for stateless query!"); } session.ConnectionSet = new mdo.dao.ConnectionSet(); foreach (String site in base.QuerySites) { session.ConnectionSet.Add((AbstractConnection)ConnectionPools.getInstance().checkOutAlive(site)); } }
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); }
public string[] ddrGetsEntry(string siteId, string vistaFile, string iens, string flds, string flags) { AbstractConnection cxn = null; try { logging.Log.LOG(String.Format("DDR GETS ENTRY: {0}, {1}, {2}, {3}", siteId, vistaFile, iens, flds)); cxn = (AbstractConnection)ConnectionPools.getInstance().checkOutAlive(siteId); DdrGetsEntry ddr = new DdrGetsEntry(cxn); ddr.File = vistaFile; ddr.Iens = iens; ddr.Fields = flds; ddr.Flags = flags; String[] result = null; result = ddr.execute(); return(result); } catch (UnauthorizedAccessException uae) { logging.Log.LOG("Connection not properly authenticated: " + uae.Message); cxn.disconnect(); // will cause cxn pool to discard throw uae; } catch (System.Net.Sockets.SocketException se) { logging.Log.LOG("Socket error: " + se.Message); cxn.disconnect(); // will cause cxn pool to discard throw se; } catch (gov.va.medora.mdo.exceptions.ConnectionException ce) { logging.Log.LOG("Cxn error: " + ce.Message); cxn.disconnect(); // will cause cxn pool to discard throw ce; } catch (Exception exc) { logging.Log.LOG("DDR GETS ENTRY Exception: " + exc.Message); throw exc; } finally { try { ConnectionPools.getInstance().checkIn(cxn); } catch (Exception) { } } }
internal void setConnection(MySession session, string sitecode) { AbstractConnection cxn = (AbstractConnection)ConnectionPools.getInstance().checkOut(sitecode); if (session.Sessions == null) { Dictionary <string, AbstractState> state0 = new Dictionary <string, AbstractState>(); state0.Add(sitecode, new VistaState()); session.Sessions = new VistaStates(state0); } if (null != session.Sessions && null != session.Sessions.States && session.Sessions.States.ContainsKey(sitecode) && null != session.Sessions.States[sitecode].State) { cxn.setState(session.Sessions.States[sitecode].State as Dictionary <string, object>); } session.ConnectionSet.Add(cxn); // only adds if not present }
internal void setConnection(MySession session) { if (session.ConnectionSet == null || session.ConnectionSet.BaseConnection == null) { throw new ArgumentNullException("Invalid session - need to connect?"); } AbstractConnection cxn = (AbstractConnection)ConnectionPools.getInstance().checkOut(session.ConnectionSet.BaseSiteId); // set the state for this connection only if the state has been instantiated elsewhere if (null != session.Sessions && null != session.Sessions.States && session.Sessions.States.ContainsKey(session.ConnectionSet.BaseSiteId) && null != session.Sessions.States[session.ConnectionSet.BaseSiteId].State) { cxn.setState(session.Sessions.States[session.ConnectionSet.BaseSiteId].State as Dictionary <string, object>); } }
public string getVariableValueQuery(string siteId, string arg) { AbstractConnection cxn = null; try { logging.Log.LOG(String.Format("GVV: {0}, {1}", siteId, arg)); cxn = (AbstractConnection)ConnectionPools.getInstance().checkOutAlive(siteId); VistaToolsDao dao = new VistaToolsDao(cxn); String result = null; result = dao.getVariableValue(arg); return(result); } catch (UnauthorizedAccessException uae) { logging.Log.LOG("Connection not properly authenticated: " + uae.Message); cxn.disconnect(); // will cause cxn pool to discard throw uae; } catch (System.Net.Sockets.SocketException se) { logging.Log.LOG("Socket error: " + se.Message); cxn.disconnect(); // will cause cxn pool to discard throw se; } catch (gov.va.medora.mdo.exceptions.ConnectionException ce) { logging.Log.LOG("Cxn error: " + ce.Message); cxn.disconnect(); // will cause cxn pool to discard throw ce; } catch (Exception exc) { logging.Log.LOG("GVV Exception: " + exc.Message); throw exc; } finally { try { ConnectionPools.getInstance().checkIn(cxn); } catch (Exception) { } } }
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"); }
/// <summary> /// Get the state on each connection (XWB SERIALIZE), set the MySession.Sessions state info, return the connections to the pool /// </summary> /// <param name="session"></param> internal void returnConnections(MySession session) { if (session.ConnectionSet == null || session.ConnectionSet.Count == 0) { return; } foreach (string key in session.ConnectionSet.Connections.Keys) { AbstractConnection cxn = session.ConnectionSet.getConnection(key); if (cxn == null) // if no connection was checked out for this key { continue; } session.Sessions.setState(key, new VistaState(cxn.getState())); ConnectionPools.getInstance().checkIn(cxn); } }
void doCheckOutAndWait(String siteId) { AbstractConnection cxn = null; try { cxn = (AbstractConnection)ConnectionPools.getInstance().checkOutAlive(siteId); // we want real cxns even though we aren't really doing anything with them System.Threading.Thread.Sleep(1000); // simulate a small amount of wait but don't actually make any calls to Vista... } catch (Exception) { throw; } finally { ConnectionPools.getInstance().checkIn(cxn); } }
public Pool(ConnectionPools connectionPools) { _queue = new ConcurrentQueue <JsonRpcConnection>(); _owner = connectionPools; }
public TextArray ddrListerPlus( string sitecode, string file, string iens, string fields, string flags, string maxrex, string from, string part, string xref, string screen, string identifier) { AbstractConnection cxn = null; try { cxn = (AbstractConnection)ConnectionPools.getInstance().checkOutAlive(sitecode); DdrLister ddr = new DdrLister(cxn) { File = file, Iens = iens, Fields = fields, Flags = flags, Max = maxrex, From = from, Part = part, Xref = String.IsNullOrEmpty(xref) ? "#" : xref, Screen = screen, Id = identifier }; return(new TextArray(ddr.execute())); //VistaRpcQuery ddrResult = ddr.execute(); //return new DdrRpcResult(ddrResult); } catch (System.Net.Sockets.SocketException se) { try { cxn.disconnect(); } catch (Exception) { } return(new TextArray() { fault = new FaultTO(se) }); //return new DdrRpcResult() { fault = new FaultTO(se) }; } catch (Exception exc) { return(new TextArray() { fault = new FaultTO(exc) }); //return new DdrRpcResult() { fault = new FaultTO(exc) }; } finally { if (cxn != null) { ConnectionPools.getInstance().checkIn(cxn); } } }
public string[] ddrLister(string siteId, string vistaFile, string iens, string fields, string flags, string maxRex, string from, string part, string xref, string screen, string identifier) { AbstractConnection cxn = null; try { logging.Log.logDDR(String.Format("DDR LISTER: Site {0}, File {1}, IENS {2}, Fields {3}, Flags {7}, From {4}, Screen {5}, Identifier {6}", siteId, vistaFile, iens, fields, from, screen, identifier, flags)); cxn = (AbstractConnection)ConnectionPools.getInstance().checkOutAlive(siteId); DdrLister ddr = new DdrLister(cxn); ddr.File = vistaFile; ddr.Iens = iens; ddr.Fields = fields; ddr.Flags = flags; if (String.Equals(flags, "I") && !String.IsNullOrEmpty(identifier)) { ddr.Options = "WID"; // this is how we get identifier part for unpacked query results } if (String.IsNullOrEmpty(xref)) { ddr.Xref = "#"; } else { ddr.Xref = xref; } ddr.Max = maxRex; ddr.From = from; ddr.Part = part; ddr.Screen = screen; ddr.Id = identifier; String[] result = null; result = ddr.execute(); return(result); } catch (UnauthorizedAccessException uae) { logging.Log.LOG("Connection not properly authenticated: " + uae.Message); cxn.disconnect(); // will cause cxn pool to discard throw uae; } catch (System.Net.Sockets.SocketException se) { logging.Log.LOG("Socket error: " + se.Message); cxn.disconnect(); // will cause cxn pool to discard throw se; } catch (gov.va.medora.mdo.exceptions.ConnectionException ce) { logging.Log.LOG("Cxn error: " + ce.Message); cxn.disconnect(); // will cause cxn pool to discard throw ce; } catch (Exception exc) { logging.Log.LOG("DDR LISTER Exception: " + exc.Message); throw exc; } finally { try { ConnectionPools.getInstance().checkIn(cxn); } catch (Exception) { } } }