diff options
author | Michi Henning <michi@zeroc.com> | 2009-12-19 07:46:20 +1000 |
---|---|---|
committer | Michi Henning <michi@zeroc.com> | 2009-12-19 07:46:20 +1000 |
commit | 038798a0826fa20b70575997f7f37b4a80f711a4 (patch) | |
tree | 728a8326da646f28d670d8eb14cd2a28a014a5ad /cpp | |
parent | Fixed bug 4511 - properties override doesn't handle quotes (diff) | |
download | ice-038798a0826fa20b70575997f7f37b4a80f711a4.tar.bz2 ice-038798a0826fa20b70575997f7f37b4a80f711a4.tar.xz ice-038798a0826fa20b70575997f7f37b4a80f711a4.zip |
Bug 4512: demo/book/evictor_filesystem issues
Diffstat (limited to 'cpp')
4 files changed, 59 insertions, 91 deletions
diff --git a/cpp/demo/book/evictor_filesystem/PersistentFilesystem.ice b/cpp/demo/book/evictor_filesystem/PersistentFilesystem.ice index b8e915644d6..fe0216eb4d2 100644 --- a/cpp/demo/book/evictor_filesystem/PersistentFilesystem.ice +++ b/cpp/demo/book/evictor_filesystem/PersistentFilesystem.ice @@ -19,14 +19,14 @@ module Filesystem PersistentDirectory* parent; }; - ["cpp:virtual"]class PersistentFile extends PersistentNode implements File + class PersistentFile extends PersistentNode implements File { Lines text; }; dictionary<string, NodeDesc> NodeDict; - ["cpp:virtual"]class PersistentDirectory extends PersistentNode implements Directory + class PersistentDirectory extends PersistentNode implements Directory { ["freeze:write"] void removeNode(string name); diff --git a/cpp/demo/book/evictor_filesystem/PersistentFilesystemI.cpp b/cpp/demo/book/evictor_filesystem/PersistentFilesystemI.cpp index dc5ed333dff..4813ca17573 100644 --- a/cpp/demo/book/evictor_filesystem/PersistentFilesystemI.cpp +++ b/cpp/demo/book/evictor_filesystem/PersistentFilesystemI.cpp @@ -12,27 +12,19 @@ using namespace std; // -// Filesystem::NodeI +// Filesystem::FileI // -Freeze::EvictorPtr Filesystem::NodeI::_evictor; -Filesystem::NodeI::NodeI() - : _destroyed(false), _id(Ice::Identity()) -{ -} +Freeze::EvictorPtr Filesystem::FileI::_evictor; -Filesystem::NodeI::NodeI(const Ice::Identity& id) - : _destroyed(false), _id(id) +Filesystem::FileI::FileI() : _destroyed(false) { } -// -// Filesystem::FileI -// string Filesystem::FileI::name(const Ice::Current& c) { - IceUtil::Mutex::Lock lock(*this); + IceUtil::Mutex::Lock lock(_mutex); if(_destroyed) { @@ -46,7 +38,7 @@ void Filesystem::FileI::destroy(const Ice::Current& c) { { - IceUtil::Mutex::Lock lock(*this); + IceUtil::Mutex::Lock lock(_mutex); if(_destroyed) { @@ -55,14 +47,17 @@ Filesystem::FileI::destroy(const Ice::Current& c) _destroyed = true; } + // + // Because we use a transactional evictor, these updates are guaranteed to be atomic. + // parent->removeNode(nodeName); - _evictor->remove(_id); + _evictor->remove(c.id); } Filesystem::Lines Filesystem::FileI::read(const Ice::Current& c) { - IceUtil::Mutex::Lock lock(*this); + IceUtil::Mutex::Lock lock(_mutex); if(_destroyed) { @@ -75,7 +70,7 @@ Filesystem::FileI::read(const Ice::Current& c) void Filesystem::FileI::write(const Filesystem::Lines& text, const Ice::Current& c) { - IceUtil::Mutex::Lock lock(*this); + IceUtil::Mutex::Lock lock(_mutex); if(_destroyed) { @@ -85,22 +80,20 @@ Filesystem::FileI::write(const Filesystem::Lines& text, const Ice::Current& c) this->text = text; } -Filesystem::FileI::FileI() -{ -} +// +// Filesystem::DirectoryI +// -Filesystem::FileI::FileI(const Ice::Identity& id) - : NodeI(id) +Freeze::EvictorPtr Filesystem::DirectoryI::_evictor; + +Filesystem::DirectoryI::DirectoryI() : _destroyed(false) { } -// -// Filesystem::DirectoryI -// string Filesystem::DirectoryI::name(const Ice::Current& c) { - IceUtil::Mutex::Lock lock(*this); + IceUtil::Mutex::Lock lock(_mutex); if(_destroyed) { @@ -119,7 +112,7 @@ Filesystem::DirectoryI::destroy(const Ice::Current& c) } { - IceUtil::Mutex::Lock lock(*this); + IceUtil::Mutex::Lock lock(_mutex); if(_destroyed) { @@ -132,14 +125,17 @@ Filesystem::DirectoryI::destroy(const Ice::Current& c) _destroyed = true; } + // + // Because we use a transactional evictor, these updates are guaranteed to be atomic. + // parent->removeNode(nodeName); - _evictor->remove(_id); + _evictor->remove(c.id); } Filesystem::NodeDescSeq Filesystem::DirectoryI::list(const Ice::Current& c) { - IceUtil::Mutex::Lock lock(*this); + IceUtil::Mutex::Lock lock(_mutex); if(_destroyed) { @@ -158,7 +154,7 @@ Filesystem::DirectoryI::list(const Ice::Current& c) Filesystem::NodeDesc Filesystem::DirectoryI::find(const string& name, const Ice::Current& c) { - IceUtil::Mutex::Lock lock(*this); + IceUtil::Mutex::Lock lock(_mutex); if(_destroyed) { @@ -176,7 +172,7 @@ Filesystem::DirectoryI::find(const string& name, const Ice::Current& c) Filesystem::DirectoryPrx Filesystem::DirectoryI::createDirectory(const string& name, const Ice::Current& c) { - IceUtil::Mutex::Lock lock(*this); + IceUtil::Mutex::Lock lock(_mutex); if(_destroyed) { @@ -190,7 +186,7 @@ Filesystem::DirectoryI::createDirectory(const string& name, const Ice::Current& Ice::Identity id; id.name = IceUtil::generateUUID(); - PersistentDirectoryPtr dir = new DirectoryI(id); + PersistentDirectoryPtr dir = new DirectoryI; dir->nodeName = name; dir->parent = PersistentDirectoryPrx::uncheckedCast(c.adapter->createProxy(c.id)); DirectoryPrx proxy = DirectoryPrx::uncheckedCast(_evictor->add(dir, id)); @@ -207,7 +203,7 @@ Filesystem::DirectoryI::createDirectory(const string& name, const Ice::Current& Filesystem::FilePrx Filesystem::DirectoryI::createFile(const string& name, const Ice::Current& c) { - IceUtil::Mutex::Lock lock(*this); + IceUtil::Mutex::Lock lock(_mutex); if(_destroyed) { @@ -221,7 +217,7 @@ Filesystem::DirectoryI::createFile(const string& name, const Ice::Current& c) Ice::Identity id; id.name = IceUtil::generateUUID(); - PersistentFilePtr file = new FileI(id); + PersistentFilePtr file = new FileI; file->nodeName = name; file->parent = PersistentDirectoryPrx::uncheckedCast(c.adapter->createProxy(c.id)); FilePrx proxy = FilePrx::uncheckedCast(_evictor->add(file, id)); @@ -238,22 +234,13 @@ Filesystem::DirectoryI::createFile(const string& name, const Ice::Current& c) void Filesystem::DirectoryI::removeNode(const string& name, const Ice::Current&) { - IceUtil::Mutex::Lock lock(*this); + IceUtil::Mutex::Lock lock(_mutex); NodeDict::iterator p = nodes.find(name); assert(p != nodes.end()); nodes.erase(p); } -Filesystem::DirectoryI::DirectoryI() -{ -} - -Filesystem::DirectoryI::DirectoryI(const Ice::Identity& id) : - NodeI(id) -{ -} - // // Filesystem::NodeFactory // @@ -279,17 +266,3 @@ void Filesystem::NodeFactory::destroy() { } - -// -// Filesystem::NodeInitializer -// -void -Filesystem::NodeInitializer::initialize(const Ice::ObjectAdapterPtr&, - const Ice::Identity& id, - const string& facet, - const Ice::ObjectPtr& obj) -{ - NodeIPtr node = NodeIPtr::dynamicCast(obj); - assert(node); - const_cast<Ice::Identity&>(node->_id) = id; -} diff --git a/cpp/demo/book/evictor_filesystem/PersistentFilesystemI.h b/cpp/demo/book/evictor_filesystem/PersistentFilesystemI.h index ae6773be1fe..bd112facb5a 100644 --- a/cpp/demo/book/evictor_filesystem/PersistentFilesystemI.h +++ b/cpp/demo/book/evictor_filesystem/PersistentFilesystemI.h @@ -27,36 +27,37 @@ public: protected: NodeI(); - NodeI(const Ice::Identity&); bool _destroyed; - -public: - - const Ice::Identity _id; }; typedef IceUtil::Handle<NodeI> NodeIPtr; -class FileI : virtual public PersistentFile, - virtual public NodeI +class FileI : virtual public PersistentFile { public: + FileI(); + virtual std::string name(const Ice::Current&); virtual void destroy(const Ice::Current&); virtual Lines read(const Ice::Current&); virtual void write(const Lines&, const Ice::Current&); - FileI(); - FileI(const Ice::Identity&); + static Freeze::EvictorPtr _evictor; + +private: + + bool _destroyed; + IceUtil::Mutex _mutex; }; -class DirectoryI : virtual public PersistentDirectory, - virtual public NodeI +class DirectoryI : virtual public PersistentDirectory { public: + DirectoryI(); + virtual std::string name(const Ice::Current&); virtual void destroy(const Ice::Current&); @@ -66,9 +67,12 @@ public: virtual FilePrx createFile(const std::string&, const Ice::Current&); virtual void removeNode(const std::string&, const Ice::Current&); - DirectoryI(); - DirectoryI(const Ice::Identity&); + static Freeze::EvictorPtr _evictor; +public: + + bool _destroyed; + IceUtil::Mutex _mutex; }; class NodeFactory : virtual public Ice::ObjectFactory @@ -79,16 +83,6 @@ public: virtual void destroy(); }; -class NodeInitializer : virtual public Freeze::ServantInitializer -{ -public: - - virtual void initialize(const Ice::ObjectAdapterPtr&, - const Ice::Identity&, - const std::string&, - const Ice::ObjectPtr&); -}; - } #endif diff --git a/cpp/demo/book/evictor_filesystem/Server.cpp b/cpp/demo/book/evictor_filesystem/Server.cpp index 72af8fe658d..4692488244a 100644 --- a/cpp/demo/book/evictor_filesystem/Server.cpp +++ b/cpp/demo/book/evictor_filesystem/Server.cpp @@ -36,23 +36,24 @@ public: Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("EvictorFilesystem"); // - // Create the Freeze evictor (stored in the NodeI::_evictor static member). + // Create the Freeze evictor. // - Freeze::ServantInitializerPtr init = new NodeInitializer; - NodeI::_evictor = Freeze::createTransactionalEvictor(adapter, _envName, "evictorfs", - Freeze::FacetTypeMap(), init); + Freeze::EvictorPtr evictor = Freeze::createTransactionalEvictor(adapter, _envName, "evictorfs"); + FileI::_evictor = evictor; + DirectoryI::_evictor = evictor; - adapter->addServantLocator(NodeI::_evictor, ""); + adapter->addServantLocator(evictor, ""); // // Create the root node if it doesn't exist. // - Ice::Identity rootId = communicator()->stringToIdentity("RootDir"); - if(!NodeI::_evictor->hasObject(rootId)) + Ice::Identity rootId; + rootId.name = "RootDir"; + if(!evictor->hasObject(rootId)) { - PersistentDirectoryPtr root = new DirectoryI(rootId); + PersistentDirectoryPtr root = new DirectoryI; root->nodeName = "/"; - NodeI::_evictor->add(root, rootId); + evictor->add(root, rootId); } // |