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