GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4TaskHandlerAbortException.cxx
Go to the documentation of this file.
1 // $Id$
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
15 
16 #include "TApplication.h"
17 
18 #include "TGo4Log.h"
19 #include "TGo4Thread.h"
20 #include "TGo4Task.h"
21 #include "TGo4TaskHandler.h"
23 #include "TGo4Slave.h"
24 #include "TGo4ComRemoveClient.h"
25 #include "TGo4ComDisconnectSlave.h"
26 
28 : TGo4TaskHandlerException(taskhandler)
29 {
30  fxDescription= "!!!-- Go4 TaskHandler Abort Exception --!!!";
31 }
32 
35 {
36  fxDescription= "!!!-- Go4 TaskHandler Abort Exception --!!!";
37 }
38 
40 {
41 }
42 
44 {
45  if (fxCaller) {
46  // we know the calling thread, stop it!
47  fxCaller->GetThread()->Stop();
48  } else {
49  // no caller specified, continue
50  }
51 
52  if (fxTaskHandler->IsAborting()) {
53  // a concurrent exception is already performing, we do nothing
54  TGo4Log::Debug(" TaskHandlerAbortException: taskhandler is already aborting ");
55  return 0;
56  } else {
57  // just go on with the show
58  fxTaskHandler->SetAborting(kTRUE);
59  } // if (fxTaskHandler->IsAborting())
60 
61  if (!fxThreadManager) {
62  // error
63  fxTaskHandler->SetAborting(kFALSE);
64  return -1;
65  }
66 
67  const char *taskname = fxTaskHandler->GetName();
68  TGo4Master *master = nullptr;
69  TGo4Slave *slave = nullptr;
70  TGo4Task *task = dynamic_cast<TGo4Task *>(fxThreadManager);
71  if (task) {
72  master = task->GetMaster();
73  slave = task->GetSlave();
74  }
75  if (slave) {
76  TGo4Log::Debug(" TaskHandlerAbortException for slave %s ... ", taskname);
77  if (slave->IsServer()) {
78  // note: we need a local command here (executed in local thread),
79  // since this is running inside thread of taskhandler to be deleted!
80  TGo4ComRemoveClient *removecommand = new TGo4ComRemoveClient;
81  // removecommand->SetClient("currentclient");
82  removecommand->SetClient(taskname);
83  removecommand->SetWaitForClient(kFALSE);
84  TGo4Log::Debug(" TaskHandlerAbortException on slave server: revoming client %s", taskname);
85  task->SubmitCommand(removecommand);
86  } else {
87  TGo4Log::Debug(" TaskHandlerAbortException: Terminating slave...");
88  fxThreadManager->SetBeingQuit(kTRUE); // flag for the application that we expect to be quit soon
89  TGo4Log::Debug(" TaskHandlerAbortException set the being quit");
90  slave->TerminateFast();
91  }
92  } else if (master) {
93  TGo4Log::Debug(" TaskHandlerAbortException: Removing current slave... ");
94  // note: we need a local command here (executed in local thread), since
95  // this is running inside thread of taskhandler to be deleted!
97  discommand->SetSlave("currentclient");
98  discommand->SetWaitForSlave(kFALSE);
99  TGo4Log::Debug(" TaskHandlerAbortException: Disconnecting current slave");
100  task->SubmitCommand(discommand);
101  } else if (task) {
102  // no master, no slave: old style connection, test client and server role
103  if (fxTaskHandler->IsClientMode()) {
104  // exception was raised by client task handler
105  TGo4Log::Debug(" TaskHandlerAbortException: Quit client %s ... ", taskname);
106  fxThreadManager->SetBeingQuit(kTRUE); // flag for the application that we expect to be quit soon
107  task->TerminateFast();
108  } else {
109  // exception was raised by server task handler
110  TGo4ComRemoveClient *removecommand = new TGo4ComRemoveClient;
111  removecommand->SetClient(taskname);
112  removecommand->SetWaitForClient(kFALSE);
113  TGo4Log::Debug(" TaskHandlerAbortException: Disconnecting client %s ... ", taskname);
114  task->SubmitCommand(removecommand);
115  // we cannot remove our own thread, so use local command thread
116  } // if (fxTaskHandler->IsClientMode())
117  } else {
118  // no task: something is very wrong!
119  gApplication->Terminate();
120  }
121  return 0;
122 }
TGo4Thread * GetThread() const
Definition: TGo4Runnable.h:44
TGo4ThreadManager * fxThreadManager
void SetWaitForClient(Bool_t wait=kTRUE)
virtual void TerminateFast()
Definition: TGo4Slave.cxx:92
Bool_t Stop()
Definition: TGo4Thread.cxx:287
void SetAborting(Bool_t isaborting=kTRUE)
void TerminateFast() override
Definition: TGo4Task.cxx:138
Bool_t IsClientMode() const
static void Debug(const char *text,...) GO4_PRINTF_ARGS
Definition: TGo4Log.cxx:281
Bool_t SubmitCommand(const char *name)
Definition: TGo4Task.cxx:409
Bool_t IsServer() const
Definition: TGo4TaskOwner.h:40
Bool_t IsAborting() const
TGo4TaskHandlerRunnable * fxCaller
TGo4Slave * GetSlave() const
Definition: TGo4Task.h:259
void SetWaitForSlave(Bool_t wait=kTRUE)
void SetClient(const char *name)
void SetSlave(const char *name)
void SetBeingQuit(Bool_t on)
TString fxDescription
Definition: TGo4Exception.h:38
TGo4Master * GetMaster() const
Definition: TGo4Task.h:257