diff options
author | Benoit Foucher <benoit@zeroc.com> | 2009-03-24 11:45:18 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2009-03-24 11:45:18 +0100 |
commit | 06a08ecf28e205277336a97a6173db7ccbed1adc (patch) | |
tree | a369a5044a63f8cdba9e7c0a461e24ae344486b4 /cpp/demo/book/lifecycle/FilesystemI.cpp | |
parent | Merge branch 'R3_3_branch' (diff) | |
parent | Bug 3924: slice2py missing from VC60 installer (diff) | |
download | ice-06a08ecf28e205277336a97a6173db7ccbed1adc.tar.bz2 ice-06a08ecf28e205277336a97a6173db7ccbed1adc.tar.xz ice-06a08ecf28e205277336a97a6173db7ccbed1adc.zip |
Merge commit 'origin/R3_3_branch'
Conflicts:
CHANGES
cpp/demo/Freeze/backup/.depend
cpp/demo/Freeze/bench/.depend
cpp/demo/Freeze/casino/.depend
cpp/demo/Freeze/customEvictor/.depend
cpp/demo/Freeze/library/.depend
cpp/demo/Freeze/phonebook/.depend
cpp/demo/Freeze/transform/.depend
cpp/demo/Glacier2/callback/.depend
cpp/demo/Glacier2/chat/.depend
cpp/demo/Ice/async/.depend
cpp/demo/Ice/bidir/.depend
cpp/demo/Ice/callback/.depend
cpp/demo/Ice/converter/.depend
cpp/demo/Ice/hello/.depend
cpp/demo/Ice/invoke/.depend
cpp/demo/Ice/latency/.depend
cpp/demo/Ice/minimal/.depend
cpp/demo/Ice/multicast/.depend
cpp/demo/Ice/nested/.depend
cpp/demo/Ice/nrvo/.depend
cpp/demo/Ice/session/.depend
cpp/demo/Ice/throughput/.depend
cpp/demo/Ice/value/.depend
cpp/demo/IceBox/hello/.depend
cpp/demo/IceGrid/allocate/.depend
cpp/demo/IceGrid/icebox/.depend
cpp/demo/IceGrid/replication/.depend
cpp/demo/IceGrid/sessionActivation/.depend
cpp/demo/IceGrid/simple/.depend
cpp/demo/IceStorm/clock/.depend
cpp/demo/IceStorm/counter/.depend
cpp/demo/IceStorm/replicated/.depend
cpp/demo/IceStorm/replicated2/.depend
cpp/demo/book/freeze_filesystem/.depend
cpp/demo/book/lifecycle/.depend
cpp/demo/book/printer/.depend
cpp/demo/book/simple_filesystem/.depend
cpp/src/Freeze/.depend
cpp/src/FreezeScript/.depend
cpp/src/Ice/.depend
cpp/src/Ice/UdpTransceiver.cpp
cpp/src/Ice/UdpTransceiver.h
cpp/src/IceBox/.depend
cpp/src/IceGrid/.depend
cpp/src/IceGridLib/.depend
cpp/src/IcePatch2/.depend
cpp/src/IceStorm/.depend
cpp/src/slice2freeze/.depend
cpp/test/Freeze/complex/.depend
cpp/test/Freeze/dbmap/.depend
cpp/test/Freeze/evictor/.depend
cpp/test/Freeze/oldevictor/.depend
cpp/test/FreezeScript/dbmap/.depend
cpp/test/FreezeScript/evictor/.depend
cpp/test/Glacier2/attack/.depend
cpp/test/Glacier2/dynamicFiltering/.depend
cpp/test/Glacier2/router/.depend
cpp/test/Glacier2/sessionControl/.depend
cpp/test/Glacier2/ssl/.depend
cpp/test/Glacier2/staticFiltering/.depend
cpp/test/Ice/adapterDeactivation/.depend
cpp/test/Ice/background/.depend
cpp/test/Ice/binding/.depend
cpp/test/Ice/checksum/.depend
cpp/test/Ice/checksum/server/.depend
cpp/test/Ice/custom/.depend
cpp/test/Ice/exceptions/.depend
cpp/test/Ice/facets/.depend
cpp/test/Ice/faultTolerance/.depend
cpp/test/Ice/gc/.depend
cpp/test/Ice/hold/.depend
cpp/test/Ice/inheritance/.depend
cpp/test/Ice/interceptor/.depend
cpp/test/Ice/location/.depend
cpp/test/Ice/objects/.depend
cpp/test/Ice/operations/.depend
cpp/test/Ice/proxy/.depend
cpp/test/Ice/retry/.depend
cpp/test/Ice/servantLocator/.depend
cpp/test/Ice/slicing/exceptions/.depend
cpp/test/Ice/slicing/objects/.depend
cpp/test/Ice/stream/.depend
cpp/test/Ice/stringConverter/.depend
cpp/test/Ice/timeout/.depend
cpp/test/Ice/udp/.depend
cpp/test/IceBox/configuration/.depend
cpp/test/IceGrid/activation/.depend
cpp/test/IceGrid/allocation/.depend
cpp/test/IceGrid/deployer/.depend
cpp/test/IceGrid/distribution/.depend
cpp/test/IceGrid/replicaGroup/.depend
cpp/test/IceGrid/replication/.depend
cpp/test/IceGrid/session/.depend
cpp/test/IceGrid/simple/.depend
cpp/test/IceGrid/update/.depend
cpp/test/IceSSL/configuration/.depend
cpp/test/IceStorm/federation/.depend
cpp/test/IceStorm/federation2/.depend
cpp/test/IceStorm/rep1/.depend
cpp/test/IceStorm/repgrid/.depend
cpp/test/IceStorm/repstress/.depend
cpp/test/IceStorm/single/.depend
cpp/test/IceStorm/stress/.depend
cpp/test/Slice/keyword/.depend
cs/src/Ice/Instance.cs
cs/src/IceSSL/ConnectorI.cs
java/demo/book/simple_filesystem/Filesystem/DirectoryI.java
java/demo/book/simple_filesystem/Filesystem/FileI.java
java/src/IceInternal/TcpConnector.java
java/src/IceSSL/ConnectorI.java
py/modules/IcePy/.depend
rb/src/IceRuby/.depend
Diffstat (limited to 'cpp/demo/book/lifecycle/FilesystemI.cpp')
-rw-r--r-- | cpp/demo/book/lifecycle/FilesystemI.cpp | 154 |
1 files changed, 43 insertions, 111 deletions
diff --git a/cpp/demo/book/lifecycle/FilesystemI.cpp b/cpp/demo/book/lifecycle/FilesystemI.cpp index 463087c756d..c48ba2f227d 100644 --- a/cpp/demo/book/lifecycle/FilesystemI.cpp +++ b/cpp/demo/book/lifecycle/FilesystemI.cpp @@ -15,9 +15,6 @@ using namespace Ice; using namespace Filesystem; using namespace FilesystemI; -IceUtil::StaticMutex FilesystemI::DirectoryI::_lcMutex = ICE_STATIC_MUTEX_INITIALIZER; -FilesystemI::DirectoryI::ReapMap FilesystemI::DirectoryI::_reapMap; - // Slice Node::name() operation. std::string @@ -41,19 +38,6 @@ FilesystemI::NodeI::id() const return _id; } -// Activate the servant and add it to the parent's contents map. - -ObjectPrx -FilesystemI::NodeI::activate(const ObjectAdapterPtr& a) -{ - ObjectPrx node = a->add(this, _id); - if(_parent) - { - _parent->addChild(_name, this); - } - return node; -} - // NodeI constructor. FilesystemI::NodeI::NodeI(const string& name, const DirectoryIPtr& parent) @@ -113,13 +97,12 @@ FilesystemI::FileI::destroy(const Current& c) { throw ObjectNotExistException(__FILE__, __LINE__, c.id, c.facet, c.operation); } + + c.adapter->remove(id()); _destroyed = true; } - IceUtil::StaticMutex::Lock lock(DirectoryI::_lcMutex); - - c.adapter->remove(id()); - _parent->addReapEntry(_name); + _parent->removeEntry(_name); } // FileI constructor. @@ -134,19 +117,13 @@ FilesystemI::FileI::FileI(const string& name, const DirectoryIPtr& parent) NodeDescSeq FilesystemI::DirectoryI::list(const Current& c) { + IceUtil::Mutex::Lock lock(_m); + + if(_destroyed) { - IceUtil::Mutex::Lock lock(_m); - - if(_destroyed) - { - throw ObjectNotExistException(__FILE__, __LINE__, c.id, c.facet, c.operation); - } + throw ObjectNotExistException(__FILE__, __LINE__, c.id, c.facet, c.operation); } - IceUtil::StaticMutex::Lock lock(_lcMutex); - - reap(); - NodeDescSeq ret; for(Contents::const_iterator i = _contents.begin(); i != _contents.end(); ++i) { @@ -164,19 +141,13 @@ FilesystemI::DirectoryI::list(const Current& c) NodeDesc FilesystemI::DirectoryI::find(const string& name, const Current& c) { + IceUtil::Mutex::Lock lock(_m); + + if(_destroyed) { - IceUtil::Mutex::Lock lock(_m); - - if(_destroyed) - { - throw ObjectNotExistException(__FILE__, __LINE__, c.id, c.facet, c.operation); - } + throw ObjectNotExistException(__FILE__, __LINE__, c.id, c.facet, c.operation); } - IceUtil::StaticMutex::Lock lock(_lcMutex); - - reap(); - Contents::const_iterator pos = _contents.find(name); if(pos == _contents.end()) { @@ -196,26 +167,22 @@ FilesystemI::DirectoryI::find(const string& name, const Current& c) FilePrx FilesystemI::DirectoryI::createFile(const string& name, const Current& c) { - { - IceUtil::Mutex::Lock lock(_m); + IceUtil::Mutex::Lock lock(_m); - if(_destroyed) - { - throw ObjectNotExistException(__FILE__, __LINE__, c.id, c.facet, c.operation); - } + if(_destroyed) + { + throw ObjectNotExistException(__FILE__, __LINE__, c.id, c.facet, c.operation); } - IceUtil::StaticMutex::Lock lock(_lcMutex); - - reap(); - if(name.empty() || _contents.find(name) != _contents.end()) { throw NameInUse(name); } FileIPtr f = new FileI(name, this); - return FilePrx::uncheckedCast(f->activate(c.adapter)); + ObjectPrx node = c.adapter->add(f, f->id()); + _contents[name] = f; + return FilePrx::uncheckedCast(node); } // Slice Directory::createDirectory() operation. @@ -223,26 +190,22 @@ FilesystemI::DirectoryI::createFile(const string& name, const Current& c) DirectoryPrx FilesystemI::DirectoryI::createDirectory(const string& name, const Current& c) { - { - IceUtil::Mutex::Lock lock(_m); + IceUtil::Mutex::Lock lock(_m); - if(_destroyed) - { - throw ObjectNotExistException(__FILE__, __LINE__, c.id, c.facet, c.operation); - } + if(_destroyed) + { + throw ObjectNotExistException(__FILE__, __LINE__, c.id, c.facet, c.operation); } - IceUtil::StaticMutex::Lock lock(_lcMutex); - - reap(); - if(name.empty() || _contents.find(name) != _contents.end()) { throw NameInUse(name); } DirectoryIPtr d = new DirectoryI(name, this); - return DirectoryPrx::uncheckedCast(d->activate(c.adapter)); + ObjectPrx node = c.adapter->add(d, d->id()); + _contents[name] = d; + return DirectoryPrx::uncheckedCast(node); } // Slice Directory::destroy() operation. @@ -250,31 +213,29 @@ FilesystemI::DirectoryI::createDirectory(const string& name, const Current& c) void FilesystemI::DirectoryI::destroy(const Current& c) { - if(!_parent) { throw PermissionDenied("Cannot destroy root directory"); } - IceUtil::Mutex::Lock lock(_m); - - if(_destroyed) { - throw ObjectNotExistException(__FILE__, __LINE__, c.id, c.facet, c.operation); - } + IceUtil::Mutex::Lock lock(_m); - IceUtil::StaticMutex::Lock lcLock(_lcMutex); + if(_destroyed) + { + throw ObjectNotExistException(__FILE__, __LINE__, c.id, c.facet, c.operation); + } - reap(); + if(!_contents.empty()) + { + throw PermissionDenied("Cannot destroy non-empty directory"); + } - if(!_contents.empty()) - { - throw PermissionDenied("Cannot destroy non-empty directory"); + c.adapter->remove(id()); + _destroyed = true; } - c.adapter->remove(id()); - _parent->addReapEntry(_name); - _destroyed = true; + _parent->removeEntry(_name); } // DirectoryI constructor. @@ -284,44 +245,15 @@ FilesystemI::DirectoryI::DirectoryI(const string& name, const DirectoryIPtr& par { } -// Add the passed name-node pair to the _contents map. +// Remove the entry from the _contents map. void -FilesystemI::DirectoryI::addChild(const string& name, const NodeIPtr& node) +FilesystemI::DirectoryI::removeEntry(const string& name) { - _contents[name] = node; -} - - -// Add this directory and the name of a deleted entry to the reap map. - -void -FilesystemI::DirectoryI::addReapEntry(const string& name) -{ - ReapMap::iterator pos = _reapMap.find(this); - if(pos != _reapMap.end()) - { - pos->second.push_back(name); - } - else + IceUtil::Mutex::Lock lock(_m); + Contents::iterator i = _contents.find(name); + if(i != _contents.end()) { - vector<string> v; - v.push_back(name); - _reapMap[this] = v; + _contents.erase(i); } } - -// Remove all names in the reap map from the corresponding directory contents. - -void -FilesystemI::DirectoryI::reap() -{ - for(ReapMap::const_iterator i = _reapMap.begin(); i != _reapMap.end(); ++i) - { - for(vector<string>::const_iterator j = i->second.begin(); j != i->second.end(); ++j) - { - i->first->_contents.erase(*j); - } - } - _reapMap.clear(); -} |