summaryrefslogtreecommitdiff
path: root/cpp/src/IcePack/LocatorI.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/IcePack/LocatorI.cpp')
-rw-r--r--cpp/src/IcePack/LocatorI.cpp232
1 files changed, 170 insertions, 62 deletions
diff --git a/cpp/src/IcePack/LocatorI.cpp b/cpp/src/IcePack/LocatorI.cpp
index 032d18a1fd4..bf7ca0e016a 100644
--- a/cpp/src/IcePack/LocatorI.cpp
+++ b/cpp/src/IcePack/LocatorI.cpp
@@ -18,104 +18,212 @@
using namespace std;
using namespace IcePack;
-IcePack::LocatorI::LocatorI(const AdapterRegistryPtr& adapterRegistry,
- const ObjectRegistryPtr& objectRegistry,
- const Ice::LocatorRegistryPrx& locatorRegistry) :
- _adapterRegistry(adapterRegistry),
- _objectRegistry(objectRegistry),
- _locatorRegistry(locatorRegistry)
+namespace IcePack
{
-}
//
-// Find an object by identity. The object is searched in the object
-// registry. If found and if the object was registered with an
-// adapter, we get the adapter direct proxy and return a proxy created
-// from the adapter direct proxy and the object identity. We could
-// just return the registered proxy but this would be less efficient
-// since the client would have to make a second call to find out the
-// adapter direct proxy.
+// Callback from asynchronous call to adapter->getDirectProxy()
+// invoked in LocatorI::findAdapterById_async().
//
-Ice::ObjectPrx
-IcePack::LocatorI::findObjectById(const Ice::Identity& id, const Ice::Current& current) const
+class AMI_Adapter_getDirectProxyI : public AMI_Adapter_getDirectProxy
{
- ObjectDescription obj;
+public:
- try
+ AMI_Adapter_getDirectProxyI(const Ice::AMD_Locator_findAdapterByIdPtr& cb) : _cb(cb)
{
- obj = _objectRegistry->getObjectDescription(id);
}
- catch(const ObjectNotExistException&)
+
+ virtual void ice_response(const ::Ice::ObjectPrx& obj)
{
- throw Ice::ObjectNotFoundException();
+ //
+ // Return the adapter dummy direct proxy.
+ //
+ _cb->ice_response(obj);
}
- if(!obj.adapterId.empty())
+ virtual void ice_exception(const ::Ice::Exception& ex)
+ {
+ try
+ {
+ ex.ice_throw();
+ }
+ catch(const Ice::ObjectNotExistException&)
+ {
+ //
+ // Expected if the adapter is destroyed.
+ //
+ _cb->ice_exception(Ice::AdapterNotFoundException());
+ return;
+ }
+ catch(const Ice::LocalException& ex)
+ {
+ //
+ // Expected if we couldn't contact the adapter object
+ // (possibly because the IcePack node is down). Return a
+ // null proxy in this case (the client will get empty
+ // endpoints and throw a NoEndpointException).
+ //
+ _cb->ice_response(0);
+ return;
+ }
+ catch(const Ice::Exception& ex)
+ {
+ //
+ // Rethrow unexpected exception.
+ //
+ _cb->ice_exception(ex);
+ return;
+ }
+
+ assert(false);
+ }
+
+private:
+
+ Ice::AMD_Locator_findAdapterByIdPtr _cb;
+};
+
+//
+// Callback from asynchrnous call to LocatorI::findAdapterById_async()
+// invoked in LocatorI::findObjectById_async().
+//
+class AMD_Locator_findAdapterByIdI : public Ice::AMD_Locator_findAdapterById
+{
+public:
+
+ AMD_Locator_findAdapterByIdI(const Ice::AMD_Locator_findObjectByIdPtr& cb, const Ice::ObjectPrx& obj) :
+ _cb(cb),
+ _obj(obj)
+ {
+ }
+
+ virtual void ice_response(const ::Ice::ObjectPrx& obj)
+ {
+ //
+ // If the adapter dummy direct proxy is not null, return a
+ // proxy containing the identity we were looking for and the
+ // endpoints of the adapter.
+ //
+ // If null, return the proxy registered with the object
+ // registry.
+ //
+ if(obj)
+ {
+ _cb->ice_response(obj->ice_newIdentity(_obj->ice_getIdentity()));
+ }
+ else
+ {
+ _cb->ice_response(_obj);
+ }
+ }
+
+ virtual void ice_exception(const ::Ice::Exception& ex)
{
try
{
- Ice::ObjectPrx directProxy = findAdapterById(obj.adapterId, current);
- if(directProxy)
- {
- return directProxy->ice_newIdentity(id);
- }
+ ex.ice_throw();
}
catch(Ice::AdapterNotFoundException&)
{
//
- // Ignore.
+ // We couldn't find the adapter, we ignore and return the
+ // original proxy containing the adapter id.
+ //
+ _cb->ice_response(_obj);
+ return;
+ }
+ catch(const Ice::Exception& ex)
+ {
//
+ // Rethrow unexpected exception.
+ //
+ _cb->ice_exception(ex);
+ return;
}
+
+ assert(false);
}
- return obj.proxy;
-}
+ virtual void ice_exception(const std::exception& ex)
+ {
+ _cb->ice_exception(ex);
+ }
+
+ virtual void ice_exception()
+ {
+ _cb->ice_exception();
+ }
+
+private:
-Ice::ObjectPrx
-IcePack::LocatorI::findAdapterById(const string& id, const Ice::Current&) const
+ Ice::AMD_Locator_findObjectByIdPtr _cb;
+ Ice::ObjectPrx _obj;
+
+};
+
+}
+
+IcePack::LocatorI::LocatorI(const AdapterRegistryPtr& adapterRegistry,
+ const ObjectRegistryPtr& objectRegistry,
+ const Ice::LocatorRegistryPrx& locatorRegistry) :
+ _adapterRegistry(adapterRegistry),
+ _objectRegistry(objectRegistry),
+ _locatorRegistry(locatorRegistry)
{
- //
- // TODO: I think will need to do something more sensible in cases
- // where the adapter is found but the adapter proxy is null
- // (possibly because the server activation failed or timed out) or
- // if the adapter object isn't reachable (possibly because the
- // IcePack node is down or unreachable). Right now the Ice client
- // will always throw a NoEndpointException because we return a
- // null proxy here...
- //
+}
+//
+// Find an object by identity. The object is searched in the object
+// registry.
+//
+void
+IcePack::LocatorI::findObjectById_async(const Ice::AMD_Locator_findObjectByIdPtr& response, const Ice::Identity& id,
+ const Ice::Current& current) const
+{
+ ObjectDescription obj;
try
{
- return _adapterRegistry->findById(id)->getDirectProxy(true);
+ obj = _objectRegistry->getObjectDescription(id);
}
- catch(const AdapterNotExistException&)
+ catch(const ObjectNotExistException&)
{
- throw Ice::AdapterNotFoundException();
+ throw Ice::ObjectNotFoundException();
}
- catch(const Ice::ObjectNotExistException&)
+
+ //
+ // OPTIMIZATION: If the object is registered with an adapter id,
+ // try to get the adapter direct proxy (which might caused the
+ // server activation). This will avoid the client to lookup for
+ // the adapter id endpoints.
+ //
+ if(!obj.adapterId.empty())
{
- //
- // Expected if the adapter is destroyed.
- //
- throw Ice::AdapterNotFoundException();
+ Ice::AMD_Locator_findAdapterByIdPtr cb = new AMD_Locator_findAdapterByIdI(response, obj.proxy);
+ findAdapterById_async(cb, obj.adapterId, current);
}
- catch(const Ice::NoEndpointException&)
+ else
{
- //
- // This could be because we can't locate the IcePack node
- // adapter (IcePack server adapter proxies are not direct
- // proxies)
- //
+ response->ice_response(obj.proxy);
}
- catch(const Ice::LocalException&)
+}
+
+//
+// Find an adapter by identity. The object is searched in the adapter
+// registry. If found, we try to get its direct proxy.
+//
+void
+IcePack::LocatorI::findAdapterById_async(const Ice::AMD_Locator_findAdapterByIdPtr& response,
+ const string& id, const Ice::Current&) const
+{
+ try
{
- //
- // Expected if we couldn't contact the adapter object
- // (possibly because the IcePack node is down).
- //
+ AMI_Adapter_getDirectProxyPtr cb = new AMI_Adapter_getDirectProxyI(response);
+ _adapterRegistry->findById(id)->getDirectProxy_async(cb, true);
+ }
+ catch(const AdapterNotExistException&)
+ {
+ throw Ice::AdapterNotFoundException();
}
-
- return 0;
}
Ice::LocatorRegistryPrx