diff --git a/objectstore/Action.hpp b/objectstore/Action.hpp index 59a45634f81b81f2fdfd3b0bfdccde6295cd8e6a..00ef8b0bcc5864174ea1409922cb1e283ef3d6cb 100644 --- a/objectstore/Action.hpp +++ b/objectstore/Action.hpp @@ -1,6 +1,12 @@ #pragma once +namespace cta { namespace objectstore { + class Action { public: void execute() {} -}; \ No newline at end of file +}; + +}} + + diff --git a/objectstore/Agent.cpp b/objectstore/Agent.cpp index 9f9861718dd7c373e9b6022ebc2833fb3271f878..0eca49395a6e90a4a26d599de4ea8754989e0731 100644 --- a/objectstore/Agent.cpp +++ b/objectstore/Agent.cpp @@ -6,27 +6,27 @@ #include <sys/syscall.h> #include <ctime> -Agent::Agent(ObjectStore & os): - ObjectOps<cta::objectstore::Agent>(os), +cta::objectstore::Agent::Agent(ObjectStore & os): + ObjectOps<cta::objectstore::serializers::Agent>(os), m_nextId(0), m_setupDone(false), m_creationDone(false), m_observerVersion(false) {}; -Agent::Agent(ObjectStore & os, const std::string & typeName): - ObjectOps<cta::objectstore::Agent>(os), +cta::objectstore::Agent::Agent(ObjectStore & os, const std::string & typeName): + ObjectOps<cta::objectstore::serializers::Agent>(os), m_nextId(0), m_setupDone(false), m_creationDone(false), m_observerVersion(false) { setup(typeName); } // Passive constructor, used for looking at existing agent records -Agent::Agent(const std::string & name, Agent & agent): - ObjectOps<cta::objectstore::Agent>(agent.objectStore(), name), +cta::objectstore::Agent::Agent(const std::string & name, Agent & agent): + ObjectOps<cta::objectstore::serializers::Agent>(agent.objectStore(), name), m_nextId(0), m_setupDone(true), m_creationDone(true), m_observerVersion(true) { // check the presence of the entry - cta::objectstore::Agent as; + cta::objectstore::serializers::Agent as; updateFromObjectStore(as, agent.getFreeContext()); } -void Agent::setup(const std::string & typeName) { +void cta::objectstore::Agent::setup(const std::string & typeName) { std::stringstream aid; // Get time time_t now = time(0); @@ -45,36 +45,36 @@ void Agent::setup(const std::string & typeName) { << std::setw(2) << localNow.tm_hour << ":" << std::setw(2) << localNow.tm_min << ":" << std::setw(2) << localNow.tm_sec; - ObjectOps<cta::objectstore::Agent>::setName(aid.str()); + ObjectOps<cta::objectstore::serializers::Agent>::setName(aid.str()); m_setupDone = true; } -void Agent::create() { +void cta::objectstore::Agent::create() { if (!m_setupDone) throw SetupNotDone("In Agent::create(): setup() not yet done"); RootEntry re(*this); AgentRegister ar(re.allocateOrGetAgentRegister(*this), *this); ar.addIntendedElement(selfName(), *this); - cta::objectstore::Agent as; + cta::objectstore::serializers::Agent as; as.set_name(selfName()); writeChild(selfName(), as); ar.upgradeIntendedElementToActual(selfName(), *this); m_creationDone = true; } -std::string Agent::type() { +std::string cta::objectstore::Agent::type() { if (!m_setupDone) throw SetupNotDone("In Agent::type(): setup() not yet done"); return m_typeName; } -std::string Agent::name() { +std::string cta::objectstore::Agent::name() { if (!m_setupDone) throw SetupNotDone("In Agent::name(): setup() not yet done"); return selfName(); } -Agent::~Agent() { +cta::objectstore::Agent::~Agent() { for (size_t i=0; i < c_handleCount; i++) { m_contexts[i].release(); } @@ -88,7 +88,7 @@ Agent::~Agent() { } } -std::string Agent::nextId(const std::string & childType) { +std::string cta::objectstore::Agent::nextId(const std::string & childType) { if (!m_setupDone) throw SetupNotDone("In Agent::nextId(): setup() not yet done"); if (m_observerVersion) @@ -98,7 +98,8 @@ std::string Agent::nextId(const std::string & childType) { return id.str(); } -ContextHandleImplementation<myOS> & Agent::getFreeContext() { +cta::objectstore::ContextHandleImplementation<myOS> & + cta::objectstore::Agent::getFreeContext() { for (size_t i=0; i < c_handleCount; i++) { if (!m_contexts[i].isSet()) return m_contexts[i]; @@ -106,13 +107,13 @@ ContextHandleImplementation<myOS> & Agent::getFreeContext() { throw cta::exception::Exception("Could not find free context slot"); } -void Agent::addToIntend (std::string container, std::string name, std::string typeName) { +void cta::objectstore::Agent::addToIntend (std::string container, std::string name, std::string typeName) { if (!m_creationDone) throw CreationNotDone("In Agent::addToIntend(): creation() not yet done"); - cta::objectstore::Agent as; + cta::objectstore::serializers::Agent as; ContextHandle & ctx = getFreeContext(); lockExclusiveAndRead(as, ctx); - cta::objectstore::ObjectCreationIntent * oca = + cta::objectstore::serializers::ObjectCreationIntent * oca = as.mutable_creationintent()->Add(); oca->set_container(container); oca->set_name(name); @@ -121,10 +122,10 @@ void Agent::addToIntend (std::string container, std::string name, std::string ty unlock(ctx); } -void Agent::removeFromIntent (std::string container, std::string name, std::string typeName) { +void cta::objectstore::Agent::removeFromIntent (std::string container, std::string name, std::string typeName) { if (!m_creationDone) throw CreationNotDone("In Agent::removeFromIntent(): creation() not yet done"); - cta::objectstore::Agent as; + cta::objectstore::serializers::Agent as; ContextHandle & ctx = getFreeContext(); lockExclusiveAndRead(as, ctx); bool found; @@ -145,13 +146,13 @@ void Agent::removeFromIntent (std::string container, std::string name, std::stri unlock(ctx); } -void Agent::addToOwnership(std::string name, std::string typeName) { +void cta::objectstore::Agent::addToOwnership(std::string name, std::string typeName) { if (!m_creationDone) throw CreationNotDone("In Agent::addToOwnership(): creation() not yet done"); - cta::objectstore::Agent as; + cta::objectstore::serializers::Agent as; ContextHandle & ctx = getFreeContext(); lockExclusiveAndRead(as, ctx); - cta::objectstore::ObjectOwnershipIntent * ooi = + cta::objectstore::serializers::ObjectOwnershipIntent * ooi = as.mutable_ownershipintent()->Add(); ooi->set_name(name); ooi->set_type(typeName); @@ -159,10 +160,10 @@ void Agent::addToOwnership(std::string name, std::string typeName) { unlock(ctx); } -void Agent::removeFromOwnership(std::string name, std::string typeName) { +void cta::objectstore::Agent::removeFromOwnership(std::string name, std::string typeName) { if (!m_creationDone) throw CreationNotDone("In Agent::removeFromOwnership(): creation() not yet done"); - cta::objectstore::Agent as; + cta::objectstore::serializers::Agent as; ContextHandle & ctx = getFreeContext(); lockExclusiveAndRead(as, ctx); bool found; @@ -182,10 +183,11 @@ void Agent::removeFromOwnership(std::string name, std::string typeName) { unlock(ctx); } -std::list<Agent::intentEntry> Agent::getIntentLog() { +std::list<cta::objectstore::Agent::intentEntry> + cta::objectstore::Agent::getIntentLog() { if (!m_creationDone) throw CreationNotDone("In Agent::getIntentLog(): creation() not yet done"); - cta::objectstore::Agent as; + cta::objectstore::serializers::Agent as; updateFromObjectStore(as, getFreeContext()); std::list<intentEntry> ret; for (int i=0; i<as.creationintent_size(); i++) { @@ -196,10 +198,11 @@ std::list<Agent::intentEntry> Agent::getIntentLog() { return ret; } -std::list<Agent::ownershipEntry> Agent::getOwnershipLog() { +std::list<cta::objectstore::Agent::ownershipEntry> + cta::objectstore::Agent::getOwnershipLog() { if (!m_creationDone) throw CreationNotDone("In Agent::getOwnershipLog(): creation() not yet done"); - cta::objectstore::Agent as; + cta::objectstore::serializers::Agent as; updateFromObjectStore(as, getFreeContext()); std::list<ownershipEntry> ret; for (int i=0; i<as.creationintent_size(); i++) { @@ -209,12 +212,12 @@ std::list<Agent::ownershipEntry> Agent::getOwnershipLog() { return ret; } -ObjectStore & Agent::objectStore() { - return ObjectOps<cta::objectstore::Agent>::objectStore(); +cta::objectstore::ObjectStore & cta::objectstore::Agent::objectStore() { + return ObjectOps<cta::objectstore::serializers::Agent>::objectStore(); } -std::string Agent::dump(Agent & agent) { - cta::objectstore::Agent as; +std::string cta::objectstore::Agent::dump(Agent & agent) { + cta::objectstore::serializers::Agent as; updateFromObjectStore(as, agent.getFreeContext()); std::stringstream ret; ret<< "<<<< Agent " << selfName() << " dump start" << std::endl diff --git a/objectstore/Agent.hpp b/objectstore/Agent.hpp index 72a6e696c8e0e84b57b8f5b89ee7afce7fd358c6..95883c7a440b68f8dc1c2e11bdee1b2cbd395402 100644 --- a/objectstore/Agent.hpp +++ b/objectstore/Agent.hpp @@ -5,6 +5,8 @@ #include "ContextHandle.hpp" #include "objectstore/cta.pb.h" +namespace cta { namespace objectstore { + /** * Class containing agent information and managing the update of the * agent's persitent representation in the object store. @@ -14,7 +16,7 @@ * It handles (in the base class): */ -class Agent: protected ObjectOps<cta::objectstore::Agent> { +class Agent: protected ObjectOps<cta::objectstore::serializers::Agent> { public: Agent(ObjectStore & os); @@ -93,4 +95,6 @@ private: uint64_t m_nextId; static const size_t c_handleCount = 100; ContextHandleImplementation<myOS> m_contexts[c_handleCount]; -}; \ No newline at end of file +}; + +}} \ No newline at end of file diff --git a/objectstore/AgentRegister.cpp b/objectstore/AgentRegister.cpp index ec7519a864b9afaec92e75562e4b241197dc84cb..ae9ad9f7f28d14051412dbc085a4adc753740347 100644 --- a/objectstore/AgentRegister.cpp +++ b/objectstore/AgentRegister.cpp @@ -1,15 +1,15 @@ #include "AgentRegister.hpp" -AgentRegister::AgentRegister(const std::string & name, Agent & agent): -ObjectOps<cta::objectstore::AgentRegister>(agent.objectStore(), name) { +cta::objectstore::AgentRegister::AgentRegister(const std::string & name, Agent & agent): +ObjectOps<cta::objectstore::serializers::AgentRegister>(agent.objectStore(), name) { // Check that the entry is present and readable (depending on implementation // of object store, locking might or might not succeed) - cta::objectstore::AgentRegister rs; + cta::objectstore::serializers::AgentRegister rs; updateFromObjectStore(rs, agent.getFreeContext()); } -void AgentRegister::addElement (std::string name, Agent & agent) { - cta::objectstore::AgentRegister rs; +void cta::objectstore::AgentRegister::addElement (std::string name, Agent & agent) { + cta::objectstore::serializers::AgentRegister rs; ContextHandle & context = agent.getFreeContext(); lockExclusiveAndRead(rs, context); rs.add_elements(name); @@ -17,8 +17,8 @@ void AgentRegister::addElement (std::string name, Agent & agent) { unlock(context); } -void AgentRegister::removeElement (const std::string & name, Agent & agent) { - cta::objectstore::AgentRegister rs; +void cta::objectstore::AgentRegister::removeElement (const std::string & name, Agent & agent) { + cta::objectstore::serializers::AgentRegister rs; ContextHandle & context = agent.getFreeContext(); lockExclusiveAndRead(rs, context); bool found; @@ -37,8 +37,8 @@ void AgentRegister::removeElement (const std::string & name, Agent & agent) { unlock(context); } -void AgentRegister::addIntendedElement(std::string name, Agent& agent) { - cta::objectstore::AgentRegister rs; +void cta::objectstore::AgentRegister::addIntendedElement(std::string name, Agent& agent) { + cta::objectstore::serializers::AgentRegister rs; ContextHandle & context = agent.getFreeContext(); lockExclusiveAndRead(rs, context); rs.add_intendedelements(name); @@ -46,8 +46,8 @@ void AgentRegister::addIntendedElement(std::string name, Agent& agent) { unlock(context); } -void AgentRegister::upgradeIntendedElementToActual(std::string name, Agent& agent) { - cta::objectstore::AgentRegister rs; +void cta::objectstore::AgentRegister::upgradeIntendedElementToActual(std::string name, Agent& agent) { + cta::objectstore::serializers::AgentRegister rs; ContextHandle & context = agent.getFreeContext(); lockExclusiveAndRead(rs, context); bool found; @@ -68,8 +68,8 @@ void AgentRegister::upgradeIntendedElementToActual(std::string name, Agent& agen } -void AgentRegister::removeIntendedElement(const std::string& name, Agent& agent) { - cta::objectstore::AgentRegister rs; +void cta::objectstore::AgentRegister::removeIntendedElement(const std::string& name, Agent& agent) { + cta::objectstore::serializers::AgentRegister rs; ContextHandle & context = agent.getFreeContext(); lockExclusiveAndRead(rs, context); bool found; @@ -90,8 +90,8 @@ void AgentRegister::removeIntendedElement(const std::string& name, Agent& agent) -std::list<std::string> AgentRegister::getElements(Agent & agent) { - cta::objectstore::AgentRegister rs; +std::list<std::string> cta::objectstore::AgentRegister::getElements(Agent & agent) { + cta::objectstore::serializers::AgentRegister rs; updateFromObjectStore(rs, agent.getFreeContext()); std::list<std::string> ret; for (int i=0; i<rs.elements_size(); i++) { @@ -100,8 +100,8 @@ std::list<std::string> AgentRegister::getElements(Agent & agent) { return ret; } -std::string AgentRegister::dump(Agent & agent) { - cta::objectstore::AgentRegister rs; +std::string cta::objectstore::AgentRegister::dump(Agent & agent) { + cta::objectstore::serializers::AgentRegister rs; updateFromObjectStore(rs, agent.getFreeContext()); std::stringstream ret; ret<< "<<<< AgentRegister " << selfName() << " dump start" << std::endl diff --git a/objectstore/AgentRegister.hpp b/objectstore/AgentRegister.hpp index c2c2e03a55e8f01de546c106999e96be7a81c06c..04ffe44c17c632a2d8452169331755407e4d7eb5 100644 --- a/objectstore/AgentRegister.hpp +++ b/objectstore/AgentRegister.hpp @@ -4,7 +4,9 @@ #include "Agent.hpp" #include <algorithm> -class AgentRegister: private ObjectOps<cta::objectstore::AgentRegister> { +namespace cta { namespace objectstore { + +class AgentRegister: private ObjectOps<cta::objectstore::serializers::AgentRegister> { public: AgentRegister(const std::string & name, Agent & agent); void addElement (std::string name, Agent & agent); @@ -14,4 +16,6 @@ public: void removeIntendedElement (const std::string & name, Agent & agent); std::list<std::string> getElements(Agent & agent); std::string dump(Agent & agent); -}; \ No newline at end of file +}; + +}} \ No newline at end of file diff --git a/objectstore/ContextHandle.hpp b/objectstore/ContextHandle.hpp index c32ec5903b8572fbe3f7e96df9d8dc32f8639a60..7d7b990311ba7f8137df51832fa1984f0b1ab1fa 100644 --- a/objectstore/ContextHandle.hpp +++ b/objectstore/ContextHandle.hpp @@ -2,6 +2,8 @@ #include "ObjectStores.hpp" +namespace cta { namespace objectstore { + template <class C> class ContextHandleImplementation: public ContextHandle {}; @@ -29,4 +31,6 @@ public: void release() { reset(); } private: bool m_set; -}; \ No newline at end of file +}; + +}} \ No newline at end of file diff --git a/objectstore/FIFO.hpp b/objectstore/FIFO.hpp index 72259711dc579d5d40c5d8ca6887736346a9e6ce..36a999c1c135a02f4859b5dd1213a5963bfcc0b1 100644 --- a/objectstore/FIFO.hpp +++ b/objectstore/FIFO.hpp @@ -4,11 +4,13 @@ #include "Agent.hpp" #include "exception/Exception.hpp" -class FIFO: private ObjectOps<cta::objectstore::FIFO> { +namespace cta { namespace objectstore { + +class FIFO: private ObjectOps<cta::objectstore::serializers::FIFO> { public: FIFO(const std::string & name, Agent & agent): - ObjectOps<cta::objectstore::FIFO>(agent.objectStore(), name) { - cta::objectstore::FIFO fs; + ObjectOps<cta::objectstore::serializers::FIFO>(agent.objectStore(), name) { + cta::objectstore::serializers::FIFO fs; updateFromObjectStore(fs, agent.getFreeContext()); } @@ -53,8 +55,9 @@ public: return Transaction(*this, agent); } - void push(std::string name, ContextHandle & context) { - cta::objectstore::FIFO fs; + void push(std::string name, Agent & agent) { + cta::objectstore::serializers::FIFO fs; + ContextHandle & context = agent.getFreeContext(); lockExclusiveAndRead(fs, context); fs.add_name(name); write(fs); @@ -62,7 +65,7 @@ public: } std::string dump(Agent & agent) { - cta::objectstore::FIFO fs; + cta::objectstore::serializers::FIFO fs; updateFromObjectStore(fs, agent.getFreeContext()); std::stringstream ret; ret<< "<<<< FIFO dump start" << std::endl @@ -77,7 +80,7 @@ public: } private: - cta::objectstore::FIFO m_currentState; + cta::objectstore::serializers::FIFO m_currentState; void compactCurrentState() { uint64_t oldReadPointer = m_currentState.readpointer(); @@ -102,4 +105,6 @@ private: throw cta::exception::Exception(err.str()); } } -}; \ No newline at end of file +}; + +}} \ No newline at end of file diff --git a/objectstore/JobPool.hpp b/objectstore/JobPool.hpp index c1aa7b1844df748ddafae2396b61cfafcc8b2d11..1fc8205dda6f3403b703bb3da48fb4f62ae09425 100644 --- a/objectstore/JobPool.hpp +++ b/objectstore/JobPool.hpp @@ -4,17 +4,19 @@ #include "FIFO.hpp" #include "Agent.hpp" -class JobPool: private ObjectOps<cta::objectstore::JobPool> { +namespace cta { namespace objectstore { + +class JobPool: private ObjectOps<cta::objectstore::serializers::JobPool> { public: JobPool(const std::string & name, Agent & agent): - ObjectOps<cta::objectstore::JobPool>(agent.objectStore(), name) { - cta::objectstore::JobPool jps; + ObjectOps<cta::objectstore::serializers::JobPool>(agent.objectStore(), name) { + cta::objectstore::serializers::JobPool jps; updateFromObjectStore(jps, agent.getFreeContext()); } - void PostRecallJob (const std::string & string, ContextHandle & context, const std::string & MigrationFIFOId) { - cta::objectstore::JobPool jps; - lockExclusiveAndRead(jps, context); + void PostRecallJob (const std::string & job, Agent & agent) { + FIFO recallFIFO(allocateOrGetRecallFIFO(agent), agent); + recallFIFO.push(job, agent); } class NotAllocatedEx: public cta::exception::Exception { @@ -23,7 +25,7 @@ public: }; std::string dump(Agent & agent) { - cta::objectstore::JobPool jps; + cta::objectstore::serializers::JobPool jps; updateFromObjectStore(jps, agent.getFreeContext()); std::stringstream ret; ret << "<<<< JobPool " << selfName() << " dump start" << std::endl @@ -35,7 +37,7 @@ public: std::string getRecallFIFO (Agent & agent) { // Check if the recall FIFO exists - cta::objectstore::JobPool res; + cta::objectstore::serializers::JobPool res; updateFromObjectStore(res, agent.getFreeContext()); // If the registry is defined, return it, job done. if (res.recall().size()) @@ -44,14 +46,14 @@ public: } // Get the name of a (possibly freshly created) recall FIFO - std::string allocateOrGetJobPool(Agent & agent) { + std::string allocateOrGetRecallFIFO(Agent & agent) { // Check if the job pool exists try { return getRecallFIFO(agent); } catch (NotAllocatedEx &) { // If we get here, the job pool is not created yet, so we have to do it: // lock the entry again, for writing - cta::objectstore::JobPool res; + cta::objectstore::serializers::JobPool res; ContextHandle ctx = agent.getFreeContext(); lockExclusiveAndRead(res, ctx); // If the registry is already defined, somebody was faster. We're done. @@ -66,7 +68,7 @@ public: agent.addToIntend(selfName(), FIFOName, "recallFIFO"); // The potential object can now be garbage collected if we die from here. // Create the object, then lock. The name should be unique, so no race. - cta::objectstore::JobPool jps; + cta::objectstore::serializers::JobPool jps; jps.set_migration(""); jps.set_recall(""); writeChild(FIFOName, jps); @@ -84,4 +86,6 @@ public: // higher level functionnality //std::string allocateOrGetMigrationFIFO -}; \ No newline at end of file +}; + +}} diff --git a/objectstore/ObjectOps.hpp b/objectstore/ObjectOps.hpp index 5697db3d574f79df82a49864bd1889751493b38d..bc9a290ed64b2b41dfc9957772092bd04c096ab1 100644 --- a/objectstore/ObjectOps.hpp +++ b/objectstore/ObjectOps.hpp @@ -2,6 +2,8 @@ #include "ObjectStores.hpp" +namespace cta { namespace objectstore { + template <class C> class ObjectOps { public: @@ -75,4 +77,6 @@ private: bool m_nameSet; std::string m_name; ObjectStore & m_objectStore; -}; \ No newline at end of file +}; + +}} \ No newline at end of file diff --git a/objectstore/ObjectStoreChoice.hpp b/objectstore/ObjectStoreChoice.hpp index 14e20225f83b2d0b9cb5b61b3b77a2d86082ef1e..2d1fc3a625618e50069d0e24e62a1fe16d1be872 100644 --- a/objectstore/ObjectStoreChoice.hpp +++ b/objectstore/ObjectStoreChoice.hpp @@ -1,4 +1,4 @@ #pragma once #include "ObjectOps.hpp" -typedef ObjectStoreRados myOS; \ No newline at end of file +typedef cta::objectstore::ObjectStoreRados myOS; \ No newline at end of file diff --git a/objectstore/ObjectStores.hpp b/objectstore/ObjectStores.hpp index d71572c46c2531afd73d7b15683cc509bad24894..88ffda87b0fb662789a3fd246671d5ce9d7c8f66 100644 --- a/objectstore/ObjectStores.hpp +++ b/objectstore/ObjectStores.hpp @@ -13,6 +13,8 @@ #include "exception/Exception.hpp" #include "exception/Errnum.hpp" +namespace cta { namespace objectstore { + class ContextHandle { public: template <typename T> @@ -290,4 +292,6 @@ private: std::string m_pool; librados::Rados m_cluster; librados::IoCtx m_radosCtx; -}; \ No newline at end of file +}; + +}} \ No newline at end of file diff --git a/objectstore/ObjectStructureDumper.hpp b/objectstore/ObjectStructureDumper.hpp index 5be563d3799303ed6584f013af1894cb58c32c71..aadfc062340219b014c7f6ca15eedf964448295d 100644 --- a/objectstore/ObjectStructureDumper.hpp +++ b/objectstore/ObjectStructureDumper.hpp @@ -6,6 +6,8 @@ #include "JobPool.hpp" #include <iostream> +namespace cta { namespace objectstore { + class ObjectStrucutreDumper { public: std::string dump(Agent & agent) { @@ -33,4 +35,6 @@ public: ret << ">> Structure dump end" << std::endl; return ret.str(); } -}; \ No newline at end of file +}; + +}} \ No newline at end of file diff --git a/objectstore/Register.hpp b/objectstore/Register.hpp index 929ece89e28bbaceb2fb7a34d860be6ffd50e6b1..c6bec23cc86358882d7bbe6151d8713acf064717 100644 --- a/objectstore/Register.hpp +++ b/objectstore/Register.hpp @@ -3,18 +3,20 @@ #include "ObjectOps.hpp" #include <algorithm> -class Register: private ObjectOps<cta::objectstore::Register> { +namespace cta { namespace objectstore { + +class Register: private ObjectOps<cta::objectstore::serializers::Register> { public: Register(const std::string & name, Agent & agent): - ObjectOps<cta::objectstore::Register>(agent.objectStore(), name) { + ObjectOps<cta::objectstore::serializers::Register>(agent.objectStore(), name) { // Check that the entry is present and readable (depending on implementation // of object store, locking might or might not succeed) - cta::objectstore::Register rs; + cta::objectstore::serializers::Register rs; updateFromObjectStore(rs, agent.getFreeContext()); } void addElement (std::string name, ContextHandle & context) { - cta::objectstore::Register rs; + cta::objectstore::serializers::Register rs; lockExclusiveAndRead(rs, context); rs.add_elements(name); write(rs); @@ -22,7 +24,7 @@ public: } void removeElement (const std::string & name, ContextHandle & context) { - cta::objectstore::Register rs; + cta::objectstore::serializers::Register rs; lockExclusiveAndRead(rs, context); bool found; do { @@ -41,7 +43,7 @@ public: } std::list<std::string> getElements(Agent & agent) { - cta::objectstore::Register rs; + cta::objectstore::serializers::Register rs; updateFromObjectStore(rs, agent.getFreeContext()); std::list<std::string> ret; for (int i=0; i<rs.elements_size(); i++) { @@ -51,7 +53,7 @@ public: } std::string dump(const std::string & title, Agent & agent) { - cta::objectstore::Register rs; + cta::objectstore::serializers::Register rs; updateFromObjectStore(rs, agent.getFreeContext()); std::stringstream ret; ret<< "<<<< Register " << title << " dump start" << std::endl @@ -62,4 +64,6 @@ public: ret<< ">>>> Register " << title << " dump end" << std::endl; return ret.str(); } -}; \ No newline at end of file +}; + +}} \ No newline at end of file diff --git a/objectstore/RootEntry.cpp b/objectstore/RootEntry.cpp index 329d282f6b08fd34717cbf58def28a85ebec2e01..7825d2944040b24bbf661d04b7b2199f051657a2 100644 --- a/objectstore/RootEntry.cpp +++ b/objectstore/RootEntry.cpp @@ -3,28 +3,28 @@ #include "Agent.hpp" // Initializer. -void RootEntry::init(ObjectStore & os) { +void cta::objectstore::RootEntry::init(ObjectStore & os) { // check existence of root entry before creating it. We expect read to fail. try { os.read(s_rootEntryName); throw cta::exception::Exception("In RootEntry::init: root entry already exists"); } catch (...) {} - cta::objectstore::RootEntry res; + cta::objectstore::serializers::RootEntry res; os.atomicOverwrite(s_rootEntryName, res.SerializeAsString()); } // construtor, when the backend store exists. // Checks the existence and correctness of the root entry -RootEntry::RootEntry(Agent & agent): - ObjectOps<cta::objectstore::RootEntry>(agent.objectStore(), s_rootEntryName) { +cta::objectstore::RootEntry::RootEntry(Agent & agent): + ObjectOps<cta::objectstore::serializers::RootEntry>(agent.objectStore(), s_rootEntryName) { // Check that the root entry is readable. - cta::objectstore::RootEntry res; + cta::objectstore::serializers::RootEntry res; updateFromObjectStore(res, agent.getFreeContext()); } // Get the name of the agent register (or exception if not available) -std::string RootEntry::getAgentRegister(Agent & agent) { +std::string cta::objectstore::RootEntry::getAgentRegister(Agent & agent) { // Check if the agent register exists - cta::objectstore::RootEntry res; + cta::objectstore::serializers::RootEntry res; updateFromObjectStore(res, agent.getFreeContext()); // If the registry is defined, return it, job done. if (res.agentregister().size()) @@ -33,14 +33,14 @@ std::string RootEntry::getAgentRegister(Agent & agent) { } // Get the name of a (possibly freshly created) agent register -std::string RootEntry::allocateOrGetAgentRegister(Agent & agent) { +std::string cta::objectstore::RootEntry::allocateOrGetAgentRegister(Agent & agent) { // Check if the agent register exists try { return getAgentRegister(agent); } catch (NotAllocatedEx &) { // If we get here, the agent register is not created yet, so we have to do it: // lock the entry again, for writing - cta::objectstore::RootEntry res; + cta::objectstore::serializers::RootEntry res; ContextHandle & context = agent.getFreeContext(); lockExclusiveAndRead(res, context); // If the registry is already defined, somebody was faster. We're done. @@ -57,7 +57,7 @@ std::string RootEntry::allocateOrGetAgentRegister(Agent & agent) { write(res); // The potential object can now be garbage collected if we die from here. // Create the object, then lock. The name should be unique, so no race. - cta::objectstore::Register ars; + cta::objectstore::serializers::Register ars; writeChild(arName, ars); // If we lived that far, we can update the root entry to point to our // new agent register, and remove the name from the intent log. @@ -71,9 +71,9 @@ std::string RootEntry::allocateOrGetAgentRegister(Agent & agent) { } // Get the name of the JobPool (or exception if not available) -std::string RootEntry::getJobPool(Agent & agent) { +std::string cta::objectstore::RootEntry::getJobPool(Agent & agent) { // Check if the job pool exists - cta::objectstore::RootEntry res; + cta::objectstore::serializers::RootEntry res; updateFromObjectStore(res, agent.getFreeContext()); // If the registry is defined, return it, job done. if (res.jobpool().size()) @@ -82,14 +82,14 @@ std::string RootEntry::getJobPool(Agent & agent) { } // Get the name of a (possibly freshly created) job pool -std::string RootEntry::allocateOrGetJobPool(Agent & agent) { +std::string cta::objectstore::RootEntry::allocateOrGetJobPool(Agent & agent) { // Check if the job pool exists try { return getJobPool(agent); } catch (NotAllocatedEx &) { // If we get here, the job pool is not created yet, so we have to do it: // lock the entry again, for writing - cta::objectstore::RootEntry res; + cta::objectstore::serializers::RootEntry res; ContextHandle & context = agent.getFreeContext(); lockExclusiveAndRead(res, context); // If the registry is already defined, somebody was faster. We're done. @@ -104,7 +104,7 @@ std::string RootEntry::allocateOrGetJobPool(Agent & agent) { agent.addToIntend(s_rootEntryName, jpName, "jobPool"); // The potential object can now be garbage collected if we die from here. // Create the object, then lock. The name should be unique, so no race. - cta::objectstore::JobPool jps; + cta::objectstore::serializers::JobPool jps; jps.set_migration(""); jps.set_recall(""); writeChild(jpName, jps); @@ -121,9 +121,9 @@ std::string RootEntry::allocateOrGetJobPool(Agent & agent) { } // Dump the root entry -std::string RootEntry::dump (Agent & agent) { +std::string cta::objectstore::RootEntry::dump (Agent & agent) { std::stringstream ret; - cta::objectstore::RootEntry res; + cta::objectstore::serializers::RootEntry res; updateFromObjectStore(res, agent.getFreeContext()); ret << "<<<< Root entry dump start" << std::endl; if (res.has_agentregister()) ret << "agentRegister=" << res.agentregister() << std::endl; @@ -138,4 +138,4 @@ std::string RootEntry::dump (Agent & agent) { return ret.str(); } -const std::string RootEntry::s_rootEntryName("root"); \ No newline at end of file +const std::string cta::objectstore::RootEntry::s_rootEntryName("root"); \ No newline at end of file diff --git a/objectstore/RootEntry.hpp b/objectstore/RootEntry.hpp index ac1597dfb0bbff2962dacb0bf1f4f95265ab069d..33cd623b20e90619f917cbda638d7e1ac00d1c10 100644 --- a/objectstore/RootEntry.hpp +++ b/objectstore/RootEntry.hpp @@ -6,7 +6,9 @@ #include "ObjectOps.hpp" #include "Agent.hpp" -class RootEntry: private ObjectOps<cta::objectstore::RootEntry> { +namespace cta { namespace objectstore { + +class RootEntry: private ObjectOps<cta::objectstore::serializers::RootEntry> { public: // Initializer. static void init(ObjectStore & os); @@ -39,4 +41,6 @@ public: static const std::string s_rootEntryName; }; +}} + diff --git a/objectstore/cta.proto b/objectstore/cta.proto index ab56046748b847257cd4e1c3f35ce2c9f0c68d73..515f99de841e0f62b5c909c400930ceee61791af 100644 --- a/objectstore/cta.proto +++ b/objectstore/cta.proto @@ -1,4 +1,4 @@ -package cta.objectstore; +package cta.objectstore.serializers; // The root entry: it point to an agent register and a job pool register. // There is an integrated intent log, but the updates should be very rare (besides first registers creation). diff --git a/objectstore/tapeResourceManagerTest.cpp b/objectstore/tapeResourceManagerTest.cpp index f0b3ae6510d4d94631f381fef44f5d7d17009a1a..22881f35b5eb895f57614244d1630a5007a86825 100644 --- a/objectstore/tapeResourceManagerTest.cpp +++ b/objectstore/tapeResourceManagerTest.cpp @@ -15,18 +15,20 @@ class jobExecutorThread: public cta::threading::Thread { public: - jobExecutorThread(Action & a): cta::threading::Thread(), m_action(a) {} + jobExecutorThread(cta::objectstore::Action & a): + cta::threading::Thread(), m_action(a) {} private: virtual void run () { // make the agent act m_action.execute(); } - Action & m_action; + cta::objectstore::Action & m_action; }; class jobExecutorProcess: public cta::threading::ChildProcess { public: - jobExecutorProcess(Action & a): cta::threading::ChildProcess(), m_action(a) {} + jobExecutorProcess(cta::objectstore::Action & a): + cta::threading::ChildProcess(), m_action(a) {} private: virtual int run () { // increase 100 time root entry's @@ -39,7 +41,7 @@ private: } return 0; } - Action & m_action; + cta::objectstore::Action & m_action; }; class dummyCleanup: public cta::threading::ChildProcess::Cleanup { @@ -53,25 +55,25 @@ int main(void){ std::cout << "os.path=" << os.path() << " os.user=" << os.user() << "os.pool=" << os.pool() << std::endl; // Initialize the root entry - RootEntry::init(os); + cta::objectstore::RootEntry::init(os); // Create our own agent representation - Agent self(os, "masterProcess"); + cta::objectstore::Agent self(os, "masterProcess"); self.create(); - ContextHandleImplementation<myOS> ctx; + cta::objectstore::ContextHandleImplementation<myOS> ctx; // Dump the structure - ObjectStrucutreDumper osd; + cta::objectstore::ObjectStrucutreDumper osd; std::cout << osd.dump(self) << std::endl; // Get hold of the root entry - RootEntry re(self); + cta::objectstore::RootEntry re(self); // Create and populate the job queues std::cout << "About to add agentRegister" << std::endl; - AgentRegister agentRegister(re.allocateOrGetAgentRegister(self), self); + cta::objectstore::AgentRegister agentRegister(re.allocateOrGetAgentRegister(self), self); std::cout << osd.dump(self) << std::endl; // Create the job pool std::cout << "=============== About to add job pool" << std::endl; - JobPool jobPool(re.allocateOrGetJobPool(self), self); + cta::objectstore::JobPool jobPool(re.allocateOrGetJobPool(self), self); // Dump again std::cout << osd.dump(self) << std::endl;