XrdProofdProofServ.h

Go to the documentation of this file.
00001 // @(#)root/proofd:$Id: XrdProofdProofServ.h 31935 2009-12-18 08:03:40Z ganis $
00002 // Author: G. Ganis  June 2005
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_XrdProofdProofServ
00013 #define ROOT_XrdProofdProofServ
00014 
00015 #include <string.h>
00016 #include <unistd.h>
00017 #include <sys/uio.h>
00018 #if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__APPLE__)
00019 #include <sched.h>
00020 #endif
00021 
00022 // #include <list>
00023 // #include <map>
00024 #include <vector>
00025 
00026 #ifdef OLDXRDOUC
00027 #  include "XrdSysToOuc.h"
00028 #  include "XrdOuc/XrdOucPthread.hh"
00029 #  include "XrdOuc/XrdOucSemWait.hh"
00030 #else
00031 #  include "XrdSys/XrdSysPthread.hh"
00032 #  include "XrdSys/XrdSysSemWait.hh"
00033 #endif
00034 
00035 #include "Xrd/XrdLink.hh"
00036 #include "XrdOuc/XrdOucHash.hh"
00037 
00038 #include "XProofProtocol.h"
00039 #include "XrdProofdClient.h"
00040 #include "XrdProofWorker.h"
00041 
00042 //////////////////////////////////////////////////////////////////////////
00043 //                                                                      //
00044 // XrdSrvBuffer                                                         //
00045 //                                                                      //
00046 // Authors: G. Ganis, CERN, 2005                                        //
00047 //                                                                      //
00048 // The following structure is used to store buffers to be sent or       //
00049 // received from clients                                                //
00050 //                                                                      //
00051 //////////////////////////////////////////////////////////////////////////
00052 class XrdSrvBuffer {
00053 public:
00054    int   fSize;
00055    char *fBuff;
00056 
00057    XrdSrvBuffer(char *bp=0, int sz=0, bool dup=0) {
00058       if (dup && bp && sz > 0) {
00059          fMembuf = (char *)malloc(sz);
00060          if (fMembuf) {
00061             memcpy(fMembuf, bp, sz);
00062             fBuff = fMembuf;
00063             fSize = sz;
00064          }
00065       } else {
00066          fBuff = fMembuf = bp;
00067          fSize = sz;
00068       }}
00069    ~XrdSrvBuffer() {if (fMembuf) free(fMembuf);}
00070 
00071 private:
00072    char *fMembuf;
00073 };
00074 
00075 
00076 //////////////////////////////////////////////////////////////////////////
00077 //                                                                      //
00078 // XrdProofQuery                                                        //
00079 //                                                                      //
00080 // Helper class describing a query. Used for scheduling.                //
00081 //                                                                      //
00082 //////////////////////////////////////////////////////////////////////////
00083 class XrdProofQuery
00084 {
00085    XrdOucString      fTag;
00086    XrdOucString      fDSName;
00087    long              fDSSize;
00088 public:
00089    XrdProofQuery(const char *t, const char *n = "", long s = 0) : fTag(t), fDSName(n), fDSSize(s) { }
00090 
00091    const char       *GetTag()     { return fTag.c_str(); }
00092    const char       *GetDSName()  { return fDSName.c_str(); }
00093    long              GetDSSize()  { return fDSSize; }
00094 };
00095 
00096 
00097 class XrdROOT;
00098 
00099 //////////////////////////////////////////////////////////////////////////
00100 //                                                                      //
00101 // XrdProofdProofServ                                                   //
00102 //                                                                      //
00103 // Authors: G. Ganis, CERN, 2005                                        //
00104 //                                                                      //
00105 // This class represent an instance of TProofServ                       //
00106 //                                                                      //
00107 //////////////////////////////////////////////////////////////////////////
00108 #define kXPROOFSRVTAGMAX   64
00109 #define kXPROOFSRVALIASMAX 256
00110 
00111 class XrdProofGroup;
00112 class XrdSysSemWait;
00113 
00114 class XrdProofdProofServ
00115 {
00116 
00117 public:
00118    XrdProofdProofServ();
00119    ~XrdProofdProofServ();
00120 
00121    void                AddWorker(const char *o, XrdProofWorker *w);
00122    inline const char  *AdminPath() const { XrdSysMutexHelper mhp(fMutex); return fAdminPath.c_str(); }
00123    inline const char  *Alias() const { XrdSysMutexHelper mhp(fMutex); return fAlias.c_str(); }
00124    void                Broadcast(const char *msg, int type = kXPD_srvmsg);
00125    int                 BroadcastPriority(int priority);
00126    inline const char  *Client() const { XrdSysMutexHelper mhp(fMutex); return fClient.c_str(); }
00127    int                 CheckSession(bool oldvers, bool isrec,
00128                                     int shutopt, int shutdel, bool changeown, int &nc);
00129    XrdProofQuery      *CurrentQuery() { XrdSysMutexHelper mhp(fMutex); return (fQueries.empty()? 0 : fQueries.front()); }
00130    void                DeleteStartMsg()
00131                        { XrdSysMutexHelper mhp(fMutex); if (fStartMsg) delete fStartMsg; fStartMsg = 0;}
00132    int                 DisconnectTime();
00133    void                DumpQueries();
00134    int                 Enqueue(XrdProofQuery *q) { XrdSysMutexHelper mhp(fMutex);
00135                                                    if (q) { fQueries.push_back(q); }; return fQueries.size(); }
00136    void                ExportBuf(XrdOucString &buf);
00137    void                ExportWorkers(XrdOucString &wrks);
00138    inline const char  *Fileout() const { XrdSysMutexHelper mhp(fMutex); return fFileout.c_str(); }
00139    int                 FreeClientID(int pid);
00140    XrdClientID        *GetClientID(int cid);
00141    int                 GetNClients(bool check);
00142    XrdProofQuery      *GetQuery(const char *tag);
00143    inline const char  *Group() const { XrdSysMutexHelper mhp(fMutex); return fGroup.c_str(); }
00144    int                 IdleTime();
00145    inline short int    ID() const { XrdSysMutexHelper mhp(fMutex); return fID; }
00146    inline bool         IsShutdown() const { XrdSysMutexHelper mhp(fMutex); return fIsShutdown; }
00147    inline bool         IsValid() const { XrdSysMutexHelper mhp(fMutex); return fIsValid; }
00148    inline bool         Match(short int id) const { XrdSysMutexHelper mhp(fMutex); return (id == fID); }
00149    inline const char  *Ordinal() const { XrdSysMutexHelper mhp(fMutex); return fOrdinal.c_str(); }
00150    inline XrdClientID *Parent() const { XrdSysMutexHelper mhp(fMutex); return fParent; }
00151    inline void         PingSem() const { XrdSysMutexHelper mhp(fMutex); if (fPingSem) fPingSem->Post(); }
00152    inline XrdProofdProtocol *Protocol() const { XrdSysMutexHelper mhp(fMutex); return fProtocol; }
00153    inline std::list<XrdProofQuery *> *Queries() const
00154                        { return (std::list<XrdProofQuery *> *)&fQueries; }
00155    void                RemoveQuery(const char *tag);
00156    void                RemoveWorker(const char *o);
00157    void                Reset();
00158    int                 Reset(const char *msg, int type);
00159    int                 Resume();
00160 
00161    inline XrdROOT     *ROOT() const { XrdSysMutexHelper mhp(fMutex); return fROOT; }
00162    inline XrdProofdResponse *Response() const { XrdSysMutexHelper mhp(fMutex); return fResponse; }
00163    int                 SendData(int cid, void *buff, int len);
00164    int                 SendDataN(void *buff, int len);
00165    void                SendClusterInfo(int nsess, int nacti);
00166    int                 SetAdminPath(const char *a, bool assert);
00167    void                SetAlias(const char *a) { XrdSysMutexHelper mhp(fMutex); fAlias = a; }
00168    void                SetClient(const char *c) { XrdSysMutexHelper mhp(fMutex); fClient = c; }
00169    inline void         SetConnection(XrdProofdResponse *r) { XrdSysMutexHelper mhp(fMutex); fResponse = r;}
00170 
00171    void                SetFileout(const char *f) { XrdSysMutexHelper mhp(fMutex); fFileout = f; }
00172    inline void         SetGroup(const char *g) { XrdSysMutexHelper mhp(fMutex); fGroup = g; }
00173    void                SetIdle();
00174    inline void         SetID(short int id) { XrdSysMutexHelper mhp(fMutex); fID = id;}
00175    void                SetOrdinal(const char *o) { XrdSysMutexHelper mhp(fMutex); fOrdinal = o; }
00176    inline void         SetParent(XrdClientID *cid) { XrdSysMutexHelper mhp(fMutex); fParent = cid; }
00177    inline void         SetProtocol(XrdProofdProtocol *p) { XrdSysMutexHelper mhp(fMutex); fProtocol = p; }
00178    inline void         SetProtVer(int pv) { XrdSysMutexHelper mhp(fMutex); fProtVer = pv; }
00179    inline void         SetROOT(XrdROOT *r) { XrdSysMutexHelper mhp(fMutex); fROOT = r; }
00180    void                SetRunning();
00181    inline void         SetShutdown() { XrdSysMutexHelper mhp(fMutex); fIsShutdown = true; }
00182    inline void         SetSkipCheck() { XrdSysMutexHelper mhp(fMutex); fSkipCheck = true; }
00183    void                SetSrvPID(int pid) { XrdSysMutexHelper mhp(fMutex); fSrvPID = pid; }
00184    inline void         SetSrvType(int id) { XrdSysMutexHelper mhp(fMutex); fSrvType = id; }
00185    inline void         SetStartMsg(XrdSrvBuffer *sm) { XrdSysMutexHelper mhp(fMutex); delete fStartMsg; fStartMsg = sm; }
00186    inline void         SetStatus(int st) { XrdSysMutexHelper mhp(fMutex); fStatus = st; }
00187    void                SetTag(const char *t) { XrdSysMutexHelper mhp(fMutex); fTag = t; }
00188    void                SetUNIXSockPath(const char *s) { XrdSysMutexHelper mhp(fMutex); fUNIXSockPath = s; };
00189    void                SetUserEnvs(const char *t) { XrdSysMutexHelper mhp(fMutex); fUserEnvs = t; }
00190    inline void         SetValid(bool valid = 1) { XrdSysMutexHelper mhp(fMutex); fIsValid = valid; }
00191    bool                SkipCheck();
00192    inline int          SrvPID() const { XrdSysMutexHelper mhp(fMutex); return fSrvPID; }
00193    inline int          SrvType() const { XrdSysMutexHelper mhp(fMutex); return fSrvType; }
00194    inline XrdSrvBuffer *StartMsg() const { XrdSysMutexHelper mhp(fMutex); return fStartMsg; }
00195    inline int          Status() const { XrdSysMutexHelper mhp(fMutex); return fStatus;}
00196    inline const char  *Tag() const { XrdSysMutexHelper mhp(fMutex); return fTag.c_str(); }
00197    int                 TerminateProofServ(bool changeown);
00198    inline const char  *UserEnvs() const { XrdSysMutexHelper mhp(fMutex); return fUserEnvs.c_str(); }
00199    int                 VerifyProofServ(bool fw);
00200    inline XrdOucHash<XrdProofWorker> *Workers() const
00201                       { XrdSysMutexHelper mhp(fMutex); return (XrdOucHash<XrdProofWorker> *)&fWorkers; }
00202 
00203    // UNIX socket related methods
00204    int                 CreateUNIXSock(XrdSysError *edest);
00205    void                DeleteUNIXSock();
00206    XrdNet             *UNIXSock() const { return fUNIXSock; }
00207    const char         *UNIXSockPath() const { return fUNIXSockPath.c_str(); }
00208 
00209  private:
00210 
00211    XrdSysRecMutex           *fMutex;
00212    XrdProofdProtocol        *fProtocol;  // Protocol instance attached to this session
00213    XrdProofdResponse        *fResponse;  // Response instance attached to this session
00214 
00215    XrdClientID              *fParent;    // Parent creating this session
00216    int                       fNClients;   // Number of attached clients
00217    std::vector<XrdClientID *> fClients;  // Attached clients stream ids
00218    XrdOucHash<XrdProofWorker> fWorkers; // Workers assigned to the session
00219 
00220    XrdSysSemWait            *fPingSem;   // To sychronize ping requests
00221 
00222    XrdSrvBuffer             *fStartMsg;  // Msg with start processing info
00223 
00224    time_t                    fDisconnectTime; // Time at which all clients disconnected
00225    time_t                    fSetIdleTime; // Time at which the session went idle
00226 
00227    int                       fStatus;
00228    int                       fSrvPID;     // Srv process ID
00229    int                       fSrvType;
00230    short int                 fID;
00231    char                      fProtVer;
00232    XrdOucString              fFileout;
00233 
00234    XrdNet                   *fUNIXSock;     // UNIX server socket for internal connections
00235    XrdOucString              fUNIXSockPath; // UNIX server socket path
00236 
00237    bool                      fIsShutdown; // Whether asked to shutdown
00238    bool                      fIsValid;    // Validity flag
00239    bool                      fSkipCheck;  // Skip next validity check
00240 
00241    XrdOucString              fAlias;     // Session alias
00242    XrdOucString              fClient;    // Client name
00243    XrdOucString              fTag;       // Session unique tag
00244    XrdOucString              fOrdinal;   // Session ordinal number
00245    XrdOucString              fUserEnvs;  // List of envs received from the user
00246    XrdOucString              fAdminPath; // Admin file in the form "<active-sessions>/<usr>.<grp>.<pid>"
00247 
00248    XrdROOT                  *fROOT;      // ROOT version run by this session
00249 
00250    XrdOucString              fGroup;     // Group, if any, to which the owner belongs
00251 
00252    void                      ClearWorkers();
00253 
00254    void                      CreatePingSem()
00255                              { XrdSysMutexHelper mhp(fMutex); fPingSem = new XrdSysSemWait(0);}
00256    void                      DeletePingSem()
00257                              { XrdSysMutexHelper mhp(fMutex); if (fPingSem) delete fPingSem; fPingSem = 0;}
00258    std::list<XrdProofQuery *> fQueries;  // the enqueued queries of this session
00259 };
00260 #endif

Generated on Tue Jul 5 14:51:45 2011 for ROOT_528-00b_version by  doxygen 1.5.1