internal ThreadInfo(string tableName, int timeout, QueryThread thread) { TimeOut = timeout; TimeRemain = timeout; Thread = null; TableName = tableName; QueryThread = thread; }
protected internal void InitializeThreads() { // Initialize threads. for (int i = 0; i < nodes.Length; i++) { MultiCommand command = CreateCommand(); threads[i] = new QueryThread(this, nodes[i], command); } }
public static IndexedHashtable execute2(IndexedHashtable cxnTable, string daoName, string methodName, Object[] args) { if (cxnTable == null || cxnTable.Count == 0) { throw new Exception("No connections!"); } int lth = cxnTable.Count; QueryThread[] queries = new QueryThread[lth]; Thread[] threads = new Thread[lth]; for (int i = 0; i < lth; i++) { if (cxnTable.GetValue(i).GetType().IsAssignableFrom(typeof(Exception))) { continue; } Connection cxn = (Connection)cxnTable.GetValue(i); if (!cxn.IsConnected) { continue; } Object dao = ((Connection)cxnTable.GetValue(i)).getDao(daoName); if (dao == null) { continue; } queries[i] = new QueryThread(dao, methodName, args); threads[i] = new Thread(new ThreadStart(queries[i].execute)); threads[i].Start(); } IndexedHashtable result = new IndexedHashtable(cxnTable.Count); for (int i = 0; i < threads.Length; i++) { if (cxnTable.GetValue(i).GetType().IsAssignableFrom(typeof(Exception))) { result.Add((string)cxnTable.GetKey(i), (Exception)cxnTable.GetValue(i)); continue; } Connection cxn = (Connection)cxnTable.GetValue(i); if (!cxn.IsConnected) { result.Add((string)cxnTable.GetKey(i), new Exception("Source is not connected")); continue; } Object dao = ((Connection)cxnTable.GetValue(i)).getDao(daoName); if (dao == null) { result.Add((string)cxnTable.GetKey(i), new Exception("Invalid dao: " + daoName)); continue; } threads[i].Join(); result.Add((String)cxnTable.GetKey(i), queries[i].Result); } return result; }
private void Window_Loaded(object sender, RoutedEventArgs e) { try { FindTheHid(); _queryThread = new QueryThread(this); _queryThread.Start(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
protected internal void InitializeThreads() { // Detect cluster migrations when performing scan. ulong clusterKey = policy.failOnClusterChange ? QueryValidate.ValidateBegin(nodes[0], statement.ns) : 0; bool first = true; // Initialize threads. for (int i = 0; i < nodes.Length; i++) { MultiCommand command = CreateCommand(clusterKey, first); threads[i] = new QueryThread(this, nodes[i], command); first = false; } }
public void queue(QueryThread qt, string siteId) { lock (_connectionQueues) { if (!_connectionQueues.ContainsKey(siteId)) { _connectionQueues.Add(siteId, new Queue<QueryThread>()); } _connectionQueues[siteId].Enqueue(qt); } QueryThreadPoolEventArgs e = new QueryThreadPoolEventArgs() { QueueEventType = QueryThreadPoolEventArgs.QueueChangeEventType.QueryAdded, SiteId = siteId }; QueueChanged(e); }
/// <exception cref="UnknownHostException"></exception> internal static NbtAddress[] LookupServerOrWorkgroup(string name, IPAddress svr) { Sem sem = new Sem(2); int type = NbtAddress.IsWins(svr) ? unchecked (0x1b) : unchecked (0x1d); QueryThread q1X = new QueryThread(sem, name, type, null, svr); QueryThread q20 = new QueryThread(sem, name, unchecked (0x20), null, svr); q1X.SetDaemon(true); q20.SetDaemon(true); try { lock (sem) { q1X.Start(); q20.Start(); while (sem.Count > 0 && q1X.Ans == null && q20.Ans == null) { Runtime.Wait(sem); } } } catch (Exception) { throw new UnknownHostException(name); } if (q1X.Ans != null) { return(q1X.Ans); } if (q20.Ans != null) { return(q20.Ans); } throw q1X.Uhe; }
public override void handleNonException(QueryThread t) { }
public override void handleNonException(QueryThread t) { ConnectionSet.Remove(t.Id); }
public IndexedHashtable disconnect() { if (cxnTbl.Count == 0) { throw new Exception("No connections"); } // Only disconnect from the ones that are connected IndexedHashtable myCxns = getConnections(); int lth = myCxns.Count; QueryThread[] queries = new QueryThread[lth]; Thread[] threads = new Thread[lth]; for (int i = 0; i < lth; i++) { queries[i] = new QueryThread(myCxns.GetValue(i), "disconnect", new Object[0]); threads[i] = new Thread(new ThreadStart(queries[i].execute)); threads[i].Start(); } IndexedHashtable result = new IndexedHashtable(lth); for (int i = 0; i < lth; i++) { string key = (string)myCxns.GetKey(i); threads[i].Join(); if (queries[i].isExceptionResult()) { result.Add(key, queries[i].Result); } else { result.Add(key, "OK"); } } // We only disconnected from connected connections, but we want to clear // the entire table cxnTbl = new IndexedHashtable(); return result; }
/// <exception cref="UnknownHostException"></exception> internal static NbtAddress[] LookupServerOrWorkgroup(string name, IPAddress svr) { Sem sem = new Sem(2); int type = NbtAddress.IsWins(svr) ? unchecked(0x1b) : unchecked(0x1d); QueryThread q1X = new QueryThread(sem, name, type, null, svr ); QueryThread q20 = new QueryThread(sem, name, unchecked(0x20), null, svr); q1X.SetDaemon(true); q20.SetDaemon(true); try { lock (sem) { q1X.Start(); q20.Start(); while (sem.Count > 0 && q1X.Ans == null && q20.Ans == null) { Runtime.Wait(sem); } } } catch (Exception) { throw new UnknownHostException(name); } if (q1X.Ans != null) { return q1X.Ans; } if (q20.Ans != null) { return q20.Ans; } throw q1X.Uhe; }
public void queue(QueryThread qt, string siteId) { _queue.queue(qt, siteId); }
public IndexedHashtable connect() { int lth = cxnTbl.Count; QueryThread[] queries = new QueryThread[lth]; Thread[] threads = new Thread[lth]; for (int i = 0; i < lth; i++) { queries[i] = new QueryThread(cxnTbl.GetValue(i), "connect", new Object[0]); threads[i] = new Thread(new ThreadStart(queries[i].execute)); threads[i].Start(); } IndexedHashtable result = new IndexedHashtable(lth); for (int i = 0; i < lth; i++) { string key = (string)cxnTbl.GetKey(i); threads[i].Join(); //Need to report result whether it's a connection or an exception. if (queries[i].isExceptionResult()) { result.Add(key, queries[i].Result); Connection cxn = (Connection)cxnTbl.GetValue(i); cxn.ErrorMessage = ((Exception)queries[i].Result).Message; cxn.IsConnected = false; } else { result.Add(key, ((Connection)cxnTbl.GetValue(key)).DataSource); } } return result; }
public IndexedHashtable disconnectRemoteSites() { int lth = cxnTable.Count - 1; if (lth <= 0) { return null; } QueryThread[] queries = new QueryThread[lth]; Thread[] threads = new Thread[lth]; for (int i = 0; i < lth; i++) { queries[i] = new QueryThread(cxnTable.GetValue(i+1), "disconnect", new Object[0]); threads[i] = new Thread(new ThreadStart(queries[i].execute)); threads[i].Start(); } IndexedHashtable result = new IndexedHashtable(lth); for (int i = 0; i < lth; i++) { string key = (string)cxnTable.GetKey(i + 1); threads[i].Join(); if (queries[i].isExceptionResult()) { result.Add(key, queries[i].Result); } else { result.Add(key, "OK"); } } for (int i = 0; i < result.Count; i++) { cxnTable.Remove(result.GetKey(i)); } return result; }
public Dictionary<string, object> debug(String daoName, String methodName, Object[] args) { int lth = cxnTable.Count; QueryThread[] queries = new QueryThread[lth]; Dictionary<string, object> result = new Dictionary<string, object>(cxnTable.Count); for (int i = 0; i < lth; i++) { Object dao = ((Connection)cxnTable.GetValue(i)).getDao(daoName); queries[i] = new QueryThread(cxnTable.GetValue(i), methodName, args); queries[i].execute(); result.Add((String)cxnTable.GetKey(i), queries[i].Result); } return result; }
public IndexedHashtable connect() { int lth = cxnTable.Count; QueryThread[] queries = new QueryThread[lth]; Thread[] threads = new Thread[lth]; for (int i = 0; i < lth; i++) { queries[i] = new QueryThread(cxnTable.GetValue(i), "connect", new Object[0]); //queries[i].execute(); threads[i] = new Thread(new ThreadStart(queries[i].execute)); threads[i].Start(); } IndexedHashtable result = new IndexedHashtable(lth); for (int i = 0; i < lth; i++) { string key = (string)cxnTable.GetKey(i); threads[i].Join(); //Need to report result whether it's a connection or an exception. if (queries[i].isExceptionResult()) { result.Add(key,queries[i].Result); } else { result.Add(key,((Connection)cxnTable.GetValue(key)).DataSource); } } //Now for all the results that failed to connect, we remove them from the connection table. for (int i = 0; i < lth; i++) { if (queries[i].isExceptionResult()) { string key = (string)cxnTable.GetKey(i); cxnTable.Remove(key); cxnTable.Add(key, queries[i].Result); } } return result; }
protected internal void InitializeThreads() { // Initialize threads. for (int i = 0; i < nodes.Length; i++) { MultiCommand command = CreateCommand(nodes[i]); threads[i] = new QueryThread(this, command); } }
public abstract void handleNonException(QueryThread t);
public IndexedHashtable disconnectRemoteSites() { if (cxnTbl.Count < 2) { throw new Exception("No remote connections"); } // Only disconnect from the ones that are connected IndexedHashtable myCxns = getConnections(); int lth = myCxns.Count - 1; QueryThread[] queries = new QueryThread[lth]; Thread[] threads = new Thread[lth]; for (int threadIdx = 0, cxnIdx = 1; threadIdx < lth; threadIdx++, cxnIdx++) { queries[threadIdx] = new QueryThread(myCxns.GetValue(cxnIdx), "disconnect", new Object[0]); threads[threadIdx] = new Thread(new ThreadStart(queries[threadIdx].execute)); threads[threadIdx].Start(); } IndexedHashtable result = new IndexedHashtable(lth); for (int threadIdx = 0, cxnIdx = 1; threadIdx < lth; threadIdx++, cxnIdx++) { string key = (string)myCxns.GetKey(cxnIdx); threads[threadIdx].Join(); if (queries[threadIdx].isExceptionResult()) { result.Add(key, queries[threadIdx].Result); } else { result.Add(key, "OK"); } } // Now remove all but the logon connection from the table Connection loginCxn = LoginConnection; cxnTbl = new IndexedHashtable(); cxnTbl.Add(loginCxn.SiteId.Key, loginCxn); return result; }
public void QueryMethod(string daoName, string methodName, object[] args) { ArrayList queries = new ArrayList(myCset.Count); ArrayList threads = new ArrayList(myCset.Count); foreach (KeyValuePair<string, AbstractConnection> kvp in myCset.Connections) { AbstractConnection c = kvp.Value; if (skipThisConnection(c)) { continue; } object dao = getDao(daoName, c); QueryThread q = new QueryThread(c.DataSource.SiteId.Id, dao, methodName, args); Thread t = new Thread(new ThreadStart(q.execute)); queries.Add(q); threads.Add(t); t.Start(); } for (int i = 0; i < threads.Count; i++) { ((Thread)threads[i]).Join(); } myCset.Results = new IndexedHashtable(); myCset.Exceptions = null; for (int i = 0; i < queries.Count; i++) { QueryThread t = (QueryThread)queries[i]; if (t.isExceptionResult()) { handleException(t); if (myCset.Exceptions == null) { myCset.Exceptions = new IndexedHashtable(); } myCset.Exceptions.Add(t.Id, t.Result); } else { handleNonException(t); myCset.Results.Add(t.Id, t.Result); } } }
public void Dispose() { EndQueryThread = true; AnyOutstandingQuery.Signal(); QueryThread.Join(); }
public IndexedHashtable execute(String daoName, String methodName, Object[] args) { int lth = cxnTable.Count; QueryThread[] queries = new QueryThread[lth]; Thread[] threads = new Thread[lth]; for (int i = 0; i < lth; i++) { if (cxnTable.GetValue(i).GetType().IsAssignableFrom(typeof(Exception))) { continue; } Object dao = ((Connection)cxnTable.GetValue(i)).getDao(daoName); queries[i] = new QueryThread(dao, methodName, args); threads[i] = new Thread(new ThreadStart(queries[i].execute)); threads[i].Start(); } IndexedHashtable result = new IndexedHashtable(cxnTable.Count); for (int i=0; i<threads.Length; i++) { if (cxnTable.GetValue(i).GetType().IsAssignableFrom(typeof(Exception))) { result.Add((string)cxnTable.GetKey(i),(Exception)cxnTable.GetValue(i)); continue; } try { threads[i].Join(); result.Add((String)cxnTable.GetKey(i), queries[i].Result); } catch (Exception) { //throw new MdoException(e); } } return result; }
/// <summary> /// This function is the heart of the connection pool dictionary. It connects to a site /// and attaches the event handlers by executing a standard gettimestamp request /// so the connection can immediately begin processing queued query threads /// </summary> /// <param name="site">Site to which to connect</param> /// <param name="addToCxnCollection">Should the site be added to the pools connection collection?</param> /// <returns></returns> AbstractConnection connectWithReturn(Site site, bool addToCxnCollection) { //Site[] sites = _poolSites.ToArray(); Site currentSite = site; DataSource src = currentSite.Sources[0]; AbstractDaoFactory factory = AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.getConstant(src.Protocol)); AbstractConnection c = factory.getConnection(src); //c.ConnectionId = new Guid(); c.Account = _account; c.Account = new VistaAccount(c); c.Account.AuthenticationMethod = _account.AuthenticationMethod; c.Account.Permissions = new Dictionary<string, AbstractPermission>(); AbstractPermission cprs = new MenuOption("OR CPRS GUI CHART"); cprs.IsPrimary = true; c.Account.Permissions.Add(cprs.Name, cprs); // this needs to be up here so we can reference it if an error occurs QueryThread qt = new QueryThread("", new VistaToolsDao(null), "getTimestamp", new object[] { }); EventHandler eh = new EventHandler(QueryThreadChanged); try { User user = (User)c.authorizedConnect(_credentials, cprs, src); c.IsAvailable = true; // initiliaze this connection's eventhandler by making a standard timestamp request qt.setConnection(c); qt.Changed += eh; _currentActiveConnections++; qt.execute(); if (!(qt.Result is string)) { throw new ConnectionException("Connection does not appear to be active"); } if (addToCxnCollection) { addConnection(currentSite.Id, c); } return c; } catch (Exception) { qt.Changed -= eh; c.IsAvailable = false; _currentActiveConnections--; try { c.disconnect(); } catch (Exception) { } } return null; }