diff options
author | Benoit Foucher <benoit@zeroc.com> | 2006-09-06 15:39:41 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2006-09-06 15:39:41 +0000 |
commit | 6f46bb760b30ef883b386dfa8e695c8d5004f05f (patch) | |
tree | c3dabd2d404b72a8e4ad16996a913ceee963815e /cpp/src/IceGrid/LocatorRegistryI.cpp | |
parent | Fixed bug 1209 (diff) | |
download | ice-6f46bb760b30ef883b386dfa8e695c8d5004f05f.tar.bz2 ice-6f46bb760b30ef883b386dfa8e695c8d5004f05f.tar.xz ice-6f46bb760b30ef883b386dfa8e695c8d5004f05f.zip |
The master now waits for the replicas to be updated before to return.
Added support for dynamic registration of adapters in the replicas.
Diffstat (limited to 'cpp/src/IceGrid/LocatorRegistryI.cpp')
-rw-r--r-- | cpp/src/IceGrid/LocatorRegistryI.cpp | 125 |
1 files changed, 116 insertions, 9 deletions
diff --git a/cpp/src/IceGrid/LocatorRegistryI.cpp b/cpp/src/IceGrid/LocatorRegistryI.cpp index f2963143fb6..38aa82b03e5 100644 --- a/cpp/src/IceGrid/LocatorRegistryI.cpp +++ b/cpp/src/IceGrid/LocatorRegistryI.cpp @@ -9,12 +9,16 @@ #include <Ice/Ice.h> #include <IceGrid/LocatorRegistryI.h> +#include <IceGrid/ReplicaSessionManager.h> #include <IceGrid/Database.h> #include <IceGrid/Util.h> using namespace std; using namespace IceGrid; +namespace IceGrid +{ + class SetDirectProxyCB : public AMI_Adapter_setDirectProxy { public: @@ -41,7 +45,7 @@ public: } catch(const Ice::ObjectNotExistException&) { - _cb->ice_exception(Ice::AdapterNotFoundException());// Expected if the adapter was destroyed. + _cb->ice_exception(Ice::AdapterNotFoundException()); // Expected if the adapter was destroyed. return; } catch(const Ice::LocalException&) @@ -85,7 +89,7 @@ public: } catch(const Ice::ObjectNotExistException&) { - _cb->ice_exception(Ice::AdapterNotFoundException());// Expected if the adapter was destroyed. + _cb->ice_exception(Ice::AdapterNotFoundException()); // Expected if the adapter was destroyed. return; } catch(const Ice::LocalException&) @@ -140,9 +144,74 @@ private: Ice::AMD_LocatorRegistry_setServerProcessProxyPtr _cb; }; -LocatorRegistryI::LocatorRegistryI(const DatabasePtr& database, bool dynamicRegistration) : +template<class AmdCB> +class MasterSetDirectProxyCB : public AMI_ReplicaSession_setAdapterDirectProxy +{ +public: + + MasterSetDirectProxyCB(const AmdCB& cb) : + _cb(cb) + { + } + + virtual void ice_response() + { + _cb->ice_response(); + } + + virtual void ice_exception(const ::Ice::Exception& ex) + { + try + { + ex.ice_throw(); + } + catch(const AdapterActiveException&) + { + _cb->ice_exception(Ice::AdapterAlreadyActiveException()); + return; + } + catch(const AdapterNotExistException&) + { + _cb->ice_exception(Ice::AdapterNotFoundException()); + return; + } + catch(const Ice::UserException& ex) + { + _cb->ice_exception(ex); + return; + } + catch(const Ice::LocalException& ex) // Master unreachable. + { + // + // TODO: Add a better exception? + // + _cb->ice_exception(Ice::AdapterNotFoundException()); + return; + } + assert(false); + } + +private: + + AmdCB _cb; +}; + +template<class AmdCB> MasterSetDirectProxyCB<AmdCB>* +newMasterSetDirectProxyCB(const AmdCB& cb) +{ + return new MasterSetDirectProxyCB<AmdCB>(cb); +} + +}; + +LocatorRegistryI::LocatorRegistryI(const DatabasePtr& database, + bool dynamicRegistration, + bool master, + ReplicaSessionManager& session) : _database(database), - _dynamicRegistration(dynamicRegistration) + _dynamicRegistration(dynamicRegistration), + _master(master), + _session(session) { } @@ -194,11 +263,30 @@ LocatorRegistryI::setAdapterDirectProxy_async(const Ice::AMD_LocatorRegistry_set cb->ice_response(); return; } - + assert(_dynamicRegistration); - if(_database->setAdapterDirectProxy(adapterId, "", proxy)) + if(_master) { - cb->ice_response(); + if(_database->setAdapterDirectProxy(adapterId, "", proxy)) + { + cb->ice_response(); + return; + } + } + else + { + ReplicaSessionPrx session = _session.getSession(); + if(session) + { + session->setAdapterDirectProxy_async(newMasterSetDirectProxyCB(cb), adapterId, "", proxy); + } + else + { + // + // TODO: Add a better exception? + // + cb->ice_exception(Ice::AdapterNotFoundException()); + } return; } } @@ -250,9 +338,28 @@ LocatorRegistryI::setReplicatedAdapterDirectProxy_async( } assert(_dynamicRegistration); - if(_database->setAdapterDirectProxy(adapterId, replicaGroupId, proxy)) + if(_master) { - cb->ice_response(); + if(_database->setAdapterDirectProxy(adapterId, replicaGroupId, proxy)) + { + cb->ice_response(); + return; + } + } + else + { + ReplicaSessionPrx session = _session.getSession(); + if(session) + { + session->setAdapterDirectProxy_async(newMasterSetDirectProxyCB(cb), adapterId, replicaGroupId, proxy); + } + else + { + // + // TODO: Add a better exception? + // + cb->ice_exception(Ice::AdapterNotFoundException()); + } return; } } |