Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4TaskHandler/TGo4TaskHandlerAbortException.cxx

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

Generated on Tue Nov 8 10:56:06 2005 for Go4-v2.10-5 by doxygen1.2.15