Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4TaskHandlerAbortException.cxx

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE 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 "Riostream.h"
00019 
00020 #include "TApplication.h"
00021 
00022 #include "TGo4Log.h"
00023 #include "TGo4Thread.h"
00024 #include "TGo4Task.h"
00025 #include "TGo4TaskHandler.h"
00026 #include "TGo4TaskHandlerRunnable.h"
00027 #include "TGo4Slave.h"
00028 #include "TGo4Master.h"
00029 #include "TGo4ComRemoveClient.h"
00030 #include "TGo4ComDisconnectSlave.h"
00031 
00032 TGo4TaskHandlerAbortException::TGo4TaskHandlerAbortException (TGo4TaskHandler* taskhandler)
00033 : TGo4TaskHandlerException(taskhandler)
00034 {
00035    fxDescription= "!!!-- Go4 TaskHandler Abort Exception --!!!";
00036 }
00037 
00038 TGo4TaskHandlerAbortException::TGo4TaskHandlerAbortException(TGo4TaskHandlerRunnable * run)
00039 : TGo4TaskHandlerException(run)
00040 {
00041    fxDescription= "!!!-- Go4 TaskHandler Abort Exception --!!!";
00042 }
00043 
00044 TGo4TaskHandlerAbortException::~TGo4TaskHandlerAbortException()
00045 {
00046 }
00047 
00048 Int_t TGo4TaskHandlerAbortException::Handle()
00049 {
00050    if(fxCaller)
00051       {
00052          // we know the calling thread, stop it!
00053          fxCaller->GetThread()->Stop();
00054       }
00055    else
00056       {
00057          // no caller specified, continue
00058       }
00059 
00060    if (fxTaskHandler->IsAborting())
00061       {
00062          // a concurrent exception is already performing, we do nothing
00063          TGo4Log::Debug(" TaskHandlerAbortException: taskhandler is already aborting ");
00064          return 0;
00065       }
00066    else
00067       {
00068          // just go on with the show
00069          fxTaskHandler->SetAborting(kTRUE);
00070       } // if (fxTaskHandler->IsAborting())
00071 
00072    if (fxThreadManager==0)
00073          {
00074             // error
00075             fxTaskHandler->SetAborting(kFALSE);
00076             return -1;
00077          }
00078       else
00079          {
00080             // continue
00081          }  //   if (fxThreadManager==0)
00082 
00083    const char* taskname = fxTaskHandler->GetName();
00084    TGo4Master* master=0;
00085    TGo4Slave* slave=0;
00086    TGo4Task* task = dynamic_cast<TGo4Task*> (fxThreadManager);
00087    if(task)
00088       {
00089          master=task->GetMaster();
00090          slave=task->GetSlave();
00091       }
00092    if(slave)
00093       {
00094          TGo4Log::Debug(" TaskHandlerAbortException for slave %s ... ",taskname);
00095          if(slave->IsServer())
00096             {
00097                // note: we need a local command  here (executed in local thread),
00098                // since this is running inside thread of taskhandler to be deleted!
00099                TGo4ComRemoveClient* removecommand = new TGo4ComRemoveClient;
00100                //removecommand->SetClient("currentclient");
00101                removecommand->SetClient(taskname);
00102                removecommand->SetWaitForClient(kFALSE);
00103                TGo4Log::Debug(" TaskHandlerAbortException on slave server: revoming client %s",taskname);
00104                task->SubmitCommand(removecommand);
00105             }
00106          else
00107             {
00108                TGo4Log::Debug(" TaskHandlerAbortException: Terminating slave...");
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                task->TerminateFast();
00131             }
00132          else
00133             {
00134                // exception was raised by server task handler
00135                TGo4ComRemoveClient* removecommand = new TGo4ComRemoveClient;
00136                removecommand->SetClient(taskname);
00137                removecommand->SetWaitForClient(kFALSE);
00138                TGo4Log::Debug(" TaskHandlerAbortException: Disconnecting client %s ... ",taskname);
00139                task->SubmitCommand(removecommand);
00140                // we cannot remove our own thread, so use local command thread
00141             } // if (fxTaskHandler->IsClientMode())
00142       }
00143    else
00144       {
00145          // no task: something is very wrong!
00146          gApplication->Terminate();
00147       }
00148     return 0;
00149 }
00150 
00151 
00152 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:30 2008 for Go4-v3.04-1 by  doxygen 1.4.2