// JobId.cxx #include "dial_job/JobId.h" #include //#include #include #include "dataset_id/UniqueIdGenerator.h" #include "dataset_id/SimpleUniqueIdGenerator.h" #include "dataset_util/DtdRegistry.h" using std::string; using dial::JobId; //********************************************************************** // Local data. //********************************************************************** namespace { // Register the DTD. DtdRegistry::Status ISTAT_DTD_JobId = DtdRegistry::register_dtd("dial"); } //********************************************************************** // Static member functions. //********************************************************************** // DTD const Text& JobId::dtd() { static Text txt; if ( txt.size() == 0 ) { txt = UniqueId::make_dtd(xml_name()); } return txt; } //********************************************************************** // Return the ID generator. UniqueIdGenerator* JobId::generator() { static PThreadMutex mtx; mtx.lock(); //std::cout << "----------- Thread " << getpid() << std::endl; static UniqueIdGenerator* pgen = 0; if ( pgen == 0 ) { pgen = UniqueIdGenerator::find_generator(JobId::id_context()); if ( pgen == 0 ) { pgen = new SimpleUniqueIdGenerator; } } mtx.unlock(); return pgen; } //********************************************************************** // Generate an ID. JobId JobId::generate() { static PThreadMutex mtx; mtx.lock(); UniqueIdGenerator* pgen = generator(); if ( pgen == 0 ) return JobId(); JobId jid = pgen->next(); //std::cout << " ID " << jid.to_string() << std::endl; mtx.unlock(); return jid; } //********************************************************************** // Non-static member functions. //********************************************************************** // Default constructor. JobId::JobId() { } //********************************************************************** // Constructor from an UniqueID. JobId::JobId(const UniqueId& uid) : UniqueId(uid) { } //********************************************************************** // Constructor from indices. JobId::JobId(Index col, Index ent) : UniqueId(col, ent) { } //********************************************************************** // Constructor from a string. JobId::JobId(string sid) : UniqueId(sid) { } //********************************************************************** // Constructor from XML. JobId::JobId(const XmlElement& ele) : UniqueId(ele) { } //********************************************************************** // Write to XML. const XmlElement* JobId::xml() const { return xml_with_name(xml_name()); } //**********************************************************************