예제 #1
0
 internal ThreadInfo(string tableName, int timeout, QueryThread thread)
 {
     TimeOut     = timeout;
     TimeRemain  = timeout;
     Thread      = null;
     TableName   = tableName;
     QueryThread = thread;
 }
예제 #2
0
 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);
     }
 }
예제 #3
0
 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;
 }
예제 #4
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         FindTheHid();
         _queryThread = new QueryThread(this);
         _queryThread.Start();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #5
0
        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);
 }
예제 #7
0
        /// <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;
        }
예제 #8
0
파일: ConnectionSet.cs 프로젝트: OSEHRA/mdo
 public override void handleNonException(QueryThread t)
 {
 }
예제 #9
0
파일: ConnectionSet.cs 프로젝트: OSEHRA/mdo
 public override void handleNonException(QueryThread t)
 {
     ConnectionSet.Remove(t.Id);
 }
예제 #10
0
        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;
        }
예제 #11
0
		/// <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;
		}
예제 #12
0
 public void queue(QueryThread qt, string siteId)
 {
     _queue.queue(qt, siteId);
 }
예제 #13
0
        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;
        }
예제 #14
0
 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;
 }
예제 #15
0
 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;
 }
예제 #16
0
        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;
        }
예제 #17
0
 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);
     }
 }
예제 #18
0
파일: ConnectionSet.cs 프로젝트: OSEHRA/mdo
 public abstract void handleNonException(QueryThread t);
예제 #19
0
        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;
        }
예제 #20
0
파일: ConnectionSet.cs 프로젝트: OSEHRA/mdo
            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);
                    }
                }
            }
예제 #21
0
 public void Dispose()
 {
     EndQueryThread = true;
     AnyOutstandingQuery.Signal();
     QueryThread.Join();
 }
예제 #22
0
 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;
 }
예제 #23
0
        /// <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;
        }