17#include "TApplication.h"
22#include "TGo4LockGuard.h"
49 UInt_t negotiationport,
55 :
TGo4Task(name,blockingmode, autostart,autocreate,ismaster),
63 TString nomen(
"TaskManager of "); nomen += name;
66 if(negotiationport!=42)
69 nomen.Form(
"ConnectorRunnable of %s", name);
71 nomen.Form(
"CONNECTOR-%s", name);
104 if(name && strstr(name,
"current"))
111 TGo4Log::Debug(
" ServerTask -- RemoveClient FAILED, no client %s !!! ",
132 TGo4Log::Debug(
" Server Task -- Waiting for client %s disconnection...",taskhandler->GetName());
140 TGo4Log::Debug(
" !!! Server Task -- client remove wait TIMEOUT !!! ");
141 rev=
fxTaskManager->DisConnectClient(taskhandler->GetName(),kFALSE);
146 TGo4Log::Debug(
" !!! Server Task -- client remove aborted for TERMINATION MODE !!! ");
152 TGo4Log::Debug(
" Server Task -- waited %d cycles until client was removed. ",removeresult);
161 TGo4Log::Debug(
" !!! Server Task -- removing client %s without waiting... ",
162 taskhandler->GetName());
164 rev= (
fxTaskManager->DisConnectClient(taskhandler->GetName(),kFALSE) == 0);
176 Bool_t reset = kTRUE;
177 while (
auto taskhandler =
fxTaskManager->NextTaskHandler(reset)) {
179 names.AddLast(
new TNamed(taskhandler->GetName(),
"title"));
182 while (
auto nomen = niter()) {
198 TGo4Log::Debug(
" Server task -- removing current client %s ", taskhandler->GetName());
210 TGo4Log::Debug(
" TGo4ServerTask ''%s'' ERROR- task manager not existing!!! ", GetName());
234 TGo4Log::Debug(
" ServerTask: FAILED setting current task to %s-- no such client! ", name);
434 if(!name || strstr(name,
"current"))
460 if(!name || strstr(name,
"current"))
474 Bool_t reset = kTRUE;
503 Bool_t reset = kTRUE;
508 TGo4Log::Debug(
" Task - sending status %s to task %s", stat->ClassName(), han->GetName());
509 statq->AddBufferFromObject(stat);
523 TGo4Log::Debug(
" Task - sending status buffer to task %s", han->GetName());
537 const char *host = gSystem->HostName();
540 connector->
Open(host,negotiationport);
556 TGo4Log::Debug(
" ServerTask Quit -- removing all connected clients ");
557 SendStatusMessage(2,kTRUE,
"ServerTask %s is shutting down now! All clients are removed...",GetName());
577 TGo4Log::Debug(
" ServerTask Shutdown without disconnect waiting");
578 SendStatusMessage(2,kTRUE,
"ServerTask %s is shutting down now! All clients are removed...",GetName());
591 slave->SetTask(
nullptr, kFALSE);
596 gApplication->Terminate();
Class containing a pointer queue for TBuffers.
void AddBuffer(TBuffer *buffer, Bool_t clone=kFALSE)
Add buffer pointer to queue.
TObject * WaitObjectFromBuffer()
Wait for buffer object from queue.
static TGo4CommandInvoker * Instance()
static void UnRegister(TGo4CommandReceiver *p)
static void Register(const char *name, TGo4CommandReceiver *p)
This is the Go4 Abstract Command Class; part of the Base command pattern.
void SetMode(Go4CommandMode_t m)
void SetTaskName(const char *)
Runnable to handle connection request from a new client which connects to a listening Transport chann...
static void Debug(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 0.
static const UInt_t fguCONNECTWAITCYCLETIME
time for each connect wait cycle
Bool_t fbKeepServerSocket
True if open in server mode shall keep the server socket instance.
Bool_t RemoveCurrentClient()
removes the currently active client from server (disconnect)
static const UInt_t fguCLOSEWAITCYCLETIME
time for each close wait cycle
void SendStatus(TGo4Status *stat, const char *receiver=nullptr) override
Send status object via status channel to the master.
Bool_t ConnectorThreadIsStopped()
Returns the waiting state fbIsWaiting of the Connector Thread;.
TGo4Command * NextCommand() override
Delivers next command.
const char * GetConnectorName() const
TGo4ServerTask(const char *name, UInt_t negotiationport=0, Bool_t blockingmode=kFALSE, Bool_t standalone=kFALSE, Bool_t autostart=kTRUE, Bool_t autocreate=kTRUE, Bool_t ismaster=kTRUE)
virtual Bool_t StartConnectorThread()
starts the thread that listens to the connector port for a client negotiation request; used after lau...
virtual ~TGo4ServerTask()
TGo4TaskHandler * GetCurrentTaskHandler()
Get task handler of the currently activated client connection.
void SendStatusBuffer() override
Send internal status buffer to the master(s).
static const UInt_t fguCONNECTTIMERPERIOD
period of task connector timer
TGo4BufferQueue * GetStatusQueue(const char *task=nullptr) override
void SetCurrentTask(const char *name)
sets current client task (i.e.
TGo4Socket * GetConnectTransport()
TGo4TaskManager * fxTaskManager
aggregationByValue 1
virtual Int_t TimerConnect()
this method is used by the connectortimer Notify to connect or disconnect a transportchannel (TSocket...
TGo4Socket * fxDisConnectTransport
link to the next TaskHandler transport instance that shall be disconnected by the Application Control...
static const Int_t fgiOPENWAITCYCLES
maximum cycles to wait until transport is open
virtual Int_t RemoveAllClients(Bool_t force=false)
Remove all connected client task from this server.
static const char * Get_fgcLAUNCHPREFSFILE()
UInt_t fuConnectPort
port number for timer connect
static const UInt_t fguOPENWAITCYCLETIME
time for each open wait cycle
TGo4BufferQueue * GetCommandQueue(const char *task=nullptr) override
Bool_t fbConnectIsClose
True if fxConnectTransport has returned from Close(), i.e.
static const char * fgcLAUNCHPREFSFILE
Name of the Preferences file for the client startup.
Bool_t fbConnectIsOpen
True if fxConnectTransport waits in server Open() call.
Int_t WaitForConnection()
Bool_t fbDisConnectRequest
True if fxConnectTransport shall be Close() by AppControlTimer.
void Quit() override
Quit method used by quit command; may be overridden in special application.
Bool_t fbConnectRequest
True if fxConnectTransport shall be Open() by AppControlTimer.
TGo4TaskManager * GetTaskManager()
Bool_t fbConnectIsDone
True if fxConnectTransport has returned from Open(), i.e.
const char * GetConnectHost() const
void SetConnect(TGo4Socket *trans, const char *host, UInt_t port, Bool_t keepserv=kFALSE)
static const Int_t fgiCLOSEWAITCYCLES
maximum cycles to wait until transport is closed
TString fxConnectHost
hostname for timer connect
TGo4BufferQueue * GetDataQueue(const char *task=nullptr) override
void Shutdown()
Fast Quit() without waiting for proper disconnection.
TGo4TaskHandler * fxCurrentTaskHandler
1
virtual Bool_t StopConnectorThread()
stops the thread that listens to the connector port for a client negotiation request; used before lau...
TString fxConnectorName
remember name of connector thread
TGo4Socket * fxConnectTransport
link to the next TaskHandler transport instance that shall be connected by the Application Control Ti...
static const Int_t fgiCONNECTWAITCYCLES
maximum cycles to wait until transport is connected
TGo4TaskConnectorTimer * fxConnectorTimer
timer responsible for the connection/disconnection of clients; independent of application control tim...
void SetDisConnect(TGo4Socket *trans)
virtual Bool_t RemoveClient(const char *name, Bool_t clientwait=kTRUE, Bool_t isterminating=kFALSE)
Remove the client task specified by name from this server.
TGo4TaskHandler * GetTaskHandler() override
Get task handler for client specified by name.
virtual Int_t Send(TObject *obj)
virtual Int_t Close(Option_t *opt="")
virtual Int_t Open(const char *host, Int_t port, Bool_t keepservsock=kFALSE)
timer aggregated to the servertask which is responsible to open and handle the negotiation requests o...
This class is responsible for the interconnection of two tasks: provided are three communication chan...
static const char * Get_fgcERROR()
TGo4Queue * GetStatusQueue() const
TGo4Queue * GetDataQueue() const
TGo4Queue * GetCommandQueue() const
virtual Int_t StopWorkThreads()
stop the working threads of the task implementation; this method is used before the current connectio...
static Int_t Get_fgiTERMID()
TGo4Task(const char *name, Bool_t blockingmode, Bool_t autostart=kFALSE, Bool_t autocreate=kTRUE, Bool_t ismaster=kFALSE)
Bool_t SubmitEmergencyCommand(Go4EmergencyCommand_t val)
send emergency quit command to the current client task
void SendStopBuffers(const char *taskname=nullptr)
Send message buffers with stop values into queues and via socket connections.
void Terminate(Bool_t termapp=kTRUE) override
deletes the Manager instance via Control timer.
virtual void SendStatus(TGo4Status *stat, const char *receiver=nullptr)
Send status object via status channel to the master.
void SendStatusMessage(Int_t level, Bool_t printout, const char *text,...)
Send message string in a status object to the gui.
TBuffer * fxStatusBuffer
Buffer containing the analysis status which is updated by the main thread.
Bool_t SubmitEmergencyData(Go4EmergencyCommand_t val, const char *receiver=nullptr)
Send emergency command via data channel.
TGo4Slave * GetSlave() const
virtual Int_t StartWorkThreads()
start the working threads of the task implementation; this method is used after the current connectio...
TMutex * fxStatusMutex
Mutex protecting status buffer between main and watch thread.
Bool_t IsWorkStopped() const
void WakeCommandQueue(Int_t id=0)
Put dummy object into command queue to wake up user threads which might wait for a command.
TGo4Thread * GetThread(const char *name)
Access to Go4Thread by name.
Int_t CancelAll()
Cancel all Threads in the thread list.
Bool_t Start(const char *thname)
Starts work function of the Go4 Thread of name 'name'.
Bool_t Stop(const char *thname)
Stops work function of the Go4 Thread of name 'name'.
TGo4ThreadHandler * fxWorkHandler
Thread handler aggregate (threadsafe list of go4 threads) aggregationByValue 1 1.
Bool_t IsTerminating() const
returns termination status of Threadmanager
TGo4ThreadHandler * GetWorkHandler() const
Access to ThreadHandler for working threads.
void Launch()
This Method has to be called to create the startup threads and to turn on the application control tim...
Bool_t IsWaiting() const
true if Threadfunc is suspended to condition wait
static void Sleep(UInt_t millisecs)
wrapper for gSystem->Sleep with consecutive TThread::CancelPoint - necessary for proper pthread termi...