summaryrefslogtreecommitdiff
path: root/cpp/src/IceDiscovery
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2017-05-10 18:54:03 +0200
committerBenoit Foucher <benoit@zeroc.com>2017-05-10 18:54:03 +0200
commitf0fbb296946f95b2bd94e86d72df618aadf3268c (patch)
treedb0a9894acd0ff3b0c4efd7ec7dc9bc2d00d56e0 /cpp/src/IceDiscovery
parentFix slice/errorDetection test (diff)
downloadice-f0fbb296946f95b2bd94e86d72df618aadf3268c.tar.bz2
ice-f0fbb296946f95b2bd94e86d72df618aadf3268c.tar.xz
ice-f0fbb296946f95b2bd94e86d72df618aadf3268c.zip
Fixed ICE-7849 - Removed IceDiscovery/IceLocatorDiscovery ice_getConnection call, added IceGrid/simple C++11 test
Diffstat (limited to 'cpp/src/IceDiscovery')
-rw-r--r--cpp/src/IceDiscovery/LocatorI.cpp16
-rw-r--r--cpp/src/IceDiscovery/LookupI.cpp322
-rw-r--r--cpp/src/IceDiscovery/LookupI.h173
3 files changed, 270 insertions, 241 deletions
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;