GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4TaskHandlerAbortException.cxx
Go to the documentation of this file.
1 // $Id: TGo4TaskHandlerAbortException.cxx 2757 2020-04-16 11:45:21Z linev $
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  {
47  // we know the calling thread, stop it!
48  fxCaller->GetThread()->Stop();
49  }
50  else
51  {
52  // no caller specified, continue
53  }
54 
56  {
57  // a concurrent exception is already performing, we do nothing
58  TGo4Log::Debug(" TaskHandlerAbortException: taskhandler is already aborting ");
59  return 0;
60  }
61  else
62  {
63  // just go on with the show
64  fxTaskHandler->SetAborting(kTRUE);
65  } // if (fxTaskHandler->IsAborting())
66 
67  if (fxThreadManager==0)
68  {
69  // error
70  fxTaskHandler->SetAborting(kFALSE);
71  return -1;
72  }
73  else
74  {
75  // continue
76  } // if (fxThreadManager==0)
77 
78  const char* taskname = fxTaskHandler->GetName();
79  TGo4Master* master=0;
80  TGo4Slave* slave=0;
81  TGo4Task* task = dynamic_cast<TGo4Task*> (fxThreadManager);
82  if(task)
83  {
84  master=task->GetMaster();
85  slave=task->GetSlave();
86  }
87  if(slave)
88  {
89  TGo4Log::Debug(" TaskHandlerAbortException for slave %s ... ",taskname);
90  if(slave->IsServer())
91  {
92  // note: we need a local command here (executed in local thread),
93  // since this is running inside thread of taskhandler to be deleted!
94  TGo4ComRemoveClient* removecommand = new TGo4ComRemoveClient;
95  //removecommand->SetClient("currentclient");
96  removecommand->SetClient(taskname);
97  removecommand->SetWaitForClient(kFALSE);
98  TGo4Log::Debug(" TaskHandlerAbortException on slave server: revoming client %s",taskname);
99  task->SubmitCommand(removecommand);
100  }
101  else
102  {
103  TGo4Log::Debug(" TaskHandlerAbortException: Terminating slave...");
104  fxThreadManager->SetBeingQuit(kTRUE); // flag for the application that we expect to be quit soon
105  TGo4Log::Debug(" TaskHandlerAbortException set the being quit");
106  slave->TerminateFast();
107  }
108  }
109  else if(master)
110  {
111  TGo4Log::Debug(" TaskHandlerAbortException: Removing current slave... ");
112  // note: we need a local command here (executed in local thread), since
113  // this is running inside thread of taskhandler to be deleted!
115  discommand->SetSlave("currentclient");
116  discommand->SetWaitForSlave(kFALSE);
117  TGo4Log::Debug(" TaskHandlerAbortException: Disconnecting current slave");
118  task->SubmitCommand(discommand);
119  }
120  else if(task)
121  {
122  // no master, no slave: old style connection, test client and server role
124  {
125  // exception was raised by client task handler
126  TGo4Log::Debug(" TaskHandlerAbortException: Quit client %s ... ",taskname);
127  fxThreadManager->SetBeingQuit(kTRUE); // flag for the application that we expect to be quit soon
128  task->TerminateFast();
129  }
130  else
131  {
132  // exception was raised by server task handler
133  TGo4ComRemoveClient* removecommand = new TGo4ComRemoveClient;
134  removecommand->SetClient(taskname);
135  removecommand->SetWaitForClient(kFALSE);
136  TGo4Log::Debug(" TaskHandlerAbortException: Disconnecting client %s ... ",taskname);
137  task->SubmitCommand(removecommand);
138  // we cannot remove our own thread, so use local command thread
139  } // if (fxTaskHandler->IsClientMode())
140  }
141  else
142  {
143  // no task: something is very wrong!
144  gApplication->Terminate();
145  }
146  return 0;
147 }
148 
TGo4ThreadManager * fxThreadManager
void SetWaitForClient(Bool_t wait=kTRUE)
virtual void TerminateFast()
Definition: TGo4Slave.cxx:95
Bool_t Stop()
Definition: TGo4Thread.cxx:328
TGo4Thread * GetThread() const
Definition: TGo4Runnable.h:45
Bool_t IsAborting() const
Bool_t IsClientMode() const
void SetAborting(Bool_t isaborting=kTRUE)
virtual void TerminateFast()
Definition: TGo4Task.cxx:139
Bool_t IsServer()
Definition: TGo4TaskOwner.h:39
TGo4Slave * GetSlave()
Definition: TGo4Task.h:255
Bool_t SubmitCommand(const char *name)
Definition: TGo4Task.cxx:423
TGo4Master * GetMaster()
Definition: TGo4Task.h:253
TGo4TaskHandlerRunnable * fxCaller
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
static void Debug(const char *text,...)
Definition: TGo4Log.cxx:284