//----------------------------------------------------------------------------------------------- //initialises one thread on the manager private void SetThreadOnManager(GThread thread) { thread.SetId(++_LastThreadId); thread.SetApplication(this); Manager.Owner_SetThread( Credentials, new ThreadIdentifier(_Id, thread.Id, thread.Priority), Utils.SerializeToByteArray(thread)); }
//----------------------------------------------------------------------------------------------- //gets the finished threads private void GetFinishedThreads() { bool appCleanedup = false; logger.Info("GetFinishedThreads thread started."); try { int logCounter = 0; while (!_StopGetFinished) { try { //a couple of potential issues here: //1. the first and second calls may return different thread counts. //since more threads may finish meanwhile. //2. this sleeps for 700 ms ... which means really quick threads can't //be retrieved before 700ms. Thread.Sleep(700); byte[][] FinishedThreads = Manager.Owner_GetFinishedThreads(Credentials, _Id); _NumThreadsFinished = Manager.Owner_GetFinishedThreadCount(Credentials, _Id); if (logCounter > 20 || FinishedThreads.Length > 0) { //print log only once in a while logger.Debug("Threads finished this poll..." + FinishedThreads.Length); logger.Debug("Total Threads finished so far..." + _NumThreadsFinished); logCounter = 0; } logCounter++; for (int i = 0; i < FinishedThreads.Length; i++) { GThread th = (GThread)Utils.DeserializeFromByteArray(FinishedThreads[i]); // assign [NonSerialized] members from the old local copy th.SetApplication(this); // HACK: need to change this if the user is allowed to set the id _Threads[th.Id] = th; //RemoteException rex = Manager.Owner_GetFailedThreadException(Credentials, new ThreadIdentifier(_Id, th.Id)); //Exception ex = new Exception(rex.Message); Exception ex = Manager.Owner_GetFailedThreadException(Credentials, new ThreadIdentifier(_Id, th.Id)); RemoteException rex = ex as RemoteException; if (rex != null) { ex = rex.OriginalRemoteException; } if (ex == null) { logger.Debug("Thread completed successfully:" + th.Id); //raise the thread finish event OnThreadFinish(th); } else { logger.Debug("Thread failed:" + th.Id); //raise the thread failed event OnThreadFailed(th, ex); } } // May 10, 2006 [email protected]: Fix for bug 1485426 if ((!_MultiUse) && (_NumThreadsFinished == Threads.Count)) { logger.Debug("Application finished!" + _Id); if (!appCleanedup) { //clean up manager,executor. logger.Debug("SingleUse-Application finished cleaning up..." + _Id); Manager.Owner_CleanupApplication(Credentials, _Id); appCleanedup = true; } if (_ApplicationFinish != null) { /// January 25, 2006 [email protected]: Fix for bug 1410797 /// Mark the application as stopped in the database /// This relies on the client to mark the application as stopped on the server, /// maybe not the best approach Manager.Owner_StopApplication(Credentials, _Id); logger.Debug("Raising AppFinish event (for single-use app)..." + _Id); _Running = false; try { _ApplicationFinish.BeginInvoke(null, null); } catch (Exception ex) { logger.Debug("ApplicationFinish Event-handler error: " + ex.ToString()); } } break; //we break here since there is no point raising events mutliple times.!!! :kna: dec 3, 2006. //logger.Debug("App finished, but still looping since some-one might subscribe to this event, and we can send it to them now."); } } catch (SocketException se) { // lost connection to Manager logger.Error("Lost connection to manager. Stopping GetFinishedThreads...", se); break; } catch (RemotingException re) { // lost connection to Manager logger.Error("Lost connection to manager. Stopping GetFinishedThreads...", re); break; } catch (Exception e) { logger.Error("Error in GetFinishedThreads. Continuing to poll for finished threads...", e); } } } catch (ThreadAbortException) { logger.Debug("GetFinishedThreads Thread aborted."); Thread.ResetAbort(); } catch (Exception e) { logger.Error("Error in GetFinishedThreads. GetFinishedThreads thread stopping...", e); } logger.Info("GetFinishedThreads thread exited..."); }