Back to index

nordugrid-arc-nox  1.1.0~rc6
InfoRegister.h
Go to the documentation of this file.
00001 #ifndef __ARC_INFOSYS_REGISTER_H__
00002 #define __ARC_INFOSYS_REGISTER_H__
00003 
00004 #include <list>
00005 #include <string>
00006 #include <arc/ArcConfig.h>
00007 #include <arc/XMLNode.h>
00008 #include <arc/message/MCC.h>
00009 #include <arc/message/Service.h>
00010 #include <arc/Logger.h>
00011 #include <arc/URL.h>
00012 #include <arc/DateTime.h>
00013 
00014 #define GLUE2_D42_NAMESPACE "http://schemas.ogf.org/glue/2008/05/spec_2.0_d42_r1"
00015 #define REGISTRATION_NAMESPACE "http://www.nordugrid.org/schemas/registartion/2008/08"
00016 #define ISIS_NAMESPACE "http://www.nordugrid.org/schemas/isis/2008/08"
00017 #define REGISTRATION_CONFIG_NAMESPACE "http://www.nordugrid.org/schemas/InfoRegisterConfig/2008"
00018 
00019 namespace Arc {
00020 
00021 class InfoRegisterContainer;
00022 
00024 
00028 class InfoRegister {
00029     friend class InfoRegisterContainer;
00030     private:
00031         // Registration period
00032         long int reg_period_;
00033         // Registration information
00034         std::string serviceid;
00035         std::string expiration;
00036         std::string endpoint;
00037         // Associated service - it is used to fetch information document
00038         Service *service_;
00039         NS ns_;
00040     public:
00041         InfoRegister(XMLNode &node, Service *service_);
00042         ~InfoRegister();
00043         operator bool(void) { return service_; };
00044         bool operator!(void) { return !service_; };
00045         long int getPeriod(void) const { return reg_period_; };
00046         std::string getServiceID(void) { if (serviceid.empty()) return ""; else return serviceid; };
00047         std::string getEndpoint(void) { if (endpoint.empty()) return ""; else return endpoint; };
00048         std::string getExpiration(void) { if (expiration.empty()) return ""; else return expiration; };
00049         Service* getService(void) { return service_; };
00050 };
00051 
00053 class InfoRegisters {
00054     private:
00055         std::list<InfoRegister*> registers_;
00056     public:
00058 
00061         InfoRegisters(XMLNode &cfg, Service *service_);
00062         ~InfoRegisters(void);
00063 };
00064 
00065 // Data stucture for the InfoRegistrar class.
00066 struct Register_Info_Type{
00067     // Necessary information for the registration
00068     InfoRegister* p_register;
00069     Period period;
00070     Time next_registration;
00071     // ServiceID extracted from the first provided registration message
00072     std::string serviceid_;
00073     // Registration information
00074     std::string serviceid;
00075     std::string expiration;
00076     std::string endpoint;
00077 };
00078 
00079 // Data structure for describe a remote ISIS
00080 struct ISIS_description {
00081     std::string url;
00082     std::string key;
00083     std::string cert;
00084     std::string proxy;
00085     std::string cadir;
00086     std::string cafile;
00087 };
00088 
00090 
00094 class InfoRegistrar {
00095     friend class InfoRegisterContainer;
00096     private:
00098 
00101         InfoRegistrar(XMLNode cfg);
00102         // Configuration parameters
00103         std::string id_;
00104         int retry;
00105         // Security attributes
00106         std::string key_;
00107         std::string cert_;
00108         std::string proxy_;
00109         std::string cadir_;
00110         std::string cafile_;
00111         // Associated services
00112         std::list<Register_Info_Type> reg_;
00113         // Mutex protecting reg_ list
00114         Glib::Mutex lock_;
00115         // Condition signaled when thread has to exit
00116         Glib::Cond cond_exit_;
00117         // Condition signaled when thread exited
00118         Glib::Cond cond_exited_;
00119         // InfoRegistrar object creation time moment
00120         Time creation_time;
00121         // Time window providing some flexibility to avoid the casual slides
00122         Period stretch_window;
00123 
00124         // ISIS handle attributes & functions
00125         ISIS_description defaultBootstrapISIS;
00126         ISIS_description myISIS;
00127         bool myISISList_initialized;
00128         int originalISISCount;
00129         std::vector<ISIS_description> myISISList;
00130 
00131         void initISIS(XMLNode cfg);
00132         void removeISIS(ISIS_description isis);
00133         void getISISList(ISIS_description isis);
00134         ISIS_description getISIS(void);
00135         // End of ISIS handle attributes & functions
00136 
00137     public:
00138         ~InfoRegistrar(void);
00139         operator bool(void) { return !myISIS.url.empty(); };
00140         bool operator!(void) { return myISIS.url.empty(); };
00142 
00144         void registration(void);
00146 
00148         bool addService(InfoRegister*, XMLNode&);
00150         bool removeService(InfoRegister*);
00151         const std::string& id(void) { return id_; };
00152 
00153 
00154 };
00155 
00158 // TODO: Make it per chain, singleton solution reduces flexibility.
00159 class InfoRegisterContainer {
00160     private:
00161         static InfoRegisterContainer* instance_;
00162         //std::list<InfoRegister*> regs_;
00163         std::list<InfoRegistrar*> regr_;
00164         // Mutex protecting regr_ list
00165         Glib::Mutex lock_;
00166         InfoRegisterContainer(void);
00167         InfoRegisterContainer(const InfoRegisterContainer&) {};
00168     public:
00169         ~InfoRegisterContainer(void);
00170         static InfoRegisterContainer& Instance(void);
00172 
00175         InfoRegistrar *addRegistrar(XMLNode doc);
00177 
00185         void addService(InfoRegister* reg,const std::list<std::string>& ids,XMLNode cfg = XMLNode());
00186         // Disassociates service from all configured ISISes.
00188         void removeService(InfoRegister* reg);
00189 };
00190 
00191 } // namespace Arc
00192 
00193 #endif
00194