diff options
author | Benoit Foucher <benoit@zeroc.com> | 2005-01-27 14:09:35 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2005-01-27 14:09:35 +0000 |
commit | 9b9bd3568a59a4b111953bc016a9bcdf08ca728c (patch) | |
tree | c644accf965ae25c0c4f8d318a5a19500d36f38a /cpp/src | |
parent | Connection validation now checks for Ice.Override.ConnectTimeout (diff) | |
download | ice-9b9bd3568a59a4b111953bc016a9bcdf08ca728c.tar.bz2 ice-9b9bd3568a59a4b111953bc016a9bcdf08ca728c.tar.xz ice-9b9bd3568a59a4b111953bc016a9bcdf08ca728c.zip |
Added 'object list' and 'object describe' IcePack admin commands.
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/ConnectionFactory.cpp | 1 | ||||
-rw-r--r-- | cpp/src/Ice/PropertiesI.cpp | 52 | ||||
-rw-r--r-- | cpp/src/Ice/PropertiesI.h | 2 | ||||
-rw-r--r-- | cpp/src/IcePack/AdapterRegistryI.cpp | 4 | ||||
-rw-r--r-- | cpp/src/IcePack/AdminI.cpp | 87 | ||||
-rw-r--r-- | cpp/src/IcePack/AdminI.h | 4 | ||||
-rw-r--r-- | cpp/src/IcePack/Grammar.y | 30 | ||||
-rw-r--r-- | cpp/src/IcePack/IcePackNode.cpp | 16 | ||||
-rw-r--r-- | cpp/src/IcePack/Internal.ice | 9 | ||||
-rw-r--r-- | cpp/src/IcePack/LocatorI.cpp | 2 | ||||
-rw-r--r-- | cpp/src/IcePack/NodeRegistryI.cpp | 46 | ||||
-rw-r--r-- | cpp/src/IcePack/ObjectRegistryI.cpp | 26 | ||||
-rw-r--r-- | cpp/src/IcePack/ObjectRegistryI.h | 5 | ||||
-rw-r--r-- | cpp/src/IcePack/Parser.cpp | 83 | ||||
-rw-r--r-- | cpp/src/IcePack/Parser.h | 2 | ||||
-rw-r--r-- | cpp/src/IcePack/Registry.cpp | 10 | ||||
-rw-r--r-- | cpp/src/IceUtil/StringUtil.cpp | 48 |
17 files changed, 297 insertions, 130 deletions
diff --git a/cpp/src/Ice/ConnectionFactory.cpp b/cpp/src/Ice/ConnectionFactory.cpp index 1c3f8e53766..a62ad4ea906 100644 --- a/cpp/src/Ice/ConnectionFactory.cpp +++ b/cpp/src/Ice/ConnectionFactory.cpp @@ -1093,6 +1093,7 @@ IceInternal::IncomingConnectionFactory::run() // can accept connections with this factory's // acceptor. Therefore we don't call validate() in thread per // connection mode. + // } } diff --git a/cpp/src/Ice/PropertiesI.cpp b/cpp/src/Ice/PropertiesI.cpp index ad67bff93a0..95063f3e188 100644 --- a/cpp/src/Ice/PropertiesI.cpp +++ b/cpp/src/Ice/PropertiesI.cpp @@ -7,6 +7,7 @@ // // ********************************************************************** +#include <IceUtil/StringUtil.h> #include <Ice/PropertiesI.h> #include <Ice/Initialize.h> #include <Ice/LocalException.h> @@ -91,55 +92,6 @@ Ice::PropertiesI::getPropertiesForPrefix(const string& prefix) return result; } -// -// Match `s' against the pattern `pat'. A * in the pattern acts -// as a wildcard: it matches any non-empty sequence of characters -// other than a period (`.'). We match by hand here because -// it's portable across platforms (whereas regex() isn't). -// - -bool -Ice::PropertiesI::match(const string& s, const string& pat) -{ - assert(!s.empty()); - assert(!pat.empty()); - - if(pat.find('*') == string::npos) - { - return s == pat; - } - - string::size_type sIndex = 0; - string::size_type patIndex = 0; - do - { - if(pat[patIndex] == '*') - { - if(s[sIndex] == '.') // Don't allow matching x..y against x.*.y -- star matches non-empty sequence only. - { - return false; - } - while(sIndex < s.size() && s[sIndex] != '.') - { - ++sIndex; - } - patIndex++; - } - else - { - if(pat[patIndex] != s[sIndex]) - { - return false; - } - ++sIndex; - ++patIndex; - } - } - while(sIndex < s.size() && patIndex < pat.size()); - - return sIndex == s.size() && patIndex == pat.size(); -} - void Ice::PropertiesI::setProperty(const string& key, const string& value) { @@ -171,7 +123,7 @@ Ice::PropertiesI::setProperty(const string& key, const string& value) bool found = false; for(const char* const* j = *i; *j != 0 && !found; ++j) { - found = match(key, *j); + found = IceUtil::match(key, *j); } if(!found) { diff --git a/cpp/src/Ice/PropertiesI.h b/cpp/src/Ice/PropertiesI.h index 1ce58dc3b74..ac6a611224b 100644 --- a/cpp/src/Ice/PropertiesI.h +++ b/cpp/src/Ice/PropertiesI.h @@ -46,8 +46,6 @@ private: void loadConfig(); - static bool match(const std::string&, const std::string&); - std::map<std::string, std::string> _properties; }; diff --git a/cpp/src/IcePack/AdapterRegistryI.cpp b/cpp/src/IcePack/AdapterRegistryI.cpp index 7e6fbaf0c0e..7c30a753765 100644 --- a/cpp/src/IcePack/AdapterRegistryI.cpp +++ b/cpp/src/IcePack/AdapterRegistryI.cpp @@ -65,7 +65,7 @@ IcePack::AdapterRegistryI::add(const string& id, const AdapterPrx& adapter, cons if(_traceLevels->adapterRegistry > 0) { Ice::Trace out(_traceLevels->logger, _traceLevels->adapterRegistryCat); - out << "added adapter `" << id << "'"; + out << "updated adapter `" << id << "'"; } } else @@ -120,7 +120,7 @@ IcePack::AdapterRegistryI::findById(const string& id, const Ice::Current&) StringObjectProxyDict::iterator p = dict.find(id); if(p != dict.end()) { - return AdapterPrx::uncheckedCast(p->second->ice_collocationOptimization(false)); + return AdapterPrx::uncheckedCast(p->second); } throw AdapterNotExistException(); } diff --git a/cpp/src/IcePack/AdminI.cpp b/cpp/src/IcePack/AdminI.cpp index 9c21ab78345..8c9089376e7 100644 --- a/cpp/src/IcePack/AdminI.cpp +++ b/cpp/src/IcePack/AdminI.cpp @@ -1021,7 +1021,7 @@ ServerCleaner::visitObject(const ObjectWrapper&, const ObjectDescriptor& object) { try { - _objectRegistry->remove(object.proxy); + _objectRegistry->remove(object.proxy->ice_getIdentity()); } catch(const ObjectNotExistException&) { @@ -1029,9 +1029,12 @@ ServerCleaner::visitObject(const ObjectWrapper&, const ObjectDescriptor& object) } } -IcePack::AdminI::AdminI(const CommunicatorPtr& communicator, const NodeRegistryPtr& nodeRegistry, - const ApplicationRegistryPtr& applicationRegistry, const ServerRegistryPtr& serverRegistry, - const AdapterRegistryPtr& adapterRegistry, const ObjectRegistryPtr& objectRegistry) : +AdminI::AdminI(const CommunicatorPtr& communicator, + const NodeRegistryPtr& nodeRegistry, + const ApplicationRegistryPtr& applicationRegistry, + const ServerRegistryPtr& serverRegistry, + const AdapterRegistryPtr& adapterRegistry, + const ObjectRegistryPtr& objectRegistry) : _communicator(communicator), _nodeRegistry(nodeRegistry), _applicationRegistry(applicationRegistry), @@ -1041,12 +1044,12 @@ IcePack::AdminI::AdminI(const CommunicatorPtr& communicator, const NodeRegistryP { } -IcePack::AdminI::~AdminI() +AdminI::~AdminI() { } void -IcePack::AdminI::addApplication(const ApplicationDescriptorPtr& descriptor, const Current&) +AdminI::addApplication(const ApplicationDescriptorPtr& descriptor, const Current&) { ApplicationDeployer(_nodeRegistry, _applicationRegistry, @@ -1057,7 +1060,7 @@ IcePack::AdminI::addApplication(const ApplicationDescriptorPtr& descriptor, cons } void -IcePack::AdminI::updateApplication(const ApplicationDescriptorPtr& descriptor, const Current&) +AdminI::updateApplication(const ApplicationDescriptorPtr& descriptor, const Current&) { ApplicationUpdater(_nodeRegistry, _applicationRegistry, @@ -1068,7 +1071,7 @@ IcePack::AdminI::updateApplication(const ApplicationDescriptorPtr& descriptor, c } void -IcePack::AdminI::removeApplication(const string& name, const Current&) +AdminI::removeApplication(const string& name, const Current&) { ApplicationCleaner(_nodeRegistry, _applicationRegistry, @@ -1079,19 +1082,19 @@ IcePack::AdminI::removeApplication(const string& name, const Current&) } ApplicationDescriptorPtr -IcePack::AdminI::getApplicationDescriptor(const string& name, const Current&) const +AdminI::getApplicationDescriptor(const string& name, const Current&) const { return _applicationRegistry->getDescriptor(name); } Ice::StringSeq -IcePack::AdminI::getAllApplicationNames(const Current&) const +AdminI::getAllApplicationNames(const Current&) const { return _applicationRegistry->getAll(); } void -IcePack::AdminI::addServer(const ServerDescriptorPtr& server, const Current&) +AdminI::addServer(const ServerDescriptorPtr& server, const Current&) { if(!server->application.empty()) { @@ -1110,7 +1113,7 @@ IcePack::AdminI::addServer(const ServerDescriptorPtr& server, const Current&) } void -IcePack::AdminI::updateServer(const ServerDescriptorPtr& server, const Current&) +AdminI::updateServer(const ServerDescriptorPtr& server, const Current&) { ServerDescriptorPtr orig = _serverRegistry->getDescriptor(server->name); if(!orig->application.empty()) @@ -1177,7 +1180,7 @@ IcePack::AdminI::updateServer(const ServerDescriptorPtr& server, const Current&) } void -IcePack::AdminI::removeServer(const string& name, const Current&) +AdminI::removeServer(const string& name, const Current&) { ServerDescriptorPtr server = _serverRegistry->getDescriptor(name); if(!server->application.empty()) @@ -1197,13 +1200,13 @@ IcePack::AdminI::removeServer(const string& name, const Current&) } ServerDescriptorPtr -IcePack::AdminI::getServerDescriptor(const string& name, const Current&) const +AdminI::getServerDescriptor(const string& name, const Current&) const { return _serverRegistry->getDescriptor(name); } ServerState -IcePack::AdminI::getServerState(const string& name, const Current&) const +AdminI::getServerState(const string& name, const Current&) const { ServerPrx server = _serverRegistry->findByName(name); try @@ -1221,7 +1224,7 @@ IcePack::AdminI::getServerState(const string& name, const Current&) const } Ice::Int -IcePack::AdminI::getServerPid(const string& name, const Current&) const +AdminI::getServerPid(const string& name, const Current&) const { ServerPrx server = _serverRegistry->findByName(name); try @@ -1239,7 +1242,7 @@ IcePack::AdminI::getServerPid(const string& name, const Current&) const } bool -IcePack::AdminI::startServer(const string& name, const Current&) +AdminI::startServer(const string& name, const Current&) { ServerPrx server = _serverRegistry->findByName(name); try @@ -1257,7 +1260,7 @@ IcePack::AdminI::startServer(const string& name, const Current&) } void -IcePack::AdminI::stopServer(const string& name, const Current&) +AdminI::stopServer(const string& name, const Current&) { ServerPrx server = _serverRegistry->findByName(name); try @@ -1275,7 +1278,7 @@ IcePack::AdminI::stopServer(const string& name, const Current&) } void -IcePack::AdminI::sendSignal(const string& name, const string& signal, const Current&) +AdminI::sendSignal(const string& name, const string& signal, const Current&) { ServerPrx server = _serverRegistry->findByName(name); try @@ -1293,7 +1296,7 @@ IcePack::AdminI::sendSignal(const string& name, const string& signal, const Curr } void -IcePack::AdminI::writeMessage(const string& name, const string& message, Int fd, const Current&) +AdminI::writeMessage(const string& name, const string& message, Int fd, const Current&) { ServerPrx server = _serverRegistry->findByName(name); try @@ -1312,13 +1315,13 @@ IcePack::AdminI::writeMessage(const string& name, const string& message, Int fd, StringSeq -IcePack::AdminI::getAllServerNames(const Current&) const +AdminI::getAllServerNames(const Current&) const { return _serverRegistry->getAll(); } ServerActivation -IcePack::AdminI::getServerActivation(const ::std::string& name, const Ice::Current&) const +AdminI::getServerActivation(const ::std::string& name, const Ice::Current&) const { ServerPrx server = _serverRegistry->findByName(name); try @@ -1336,7 +1339,7 @@ IcePack::AdminI::getServerActivation(const ::std::string& name, const Ice::Curre } void -IcePack::AdminI::setServerActivation(const ::std::string& name, ServerActivation mode, const Ice::Current&) +AdminI::setServerActivation(const ::std::string& name, ServerActivation mode, const Ice::Current&) { ServerPrx server = _serverRegistry->findByName(name); try @@ -1354,7 +1357,7 @@ IcePack::AdminI::setServerActivation(const ::std::string& name, ServerActivation } string -IcePack::AdminI::getAdapterEndpoints(const string& id, const Current&) const +AdminI::getAdapterEndpoints(const string& id, const Current&) const { AdapterPrx adapter = _adapterRegistry->findById(id); try @@ -1376,13 +1379,13 @@ IcePack::AdminI::getAdapterEndpoints(const string& id, const Current&) const } StringSeq -IcePack::AdminI::getAllAdapterIds(const Current&) const +AdminI::getAllAdapterIds(const Current&) const { return _adapterRegistry->getAll(); } void -IcePack::AdminI::addObject(const Ice::ObjectPrx& proxy, const ::Ice::Current& current) +AdminI::addObject(const Ice::ObjectPrx& proxy, const ::Ice::Current& current) { ObjectDescriptor desc; desc.proxy = proxy; @@ -1400,7 +1403,7 @@ IcePack::AdminI::addObject(const Ice::ObjectPrx& proxy, const ::Ice::Current& cu } void -IcePack::AdminI::addObjectWithType(const Ice::ObjectPrx& proxy, const string& type, const ::Ice::Current&) +AdminI::addObjectWithType(const Ice::ObjectPrx& proxy, const string& type, const ::Ice::Current&) { ObjectDescriptor desc; desc.proxy = proxy; @@ -1409,13 +1412,25 @@ IcePack::AdminI::addObjectWithType(const Ice::ObjectPrx& proxy, const string& ty } void -IcePack::AdminI::removeObject(const Ice::ObjectPrx& proxy, const Ice::Current&) +AdminI::removeObject(const Ice::Identity& id, const Ice::Current&) { - _objectRegistry->remove(proxy); + _objectRegistry->remove(id); +} + +ObjectDescriptor +AdminI::getObjectDescriptor(const Ice::Identity& id, const Ice::Current&) const +{ + return _objectRegistry->getObjectDescriptor(id); +} + +ObjectDescriptorSeq +AdminI::getAllObjectDescriptors(const string& expression, const Ice::Current&) const +{ + return _objectRegistry->findAll(expression); } bool -IcePack::AdminI::pingNode(const string& name, const Current&) const +AdminI::pingNode(const string& name, const Current&) const { NodePrx node = _nodeRegistry->findByName(name); try @@ -1434,7 +1449,7 @@ IcePack::AdminI::pingNode(const string& name, const Current&) const } void -IcePack::AdminI::shutdownNode(const string& name, const Current&) +AdminI::shutdownNode(const string& name, const Current&) { NodePrx node = _nodeRegistry->findByName(name); try @@ -1452,7 +1467,7 @@ IcePack::AdminI::shutdownNode(const string& name, const Current&) } void -IcePack::AdminI::removeNode(const string& name, const Current&) +AdminI::removeNode(const string& name, const Current&) { // // Remove the node servers. @@ -1475,7 +1490,7 @@ IcePack::AdminI::removeNode(const string& name, const Current&) } string -IcePack::AdminI::getNodeHostname(const string& name, const Current&) const +AdminI::getNodeHostname(const string& name, const Current&) const { NodePrx node = _nodeRegistry->findByName(name); try @@ -1494,19 +1509,19 @@ IcePack::AdminI::getNodeHostname(const string& name, const Current&) const StringSeq -IcePack::AdminI::getAllNodeNames(const Current&) const +AdminI::getAllNodeNames(const Current&) const { return _nodeRegistry->getAll(); } void -IcePack::AdminI::shutdown(const Current&) +AdminI::shutdown(const Current&) { _communicator->shutdown(); } SliceChecksumDict -IcePack::AdminI::getSliceChecksums(const Current&) const +AdminI::getSliceChecksums(const Current&) const { return sliceChecksums(); } diff --git a/cpp/src/IcePack/AdminI.h b/cpp/src/IcePack/AdminI.h index e723c57b570..8b7e6e79387 100644 --- a/cpp/src/IcePack/AdminI.h +++ b/cpp/src/IcePack/AdminI.h @@ -49,7 +49,9 @@ public: virtual void addObject(const ::Ice::ObjectPrx&, const ::Ice::Current&); virtual void addObjectWithType(const ::Ice::ObjectPrx&, const ::std::string&, const ::Ice::Current&); - virtual void removeObject(const ::Ice::ObjectPrx&, const ::Ice::Current&); + virtual void removeObject(const ::Ice::Identity&, const ::Ice::Current&); + virtual ObjectDescriptor getObjectDescriptor(const Ice::Identity&, const ::Ice::Current&) const; + virtual ObjectDescriptorSeq getAllObjectDescriptors(const std::string&, const ::Ice::Current&) const; virtual bool pingNode(const std::string&, const Ice::Current&) const; virtual void shutdownNode(const std::string&, const Ice::Current&); diff --git a/cpp/src/IcePack/Grammar.y b/cpp/src/IcePack/Grammar.y index 01810a77ccc..4a4434e7db7 100644 --- a/cpp/src/IcePack/Grammar.y +++ b/cpp/src/IcePack/Grammar.y @@ -211,6 +211,18 @@ command { parser->findObject($3); } +| ICE_PACK_OBJECT ICE_PACK_LIST optional_strings ';' +{ + parser->listObject($3); +} +| ICE_PACK_OBJECT ICE_PACK_DESCRIBE optional_strings ';' +{ + parser->describeObject($3); +} +| ICE_PACK_OBJECT ICE_PACK_LIST ';' +{ + parser->listObject(YYSTYPE()); +} | ICE_PACK_SHUTDOWN ';' { parser->shutdown(); @@ -246,4 +258,22 @@ strings } ; +// ---------------------------------------------------------------------- +optional_strings +// ---------------------------------------------------------------------- +: ICE_PACK_STRING optional_strings +{ + $$ = $2; + $$.push_front($1.front()); +} +| ICE_PACK_STRING +{ + $$ = $1; +} +| +{ + $$ = YYSTYPE() +} +; + %% diff --git a/cpp/src/IcePack/IcePackNode.cpp b/cpp/src/IcePack/IcePackNode.cpp index 45ff530b406..c6673a2c474 100644 --- a/cpp/src/IcePack/IcePackNode.cpp +++ b/cpp/src/IcePack/IcePackNode.cpp @@ -240,15 +240,23 @@ IcePack::NodeService::start(int argc, char* argv[]) struct _stat filestat; if(::_stat(dataPath.c_str(), &filestat) != 0 || !S_ISDIR(filestat.st_mode)) { - error("property `IcePack.Node.Data' is not set to a valid directory path"); - return false; + ostringstream os; + SyscallException ex(__FILE__, __LINE__); + ex.error = getSystemErrno(); + os << ex; + error("property `IcePack.Node.Data' is set to an invalid path:\n" + os.str()); + return false; } #else struct stat filestat; if(::stat(dataPath.c_str(), &filestat) != 0 || !S_ISDIR(filestat.st_mode)) { - error("property `IcePack.Node.Data' is not set to a valid directory path"); - return false; + ostringstream os; + SyscallException ex(__FILE__, __LINE__); + ex.error = getSystemErrno(); + os << ex; + error("property `IcePack.Node.Data' is set to an invalid path:\n" + os.str()); + return false; } #endif diff --git a/cpp/src/IcePack/Internal.ice b/cpp/src/IcePack/Internal.ice index 654c60618d7..2b1d459de0b 100644 --- a/cpp/src/IcePack/Internal.ice +++ b/cpp/src/IcePack/Internal.ice @@ -38,7 +38,7 @@ interface ObjectRegistry * Remove an object from the registry. * **/ - void remove(Object* obj) + void remove(Ice::Identity id) throws ObjectNotExistException; /** @@ -70,6 +70,13 @@ interface ObjectRegistry * **/ nonmutating Ice::ObjectProxySeq findAllWithType(string type); + + /** + * + * Find all the objects matching the given expression. + * + **/ + nonmutating ObjectDescriptorSeq findAll(string expression); }; /** diff --git a/cpp/src/IcePack/LocatorI.cpp b/cpp/src/IcePack/LocatorI.cpp index 6c78c23f400..5f87a60a5af 100644 --- a/cpp/src/IcePack/LocatorI.cpp +++ b/cpp/src/IcePack/LocatorI.cpp @@ -206,7 +206,7 @@ LocatorI::findAdapterById_async(const Ice::AMD_Locator_findAdapterByIdPtr& cb, AdapterPrx adapter; try { - adapter = AdapterPrx::uncheckedCast(_adapterRegistry->findById(id)); + adapter = AdapterPrx::uncheckedCast(_adapterRegistry->findById(id)->ice_collocationOptimization(false)); } catch(const AdapterNotExistException&) { diff --git a/cpp/src/IcePack/NodeRegistryI.cpp b/cpp/src/IcePack/NodeRegistryI.cpp index b75fb2290d0..63b8dec540c 100644 --- a/cpp/src/IcePack/NodeRegistryI.cpp +++ b/cpp/src/IcePack/NodeRegistryI.cpp @@ -101,42 +101,44 @@ NodeRegistryI::add(const string& name, const NodePrx& node, const Ice::Current& break; } - AdapterPrx adapter; - while(!adapter) + // + // Set the direct proxy of the node object adapter. + // + while(true) { try { - adapter = _adapterRegistry->findById("IcePack.Node." + name); - // // TODO: ensure this adapter has been created by the adapter factory. It's possible that an // adapter has been created with the same name. In such a case, the best is probably to // prevent the node registration by throwing an appropriate exception. The user would then // need to remove the adapter from the adapter registry to be able to run the node. // + + AdapterPrx adapter = _adapterRegistry->findById("IcePack.Node." + name); + adapter->setDirectProxy(node); + return; } catch(const AdapterNotExistException&) { - // - // Create and register the node adapter. - // - adapter = _adapterFactory->createStandaloneAdapter("IcePackNodeAdapter." + name); - try - { - _adapterRegistry->add("IcePack.Node." + name, adapter); - } - catch(const AdapterExistsException&) - { - adapter->destroy(); - adapter = 0; - } } - } + catch(const Ice::ObjectNotExistException&) + { + } - // - // Set the direct proxy of the node object adapter. - // - adapter->setDirectProxy(node); + // + // Create and register the node adapter. + // + AdapterPrx adapter = _adapterFactory->createStandaloneAdapter("IcePackNodeAdapter." + name); + try + { + _adapterRegistry->add("IcePack.Node." + name, adapter); + } + catch(const AdapterExistsException&) + { + adapter->destroy(); + } + } } void diff --git a/cpp/src/IcePack/ObjectRegistryI.cpp b/cpp/src/IcePack/ObjectRegistryI.cpp index caaba45b346..2fd46f9bc83 100644 --- a/cpp/src/IcePack/ObjectRegistryI.cpp +++ b/cpp/src/IcePack/ObjectRegistryI.cpp @@ -7,6 +7,8 @@ // // ********************************************************************** +#include <IceUtil/StringUtil.h> +#include <Ice/IdentityUtil.h> #include <IcePack/ObjectRegistryI.h> #include <IcePack/TraceLevels.h> #include <Freeze/Initialize.h> @@ -84,7 +86,7 @@ ObjectRegistryI::add(const ObjectDescriptor& obj, const Ice::Current&) } void -ObjectRegistryI::remove(const Ice::ObjectPrx& object, const Ice::Current&) +ObjectRegistryI::remove(const Ice::Identity& id, const Ice::Current&) { IceUtil::Mutex::Lock sync(*this); @@ -92,8 +94,6 @@ ObjectRegistryI::remove(const Ice::ObjectPrx& object, const Ice::Current&) IdentityObjectDescDict objects(connection, _objectsDbName); StringObjectProxySeqDict types(connection, _typesDbName); - Ice::Identity id = object->ice_getIdentity(); - IdentityObjectDescDict::iterator p = objects.find(id); if(p == objects.end()) { @@ -152,6 +152,7 @@ ObjectRegistryI::getObjectDescriptor(const Ice::Identity& id, const Ice::Current Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); IdentityObjectDescDict objects(connection, _objectsDbName); + IdentityObjectDescDict::iterator p = objects.find(id); if(p == objects.end()) { @@ -206,3 +207,22 @@ ObjectRegistryI::findAllWithType(const string& type, const Ice::Current&) const return p->second; } + +ObjectDescriptorSeq +ObjectRegistryI::findAll(const string& expression, const Ice::Current&) const +{ + Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); + IdentityObjectDescDict objects(connection, _objectsDbName); + + ObjectDescriptorSeq result; + for(IdentityObjectDescDict::const_iterator p = objects.begin(); p != objects.end(); ++p) + { + if(expression.empty() || + IceUtil::match(Ice::identityToString(p->second.proxy->ice_getIdentity()), expression)) + { + result.push_back(p->second); + } + } + return result; +} + diff --git a/cpp/src/IcePack/ObjectRegistryI.h b/cpp/src/IcePack/ObjectRegistryI.h index 318ef874ebf..a232e79f803 100644 --- a/cpp/src/IcePack/ObjectRegistryI.h +++ b/cpp/src/IcePack/ObjectRegistryI.h @@ -28,14 +28,15 @@ public: ObjectRegistryI(const Ice::CommunicatorPtr& communicator, const std::string&, const TraceLevelsPtr& traceLevels); virtual void add(const IcePack::ObjectDescriptor&, const ::Ice::Current&); - virtual void remove(const Ice::ObjectPrx&, const ::Ice::Current&); + virtual void remove(const Ice::Identity&, const ::Ice::Current&); virtual ObjectDescriptor getObjectDescriptor(const Ice::Identity&, const ::Ice::Current&) const; virtual Ice::ObjectPrx findById(const ::Ice::Identity&, const ::Ice::Current&) const; virtual Ice::ObjectPrx findByType(const std::string&, const ::Ice::Current&) const; virtual Ice::ObjectProxySeq findAllWithType(const std::string&, const ::Ice::Current&) const; - + virtual ObjectDescriptorSeq findAll(const std::string&, const ::Ice::Current&) const; + private: static const std::string _objectsDbName; diff --git a/cpp/src/IcePack/Parser.cpp b/cpp/src/IcePack/Parser.cpp index dcd710a43fc..eaef6e75a37 100644 --- a/cpp/src/IcePack/Parser.cpp +++ b/cpp/src/IcePack/Parser.cpp @@ -25,6 +25,7 @@ #endif #include <iterator> +#include <iomanip> extern FILE* yyin; extern int yydebug; @@ -322,6 +323,10 @@ IcePack::Parser::usage() " optionally specifying its type.\n" "object remove IDENTITY Remove an object from the object registry.\n" "object find TYPE Find all objects with the type TYPE.\n" + "object describe EXPR Describe all registered objects whose stringified\n" + " identity match EXPR.\n" + "object list EXPR List all registered objects whose stringified\n" + " identity match EXPR.\n" "\n" "shutdown Shut the IcePack registry down.\n" #ifdef GPL_BUILD @@ -1118,7 +1123,14 @@ IcePack::Parser::endpointsAdapter(const list<string>& args) try { string endpoints = _admin->getAdapterEndpoints(args.front()); - cout << endpoints << endl; + if(endpoints.empty()) + { + cout << "<inactive>" << endl; + } + else + { + cout << endpoints << endl; + } } catch(const Ice::Exception& ex) { @@ -1194,7 +1206,7 @@ IcePack::Parser::removeObject(const list<string>& args) try { - _admin->removeObject(_communicator->stringToProxy((*(args.begin())))); + _admin->removeObject(Ice::stringToIdentity((*(args.begin())))); } catch(const Ice::Exception& ex) { @@ -1230,6 +1242,73 @@ IcePack::Parser::findObject(const list<string>& args) } void +IcePack::Parser::describeObject(const list<string>& args) +{ + try + { + ObjectDescriptorSeq objects; + if(args.size() == 1) + { + string arg = *(args.begin()); + if(arg.find('*') == string::npos) + { + ObjectDescriptor desc = _admin->getObjectDescriptor(Ice::stringToIdentity(arg)); + cout << "proxy = " << _communicator->proxyToString(desc.proxy) << endl; + cout << "type = " << desc.type << endl; + return; + } + else + { + objects = _admin->getAllObjectDescriptors(arg); + } + } + else + { + objects = _admin->getAllObjectDescriptors(""); + } + + for(ObjectDescriptorSeq::const_iterator p = objects.begin(); p != objects.end(); ++p) + { + cout << "proxy = `" << _communicator->proxyToString(p->proxy) << "' type = `" << p->type << "'" << endl; + } + } + catch(const Ice::Exception& ex) + { + ostringstream s; + s << ex; + error(s.str()); + } +} + +void +IcePack::Parser::listObject(const list<string>& args) +{ + try + { + ObjectDescriptorSeq objects; + if(args.size() == 1) + { + objects = _admin->getAllObjectDescriptors(*(args.begin())); + } + else + { + objects = _admin->getAllObjectDescriptors(""); + } + + for(ObjectDescriptorSeq::const_iterator p = objects.begin(); p != objects.end(); ++p) + { + cout << Ice::identityToString(p->proxy->ice_getIdentity()) << endl; + } + } + catch(const Ice::Exception& ex) + { + ostringstream s; + s << ex; + error(s.str()); + } +} + +void IcePack::Parser::shutdown() { try diff --git a/cpp/src/IcePack/Parser.h b/cpp/src/IcePack/Parser.h index 9ee4f3997d5..36781b29667 100644 --- a/cpp/src/IcePack/Parser.h +++ b/cpp/src/IcePack/Parser.h @@ -98,6 +98,8 @@ public: void addObject(const std::list<std::string>&); void removeObject(const std::list<std::string>&); void findObject(const std::list<std::string>&); + void describeObject(const std::list<std::string>&); + void listObject(const std::list<std::string>&); void shutdown(); diff --git a/cpp/src/IcePack/Registry.cpp b/cpp/src/IcePack/Registry.cpp index 3a83ec1a862..ee2a8b87df1 100644 --- a/cpp/src/IcePack/Registry.cpp +++ b/cpp/src/IcePack/Registry.cpp @@ -79,8 +79,10 @@ IcePack::Registry::start(bool nowarn) if(stat(_envName.c_str(), &filestat) != 0 || !S_ISDIR(filestat.st_mode)) { Error out(_communicator->getLogger()); - out << "property `IcePack.Registry.Data' is not set to a valid directory path"; - return false; + SyscallException ex(__FILE__, __LINE__); + ex.error = getSystemErrno(); + out << "property `IcePack.Registry.Data' is set to an invalid path:\n" << ex; + return false; } } @@ -246,7 +248,7 @@ IcePack::Registry::start(bool nowarn) ObjectPrx queryPrx = clientAdapter->createDirectProxy(stringToIdentity("IcePack/Query")); try { - objectRegistry->remove(queryPrx); + objectRegistry->remove(queryPrx->ice_getIdentity()); } catch(const ObjectNotExistException&) { @@ -264,7 +266,7 @@ IcePack::Registry::start(bool nowarn) ObjectPrx adminPrx = adminAdapter->createDirectProxy(stringToIdentity("IcePack/Admin")); try { - objectRegistry->remove(adminPrx); + objectRegistry->remove(adminPrx->ice_getIdentity()); } catch(const ObjectNotExistException&) { diff --git a/cpp/src/IceUtil/StringUtil.cpp b/cpp/src/IceUtil/StringUtil.cpp index a232d85dfac..72bb715369f 100644 --- a/cpp/src/IceUtil/StringUtil.cpp +++ b/cpp/src/IceUtil/StringUtil.cpp @@ -255,3 +255,51 @@ IceUtil::checkQuote(const string& s, string::size_type start) } return 0; // Not quoted. } + +// +// Match `s' against the pattern `pat'. A * in the pattern acts +// as a wildcard: it matches any non-empty sequence of characters +// other than a period (`.'). We match by hand here because +// it's portable across platforms (whereas regex() isn't). +// +bool +IceUtil::match(const string& s, const string& pat) +{ + assert(!s.empty()); + assert(!pat.empty()); + + if(pat.find('*') == string::npos) + { + return s == pat; + } + + string::size_type sIndex = 0; + string::size_type patIndex = 0; + do + { + if(pat[patIndex] == '*') + { + if(s[sIndex] == '.') // Don't allow matching x..y against x.*.y -- star matches non-empty sequence only. + { + return false; + } + while(sIndex < s.size() && s[sIndex] != '.') + { + ++sIndex; + } + patIndex++; + } + else + { + if(pat[patIndex] != s[sIndex]) + { + return false; + } + ++sIndex; + ++patIndex; + } + } + while(sIndex < s.size() && patIndex < pat.size()); + + return sIndex == s.size() && patIndex == pat.size(); +} |