Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4ServerTask.cxx

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 #include "TGo4ServerTask.h"
00017 
00018 #include "Riostream.h"
00019 
00020 #include "TMutex.h"
00021 #include "TApplication.h"
00022 #include "TObjArray.h"
00023 #include "snprintf.h"
00024 
00025 #include "TGo4Log.h"
00026 #include "TGo4LockGuard.h"
00027 #include "TGo4Socket.h"
00028 #include "TGo4BufferQueue.h"
00029 #include "TGo4Thread.h"
00030 #include "TGo4ThreadHandler.h"
00031 #include "TGo4Status.h"
00032 #include "TGo4CommandInvoker.h"
00033 #include "TGo4TaskManager.h"
00034 #include "TGo4TaskHandler.h"
00035 #include "TGo4ConnectorRunnable.h"
00036 #include "TGo4Master.h"
00037 #include "TGo4Slave.h"
00038 #include "TGo4TaskConnectorTimer.h"
00039 
00040 
00041 const Int_t TGo4ServerTask::fgiOPENWAITCYCLES=100; // wait cycles (100)
00042 const UInt_t TGo4ServerTask::fguOPENWAITCYCLETIME=100; // time in ms (20)
00043 const Int_t TGo4ServerTask::fgiCLOSEWAITCYCLES=100; // wait cycles (100)
00044 const UInt_t TGo4ServerTask::fguCLOSEWAITCYCLETIME=100; // time in ms (20)
00045 const Int_t TGo4ServerTask::fgiCONNECTWAITCYCLES=20; // wait cycles (20)
00046 const UInt_t TGo4ServerTask::fguCONNECTWAITCYCLETIME=200; // time in ms (200)
00047 const UInt_t TGo4ServerTask::fguCONNECTTIMERPERIOD=100; // time in ms (50)
00048 
00049 
00050 const char* TGo4ServerTask::fgcLAUNCHPREFSFILE = "etc/Go4LaunchClientPrefs.txt";
00051 
00052 
00053 TGo4ServerTask::TGo4ServerTask(const char* name,
00054                                UInt_t negotiationport,
00055                                Bool_t blockingmode,
00056                                Bool_t standalone,
00057                                Bool_t autostart,
00058                                Bool_t autocreate,
00059                                Bool_t ismaster)
00060    : TGo4Task(name,blockingmode, autostart,autocreate,ismaster),
00061    fxTaskManager(0),fxCurrentTaskHandler(0),
00062    fxConnectTransport(0), fxDisConnectTransport(0),
00063    fuConnectPort(0), fbKeepServerSocket(kFALSE),
00064    fbConnectRequest(kFALSE), fbDisConnectRequest(kFALSE),
00065    fbConnectIsOpen(kFALSE),fbConnectIsDone(kFALSE), fbConnectIsClose(kFALSE),
00066    fxConnectorTimer(0)
00067 {
00068    TString nomen("TaskManager of "); nomen += name;
00069    fxTaskManager= new TGo4TaskManager(nomen.Data(), this, negotiationport);
00070 
00071    if(negotiationport!=42)
00072       {
00073          // connector runnable:
00074          nomen.Form("ConnectorRunnable of %s", name);
00075          TGo4ConnectorRunnable* conny = new TGo4ConnectorRunnable(nomen.Data(),this);
00076          nomen.Form("CONNECTOR-%s", name);
00077          fxConnectorName=nomen;
00078          fxWorkHandler->NewThread(GetConnectorName(), conny);
00079       }
00080       else  {} // do not start connector port in local mode <- nameservice problems without wan!
00081 
00082    TGo4CommandInvoker::Instance(); // make sure a command invoker exists
00083    TGo4CommandInvoker::Register("ServerTask", this);
00084    fxConnectorTimer= new TGo4TaskConnectorTimer(this,fguCONNECTTIMERPERIOD);
00085    fxConnectorTimer->TurnOn();
00086    if(standalone)
00087       {
00088          Launch(); // create threads, start application control timer
00089       }
00090    else
00091       {
00092          // subclass must call Launch at end of its ctor
00093       }
00094 }
00095 
00096 
00097 TGo4ServerTask::~TGo4ServerTask()
00098 {
00099    if (GetWorkHandler()) GetWorkHandler()->CancelAll();
00100    delete fxConnectorTimer;
00101    delete fxTaskManager;
00102    TGo4CommandInvoker::UnRegister(this);
00103 }
00104 
00105 Bool_t TGo4ServerTask::RemoveClient(const char* name, Bool_t clientwait, Bool_t isterminating)
00106 {
00107    Bool_t rev=kTRUE;
00108    TGo4TaskHandler* taskhandler=0;
00109    if(name && strstr(name,"current"))
00110       taskhandler=GetCurrentTaskHandler();
00111    else
00112       taskhandler=GetTaskHandler(name);
00113    if(taskhandler==0)
00114       {
00115          // no such taskhandler for name
00116          TGo4Log::Debug(" ServerTask -- RemoveClient FAILED, no client %s !!! ",
00117                   name);
00118          rev=kFALSE;
00119       }
00120    else // if(taskhandler==0)
00121       {
00122        TGo4Log::Debug(" ServerTask -- removing client task %s ",name);
00123        // first stop all user threads waiting on or writing into the data queues
00124       StopWorkThreads();
00125       if(clientwait)
00126          {
00127          // normal mode: handshake with client to be removed
00128 
00129             // send quit command to client, client will send dummy objects back
00130             // to release waiting sockets
00131             // then client will request a disconnect action from the connector runnable
00132             if(IsMaster())
00133                SubmitEmergencyCommand(kComQuit); // master quits client when removing
00134             else
00135                SubmitEmergencyData(kComQuit, taskhandler->GetName()); // client data runnable must handle quit request of server!
00136             TGo4Log::Debug(" Server Task --  Waiting for client %s disconnection...",taskhandler->GetName());
00137             Int_t removeresult=fxTaskManager->WaitForClientRemoved();
00138                            // disconnection is done by connector
00139                            // thread using task manager methods
00140             switch(removeresult)
00141                {
00142                case -1:
00143                   // timeout
00144                   TGo4Log::Debug(" !!! Server Task -- client remove wait TIMEOUT !!!  ");
00145                   rev=fxTaskManager->DisConnectClient(taskhandler->GetName(),kFALSE); // do not wait for client ok
00146                   break;
00147 
00148                case -2:
00149                   // we are terminating the server
00150                   TGo4Log::Debug(" !!! Server Task -- client remove aborted for TERMINATION MODE !!!  ");
00151                   rev=kFALSE;
00152                   break;
00153 
00154                default:
00155                   // all right
00156                   TGo4Log::Debug(" Server Task -- waited %d cycles until client was removed. ",removeresult);
00157                   rev=kTRUE;
00158                   break;
00159 
00160                      }
00161          } // if(clientwait)
00162       else
00163          {
00164          // no communication with client, just disconnect without waiting
00165          TGo4Log::Debug(" !!! Server Task -- removing client %s without waiting...  ",
00166                                     taskhandler->GetName());
00167          SendStopBuffers(taskhandler->GetName());
00168          rev= (fxTaskManager->DisConnectClient(taskhandler->GetName(),kFALSE)==0); // do not wait
00169          }
00170       if(!isterminating) StartWorkThreads();
00171    } // else if(taskhandler==0)
00172    return rev;
00173 }
00174 
00175 Int_t TGo4ServerTask::RemoveAllClients(Bool_t force)
00176 {
00177    Int_t rev=0; // return value is number of removed clients
00178    //cout <<"TTTTTTTT TGo4ServerTask::RemoveAllClients" << endl;
00180    TGo4TaskHandler* taskhandler=0;
00181    TObjArray names;
00182    Bool_t reset=kTRUE;
00183    while((taskhandler=fxTaskManager->NextTaskHandler(reset)) !=0)
00184       {
00185          reset=kFALSE;
00186          //cout <<"adding name "<<taskhandler->GetName() << endl;
00187          names.AddLast(new TNamed(taskhandler->GetName(), "title"));
00188       }
00189    TIter niter(&names);
00190    TObject* nomen=0;
00191    while((nomen =niter.Next()) !=0)
00192       {
00193          //cout <<"removing th "<<nomen->GetName() << endl;
00194          RemoveClient(nomen->GetName(),!force,kTRUE);
00195          rev++;
00196       }
00197    names.Delete();
00198    // end iteration
00199    return rev;
00200 }
00201 
00202 
00203 Bool_t TGo4ServerTask::RemoveCurrentClient()
00204 {
00205    Bool_t rev=kTRUE;
00206    TGo4TaskHandler* taskhandler=GetCurrentTaskHandler();
00207    if(taskhandler!=0)
00208       {
00209          // we have a current client, remove it
00210          TGo4Log::Debug(" Server task -- removing current client %s ",taskhandler->GetName());
00211          rev = RemoveClient(taskhandler->GetName());
00212       }
00213    else
00214       {
00215          rev=kFALSE;
00216       }
00217    return rev;
00218 }
00219 
00220 void TGo4ServerTask::SetCurrentTask(const char* name)
00221 {
00222    //cout <<"server task setting current task to "<<name << endl;
00223    TGo4TaskHandler* han=0;
00224    if(fxTaskManager==0)
00225       {
00226          TGo4Log::Debug(" TGo4ServerTask ''%s'' ERROR- task manager not existing!!! ");
00227       }
00228    else
00229       {
00230          // first stop all user threads waiting on or writing into the data queues
00231          if(IsWorkStopped())
00232             {
00233                // Working threads have already been stopped
00234                // maybe by RemoveClient method.
00235                // We do nothing, since the current taskhandler is not
00236                // reset yet and any access to current task in the derived
00237                // _user_ method would crash the program!
00238             }
00239          else // if(IsWorkStopped())
00240             {
00241                // work has not been stopped, we do that
00242                StopWorkThreads();
00243             } // else if(fbWorkIsStopped)
00244       {
00245            if(name==0)
00246                {
00247                   // zero name given, set pointer to last handler still in list
00248                      fxCurrentTaskHandler=fxTaskManager->GetLastTaskHandler();
00249                      //cout << "**** set current th from get lastth:"<< fxCurrentTaskHandler <<endl;
00250                }
00251             else // if(name==0)
00252                {
00253                // name specified, search for it
00254                han=fxTaskManager->GetTaskHandler(name);
00255                if(han)
00256                   {
00257                      fxCurrentTaskHandler=han;
00258                      //cout << "**** set current th from name:"<< fxCurrentTaskHandler <<endl;
00259                   }
00260                else // if(han)
00261                   {
00262                       TGo4Log::Debug(" ServerTask: FAILED setting current task to %s-- no such client! ",name);
00263                   } // else if(han)
00264                } // else if(name==0)
00265 
00266       } // TGo4LockGuard
00267        // finally, start user threads again
00268          StartWorkThreads();
00269       } // else if(fxTaskManager==0)
00270 }
00271 
00272 
00273 TGo4TaskHandler* TGo4ServerTask::GetTaskHandler(const char* name)
00274 {
00275    return (fxTaskManager->GetTaskHandler(name));
00276 }
00277 
00278 TGo4TaskHandler* TGo4ServerTask::GetTaskHandler()
00279 {
00280    return (GetCurrentTaskHandler());
00281 }
00282 
00283 TGo4TaskHandler* TGo4ServerTask::GetCurrentTaskHandler()
00284 {
00285    return fxCurrentTaskHandler;
00286 }
00287 
00288 TGo4TaskManager* TGo4ServerTask::GetTaskManager()
00289 {
00290    return fxTaskManager;
00291 }
00292 
00293 void TGo4ServerTask::SetConnect(TGo4Socket * trans, const char* host, UInt_t port, Bool_t keepserv)
00294 {
00295    fxConnectTransport=trans;
00296    fxConnectHost=host;
00297    fuConnectPort=port;
00298    fbConnectRequest=kTRUE;
00299    fbKeepServerSocket=keepserv;
00300 }
00301 
00302 void TGo4ServerTask::SetDisConnect(TGo4Socket * trans)
00303 {
00304    fxDisConnectTransport=trans;
00305    fbDisConnectRequest=kTRUE;
00306 }
00307 
00308 Int_t TGo4ServerTask::TimerConnect()
00309 {
00310    Int_t rev=0;
00313    if(fbDisConnectRequest)
00314       {
00315          if(fxDisConnectTransport!=0)
00316             {
00317                // we have a transport instance to disconnect
00318                fxDisConnectTransport->Close();
00319                //delete fxDisConnectTransport; // new
00320                //cout << "++++++++Timer closed transport"<<endl;
00321                fbConnectIsClose=kTRUE;
00322                fbDisConnectRequest=kFALSE; // we served the request, reset it
00323             rev+=1;
00324             }
00325          else
00326             {
00327                // error, zero pointer given
00328                rev+=32;
00329             }
00330       }
00331    else 
00332       {
00333          // no open request, continue
00334          rev+=2;
00335       }
00336 
00339    if(fbConnectRequest)
00340       {
00341          // timer shall open a transport as server
00342       if(fxConnectTransport!=0)
00343          {
00344 
00345             if(!fxConnectTransport->IsOpen())
00346                {
00347                   // transport is not open, so do it
00348 //                  cout << "++++++++Timer will open transport"<<endl;
00349                   fbConnectIsOpen=kTRUE; // tell connector thread that we try to open
00350                   Int_t result=fxConnectTransport->Open(GetConnectHost(), fuConnectPort, fbKeepServerSocket);
00351                   if(result==0)
00352                      {
00353                         fbConnectIsDone=kTRUE; // tell connector thread we returned from open
00354                         fbConnectRequest=kFALSE; // we served the request, reset it
00355                         fbKeepServerSocket=kFALSE; // reset keep server socket flag
00356                         rev+=4;
00357                      }
00358                   else
00359                      {
00360                         rev=-4;
00361                         // open was not finished, we poll once again...
00362                      }
00363                }
00364             else
00365                {
00366                   // transport was already open
00367 //                  cout <<"OOOOOOOOOOOO TimerConnect transport already open!" << endl;
00368                   fbConnectIsOpen=kTRUE;
00369                   fbConnectIsDone=kTRUE; // tell connector thread we returned from open
00370                   fbConnectRequest=kFALSE; // we served the request, reset it
00371                   fbKeepServerSocket=kFALSE; // reset keep server socket flag
00372                   rev+=8;
00373                }
00374          } // if(fxConnectTransport!=0)
00375       else
00376          {
00377                rev+=64;
00378                // no Transport specified: create raw server for negotiation port
00379                //fxConnectTransport=new TGo4Socket("Server",3);
00380                //cout << "(((((( timer created new raw server transport"<<endl;
00381          }
00382       } 
00383    else
00384       {
00385          // no open request, continue
00386          rev+=16;
00387       }
00388    return rev;
00389 }
00390 
00391 Int_t TGo4ServerTask::WaitForOpen()
00392 {
00393    Int_t count=0;
00394    while(!fbConnectIsOpen)
00395       {
00396          if(count>TGo4ServerTask::fgiOPENWAITCYCLES)
00397             {
00398                count = -1; // timeout
00399                break;
00400             }
00401          else
00402             {
00403             TGo4Thread::Sleep(TGo4ServerTask::fguOPENWAITCYCLETIME);
00404             ++count;
00405             }
00406 //      cout << "*****WaitForOpen()"<<endl;
00407       }
00408    fbConnectIsOpen=kFALSE; //  reset for next time
00409    return count;
00410 }
00411 
00412 
00413 Int_t TGo4ServerTask::WaitForClose()
00414 {
00415    Int_t count=0;
00416    while(!fbConnectIsClose)
00417       {
00418           if(count>TGo4ServerTask::fgiCLOSEWAITCYCLES)
00419             {
00420                count = -1; // timeout
00421                break;
00422             }
00423          else
00424             {
00425                TGo4Thread::Sleep(TGo4ServerTask::fguCLOSEWAITCYCLETIME);
00426                ++count;
00427          }
00428       //cout << "*****WaitForClose() "<<count<< endl;
00429       }
00430    fbConnectIsClose=kFALSE; //  reset for next time
00431    return count;
00432 }
00433 
00434 Int_t TGo4ServerTask::WaitForConnection()
00435 {
00436    Int_t count=0;
00437    while(!fbConnectIsDone)
00438       {
00439          if(IsTerminating())
00440             {
00441                count = -2; // termination mode
00442                break;
00443             }
00444 // timeout would affect the permanent connector port Open , we skip this
00445 //         else if(count>TGo4ServerTask::fgiCONNECTWAITCYCLES)
00446 //            {
00447 //               count = -1; // timeout
00448 //               break;
00449 //            }
00450          else
00451             {
00452                TGo4Thread::Sleep(TGo4ServerTask::fguCONNECTWAITCYCLETIME);
00453                ++count;
00454             }
00455 //         cout << "*****WaitForConnection()"<<endl;
00456       }
00457    fbConnectIsDone=kFALSE; //  reset for next time
00458    return count;
00459 }
00460 
00461 TGo4Socket* TGo4ServerTask::GetConnectTransport()
00462 {
00463    return fxConnectTransport;
00464 }
00465 
00466 TGo4BufferQueue* TGo4ServerTask::GetCommandQueue(const char* name)
00467 {
00468    TGo4BufferQueue* queue=0;
00469    TGo4TaskHandler* currenttask=0;
00470    if(name==0 || strstr(name,"current"))
00471       currenttask=GetCurrentTaskHandler(); // find out the current client
00472    else
00473       currenttask=GetTaskHandler(name); // find out destination client by name
00474    if(currenttask)
00475          queue=dynamic_cast<TGo4BufferQueue*> (currenttask->GetCommandQueue());
00476    return queue;
00477 }
00478 
00479 TGo4BufferQueue * TGo4ServerTask::GetStatusQueue(const char* name)
00480 {
00481    TGo4BufferQueue* queue=0;
00482    TGo4TaskHandler* currenttask=0;
00483    if(name==0)
00484       currenttask=GetCurrentTaskHandler(); // find out the current client
00485    else
00486       currenttask=GetTaskHandler(name); // find out destination client by name
00487    if(currenttask)
00488          queue=dynamic_cast<TGo4BufferQueue*> (currenttask->GetStatusQueue());
00489    return queue;
00490 }
00491 
00492 
00493 TGo4BufferQueue * TGo4ServerTask::GetDataQueue(const char* name)
00494 {
00495    TGo4BufferQueue* queue=0;
00496    TGo4TaskHandler* currenttask=0;
00497    if(name==0 || strstr(name,"current"))
00498       currenttask=GetCurrentTaskHandler(); // find out the current client
00499    else
00500       currenttask=GetTaskHandler(name); // find out destination client by name
00501    if(currenttask)
00502          queue=dynamic_cast<TGo4BufferQueue*> (currenttask->GetDataQueue());
00503    return queue;
00504 
00505 }
00506 
00507 TGo4Command* TGo4ServerTask::NextCommand()
00508 {
00509 if(IsMaster()) return 0;
00510 TGo4Command* com=0;
00511 TGo4TaskHandler* han=0;
00512 Bool_t reset=kTRUE;
00513 TGo4LockGuard taskmutex(fxTaskManager->GetMutex());
00514 while((han=fxTaskManager->NextTaskHandler(reset))!=0)
00515    {
00516        reset=kFALSE;
00517        TGo4BufferQueue * comq=dynamic_cast<TGo4BufferQueue*> (han->GetCommandQueue());
00518        if(comq==0) continue; //NEVER COME HERE!
00519        if(!comq->IsEmpty()) // prevent waiting on queue
00520          {
00521              com= dynamic_cast<TGo4Command*>(comq->WaitObjectFromBuffer());
00522              if(com)
00523                {
00524                   com->SetTaskName(han->GetName());
00525                   com->SetMode(han->GetRole());
00526                   return com;
00527                }
00528          }
00529    } // while
00530 return com;
00531 }
00532 
00533 void TGo4ServerTask::SendStatus(TGo4Status * stat, const char* receiver)
00534 {
00535 if(IsMaster()) return;
00536 if(stat==0) return;
00537 if(receiver!=0)
00538    {
00539       //cout <<"TGo4ServerTask::SendStatus to receiver "<<receiver << endl;
00540       TGo4Task::SendStatus(stat,receiver);
00541    }
00542 else
00543    {
00544       // send status to all
00545       TGo4LockGuard taskmutex(fxTaskManager->GetMutex());
00546       TGo4TaskHandler* han=0;
00547       Bool_t reset=kTRUE;
00548       while((han=fxTaskManager->NextTaskHandler(reset))!=0)
00549          {
00550             reset=kFALSE;
00551             TGo4BufferQueue * statq=dynamic_cast<TGo4BufferQueue*> (han->GetStatusQueue());
00552             if(statq==0) continue; //NEVER COME HERE!
00553             TGo4Log::Debug(" Task - sending status %s to task %s", stat->ClassName(), han->GetName());
00554             statq->AddBufferFromObject(stat);
00555          }// while
00556    } // if(receiver)
00557 }
00558 
00559 void TGo4ServerTask::SendStatusBuffer()
00560 {
00561 if(IsMaster()) return;
00562 //cout << "TGo4ServerTask::SendStatusBuffer() apply for fxStatusMutex"<< endl;
00563 TGo4LockGuard statguard(fxStatusMutex); // do not send during buffer update
00564 //cout << "TGo4ServerTask::SendStatusBuffer() apply for taskmanager mutex"<< endl;
00565 TGo4LockGuard taskmutex(fxTaskManager->GetMutex()); // protect task list
00566 TGo4TaskHandler* han=0;
00567 Bool_t reset=kTRUE;
00568 while((han=fxTaskManager->NextTaskHandler(reset))!=0)
00569    {
00570       reset=kFALSE;
00571       TGo4BufferQueue * statq=dynamic_cast<TGo4BufferQueue*> (han->GetStatusQueue());
00572       if(statq==0) continue; //NEVER COME HERE!
00573       TGo4Log::Debug(" Task - sending status buffer to task %s", han->GetName());
00574       statq->AddBuffer(fxStatusBuffer,kTRUE);
00575    }// while
00576 }
00577 
00578 
00579 
00580 Bool_t TGo4ServerTask::StartConnectorThread()
00581 {
00582    Bool_t rev=kTRUE;
00583    rev= ( GetWorkHandler()->Start( GetConnectorName() ) );
00584       //cout << "ServerTask started connector thread"<<endl;
00585    return rev;
00586 }
00587 
00588 Bool_t TGo4ServerTask::StopConnectorThread()
00589 {
00590    Bool_t rev=kTRUE;
00591    rev= ( GetWorkHandler()->Stop( GetConnectorName() ) ); // unset running flag
00592    // now establish a dummy connection to our own server to release the listen socket:
00593    const char* host = gSystem->HostName();
00594    Int_t negotiationport=fxTaskManager->GetNegotiationPort();
00595    TGo4Socket* connector= new TGo4Socket(kTRUE); // raw socket transport
00596       //cout << "host:"<<host<<" , port:" << negotiationport <<endl;
00597    connector->Open(host,negotiationport); // open connection to server's connector runnable
00598    connector->Send(TGo4TaskHandler::Get_fgcERROR()); // force server to stop
00599    connector->Close();
00600    delete connector;
00601    return rev;
00602 }
00603 
00604 
00605 Bool_t TGo4ServerTask::ConnectorThreadIsStopped()
00606 {
00607    Bool_t rev=kTRUE;
00608    TGo4Thread* conny= GetWorkHandler()->GetThread(GetConnectorName());
00609    rev= conny->IsWaiting();
00610    return rev;
00611 }
00612 
00613 void TGo4ServerTask::Quit()
00614 {
00615    TGo4Log::Debug(" ServerTask Quit -- removing all connected clients ");
00616    SendStatusMessage(2,kTRUE,"ServerTask %s is shutting down now! All clients are removed...",GetName());
00617    RemoveAllClients();
00618    //StopWorkThreads(); // are re-started after last client is removed...
00619    WakeCommandQueue(TGo4Task::Get_fgiTERMID()); // will stop local command thread, and remote
00620    Terminate(!IsMaster()); // terminate only slave server here!
00621 }
00622 
00623 
00624 void TGo4ServerTask::Shutdown()
00625 {
00626    TGo4Log::Debug(" ServerTask Shutdown without disconnect waiting");
00627    SendStatusMessage(2,kTRUE,"ServerTask %s is shutting down now! All clients are removed...",GetName());
00628    TGo4Thread::Sleep(10*fguCONNECTTIMERPERIOD); // wait 1 s to broadcast shutdown message before terminating...
00629    StopWorkThreads();
00630    WakeCommandQueue(TGo4Task::Get_fgiTERMID()); // will stop local command thread, and remote
00631    RemoveAllClients(true);
00632    TGo4Slave* slave=GetSlave();
00633    if(slave)
00634       {
00635          slave->Stop(); // to execute analysis postloop.
00636                         // We are within main thread here, i.e. it never stops before termination!
00637          slave->SetTask(0,kFALSE); // otherwise owner dtor will delete us...
00638          delete slave;   //call dtors of analysis framework
00639          //SetOwner(0);
00640       }
00641    gApplication->Terminate(); // do not wait until appctrl timer terminates us
00642 }
00643 
00644 
00645 void TGo4ServerTask::LockAll()
00646 {
00647 //cout <<"TGo4ServerTask::LockAll" << endl;
00648 
00649 fxStatusMutex->Lock();
00650 //cout <<"TGo4ServerTask::LockAll before taskmutex" << endl;
00651 fxTaskManager->GetMutex()->Lock();
00652 //cout <<"TGo4ServerTask::LockAll before mainmutex" << endl;
00653 TGo4LockGuard::LockMainMutex();
00654 //cout <<"TGo4ServerTask::LockAll leaving" << endl;
00655 
00656 }
00657 
00658 void TGo4ServerTask::UnLockAll()
00659 {
00660 //cout <<"TGo4ServerTask::UnLockAll" << endl;
00661 TGo4LockGuard::UnLockMainMutex();
00662 //cout <<"TGo4ServerTask::UnLockAll after mainmutex" << endl;
00663 fxTaskManager->GetMutex()->UnLock();
00664 //cout <<"TGo4ServerTask::UnLockAll after taskmutex" << endl;
00665 fxStatusMutex->UnLock();
00666 //cout <<"TGo4ServerTask::UnLockAll leaving" << endl;
00667 }
00668 
00669 const char* TGo4ServerTask::Get_fgcLAUNCHPREFSFILE()
00670 {
00671    return fgcLAUNCHPREFSFILE;
00672 }
00673 
00674 
00675 
00676 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:29 2008 for Go4-v3.04-1 by  doxygen 1.4.2