GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
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"
26
28: TGo4TaskHandlerException(taskhandler)
29{
30 fxDescription= "!!!-- Go4 TaskHandler Abort Exception --!!!";
31}
32
38
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}
master command: current slave is removed (disconnected) from server
void SetWaitForSlave(Bool_t wait=kTRUE)
void SetSlave(const char *name)
Specify the name of the client to be removed.
server command: current client is removed (disconnected) from server
void SetWaitForClient(Bool_t wait=kTRUE)
void SetClient(const char *name)
Specify the name of the client to be removed.
TString fxDescription
static void Debug(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 0.
Definition TGo4Log.cxx:281
Master.
Definition TGo4Master.h:27
Baseclass for all slave process entities.
Definition TGo4Slave.h:33
virtual void TerminateFast()
Definition TGo4Slave.cxx:92
Int_t Handle() override
This is a default handler function for the respective exception type.
TGo4TaskHandlerRunnable * fxCaller
This is the abstract interface for all runnables associated with the taskhandler class.
This class is responsible for the interconnection of two tasks: provided are three communication chan...
Bool_t IsServer() const
Go4 Task.
Definition TGo4Task.h:39
Bool_t SubmitCommand(const char *name)
send command specified by name to the current client task
Definition TGo4Task.cxx:409
TGo4Slave * GetSlave() const
Definition TGo4Task.h:263
void TerminateFast() override
Overwrites the Threadmanager TerminateFast to shutdown the objectserver properly.
Definition TGo4Task.cxx:138
TGo4Master * GetMaster() const
Definition TGo4Task.h:261