diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/config/Make.rules | 12 | ||||
-rw-r--r-- | cpp/msbuild/ice.test.sln | 4 | ||||
-rw-r--r-- | cpp/src/IceDiscovery/LocatorI.cpp | 16 | ||||
-rw-r--r-- | cpp/src/IceDiscovery/LookupI.cpp | 322 | ||||
-rw-r--r-- | cpp/src/IceDiscovery/LookupI.h | 173 | ||||
-rw-r--r-- | cpp/src/IceLocatorDiscovery/PluginI.cpp | 204 | ||||
-rw-r--r-- | cpp/test/IceDiscovery/simple/AllTests.cpp | 49 | ||||
-rw-r--r-- | cpp/test/IceGrid/simple/AllTests.cpp | 119 | ||||
-rw-r--r-- | cpp/test/IceGrid/simple/Server.cpp | 2 |
9 files changed, 553 insertions, 348 deletions
diff --git a/cpp/config/Make.rules b/cpp/config/Make.rules index 6e9a1ce9b20..14767faed0c 100644 --- a/cpp/config/Make.rules +++ b/cpp/config/Make.rules @@ -51,7 +51,13 @@ shared_excludes = IceUtil Slice # Build only few components with the static configuration (core and stubs) # static_components = $(coreandstub_components) -static_projects = test/Common test/Ice/% test/IceSSL/% test/IceDiscovery/simple test/IceGrid/simple +static_projects = test/Common \ + test/Ice/% \ + test/IceSSL/% \ + test/IceDiscovery/simple \ + test/Glacier2/application \ + test/IceGrid/simple + static_excludes = test/Ice/library test/Ice/plugin # @@ -65,7 +71,9 @@ cpp11_projects = test/Common \ test/Ice/% \ test/IceSSL/% \ test/IceDiscovery/% \ - test/IceBox/% + test/IceBox/% \ + test/Glacier2/application \ + test/IceGrid/simple cpp11_excludes = IcePatch2 \ test/Ice/gc diff --git a/cpp/msbuild/ice.test.sln b/cpp/msbuild/ice.test.sln index f022f3c4e37..91969a1a3d4 100644 --- a/cpp/msbuild/ice.test.sln +++ b/cpp/msbuild/ice.test.sln @@ -3788,8 +3788,10 @@ Global {16EED45E-8D20-40EF-BB30-9DDD5A11B352}.Release|x64.ActiveCfg = Release|x64 {16EED45E-8D20-40EF-BB30-9DDD5A11B352}.Release|x64.Build.0 = Release|x64 {2B721A85-96F1-4B92-BB31-1BCEF6ACFC8E}.Cpp11-Debug|Win32.ActiveCfg = Cpp11-Debug|Win32 + {2B721A85-96F1-4B92-BB31-1BCEF6ACFC8E}.Cpp11-Debug|Win32.Build.0 = Cpp11-Debug|Win32 {2B721A85-96F1-4B92-BB31-1BCEF6ACFC8E}.Cpp11-Debug|x64.ActiveCfg = Cpp11-Debug|x64 {2B721A85-96F1-4B92-BB31-1BCEF6ACFC8E}.Cpp11-Release|Win32.ActiveCfg = Cpp11-Release|Win32 + {2B721A85-96F1-4B92-BB31-1BCEF6ACFC8E}.Cpp11-Release|Win32.Build.0 = Cpp11-Release|Win32 {2B721A85-96F1-4B92-BB31-1BCEF6ACFC8E}.Cpp11-Release|x64.ActiveCfg = Cpp11-Release|x64 {2B721A85-96F1-4B92-BB31-1BCEF6ACFC8E}.Debug|Win32.ActiveCfg = Debug|Win32 {2B721A85-96F1-4B92-BB31-1BCEF6ACFC8E}.Debug|Win32.Build.0 = Debug|Win32 @@ -3800,8 +3802,10 @@ Global {2B721A85-96F1-4B92-BB31-1BCEF6ACFC8E}.Release|x64.ActiveCfg = Release|x64 {2B721A85-96F1-4B92-BB31-1BCEF6ACFC8E}.Release|x64.Build.0 = Release|x64 {C5606B09-9FB7-4337-A490-2024CDCE4036}.Cpp11-Debug|Win32.ActiveCfg = Cpp11-Debug|Win32 + {C5606B09-9FB7-4337-A490-2024CDCE4036}.Cpp11-Debug|Win32.Build.0 = Cpp11-Debug|Win32 {C5606B09-9FB7-4337-A490-2024CDCE4036}.Cpp11-Debug|x64.ActiveCfg = Cpp11-Debug|x64 {C5606B09-9FB7-4337-A490-2024CDCE4036}.Cpp11-Release|Win32.ActiveCfg = Cpp11-Release|Win32 + {C5606B09-9FB7-4337-A490-2024CDCE4036}.Cpp11-Release|Win32.Build.0 = Cpp11-Release|Win32 {C5606B09-9FB7-4337-A490-2024CDCE4036}.Cpp11-Release|x64.ActiveCfg = Cpp11-Release|x64 {C5606B09-9FB7-4337-A490-2024CDCE4036}.Debug|Win32.ActiveCfg = Debug|Win32 {C5606B09-9FB7-4337-A490-2024CDCE4036}.Debug|Win32.Build.0 = Debug|Win32 diff --git a/cpp/src/IceDiscovery/LocatorI.cpp b/cpp/src/IceDiscovery/LocatorI.cpp index 6998007fa14..99e1cdc4fa6 100644 --- a/cpp/src/IceDiscovery/LocatorI.cpp +++ b/cpp/src/IceDiscovery/LocatorI.cpp @@ -229,20 +229,20 @@ LocatorI::LocatorI(const LookupIPtr& lookup, const LocatorRegistryPrxPtr& regist #ifdef ICE_CPP11_MAPPING void LocatorI::findObjectByIdAsync(Ice::Identity id, - function<void(const shared_ptr<ObjectPrx>&)> response, - function<void(exception_ptr)>, - const Ice::Current&) const + function<void(const shared_ptr<ObjectPrx>&)> response, + function<void(exception_ptr)> ex, + const Ice::Current&) const { - _lookup->findObject(response, id); + _lookup->findObject(make_pair(response, ex), id); } void LocatorI::findAdapterByIdAsync(string adapterId, - function<void(const shared_ptr<ObjectPrx>&)> response, - function<void(exception_ptr)>, - const Ice::Current&) const + function<void(const shared_ptr<ObjectPrx>&)> response, + function<void(exception_ptr)> ex, + const Ice::Current&) const { - _lookup->findAdapter(response, adapterId); + _lookup->findAdapter(make_pair(response, ex), adapterId); } #else void diff --git a/cpp/src/IceDiscovery/LookupI.cpp b/cpp/src/IceDiscovery/LookupI.cpp index 76fb6525f03..ae560cbacfd 100644 --- a/cpp/src/IceDiscovery/LookupI.cpp +++ b/cpp/src/IceDiscovery/LookupI.cpp @@ -12,6 +12,7 @@ #include <Ice/Communicator.h> #include <Ice/LocalException.h> #include <Ice/Initialize.h> +#include <Ice/LoggerUtil.h> #include <IceDiscovery/LookupI.h> #include <iterator> @@ -21,21 +22,112 @@ using namespace Ice; using namespace IceDiscovery; #ifndef ICE_CPP11_MAPPING -IceDiscovery::Request::Request(const LookupIPtr& lookup, int retryCount) : _lookup(lookup), _nRetry(retryCount) +namespace +{ + +class AdapterCallbackI : public IceUtil::Shared +{ +public: + + AdapterCallbackI(const LookupIPtr& lookup, const AdapterRequestPtr& request) : _lookup(lookup), _request(request) + { + } + + void + completed(const Ice::AsyncResultPtr& result) + { + try + { + result->throwLocalException(); + } + catch(const Ice::LocalException& ex) + { + _lookup->adapterRequestException(_request, ex); + } + } + +private: + + LookupIPtr _lookup; + AdapterRequestPtr _request; +}; + +class ObjectCallbackI : public IceUtil::Shared +{ +public: + + ObjectCallbackI(const LookupIPtr& lookup, const ObjectRequestPtr& request) : _lookup(lookup), _request(request) + { + } + + void + completed(const Ice::AsyncResultPtr& result) + { + try + { + result->throwLocalException(); + } + catch(const Ice::LocalException& ex) + { + _lookup->objectRequestException(_request, ex); + } + } + +private: + + LookupIPtr _lookup; + ObjectRequestPtr _request; +}; + +} +#endif + +IceDiscovery::Request::Request(const LookupIPtr& lookup, int retryCount) : + _lookup(lookup), _retryCount(retryCount), _lookupCount(0), _failureCount(0) { } bool IceDiscovery::Request::retry() { - return --_nRetry >= 0; + return --_retryCount >= 0; +} + +void +IceDiscovery::Request::invoke(const string& domainId, const vector<pair<LookupPrxPtr, LookupReplyPrxPtr> >& lookups) +{ + _lookupCount = lookups.size(); + _failureCount = 0; + for(vector<pair<LookupPrxPtr, LookupReplyPrxPtr> >::const_iterator p = lookups.begin(); p != lookups.end(); ++p) + { + invokeWithLookup(domainId, p->first, p->second); + } +} + +bool +IceDiscovery::Request::exception() +{ + // + // If all the invocations on all the lookup proxies failed, report it to the locator. + // + if(++_failureCount == _lookupCount) + { + finished(0); + return true; + } + return false; +} + +AdapterRequest::AdapterRequest(const LookupIPtr& lookup, const std::string& adapterId, int retryCount) : + RequestT<std::string, AdapterCB>(lookup, adapterId, retryCount), + _start(IceUtil::Time::now()) +{ } -#endif bool AdapterRequest::retry() { - return _proxies.empty() && --_nRetry >= 0; + return _proxies.empty() && --_retryCount >= 0; } bool @@ -61,20 +153,12 @@ AdapterRequest::finished(const ObjectPrxPtr& proxy) { if(proxy || _proxies.empty()) { -#ifdef ICE_CPP11_MAPPING - Request<string>::finished(proxy); -#else - RequestT<string, AMD_Locator_findAdapterByIdPtr>::finished(proxy); -#endif + RequestT<string, AdapterCB>::finished(proxy); return; } else if(_proxies.size() == 1) { -#ifdef ICE_CPP11_MAPPING - Request<string>::finished(_proxies[0]); -#else - RequestT<string, AMD_Locator_findAdapterByIdPtr>::finished(_proxies[0]); -#endif + RequestT<string, AdapterCB>::finished(_proxies[0]); return; } @@ -89,10 +173,28 @@ AdapterRequest::finished(const ObjectPrxPtr& proxy) Ice::EndpointSeq endpts = (*p)->ice_getEndpoints(); copy(endpts.begin(), endpts.end(), back_inserter(endpoints)); } + RequestT<string, AdapterCB>::finished(prx->ice_endpoints(endpoints)); +} + +void +AdapterRequest::invokeWithLookup(const string& domainId, const LookupPrxPtr& lookup, const LookupReplyPrxPtr& lookupReply) +{ #ifdef ICE_CPP11_MAPPING - Request<string>::finished(prx->ice_endpoints(endpoints)); + auto self = ICE_SHARED_FROM_THIS; + lookup->findAdapterByIdAsync(domainId, _id, lookupReply, nullptr, [self](exception_ptr ex) + { + try + { + rethrow_exception(ex); + } + catch(const Ice::LocalException& ex) + { + self->_lookup->adapterRequestException(self, ex); + } + }); #else - RequestT<string, AMD_Locator_findAdapterByIdPtr>::finished(prx->ice_endpoints(endpoints)); + lookup->begin_findAdapterById(domainId, _id, lookupReply, newCallback(new AdapterCallbackI(_lookup, this), + &AdapterCallbackI::completed)); #endif } @@ -102,6 +204,11 @@ AdapterRequest::runTimerTask() _lookup->adapterRequestTimedOut(ICE_SHARED_FROM_THIS); } +ObjectRequest::ObjectRequest(const LookupIPtr& lookup, const Ice::Identity& id, int retryCount) : + RequestT<Ice::Identity, ObjectCB>(lookup, id, retryCount) +{ +} + void ObjectRequest::response(const Ice::ObjectPrxPtr& proxy) { @@ -109,6 +216,29 @@ ObjectRequest::response(const Ice::ObjectPrxPtr& proxy) } void +ObjectRequest::invokeWithLookup(const string& domainId, const LookupPrxPtr& lookup, const LookupReplyPrxPtr& lookupReply) +{ +#ifdef ICE_CPP11_MAPPING + auto self = ICE_SHARED_FROM_THIS; + lookup->findObjectByIdAsync(domainId, _id, lookupReply, nullptr, [self](exception_ptr ex) + { + try + { + rethrow_exception(ex); + } + catch(const Ice::LocalException& ex) + { + self->_lookup->objectRequestException(self, ex); + } + }); +#else + lookup->begin_findObjectById(domainId, _id, lookupReply, newCallback(new ObjectCallbackI(_lookup, this), + &ObjectCallbackI::completed)); + +#endif +} + +void ObjectRequest::runTimerTask() { _lookup->objectRequestTimedOut(ICE_SHARED_FROM_THIS); @@ -116,29 +246,14 @@ ObjectRequest::runTimerTask() LookupI::LookupI(const LocatorRegistryIPtr& registry, const LookupPrxPtr& lookup, const Ice::PropertiesPtr& properties) : _registry(registry), + _lookup(lookup), _timeout(IceUtil::Time::milliSeconds(properties->getPropertyAsIntWithDefault("IceDiscovery.Timeout", 300))), _retryCount(properties->getPropertyAsIntWithDefault("IceDiscovery.RetryCount", 3)), _latencyMultiplier(properties->getPropertyAsIntWithDefault("IceDiscovery.LatencyMultiplier", 1)), _domainId(properties->getProperty("IceDiscovery.DomainId")), - _timer(IceInternal::getInstanceTimer(lookup->ice_getCommunicator())) + _timer(IceInternal::getInstanceTimer(lookup->ice_getCommunicator())), + _warnOnce(true) { -#ifndef ICE_CPP11_MAPPING - __setNoDelete(true); -#endif - try - { - // Ensure we can establish a connection to the multicast proxy - lookup->ice_getConnection(); - } - catch(const Ice::LocalException& ex) - { - ostringstream os; - os << "IceDiscovery is unable to establish a multicast connection:\n"; - os << "proxy = " << lookup << '\n'; - os << ex; - throw Ice::PluginInitializationException(__FILE__, __LINE__, os.str()); - } - // // Create one lookup proxy per endpoint from the given proxy. We want to send a multicast // datagram on each endpoint. @@ -146,22 +261,11 @@ LookupI::LookupI(const LocatorRegistryIPtr& registry, const LookupPrxPtr& lookup EndpointSeq endpoints = lookup->ice_getEndpoints(); for(vector<EndpointPtr>::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p) { - try - { - EndpointSeq single; - single.push_back(*p); - LookupPrxPtr l = lookup->ice_endpoints(single); - l->ice_getConnection(); - _lookup.push_back(make_pair(l, LookupReplyPrxPtr())); - } - catch(const Ice::LocalException&) - { - } + EndpointSeq single; + single.push_back(*p); + _lookups.push_back(make_pair(lookup->ice_endpoints(single), LookupReplyPrxPtr())); } - assert(!_lookup.empty()); -#ifndef ICE_CPP11_MAPPING - __setNoDelete(false); -#endif + assert(!_lookups.empty()); } LookupI::~LookupI() @@ -177,6 +281,7 @@ LookupI::destroy() p->second->finished(0); _timer->cancel(p->second); } + _objectRequests.clear(); for(map<string, AdapterRequestPtr>::const_iterator p = _adapterRequests.begin(); p != _adapterRequests.end(); ++p) { @@ -192,7 +297,7 @@ LookupI::setLookupReply(const LookupReplyPrxPtr& lookupReply) // // Use a lookup reply proxy whose adress matches the interface used to send multicast datagrams. // - for(vector<pair<LookupPrxPtr, LookupReplyPrxPtr> >::iterator p = _lookup.begin(); p != _lookup.end(); ++p) + for(vector<pair<LookupPrxPtr, LookupReplyPrxPtr> >::iterator p = _lookups.begin(); p != _lookups.end(); ++p) { UDPEndpointInfoPtr info = ICE_DYNAMIC_CAST(UDPEndpointInfo, p->first->ice_getEndpoints()[0]->getInfo()); if(info && !info->mcastInterface.empty()) @@ -218,13 +323,8 @@ LookupI::setLookupReply(const LookupReplyPrxPtr& lookupReply) } void -#ifdef ICE_CPP11_MAPPING -LookupI::findObjectById(string domainId, Ice::Identity id, shared_ptr<IceDiscovery::LookupReplyPrx> reply, +LookupI::findObjectById(ICE_IN(string) domainId, ICE_IN(Ice::Identity) id, ICE_IN(LookupReplyPrxPtr) reply, const Ice::Current&) -#else -LookupI::findObjectById(const string& domainId, const Ice::Identity& id, const IceDiscovery::LookupReplyPrx& reply, - const Ice::Current&) -#endif { if(domainId != _domainId) { @@ -253,13 +353,8 @@ LookupI::findObjectById(const string& domainId, const Ice::Identity& id, const I } void -#ifdef ICE_CPP11_MAPPING -LookupI::findAdapterById(string domainId, string adapterId, shared_ptr<IceDiscovery::LookupReplyPrx> reply, - const Ice::Current&) -#else -LookupI::findAdapterById(const string& domainId, const string& adapterId, const IceDiscovery::LookupReplyPrxPtr& reply, +LookupI::findAdapterById(ICE_IN(string) domainId, ICE_IN(string) adapterId, ICE_IN(LookupReplyPrxPtr) reply, const Ice::Current&) -#endif { if(domainId != _domainId) { @@ -289,11 +384,7 @@ LookupI::findAdapterById(const string& domainId, const string& adapterId, const } void -#ifdef ICE_CPP11_MAPPING -LookupI::findObject(function<void(const shared_ptr<Ice::ObjectPrx>&)> cb, const Ice::Identity& id) -#else -LookupI::findObject(const Ice::AMD_Locator_findObjectByIdPtr& cb, const Ice::Identity& id) -#endif +LookupI::findObject(const ObjectCB& cb, const Ice::Identity& id) { Lock sync(*this); map<Ice::Identity, ObjectRequestPtr>::iterator p = _objectRequests.find(id); @@ -309,15 +400,7 @@ LookupI::findObject(const Ice::AMD_Locator_findObjectByIdPtr& cb, const Ice::Ide { try { - for(vector<pair<LookupPrxPtr, LookupReplyPrxPtr> >::const_iterator l = _lookup.begin(); l != _lookup.end(); - ++l) - { -#ifdef ICE_CPP11_MAPPING - l->first->findObjectByIdAsync(_domainId, id, l->second); -#else - l->first->begin_findObjectById(_domainId, id, l->second); -#endif - } + p->second->invoke(_domainId, _lookups); _timer->schedule(p->second, _timeout); } catch(const Ice::LocalException&) @@ -329,11 +412,7 @@ LookupI::findObject(const Ice::AMD_Locator_findObjectByIdPtr& cb, const Ice::Ide } void -#ifdef ICE_CPP11_MAPPING -LookupI::findAdapter(function<void(const shared_ptr<Ice::ObjectPrx>&)> cb, const std::string& adapterId) -#else -LookupI::findAdapter(const Ice::AMD_Locator_findAdapterByIdPtr& cb, const std::string& adapterId) -#endif +LookupI::findAdapter(const AdapterCB& cb, const std::string& adapterId) { Lock sync(*this); map<string, AdapterRequestPtr>::iterator p = _adapterRequests.find(adapterId); @@ -349,15 +428,7 @@ LookupI::findAdapter(const Ice::AMD_Locator_findAdapterByIdPtr& cb, const std::s { try { - for(vector<pair<LookupPrxPtr, LookupReplyPrxPtr> >::const_iterator l = _lookup.begin(); l != _lookup.end(); - ++l) - { -#ifdef ICE_CPP11_MAPPING - l->first->findAdapterByIdAsync(_domainId, adapterId, l->second); -#else - l->first->begin_findAdapterById(_domainId, adapterId, l->second); -#endif - } + p->second->invoke(_domainId, _lookups); _timer->schedule(p->second, _timeout); } catch(const Ice::LocalException&) @@ -414,16 +485,8 @@ LookupI::objectRequestTimedOut(const ObjectRequestPtr& request) { try { - for(vector<pair<LookupPrxPtr, LookupReplyPrxPtr> >::const_iterator l = _lookup.begin(); l != _lookup.end(); - ++l) - { -#ifdef ICE_CPP11_MAPPING - l->first->findObjectByIdAsync(_domainId, request->getId(), l->second); -#else - l->first->begin_findObjectById(_domainId, request->getId(), l->second); -#endif - } - _timer->schedule(p->second, _timeout); + request->invoke(_domainId, _lookups); + _timer->schedule(request, _timeout); return; } catch(const Ice::LocalException&) @@ -437,6 +500,29 @@ LookupI::objectRequestTimedOut(const ObjectRequestPtr& request) } void +LookupI::adapterRequestException(const AdapterRequestPtr& request, const LocalException& ex) +{ + Lock sync(*this); + map<string, AdapterRequestPtr>::iterator p = _adapterRequests.find(request->getId()); + if(p == _adapterRequests.end() || p->second.get() != request.get()) + { + return; + } + + if(request->exception()) + { + if(_warnOnce) + { + Warning warn(_lookup->ice_getCommunicator()->getLogger()); + warn << "failed to lookup adapter `" << p->first << "' with lookup proxy `" << _lookup << "':\n" << ex; + _warnOnce = false; + } + _timer->cancel(request); + _adapterRequests.erase(p); + } +} + +void LookupI::adapterRequestTimedOut(const AdapterRequestPtr& request) { Lock sync(*this); @@ -450,16 +536,8 @@ LookupI::adapterRequestTimedOut(const AdapterRequestPtr& request) { try { - for(vector<pair<LookupPrxPtr, LookupReplyPrxPtr> >::const_iterator l = _lookup.begin(); l != _lookup.end(); - ++l) - { -#ifdef ICE_CPP11_MAPPING - l->first->findAdapterByIdAsync(_domainId, request->getId(), l->second); -#else - l->first->begin_findAdapterById(_domainId, request->getId(), l->second); -#endif - } - _timer->schedule(p->second, _timeout); + request->invoke(_domainId, _lookups); + _timer->schedule(request, _timeout); return; } catch(const Ice::LocalException&) @@ -472,6 +550,30 @@ LookupI::adapterRequestTimedOut(const AdapterRequestPtr& request) _timer->cancel(request); } +void +LookupI::objectRequestException(const ObjectRequestPtr& request, const LocalException& ex) +{ + Lock sync(*this); + map<Ice::Identity, ObjectRequestPtr>::iterator p = _objectRequests.find(request->getId()); + if(p == _objectRequests.end() || p->second.get() != request.get()) + { + return; + } + + if(request->exception()) + { + if(_warnOnce) + { + Warning warn(_lookup->ice_getCommunicator()->getLogger()); + string id = _lookup->ice_getCommunicator()->identityToString(p->first); + warn << "failed to lookup object `" << id << "' with lookup proxy `" << _lookup << "':\n" << ex; + _warnOnce = false; + } + _timer->cancel(request); + _objectRequests.erase(p); + } +} + LookupReplyI::LookupReplyI(const LookupIPtr& lookup) : _lookup(lookup) { } diff --git a/cpp/src/IceDiscovery/LookupI.h b/cpp/src/IceDiscovery/LookupI.h index 46f582d6118..af9d40ea1e6 100644 --- a/cpp/src/IceDiscovery/LookupI.h +++ b/cpp/src/IceDiscovery/LookupI.h @@ -21,95 +21,6 @@ namespace IceDiscovery class LookupI; -#ifdef ICE_CPP11_MAPPING - -template<class T> class Request : public IceUtil::TimerTask -{ -public: - - Request(std::shared_ptr<LookupI> lookup, const T& id, int retryCount) : - _lookup(lookup), - _id(id), - _nRetry(retryCount) - { - } - - T getId() const - { - return _id; - } - - virtual bool retry() - { - return --_nRetry >= 0; - } - - bool addCallback(std::function<void(const std::shared_ptr<::Ice::ObjectPrx>&)> cb) - { - _callbacks.push_back(cb); - return _callbacks.size() == 1; - } - - virtual void finished(const Ice::ObjectPrxPtr& proxy) - { - for(auto cb : _callbacks) - { - cb(proxy); - } - _callbacks.clear(); - } - -protected: - - LookupIPtr _lookup; - const T _id; - int _nRetry; - std::vector<std::function<void(const std::shared_ptr<::Ice::ObjectPrx>&)>> _callbacks; -}; - -class ObjectRequest : public Request<Ice::Identity>, public std::enable_shared_from_this<ObjectRequest> -{ -public: - - ObjectRequest(const std::shared_ptr<LookupI>& lookup, const Ice::Identity& id, int retryCount) : - Request<Ice::Identity>(lookup, id, retryCount) - { - } - - void response(const std::shared_ptr<Ice::ObjectPrx>&); - -private: - - virtual void runTimerTask(); -}; -typedef std::shared_ptr<ObjectRequest> ObjectRequestPtr; - -class AdapterRequest : public Request<std::string>, public std::enable_shared_from_this<AdapterRequest> -{ -public: - - AdapterRequest(std::shared_ptr<LookupI> lookup, const std::string& adapterId, int retryCount) : - Request<std::string>(lookup, adapterId, retryCount), - _start(IceUtil::Time::now()) - { - } - - bool response(const std::shared_ptr<Ice::ObjectPrx>&, bool); - - virtual bool retry(); - virtual void finished(const std::shared_ptr<Ice::ObjectPrx>&); - -private: - - virtual void runTimerTask(); - std::vector<Ice::ObjectPrxPtr> _proxies; - IceUtil::Time _start; - IceUtil::Time _latency; -}; -typedef std::shared_ptr<AdapterRequest> AdapterRequestPtr; - -#else - class Request : public IceUtil::TimerTask { public: @@ -117,18 +28,27 @@ public: Request(const LookupIPtr&, int); virtual bool retry(); + void invoke(const std::string&, const std::vector<std::pair<LookupPrxPtr, LookupReplyPrxPtr> >&); + bool exception(); + + virtual void finished(const Ice::ObjectPrxPtr&) = 0; protected: + virtual void invokeWithLookup(const std::string&, const LookupPrxPtr&, const LookupReplyPrxPtr&) = 0; + LookupIPtr _lookup; - int _nRetry; + int _retryCount; + int _lookupCount; + int _failureCount; }; +ICE_DEFINE_PTR(RequestPtr, Request); template<class T, class CB> class RequestT : public Request { public: - RequestT(LookupI* lookup, T id, int retryCount) : Request(lookup, retryCount), _id(id) + RequestT(const LookupIPtr& lookup, T id, int retryCount) : Request(lookup, retryCount), _id(id) { } @@ -137,7 +57,7 @@ public: return _id; } - bool addCallback(CB cb) + bool addCallback(const CB& cb) { _callbacks.push_back(cb); return _callbacks.size() == 1; @@ -147,7 +67,11 @@ public: { for(typename std::vector<CB>::const_iterator p = _callbacks.begin(); p != _callbacks.end(); ++p) { +#ifdef ICE_CPP11_MAPPING + p->first(proxy); +#else (*p)->ice_response(proxy); +#endif } _callbacks.clear(); } @@ -158,32 +82,42 @@ protected: std::vector<CB> _callbacks; }; -class ObjectRequest : public RequestT<Ice::Identity, Ice::AMD_Locator_findObjectByIdPtr> +#ifdef ICE_CPP11_MAPPING +typedef std::pair<std::function<void(const std::shared_ptr<::Ice::ObjectPrx>&)>, + std::function<void(std::exception_ptr)>> ObjectCB; +typedef std::pair<std::function<void(const std::shared_ptr<::Ice::ObjectPrx>&)>, + std::function<void(std::exception_ptr)>> AdapterCB; +#else +typedef Ice::AMD_Locator_findObjectByIdPtr ObjectCB; +typedef Ice::AMD_Locator_findAdapterByIdPtr AdapterCB; +#endif + +class ObjectRequest : public RequestT<Ice::Identity, ObjectCB> +#ifdef ICE_CPP11_MAPPING + , public std::enable_shared_from_this<ObjectRequest> +#endif { public: - ObjectRequest(LookupI* lookup, const Ice::Identity& id, int retryCount) : - RequestT<Ice::Identity, Ice::AMD_Locator_findObjectByIdPtr>(lookup, id, retryCount) - { - } + ObjectRequest(const LookupIPtr&, const Ice::Identity&, int); void response(const Ice::ObjectPrxPtr&); private: + virtual void invokeWithLookup(const std::string&, const LookupPrxPtr&, const LookupReplyPrxPtr&); virtual void runTimerTask(); }; -typedef IceUtil::Handle<ObjectRequest> ObjectRequestPtr; +ICE_DEFINE_PTR(ObjectRequestPtr, ObjectRequest); -class AdapterRequest : public RequestT<std::string, Ice::AMD_Locator_findAdapterByIdPtr> +class AdapterRequest : public RequestT<std::string, AdapterCB> +#ifdef ICE_CPP11_MAPPING + , public std::enable_shared_from_this<AdapterRequest> +#endif { public: - AdapterRequest(LookupI* lookup, const std::string& adapterId, int retryCount) : - RequestT<std::string, Ice::AMD_Locator_findAdapterByIdPtr>(lookup, adapterId, retryCount), - _start(IceUtil::Time::now()) - { - } + AdapterRequest(const LookupIPtr&, const std::string&, int); bool response(const Ice::ObjectPrxPtr&, bool); @@ -192,14 +126,14 @@ public: private: + virtual void invokeWithLookup(const std::string&, const LookupPrxPtr&, const LookupReplyPrxPtr&); virtual void runTimerTask(); + std::vector<Ice::ObjectPrxPtr> _proxies; IceUtil::Time _start; IceUtil::Time _latency; }; -typedef IceUtil::Handle<AdapterRequest> AdapterRequestPtr; - -#endif +ICE_DEFINE_PTR(AdapterRequestPtr, AdapterRequest); class LookupI : public Lookup, private IceUtil::Mutex @@ -216,29 +150,20 @@ public: void setLookupReply(const LookupReplyPrxPtr&); -#ifdef ICE_CPP11_MAPPING - virtual void findObjectById(std::string, - Ice::Identity, - ::std::shared_ptr<IceDiscovery::LookupReplyPrx>, + virtual void findObjectById(ICE_IN(std::string), ICE_IN(Ice::Identity), ICE_IN(IceDiscovery::LookupReplyPrxPtr), const Ice::Current&); - virtual void findAdapterById(std::string, std::string, ::std::shared_ptr<IceDiscovery::LookupReplyPrx>, + virtual void findAdapterById(ICE_IN(std::string), ICE_IN(std::string), ICE_IN(IceDiscovery::LookupReplyPrxPtr), const Ice::Current&); - void findObject(std::function<void(const std::shared_ptr<Ice::ObjectPrx>&)>, const Ice::Identity&); - void findAdapter(std::function<void(const std::shared_ptr<Ice::ObjectPrx>&)>, const std::string&); -#else - virtual void findObjectById(const std::string&, const Ice::Identity&, const IceDiscovery::LookupReplyPrx&, - const Ice::Current&); - virtual void findAdapterById(const std::string&, const std::string&, const IceDiscovery::LookupReplyPrx&, - const Ice::Current&); - void findObject(const Ice::AMD_Locator_findObjectByIdPtr&, const Ice::Identity&); - void findAdapter(const Ice::AMD_Locator_findAdapterByIdPtr&, const std::string&); -#endif + void findObject(const ObjectCB&, const Ice::Identity&); + void findAdapter(const AdapterCB&, const std::string&); void foundObject(const Ice::Identity&, const Ice::ObjectPrxPtr&); void foundAdapter(const std::string&, const Ice::ObjectPrxPtr&, bool); void adapterRequestTimedOut(const AdapterRequestPtr&); + void adapterRequestException(const AdapterRequestPtr&, const Ice::LocalException&); void objectRequestTimedOut(const ObjectRequestPtr&); + void objectRequestException(const ObjectRequestPtr&, const Ice::LocalException&); const IceUtil::TimerPtr& timer() @@ -255,7 +180,8 @@ public: private: LocatorRegistryIPtr _registry; - std::vector<std::pair<LookupPrxPtr, LookupReplyPrxPtr> > _lookup; + LookupPrxPtr _lookup; + std::vector<std::pair<LookupPrxPtr, LookupReplyPrxPtr> > _lookups; const IceUtil::Time _timeout; const int _retryCount; const int _latencyMultiplier; @@ -263,6 +189,7 @@ private: IceUtil::TimerPtr _timer; Ice::ObjectPrxPtr _wellKnownProxy; + bool _warnOnce; std::map<Ice::Identity, ObjectRequestPtr> _objectRequests; std::map<std::string, AdapterRequestPtr> _adapterRequests; diff --git a/cpp/src/IceLocatorDiscovery/PluginI.cpp b/cpp/src/IceLocatorDiscovery/PluginI.cpp index ee01719fd72..112147f8978 100644 --- a/cpp/src/IceLocatorDiscovery/PluginI.cpp +++ b/cpp/src/IceLocatorDiscovery/PluginI.cpp @@ -10,6 +10,7 @@ #include <IceUtil/IceUtil.h> #include <Ice/Ice.h> #include <Ice/Network.h> // For getInterfacesForMulticast +#include <Ice/LoggerUtil.h> #include <IceLocatorDiscovery/Plugin.h> #include <IceLocatorDiscovery/IceLocatorDiscovery.h> @@ -22,6 +23,14 @@ namespace class LocatorI; // Forward declaration +#ifdef ICE_CPP11_MAPPING +typedef std::pair<function<void(bool, const pair<const Ice::Byte*, const Ice::Byte*>&)>, + function<void(exception_ptr)>> AMDCallback; +#else +typedef Ice::AMD_Object_ice_invokePtr AMDCallback; +#endif + + class Request : #ifdef ICE_CPP11_MAPPING public std::enable_shared_from_this<Request> @@ -31,35 +40,18 @@ class Request : { public: -#ifdef ICE_CPP11_MAPPING - Request(LocatorI* locator, - const string& operation, - Ice::OperationMode mode, - const pair<const Ice::Byte*, const Ice::Byte*>& inParams, - const Ice::Context& ctx, - function<void(bool, const pair<const Ice::Byte*, const Ice::Byte*>&)> responseCB, - function<void(exception_ptr)> exceptionCB) : - _locator(locator), - _operation(operation), - _mode(mode), - _context(ctx), - _inParams(inParams.first, inParams.second), - _responseCB(move(responseCB)), - _exceptionCB(move(exceptionCB)) -#else Request(LocatorI* locator, const string& operation, Ice::OperationMode mode, const pair<const Ice::Byte*, const Ice::Byte*>& inParams, const Ice::Context& ctx, - const Ice::AMD_Object_ice_invokePtr& amdCB) : + const AMDCallback& amdCB) : _locator(locator), _operation(operation), _mode(mode), _context(ctx), _inParams(inParams.first, inParams.second), _amdCB(amdCB) -#endif { } @@ -74,12 +66,10 @@ protected: const Ice::OperationMode _mode; const Ice::Context _context; const Ice::ByteSeq _inParams; + AMDCallback _amdCB; #ifdef ICE_CPP11_MAPPING - function<void(bool, const pair<const Ice::Byte*, const Ice::Byte*>&)> _responseCB; - function<void(exception_ptr)> _exceptionCB; exception_ptr _exception; #else - const Ice::AMD_Object_ice_invokePtr _amdCB; IceInternal::UniquePtr<Ice::Exception> _exception; #endif @@ -114,11 +104,14 @@ public: vector<Ice::LocatorPrxPtr> getLocators(const string&, const IceUtil::Time&); + void exception(const Ice::LocalException&); + private: virtual void runTimerTask(); - vector<pair<LookupPrxPtr, LookupReplyPrxPtr> > _lookup; + LookupPrxPtr _lookup; + vector<pair<LookupPrxPtr, LookupReplyPrxPtr> > _lookups; const IceUtil::Time _timeout; const int _retryCount; const IceUtil::Time _retryDelay; @@ -132,6 +125,8 @@ private: IceUtil::Time _nextRetry; int _pendingRetryCount; + int _failureCount; + bool _warnOnce; vector<RequestPtr> _pendingRequests; }; ICE_DEFINE_PTR(LocatorIPtr, LocatorI); @@ -229,6 +224,36 @@ private: Ice::LocatorPrxPtr _defaultLocator; }; +#ifndef ICE_CPP11_MAPPING + +class CallbackI : public IceUtil::Shared +{ +public: + + CallbackI(const LocatorIPtr& locator) : _locator(locator) + { + } + + void + completed(const Ice::AsyncResultPtr& result) + { + try + { + result->throwLocalException(); + } + catch(const Ice::LocalException& ex) + { + _locator->exception(ex); + } + } + +private: + + LocatorIPtr _locator; +}; + +#endif + } // @@ -417,7 +442,7 @@ Request::invoke(const Ice::LocatorPrxPtr& l) else { assert(_exception); // Don't retry if the proxy didn't change - _exceptionCB(_exception); + _amdCB.second(_exception); } #else @@ -447,7 +472,7 @@ void Request::response(bool ok, const pair<const Ice::Byte*, const Ice::Byte*>& outParams) { #ifdef ICE_CPP11_MAPPING - _responseCB(ok, outParams); + _amdCB.first(ok, outParams); #else _amdCB->ice_response(ok, outParams); #endif @@ -463,11 +488,11 @@ Request::exception(const Ice::Exception& ex) } catch(const Ice::RequestFailedException&) { - _exceptionCB(current_exception()); + _amdCB.second(current_exception()); } catch(const Ice::UnknownException&) { - _exceptionCB(current_exception()); + _amdCB.second(current_exception()); } catch(const Ice::NoEndpointException&) { @@ -477,7 +502,7 @@ Request::exception(const Ice::Exception& ex) } catch(...) { - _exceptionCB(current_exception()); + _amdCB.second(current_exception()); } } catch(const Ice::CommunicatorDestroyedException&) @@ -488,7 +513,7 @@ Request::exception(const Ice::Exception& ex) } catch(...) { - _exceptionCB(current_exception()); + _amdCB.second(current_exception()); } } catch(const Ice::ObjectAdapterDeactivatedException&) @@ -499,7 +524,7 @@ Request::exception(const Ice::Exception& ex) } catch(...) { - _exceptionCB(current_exception()); + _amdCB.second(current_exception()); } } catch(const Ice::Exception&) @@ -545,6 +570,7 @@ LocatorI::LocatorI(const string& name, const Ice::PropertiesPtr& p, const string& instanceName, const Ice::LocatorPrxPtr& voidLocator) : + _lookup(lookup), _timeout(IceUtil::Time::milliSeconds(p->getPropertyAsIntWithDefault(name + ".Timeout", 300))), _retryCount(p->getPropertyAsIntWithDefault(name + ".RetryCount", 3)), _retryDelay(IceUtil::Time::milliSeconds(p->getPropertyAsIntWithDefault(name + ".RetryDelay", 2000))), @@ -553,25 +579,10 @@ LocatorI::LocatorI(const string& name, _warned(false), _locator(lookup->ice_getCommunicator()->getDefaultLocator()), _voidLocator(voidLocator), - _pendingRetryCount(0) + _pendingRetryCount(0), + _failureCount(0), + _warnOnce(true) { -#ifndef ICE_CPP11_MAPPING - __setNoDelete(true); -#endif - try - { - // Ensure we can establish a connection to the multicast proxy - lookup->ice_getConnection(); - } - catch(const Ice::LocalException& ex) - { - ostringstream os; - os << "IceLocatorDiscovery is unable to establish a multicast connection:\n"; - os << "proxy = " << lookup << '\n'; - os << ex; - throw Ice::PluginInitializationException(__FILE__, __LINE__, os.str()); - } - // // Create one lookup proxy per endpoint from the given proxy. We want to send a multicast // datagram on each endpoint. @@ -579,22 +590,11 @@ LocatorI::LocatorI(const string& name, Ice::EndpointSeq endpoints = lookup->ice_getEndpoints(); for(vector<Ice::EndpointPtr>::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p) { - try - { - Ice::EndpointSeq single; - single.push_back(*p); - LookupPrxPtr l = lookup->ice_endpoints(single); - l->ice_getConnection(); - _lookup.push_back(make_pair(l, LookupReplyPrxPtr())); - } - catch(const Ice::LocalException&) - { - } + Ice::EndpointSeq single; + single.push_back(*p); + _lookups.push_back(make_pair(lookup->ice_endpoints(single), LookupReplyPrxPtr())); } - assert(!_lookup.empty()); -#ifndef ICE_CPP11_MAPPING - __setNoDelete(false); -#endif + assert(!_lookups.empty()); } void @@ -603,7 +603,7 @@ LocatorI::setLookupReply(const LookupReplyPrxPtr& lookupReply) // // Use a lookup reply proxy whose adress matches the interface used to send multicast datagrams. // - for(vector<pair<LookupPrxPtr, LookupReplyPrxPtr> >::iterator p = _lookup.begin(); p != _lookup.end(); ++p) + for(vector<pair<LookupPrxPtr, LookupReplyPrxPtr> >::iterator p = _lookups.begin(); p != _lookups.end(); ++p) { Ice::UDPEndpointInfoPtr info = ICE_DYNAMIC_CAST(Ice::UDPEndpointInfo, p->first->ice_getEndpoints()[0]->getInfo()); if(info && !info->mcastInterface.empty()) @@ -636,7 +636,7 @@ LocatorI::ice_invokeAsync(pair<const Ice::Byte*, const Ice::Byte*> inParams, const Ice::Current& current) { invoke(nullptr, make_shared<Request>(this, current.operation, current.mode, inParams, current.ctx, - move(responseCB), move(exceptionCB))); + make_pair(move(responseCB), move(exceptionCB)))); } #else void @@ -811,16 +811,29 @@ LocatorI::invoke(const Ice::LocatorPrxPtr& locator, const RequestPtr& request) if(_pendingRetryCount == 0) // No request in progress { + _failureCount = 0; _pendingRetryCount = _retryCount; try { - for(vector<pair<LookupPrxPtr, LookupReplyPrxPtr> >::const_iterator l = _lookup.begin(); - l != _lookup.end(); ++l) + for(vector<pair<LookupPrxPtr, LookupReplyPrxPtr> >::const_iterator l = _lookups.begin(); + l != _lookups.end(); ++l) { #ifdef ICE_CPP11_MAPPING - l->first->findLocatorAsync(_instanceName, l->second); // Send multicast request. + auto self = shared_from_this(); + l->first->findLocatorAsync(_instanceName, l->second, nullptr, [self](exception_ptr ex) + { + try + { + rethrow_exception(ex); + } + catch(const Ice::LocalException& e) + { + self->exception(e); + } + }); #else - l->first->begin_findLocator(_instanceName, l->second); // Send multicast request. + l->first->begin_findLocator(_instanceName, l->second, Ice::newCallback(new CallbackI(this), + &CallbackI::completed)); #endif } _timer->schedule(ICE_SHARED_FROM_THIS, _timeout); @@ -839,6 +852,40 @@ LocatorI::invoke(const Ice::LocatorPrxPtr& locator, const RequestPtr& request) } void +LocatorI::exception(const Ice::LocalException& ex) +{ + Lock sync(*this); + if(++_failureCount == _lookups.size() && _pendingRetryCount > 0) + { + // + // All the lookup calls failed, cancel the timer and propagate the error to the requests. + // + _timer->cancel(ICE_SHARED_FROM_THIS); + _pendingRetryCount = 0; + + if(_warnOnce) + { + Ice::Warning warn(_lookup->ice_getCommunicator()->getLogger()); + warn << "failed to lookup locator with lookup proxy `" << _lookup << "':\n" << ex; + _warnOnce = false; + } + + if(_pendingRequests.empty()) + { + notify(); + } + else + { + for(vector<RequestPtr>::const_iterator p = _pendingRequests.begin(); p != _pendingRequests.end(); ++p) + { + (*p)->invoke(_voidLocator); + } + _pendingRequests.clear(); + } + } +} + +void LocatorI::runTimerTask() { Lock sync(*this); @@ -846,13 +893,26 @@ LocatorI::runTimerTask() { try { - for(vector<pair<LookupPrxPtr, LookupReplyPrxPtr> >::const_iterator l = _lookup.begin(); - l != _lookup.end(); ++l) + _failureCount = 0; + for(vector<pair<LookupPrxPtr, LookupReplyPrxPtr> >::const_iterator l = _lookups.begin(); + l != _lookups.end(); ++l) { #ifdef ICE_CPP11_MAPPING - l->first->findLocatorAsync(_instanceName, l->second); // Send multicast request. + auto self = shared_from_this(); + l->first->findLocatorAsync(_instanceName, l->second, nullptr, [self](exception_ptr ex) + { + try + { + rethrow_exception(ex); + } + catch(const Ice::LocalException& e) + { + self->exception(e); + } + }); #else - l->first->begin_findLocator(_instanceName, l->second); // Send multicast request. + l->first->begin_findLocator(_instanceName, l->second, Ice::newCallback(new CallbackI(this), + &CallbackI::completed)); #endif } _timer->schedule(ICE_SHARED_FROM_THIS, _timeout); diff --git a/cpp/test/IceDiscovery/simple/AllTests.cpp b/cpp/test/IceDiscovery/simple/AllTests.cpp index 6eb9913954f..cb2df00069e 100644 --- a/cpp/test/IceDiscovery/simple/AllTests.cpp +++ b/cpp/test/IceDiscovery/simple/AllTests.cpp @@ -197,6 +197,55 @@ allTests(const CommunicatorPtr& communicator, int num) } cout << "ok" << endl; + cout << "testing invalid lookup endpoints... " << flush; + { + string multicast; + if(communicator->getProperties()->getProperty("Ice.IPv6") == "1") + { + multicast = "\"ff15::1\""; + } + else + { + multicast = "239.255.0.1"; + } + + { + + Ice::InitializationData initData; + initData.properties = communicator->getProperties()->clone(); + initData.properties->setProperty("IceDiscovery.Lookup", "udp -h " + multicast + " --interface unknown"); + Ice::CommunicatorPtr com = Ice::initialize(initData); + test(com->getDefaultLocator()); + try + { + com->stringToProxy("controller0@control0")->ice_ping(); + test(false); + } + catch(const Ice::LocalException&) + { + } + com->destroy(); + } + { + Ice::InitializationData initData; + initData.properties = communicator->getProperties()->clone(); + string intf = initData.properties->getProperty("IceDiscovery.Interface"); + if(!intf.empty()) + { + intf = " --interface \"" + intf + "\""; + } + string port = initData.properties->getProperty("IceDiscovery.Port"); + initData.properties->setProperty("IceDiscovery.Lookup", + "udp -h " + multicast + " --interface unknown:" + + "udp -h " + multicast + " -p " + port + intf); + Ice::CommunicatorPtr com = Ice::initialize(initData); + test(com->getDefaultLocator()); + com->stringToProxy("controller0@control0")->ice_ping(); + com->destroy(); + } + } + cout << "ok" << endl; + cout << "shutting down... " << flush; for(vector<ControllerPrxPtr>::const_iterator p = proxies.begin(); p != proxies.end(); ++p) { diff --git a/cpp/test/IceGrid/simple/AllTests.cpp b/cpp/test/IceGrid/simple/AllTests.cpp index 29f1e84974d..125216db7a9 100644 --- a/cpp/test/IceGrid/simple/AllTests.cpp +++ b/cpp/test/IceGrid/simple/AllTests.cpp @@ -20,19 +20,19 @@ void allTests(const Ice::CommunicatorPtr& communicator) { cout << "testing stringToProxy... " << flush; - Ice::ObjectPrx base = communicator->stringToProxy("test @ TestAdapter"); + Ice::ObjectPrxPtr base = communicator->stringToProxy("test @ TestAdapter"); test(base); cout << "ok" << endl; cout << "testing IceGrid.Locator is present... " << flush; - IceGrid::LocatorPrx locator = IceGrid::LocatorPrx::uncheckedCast(base); + IceGrid::LocatorPrxPtr locator = ICE_UNCHECKED_CAST(IceGrid::LocatorPrx, base); test(locator); cout << "ok" << endl; cout << "testing checked cast... " << flush; - TestIntfPrx obj = TestIntfPrx::checkedCast(base); + TestIntfPrxPtr obj = ICE_CHECKED_CAST(TestIntfPrx, base); test(obj); - test(obj == base); + test(Ice::targetEqualTo(obj, base)); cout << "ok" << endl; cout << "pinging server... " << flush; @@ -43,7 +43,7 @@ allTests(const Ice::CommunicatorPtr& communicator) Ice::Identity finderId; finderId.category = "Ice"; finderId.name = "LocatorFinder"; - Ice::LocatorFinderPrx finder = Ice::LocatorFinderPrx::checkedCast( + Ice::LocatorFinderPrxPtr finder = ICE_CHECKED_CAST(Ice::LocatorFinderPrx, communicator->getDefaultLocator()->ice_identity(finderId)); test(finder->getLocator()); cout << "ok" << endl; @@ -54,11 +54,11 @@ allTests(const Ice::CommunicatorPtr& communicator) cout << "testing discovery... " << flush; { // Add test well-known object - IceGrid::RegistryPrx registry = IceGrid::RegistryPrx::checkedCast( + IceGrid::RegistryPrxPtr registry = ICE_CHECKED_CAST(IceGrid::RegistryPrx, communicator->stringToProxy(communicator->getDefaultLocator()->ice_getIdentity().category + "/Registry")); test(registry); - IceGrid::AdminSessionPrx session = registry->createAdminSession("foo", "bar"); + IceGrid::AdminSessionPrxPtr session = registry->createAdminSession("foo", "bar"); session->getAdmin()->addObjectWithType(base, "::Test"); session->destroy(); @@ -71,11 +71,6 @@ allTests(const Ice::CommunicatorPtr& communicator) initData.properties->setProperty("Ice.Default.Locator", ""); initData.properties->setProperty("Ice.Plugin.IceLocatorDiscovery", "IceLocatorDiscovery:createIceLocatorDiscovery"); - { - ostringstream port; - port << getTestPort(initData.properties, 99); - initData.properties->setProperty("IceLocatorDiscovery.Port", port.str()); - } initData.properties->setProperty("AdapterForDiscoveryTest.AdapterId", "discoveryAdapter"); initData.properties->setProperty("AdapterForDiscoveryTest.Endpoints", "default"); @@ -85,9 +80,9 @@ allTests(const Ice::CommunicatorPtr& communicator) com->stringToProxy("test @ TestAdapter")->ice_ping(); com->stringToProxy("test")->ice_ping(); test(com->getDefaultLocator()->getRegistry()); - test(IceGrid::LocatorPrx::checkedCast(com->getDefaultLocator())); - test(IceGrid::LocatorPrx::uncheckedCast(com->getDefaultLocator())->getLocalRegistry()); - test(IceGrid::LocatorPrx::uncheckedCast(com->getDefaultLocator())->getLocalQuery()); + test(ICE_CHECKED_CAST(IceGrid::LocatorPrx, com->getDefaultLocator())); + test(ICE_UNCHECKED_CAST(IceGrid::LocatorPrx, com->getDefaultLocator())->getLocalRegistry()); + test(ICE_UNCHECKED_CAST(IceGrid::LocatorPrx, com->getDefaultLocator())->getLocalQuery()); Ice::ObjectAdapterPtr adapter = com->createObjectAdapter("AdapterForDiscoveryTest"); adapter->activate(); @@ -126,10 +121,10 @@ allTests(const Ice::CommunicatorPtr& communicator) { } test(!com->getDefaultLocator()->getRegistry()); - test(!IceGrid::LocatorPrx::checkedCast(com->getDefaultLocator())); + test(!ICE_CHECKED_CAST(IceGrid::LocatorPrx, com->getDefaultLocator())); try { - test(IceGrid::LocatorPrx::uncheckedCast(com->getDefaultLocator())->getLocalQuery()); + test(ICE_UNCHECKED_CAST(IceGrid::LocatorPrx, com->getDefaultLocator())->getLocalQuery()); } catch(const Ice::OperationNotExistException&) { @@ -140,6 +135,66 @@ allTests(const Ice::CommunicatorPtr& communicator) adapter->deactivate(); com->destroy(); + + string multicast; + if(communicator->getProperties()->getProperty("Ice.IPv6") == "1") + { + multicast = "\"ff15::1\""; + } + else + { + multicast = "239.255.0.1"; + } + + // + // Test invalid lookup endpoints + // + initData.properties = communicator->getProperties()->clone(); + initData.properties->setProperty("Ice.Default.Locator", ""); + initData.properties->setProperty("Ice.Plugin.IceLocatorDiscovery", + "IceLocatorDiscovery:createIceLocatorDiscovery"); + initData.properties->setProperty("IceLocatorDiscovery.Lookup", + "udp -h " + multicast + " --interface unknown"); + com = Ice::initialize(initData); + test(com->getDefaultLocator()); + try + { + com->stringToProxy("test @ TestAdapter")->ice_ping(); + test(false); + } + catch(const Ice::NoEndpointException&) + { + } + com->destroy(); + + + initData.properties = communicator->getProperties()->clone(); + initData.properties->setProperty("Ice.Default.Locator", ""); + initData.properties->setProperty("Ice.Plugin.IceLocatorDiscovery", + "IceLocatorDiscovery:createIceLocatorDiscovery"); + { + string intf = initData.properties->getProperty("IceLocatorDiscovery.Interface"); + if(!intf.empty()) + { + intf = " --interface \"" + intf + "\""; + } + ostringstream port; + port << getTestPort(initData.properties, 99); + initData.properties->setProperty("IceLocatorDiscovery.Lookup", + "udp -h " + multicast + " --interface unknown:" + + "udp -h " + multicast + " -p " + port.str() + intf); + } + com = Ice::initialize(initData); + test(com->getDefaultLocator()); + try + { + com->stringToProxy("test @ TestAdapter")->ice_ping(); + } + catch(const Ice::NoEndpointException&) + { + test(false); + } + com->destroy(); } cout << "ok" << endl; } @@ -157,19 +212,19 @@ void allTestsWithDeploy(const Ice::CommunicatorPtr& communicator) { cout << "testing stringToProxy... " << flush; - Ice::ObjectPrx base = communicator->stringToProxy("test @ TestAdapter"); + Ice::ObjectPrxPtr base = communicator->stringToProxy("test @ TestAdapter"); test(base); - Ice::ObjectPrx base2 = communicator->stringToProxy("test"); + Ice::ObjectPrxPtr base2 = communicator->stringToProxy("test"); test(base2); cout << "ok" << endl; cout << "testing checked cast... " << flush; - TestIntfPrx obj = TestIntfPrx::checkedCast(base); + TestIntfPrxPtr obj = ICE_CHECKED_CAST(TestIntfPrx, base); test(obj); - test(obj == base); - TestIntfPrx obj2 = TestIntfPrx::checkedCast(base2); + test(Ice::targetEqualTo(obj, base)); + TestIntfPrxPtr obj2 = ICE_CHECKED_CAST(TestIntfPrx, base2); test(obj2); - test(obj2 == base2); + test(Ice::targetEqualTo(obj2, base2)); cout << "ok" << endl; cout << "pinging server... " << flush; @@ -178,9 +233,9 @@ allTestsWithDeploy(const Ice::CommunicatorPtr& communicator) cout << "ok" << endl; cout << "testing encoding versioning... " << flush; - Ice::ObjectPrx base10 = communicator->stringToProxy("test10 @ TestAdapter10"); + Ice::ObjectPrxPtr base10 = communicator->stringToProxy("test10 @ TestAdapter10"); test(base10); - Ice::ObjectPrx base102 = communicator->stringToProxy("test10"); + Ice::ObjectPrxPtr base102 = communicator->stringToProxy("test10"); test(base102); try { @@ -230,15 +285,15 @@ allTestsWithDeploy(const Ice::CommunicatorPtr& communicator) } cout << "ok" << endl; - IceGrid::RegistryPrx registry = IceGrid::RegistryPrx::checkedCast( + IceGrid::RegistryPrxPtr registry = ICE_CHECKED_CAST(IceGrid::RegistryPrx, communicator->stringToProxy(communicator->getDefaultLocator()->ice_getIdentity().category + "/Registry")); test(registry); - IceGrid::AdminSessionPrx session = registry->createAdminSession("foo", "bar"); + IceGrid::AdminSessionPrxPtr session = registry->createAdminSession("foo", "bar"); session->ice_getConnection()->setACM(registry->getACMTimeout(), IceUtil::None, Ice::ICE_ENUM(ACMHeartbeat, HeartbeatAlways)); - IceGrid::AdminPrx admin = session->getAdmin(); + IceGrid::AdminPrxPtr admin = session->getAdmin(); test(admin); admin->enableServer("server", false); @@ -247,7 +302,7 @@ allTestsWithDeploy(const Ice::CommunicatorPtr& communicator) cout << "testing whether server is still reachable... " << flush; try { - obj = TestIntfPrx::checkedCast(base); + obj = ICE_CHECKED_CAST(TestIntfPrx, base); test(false); } catch(const Ice::NoEndpointException&) @@ -255,7 +310,7 @@ allTestsWithDeploy(const Ice::CommunicatorPtr& communicator) } try { - obj2 = TestIntfPrx::checkedCast(base2); + obj2 = ICE_CHECKED_CAST(TestIntfPrx, base2); test(false); } catch(const Ice::NoEndpointException&) @@ -266,7 +321,7 @@ allTestsWithDeploy(const Ice::CommunicatorPtr& communicator) try { - obj = TestIntfPrx::checkedCast(base); + obj = ICE_CHECKED_CAST(TestIntfPrx, base); } catch(const Ice::NoEndpointException&) { @@ -274,7 +329,7 @@ allTestsWithDeploy(const Ice::CommunicatorPtr& communicator) } try { - obj2 = TestIntfPrx::checkedCast(base2); + obj2 = ICE_CHECKED_CAST(TestIntfPrx, base2); } catch(const Ice::NoEndpointException&) { diff --git a/cpp/test/IceGrid/simple/Server.cpp b/cpp/test/IceGrid/simple/Server.cpp index 57f57c582f9..c252fae2b7e 100644 --- a/cpp/test/IceGrid/simple/Server.cpp +++ b/cpp/test/IceGrid/simple/Server.cpp @@ -28,7 +28,7 @@ Server::run(int argc, char* argv[]) Ice::stringSeqToArgs(args, argc, argv); Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("TestAdapter"); - Ice::ObjectPtr object = new TestI(); + Ice::ObjectPtr object = ICE_MAKE_SHARED(TestI); string id = communicator()->getProperties()->getPropertyWithDefault("Identity", "test"); adapter->add(object, Ice::stringToIdentity(id)); |