00001 // $Id: TGo4TaskHandlerAbortException.cxx 615 2010-04-14 15:34:12Z adamczew $ 00002 //----------------------------------------------------------------------- 00003 // The GSI Online Offline Object Oriented (Go4) Project 00004 // Experiment Data Processing at EE department, GSI 00005 //----------------------------------------------------------------------- 00006 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH 00007 // Planckstr. 1, 64291 Darmstadt, Germany 00008 // Contact: http://go4.gsi.de 00009 //----------------------------------------------------------------------- 00010 // This software can be used under the license agreements as stated 00011 // in Go4License.txt file which is part of the distribution. 00012 //----------------------------------------------------------------------- 00013 00014 #include "TGo4TaskHandlerAbortException.h" 00015 00016 #include "Riostream.h" 00017 00018 #include "TApplication.h" 00019 00020 #include "TGo4Log.h" 00021 #include "TGo4Thread.h" 00022 #include "TGo4Task.h" 00023 #include "TGo4TaskHandler.h" 00024 #include "TGo4TaskHandlerRunnable.h" 00025 #include "TGo4Slave.h" 00026 #include "TGo4Master.h" 00027 #include "TGo4ComRemoveClient.h" 00028 #include "TGo4ComDisconnectSlave.h" 00029 00030 TGo4TaskHandlerAbortException::TGo4TaskHandlerAbortException (TGo4TaskHandler* taskhandler) 00031 : TGo4TaskHandlerException(taskhandler) 00032 { 00033 fxDescription= "!!!-- Go4 TaskHandler Abort Exception --!!!"; 00034 } 00035 00036 TGo4TaskHandlerAbortException::TGo4TaskHandlerAbortException(TGo4TaskHandlerRunnable * run) 00037 : TGo4TaskHandlerException(run) 00038 { 00039 fxDescription= "!!!-- Go4 TaskHandler Abort Exception --!!!"; 00040 } 00041 00042 TGo4TaskHandlerAbortException::~TGo4TaskHandlerAbortException() 00043 { 00044 } 00045 00046 Int_t TGo4TaskHandlerAbortException::Handle() 00047 { 00048 if(fxCaller) 00049 { 00050 // we know the calling thread, stop it! 00051 fxCaller->GetThread()->Stop(); 00052 } 00053 else 00054 { 00055 // no caller specified, continue 00056 } 00057 00058 if (fxTaskHandler->IsAborting()) 00059 { 00060 // a concurrent exception is already performing, we do nothing 00061 TGo4Log::Debug(" TaskHandlerAbortException: taskhandler is already aborting "); 00062 return 0; 00063 } 00064 else 00065 { 00066 // just go on with the show 00067 fxTaskHandler->SetAborting(kTRUE); 00068 } // if (fxTaskHandler->IsAborting()) 00069 00070 if (fxThreadManager==0) 00071 { 00072 // error 00073 fxTaskHandler->SetAborting(kFALSE); 00074 return -1; 00075 } 00076 else 00077 { 00078 // continue 00079 } // if (fxThreadManager==0) 00080 00081 const char* taskname = fxTaskHandler->GetName(); 00082 TGo4Master* master=0; 00083 TGo4Slave* slave=0; 00084 TGo4Task* task = dynamic_cast<TGo4Task*> (fxThreadManager); 00085 if(task) 00086 { 00087 master=task->GetMaster(); 00088 slave=task->GetSlave(); 00089 } 00090 if(slave) 00091 { 00092 TGo4Log::Debug(" TaskHandlerAbortException for slave %s ... ",taskname); 00093 if(slave->IsServer()) 00094 { 00095 // note: we need a local command here (executed in local thread), 00096 // since this is running inside thread of taskhandler to be deleted! 00097 TGo4ComRemoveClient* removecommand = new TGo4ComRemoveClient; 00098 //removecommand->SetClient("currentclient"); 00099 removecommand->SetClient(taskname); 00100 removecommand->SetWaitForClient(kFALSE); 00101 TGo4Log::Debug(" TaskHandlerAbortException on slave server: revoming client %s",taskname); 00102 task->SubmitCommand(removecommand); 00103 } 00104 else 00105 { 00106 TGo4Log::Debug(" TaskHandlerAbortException: Terminating slave..."); 00107 fxThreadManager->SetBeingQuit(kTRUE); // flag for the application that we expect to be quit soon 00108 cout <<"ttttttttttt TaskHandlerAbortException set the being quit" << endl; 00109 slave->TerminateFast(); 00110 } 00111 } 00112 else if(master) 00113 { 00114 TGo4Log::Debug(" TaskHandlerAbortException: Removing current slave... "); 00115 // note: we need a local command here (executed in local thread), since 00116 // this is running inside thread of taskhandler to be deleted! 00117 TGo4ComDisconnectSlave* discommand = new TGo4ComDisconnectSlave; 00118 discommand->SetSlave("currentclient"); 00119 discommand->SetWaitForSlave(kFALSE); 00120 TGo4Log::Debug(" TaskHandlerAbortException: Disconnecting current slave"); 00121 task->SubmitCommand(discommand); 00122 } 00123 else if(task) 00124 { 00125 // no master, no slave: old style connection, test client and server role 00126 if(fxTaskHandler->IsClientMode()) 00127 { 00128 // exception was raised by client task handler 00129 TGo4Log::Debug(" TaskHandlerAbortException: Quit client %s ... ",taskname); 00130 fxThreadManager->SetBeingQuit(kTRUE); // flag for the application that we expect to be quit soon 00131 task->TerminateFast(); 00132 } 00133 else 00134 { 00135 // exception was raised by server task handler 00136 TGo4ComRemoveClient* removecommand = new TGo4ComRemoveClient; 00137 removecommand->SetClient(taskname); 00138 removecommand->SetWaitForClient(kFALSE); 00139 TGo4Log::Debug(" TaskHandlerAbortException: Disconnecting client %s ... ",taskname); 00140 task->SubmitCommand(removecommand); 00141 // we cannot remove our own thread, so use local command thread 00142 } // if (fxTaskHandler->IsClientMode()) 00143 } 00144 else 00145 { 00146 // no task: something is very wrong! 00147 gApplication->Terminate(); 00148 } 00149 return 0; 00150 } 00151