diff options
author | Jose <jose@zeroc.com> | 2009-07-02 19:39:13 +0200 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2009-07-02 19:39:13 +0200 |
commit | b288490bceaab7f9c20eb9de62fa7a7ff4f6a917 (patch) | |
tree | 8645fb6933ced669886f71f415eb57f676912ebf | |
parent | Fixed test failure introduce by previous fix (diff) | |
download | ice-b288490bceaab7f9c20eb9de62fa7a7ff4f6a917.tar.bz2 ice-b288490bceaab7f9c20eb9de62fa7a7ff4f6a917.tar.xz ice-b288490bceaab7f9c20eb9de62fa7a7ff4f6a917.zip |
Bug 2564 - ObjectAdapter::removeServantLocator
37 files changed, 384 insertions, 15 deletions
diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp index 9b56129c144..62f71b61737 100644 --- a/cpp/src/Ice/ObjectAdapterI.cpp +++ b/cpp/src/Ice/ObjectAdapterI.cpp @@ -515,6 +515,16 @@ Ice::ObjectAdapterI::addServantLocator(const ServantLocatorPtr& locator, const s } ServantLocatorPtr +Ice::ObjectAdapterI::removeServantLocator(const string& prefix) +{ + IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); + + checkForDeactivation(); + + return _servantManager->removeServantLocator(prefix); +} + +ServantLocatorPtr Ice::ObjectAdapterI::findServantLocator(const string& prefix) const { IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); diff --git a/cpp/src/Ice/ObjectAdapterI.h b/cpp/src/Ice/ObjectAdapterI.h index e550254fc91..201be76287d 100644 --- a/cpp/src/Ice/ObjectAdapterI.h +++ b/cpp/src/Ice/ObjectAdapterI.h @@ -69,6 +69,7 @@ public: virtual void addServantLocator(const ServantLocatorPtr&, const std::string&); + virtual ServantLocatorPtr removeServantLocator(const std::string&); virtual ServantLocatorPtr findServantLocator(const std::string&) const; virtual ObjectPrx createProxy(const Identity&) const; diff --git a/cpp/src/Ice/ServantManager.cpp b/cpp/src/Ice/ServantManager.cpp index 1f6b5622231..4820b979350 100644 --- a/cpp/src/Ice/ServantManager.cpp +++ b/cpp/src/Ice/ServantManager.cpp @@ -341,6 +341,40 @@ IceInternal::ServantManager::addServantLocator(const ServantLocatorPtr& locator, } ServantLocatorPtr +IceInternal::ServantManager::removeServantLocator(const string& category) +{ + IceUtil::Mutex::Lock sync(*this); + + assert(_instance); // Must not be called after destruction. + + map<string, ServantLocatorPtr>::iterator p = _locatorMap.end(); + if(_locatorMapHint != p) + { + if(_locatorMapHint->first == category) + { + p = _locatorMapHint; + } + } + + if(p == _locatorMap.end()) + { + p = _locatorMap.find(category); + } + + ServantLocatorPtr locator; + + if(p != _locatorMap.end()) + { + locator = p->second; + locator->deactivate(p->first); + _locatorMap.erase(p); + _locatorMapHint = _locatorMap.begin(); + } + + return locator; +} + +ServantLocatorPtr IceInternal::ServantManager::findServantLocator(const string& category) const { IceUtil::Mutex::Lock sync(*this); diff --git a/cpp/src/Ice/ServantManager.h b/cpp/src/Ice/ServantManager.h index 2cb1134e2e9..9699fde9c04 100644 --- a/cpp/src/Ice/ServantManager.h +++ b/cpp/src/Ice/ServantManager.h @@ -43,6 +43,7 @@ public: bool hasServant(const Ice::Identity&) const; void addServantLocator(const Ice::ServantLocatorPtr& locator, const std::string&); + Ice::ServantLocatorPtr removeServantLocator(const std::string&); Ice::ServantLocatorPtr findServantLocator(const std::string&) const; private: diff --git a/cpp/test/Ice/servantLocator/AllTests.cpp b/cpp/test/Ice/servantLocator/AllTests.cpp index b98bc9844da..778fcf96535 100644 --- a/cpp/test/Ice/servantLocator/AllTests.cpp +++ b/cpp/test/Ice/servantLocator/AllTests.cpp @@ -307,6 +307,30 @@ allTests(const CommunicatorPtr& communicator, bool collocated) testExceptions(obj, collocated); cout << "ok" << endl; + cout << "testing servant locator removal... " << flush; + base = communicator->stringToProxy("test/activation:default -p 12010"); + TestActivationPrx activation = TestActivationPrx::checkedCast(base); + activation->activateServantLocator(false); + try + { + obj->ice_ping(); + test(false); + } + catch(Ice::ObjectNotExistException&) + { + cout << "ok" << endl; + } + cout << "testing servant locator addition... " << flush; + activation->activateServantLocator(true); + try + { + obj->ice_ping(); + cout << "ok" << endl; + } + catch(...) + { + test(false); + } return obj; } diff --git a/cpp/test/Ice/servantLocator/Collocated.cpp b/cpp/test/Ice/servantLocator/Collocated.cpp index af3315d8bfd..777030c17f5 100644 --- a/cpp/test/Ice/servantLocator/Collocated.cpp +++ b/cpp/test/Ice/servantLocator/Collocated.cpp @@ -48,6 +48,25 @@ protected: } }; +class TestActivationI : public Test::TestActivation +{ +public: + + void activateServantLocator(bool activate, const Ice::Current& current) + { + if(activate) + { + current.adapter->addServantLocator(new ServantLocatorI(""), ""); + current.adapter->addServantLocator(new ServantLocatorI("category"), "category"); + } + else + { + current.adapter->removeServantLocator(""); + current.adapter->removeServantLocator("category"); + } + } +}; + class TestServer : public Application { public: @@ -70,6 +89,7 @@ TestServer::run(int argc, char* argv[]) adapter->addServantLocator(new ServantLocatorI(""), ""); adapter->addServantLocator(new ServantLocatorI("category"), "category"); adapter->add(new TestI, communicator()->stringToIdentity("asm")); + adapter->add(new TestActivationI, communicator()->stringToIdentity("test/activation")); Test::TestIntfPrx allTests(const CommunicatorPtr&, bool); allTests(communicator(), true); diff --git a/cpp/test/Ice/servantLocator/Server.cpp b/cpp/test/Ice/servantLocator/Server.cpp index 8f89c8becaf..3fd46e6af54 100644 --- a/cpp/test/Ice/servantLocator/Server.cpp +++ b/cpp/test/Ice/servantLocator/Server.cpp @@ -47,6 +47,25 @@ protected: } }; +class TestActivationI : public Test::TestActivation +{ +public: + + void activateServantLocator(bool activate, const Ice::Current& current) + { + if(activate) + { + current.adapter->addServantLocator(new ServantLocatorI(""), ""); + current.adapter->addServantLocator(new ServantLocatorI("category"), "category"); + } + else + { + current.adapter->removeServantLocator(""); + current.adapter->removeServantLocator("category"); + } + } +}; + class TestServer : public Application { public: @@ -72,6 +91,7 @@ TestServer::run(int argc, char* argv[]) adapter->addServantLocator(new ServantLocatorI(""), ""); adapter->addServantLocator(new ServantLocatorI("category"), "category"); adapter->add(new TestI, communicator()->stringToIdentity("asm")); + adapter->add(new TestActivationI, communicator()->stringToIdentity("test/activation")); adapter->activate(); adapter->waitForDeactivate(); return EXIT_SUCCESS; diff --git a/cpp/test/Ice/servantLocator/ServerAMD.cpp b/cpp/test/Ice/servantLocator/ServerAMD.cpp index 3806b3644bb..0f7a8788896 100644 --- a/cpp/test/Ice/servantLocator/ServerAMD.cpp +++ b/cpp/test/Ice/servantLocator/ServerAMD.cpp @@ -47,6 +47,25 @@ protected: } }; +class TestActivationI : public Test::TestActivation +{ +public: + + void activateServantLocator(bool activate, const Ice::Current& current) + { + if(activate) + { + current.adapter->addServantLocator(new ServantLocatorAMDI(""), ""); + current.adapter->addServantLocator(new ServantLocatorAMDI("category"), "category"); + } + else + { + current.adapter->removeServantLocator(""); + current.adapter->removeServantLocator("category"); + } + } +}; + class TestServer : public Application { public: @@ -72,6 +91,7 @@ TestServer::run(int argc, char* argv[]) adapter->addServantLocator(new ServantLocatorAMDI(""), ""); adapter->addServantLocator(new ServantLocatorAMDI("category"), "category"); adapter->add(new TestAMDI, communicator()->stringToIdentity("asm")); + adapter->add(new TestActivationI, communicator()->stringToIdentity("test/activation")); adapter->activate(); adapter->waitForDeactivate(); return EXIT_SUCCESS; diff --git a/cpp/test/Ice/servantLocator/Test.ice b/cpp/test/Ice/servantLocator/Test.ice index 939677d9a20..f95381a9ede 100644 --- a/cpp/test/Ice/servantLocator/Test.ice +++ b/cpp/test/Ice/servantLocator/Test.ice @@ -40,6 +40,11 @@ interface TestIntf void shutdown(); }; +interface TestActivation +{ + void activateServantLocator(bool activate); +}; + local class Cookie { ["cpp:const"] string message(); diff --git a/cpp/test/Ice/servantLocator/TestAMD.ice b/cpp/test/Ice/servantLocator/TestAMD.ice index a79360a26f8..4533e9404a6 100644 --- a/cpp/test/Ice/servantLocator/TestAMD.ice +++ b/cpp/test/Ice/servantLocator/TestAMD.ice @@ -40,6 +40,11 @@ exception TestImpossibleException void shutdown(); }; +interface TestActivation +{ + void activateServantLocator(bool activate); +}; + local class Cookie { ["cpp:const"] string message(); diff --git a/cs/src/Ice/ObjectAdapterI.cs b/cs/src/Ice/ObjectAdapterI.cs index 730b600dbfe..eff5272af42 100644 --- a/cs/src/Ice/ObjectAdapterI.cs +++ b/cs/src/Ice/ObjectAdapterI.cs @@ -506,6 +506,16 @@ namespace Ice _servantManager.addServantLocator(locator, prefix); } } + + public ServantLocator removeServantLocator(string prefix) + { + lock(this) + { + checkForDeactivation(); + + return _servantManager.removeServantLocator(prefix); + } + } public ServantLocator findServantLocator(string prefix) { diff --git a/cs/src/Ice/ServantManager.cs b/cs/src/Ice/ServantManager.cs index 15539b195ea..308f1d1facf 100644 --- a/cs/src/Ice/ServantManager.cs +++ b/cs/src/Ice/ServantManager.cs @@ -259,6 +259,23 @@ public sealed class ServantManager _locatorMap[category] = locator; } } + + public Ice.ServantLocator removeServantLocator(string category) + { + lock(this) + { + Debug.Assert(instance_ != null); // Must not be called after destruction. + + Ice.ServantLocator l; + _locatorMap.TryGetValue(category, out l); + if(l != null) + { + _locatorMap.Remove(category); + l.deactivate(category); + } + return l; + } + } public Ice.ServantLocator findServantLocator(string category) { diff --git a/cs/test/Ice/servantLocator/AllTests.cs b/cs/test/Ice/servantLocator/AllTests.cs index 937d441f5ad..b63b160eb30 100644 --- a/cs/test/Ice/servantLocator/AllTests.cs +++ b/cs/test/Ice/servantLocator/AllTests.cs @@ -283,6 +283,33 @@ public class AllTests testExceptions(obj, collocated); Console.Out.WriteLine("ok"); + Console.Out.Write("testing servant locator removal... "); + Console.Out.Flush(); + @base = communicator.stringToProxy("test/activation:default -p 12010"); + TestActivationPrx activation = TestActivationPrxHelper.checkedCast(@base); + activation.activateServantLocator(false); + try + { + obj.ice_ping(); + test(false); + } + catch(ObjectNotExistException) + { + Console.Out.WriteLine("ok"); + } + Console.Out.Write("testing servant locator addition... "); + Console.Out.Flush(); + activation.activateServantLocator(true); + try + { + obj.ice_ping(); + Console.Out.WriteLine("ok"); + } + catch(System.Exception) + { + test(false); + } + return obj; } } diff --git a/cs/test/Ice/servantLocator/Collocated.cs b/cs/test/Ice/servantLocator/Collocated.cs index 1a3001a1394..c3ddbc93ca7 100644 --- a/cs/test/Ice/servantLocator/Collocated.cs +++ b/cs/test/Ice/servantLocator/Collocated.cs @@ -31,6 +31,7 @@ public class Collocated adapter.addServantLocator(new ServantLocatorI("category"), "category"); adapter.addServantLocator(new ServantLocatorI(""), ""); adapter.add(new TestI(), communicator().stringToIdentity("asm")); + adapter.add(new TestActivationI(), communicator().stringToIdentity("test/activation")); AllTests.allTests(communicator(), true); diff --git a/cs/test/Ice/servantLocator/Makefile b/cs/test/Ice/servantLocator/Makefile index 956f8f8df8e..f5c05d59293 100644 --- a/cs/test/Ice/servantLocator/Makefile +++ b/cs/test/Ice/servantLocator/Makefile @@ -13,9 +13,9 @@ TARGETS = client.exe server.exe serveramd.exe collocated.exe TARGETS_CONFIG = $(TARGETS:.exe=.exe.config) C_SRCS = Client.cs AllTests.cs -S_SRCS = Server.cs CookieI.cs ServantLocatorI.cs TestI.cs -COL_SRCS = Collocated.cs AllTests.cs CookieI.cs ServantLocatorI.cs TestI.cs -SAMD_SRCS = Server.cs CookieI.cs ServantLocatorI.cs TestAMDI.cs +S_SRCS = Server.cs CookieI.cs ServantLocatorI.cs TestI.cs TestActivationI.cs +COL_SRCS = Collocated.cs AllTests.cs CookieI.cs ServantLocatorI.cs TestI.cs TestActivationI.cs +SAMD_SRCS = Server.cs CookieI.cs ServantLocatorI.cs TestAMDI.cs TestActivationI.cs SLICE_SRCS = $(SDIR)/Test.ice SLICE_AMD_SRCS = $(SDIR)/TestAMD.ice diff --git a/cs/test/Ice/servantLocator/Makefile.mak b/cs/test/Ice/servantLocator/Makefile.mak index 81e34515a61..9407799d4c1 100644 --- a/cs/test/Ice/servantLocator/Makefile.mak +++ b/cs/test/Ice/servantLocator/Makefile.mak @@ -13,9 +13,9 @@ TARGETS = client.exe server.exe serveramd.exe collocated.exe TARGETS_CONFIG = $(TARGETS:.exe=.exe.config)
C_SRCS = Client.cs AllTests.cs
-S_SRCS = Server.cs CookieI.cs ServantLocatorI.cs TestI.cs
-COL_SRCS = Collocated.cs AllTests.cs CookieI.cs ServantLocatorI.cs TestI.cs
-SAMD_SRCS = Server.cs CookieI.cs ServantLocatorI.cs TestAMDI.cs
+S_SRCS = Server.cs CookieI.cs ServantLocatorI.cs TestI.cs TestActivationI.cs
+COL_SRCS = Collocated.cs AllTests.cs CookieI.cs ServantLocatorI.cs TestI.cs TestActivationI.cs
+SAMD_SRCS = Server.cs CookieI.cs ServantLocatorI.cs TestAMDI.cs TestActivationI.cs
GEN_SRCS = $(GDIR)\Test.cs
GEN_AMD_SRCS = $(GDIR)\TestAMD.cs
diff --git a/cs/test/Ice/servantLocator/Server.cs b/cs/test/Ice/servantLocator/Server.cs index f1d4cda3d89..2462ff0bb16 100644 --- a/cs/test/Ice/servantLocator/Server.cs +++ b/cs/test/Ice/servantLocator/Server.cs @@ -30,7 +30,7 @@ public class Server adapter.addServantLocator(new ServantLocatorI("category"), "category"); adapter.addServantLocator(new ServantLocatorI(""), ""); adapter.add(new TestI(), communicator().stringToIdentity("asm")); - + adapter.add(new TestActivationI(), communicator().stringToIdentity("test/activation")); adapter.activate(); adapter.waitForDeactivate(); return 0; diff --git a/cs/test/Ice/servantLocator/Test.ice b/cs/test/Ice/servantLocator/Test.ice index 74b29f57212..d49c737ca6b 100644 --- a/cs/test/Ice/servantLocator/Test.ice +++ b/cs/test/Ice/servantLocator/Test.ice @@ -42,6 +42,11 @@ local class Cookie ["cpp:const"] string message(); }; +interface TestActivation +{ + void activateServantLocator(bool activate); +}; + }; #endif diff --git a/cs/test/Ice/servantLocator/TestAMD.ice b/cs/test/Ice/servantLocator/TestAMD.ice index 4bc081f6bfd..6d4679fbf5d 100644 --- a/cs/test/Ice/servantLocator/TestAMD.ice +++ b/cs/test/Ice/servantLocator/TestAMD.ice @@ -37,6 +37,11 @@ exception TestImpossibleException void shutdown(); }; +interface TestActivation +{ + void activateServantLocator(bool activate); +}; + local class Cookie { ["cpp:const"] string message(); diff --git a/java/src/Ice/ObjectAdapterI.java b/java/src/Ice/ObjectAdapterI.java index 8fbfb2bc4f8..62589a5bad7 100644 --- a/java/src/Ice/ObjectAdapterI.java +++ b/java/src/Ice/ObjectAdapterI.java @@ -512,6 +512,14 @@ public final class ObjectAdapterI implements ObjectAdapter } public synchronized ServantLocator + removeServantLocator(String prefix) + { + checkForDeactivation(); + + return _servantManager.removeServantLocator(prefix); + } + + public synchronized ServantLocator findServantLocator(String prefix) { checkForDeactivation(); diff --git a/java/src/IceInternal/ServantManager.java b/java/src/IceInternal/ServantManager.java index ba3c1f80cac..01ded95ffd0 100644 --- a/java/src/IceInternal/ServantManager.java +++ b/java/src/IceInternal/ServantManager.java @@ -227,6 +227,19 @@ public final class ServantManager } public synchronized Ice.ServantLocator + removeServantLocator(String category) + { + assert(_instance != null); // Must not be called after destruction. + + Ice.ServantLocator l = _locatorMap.remove(category); + if(l != null) + { + l.deactivate(category); + } + return l; + } + + public synchronized Ice.ServantLocator findServantLocator(String category) { // diff --git a/java/test/Ice/servantLocator/AMDServer.java b/java/test/Ice/servantLocator/AMDServer.java index 2234ff7c4e7..3a91b15cabc 100644 --- a/java/test/Ice/servantLocator/AMDServer.java +++ b/java/test/Ice/servantLocator/AMDServer.java @@ -18,6 +18,7 @@ public class AMDServer extends test.Util.Application adapter.addServantLocator(new AMDServantLocatorI("category"), "category"); adapter.addServantLocator(new AMDServantLocatorI(""), ""); adapter.add(new AMDTestI(), communicator().stringToIdentity("asm")); + adapter.add(new AMDTestActivationI(), communicator().stringToIdentity("test/activation")); adapter.activate(); return WAIT; } diff --git a/java/test/Ice/servantLocator/AllTests.java b/java/test/Ice/servantLocator/AllTests.java index 16c0450f5d5..b9ab0ea648f 100644 --- a/java/test/Ice/servantLocator/AllTests.java +++ b/java/test/Ice/servantLocator/AllTests.java @@ -14,6 +14,9 @@ import java.io.PrintWriter; import test.Ice.servantLocator.Test.TestImpossibleException; import test.Ice.servantLocator.Test.TestIntfPrx; import test.Ice.servantLocator.Test.TestIntfPrxHelper; +import test.Ice.servantLocator.Test.TestActivationPrx; +import test.Ice.servantLocator.Test.TestActivationPrxHelper; + import Ice.ObjectNotExistException; import Ice.ObjectPrx; import Ice.UnknownException; @@ -286,6 +289,33 @@ public class AllTests testExceptions(obj, collocated); out.println("ok"); + out.print("testing servant locator removal... "); + out.flush(); + base = communicator.stringToProxy("test/activation:default -p 12010"); + TestActivationPrx activation = TestActivationPrxHelper.checkedCast(base); + activation.activateServantLocator(false); + try + { + obj.ice_ping(); + test(false); + } + catch(ObjectNotExistException ex) + { + out.println("ok"); + } + out.print("testing servant locator addition... "); + out.flush(); + activation.activateServantLocator(true); + try + { + obj.ice_ping(); + out.println("ok"); + } + catch(Exception ex) + { + test(false); + } + return obj; } } diff --git a/java/test/Ice/servantLocator/Collocated.java b/java/test/Ice/servantLocator/Collocated.java index d47f4459683..be026ac8aa0 100644 --- a/java/test/Ice/servantLocator/Collocated.java +++ b/java/test/Ice/servantLocator/Collocated.java @@ -17,7 +17,7 @@ public class Collocated extends test.Util.Application adapter.addServantLocator(new ServantLocatorI("category"), "category"); adapter.addServantLocator(new ServantLocatorI(""), ""); adapter.add(new TestI(), communicator().stringToIdentity("asm")); - + adapter.add(new TestActivationI(), communicator().stringToIdentity("test/activation")); AllTests.allTests(communicator(), true, getWriter()); return 0; diff --git a/java/test/Ice/servantLocator/Server.java b/java/test/Ice/servantLocator/Server.java index b349abdca3f..f88bfb5b9b4 100644 --- a/java/test/Ice/servantLocator/Server.java +++ b/java/test/Ice/servantLocator/Server.java @@ -17,6 +17,7 @@ public class Server extends test.Util.Application adapter.addServantLocator(new ServantLocatorI("category"), "category"); adapter.addServantLocator(new ServantLocatorI(""), ""); adapter.add(new TestI(), communicator().stringToIdentity("asm")); + adapter.add(new TestActivationI(), communicator().stringToIdentity("test/activation")); adapter.activate(); return WAIT; } diff --git a/java/test/Ice/servantLocator/Test.ice b/java/test/Ice/servantLocator/Test.ice index 9acfa468f51..977c6cbd19f 100644 --- a/java/test/Ice/servantLocator/Test.ice +++ b/java/test/Ice/servantLocator/Test.ice @@ -38,6 +38,11 @@ interface TestIntf void shutdown(); }; +interface TestActivation +{ + void activateServantLocator(bool activate); +}; + local class Cookie { ["cpp:const"] string message(); diff --git a/java/test/Ice/servantLocator/TestAMD.ice b/java/test/Ice/servantLocator/TestAMD.ice index cd1f2a9eedf..1750cb352f3 100644 --- a/java/test/Ice/servantLocator/TestAMD.ice +++ b/java/test/Ice/servantLocator/TestAMD.ice @@ -38,6 +38,11 @@ exception TestImpossibleException void shutdown(); }; +interface TestActivation +{ + void activateServantLocator(bool activate); +}; + local class Cookie { ["cpp:const"] string message(); diff --git a/py/modules/IcePy/ObjectAdapter.cpp b/py/modules/IcePy/ObjectAdapter.cpp index 961f1e8e5f8..50cc46c5a7a 100644 --- a/py/modules/IcePy/ObjectAdapter.cpp +++ b/py/modules/IcePy/ObjectAdapter.cpp @@ -100,6 +100,8 @@ IcePy::ServantLocatorWrapper::ServantLocatorWrapper(PyObject* locator) : IcePy::ServantLocatorWrapper::~ServantLocatorWrapper() { + AdoptThread adoptThread; // Ensure the current thread is able to call into Python. + Py_DECREF(_locator); } Ice::ObjectPtr @@ -241,8 +243,6 @@ IcePy::ServantLocatorWrapper::deactivate(const string& category) ex.raise(); } - - Py_DECREF(_locator); } PyObject* @@ -1253,7 +1253,6 @@ adapterAddServantLocator(ObjectAdapterObject* self, PyObject* args) { return 0; } - assert(self->adapter); try { @@ -1273,6 +1272,47 @@ adapterAddServantLocator(ObjectAdapterObject* self, PyObject* args) extern "C" #endif static PyObject* +adapterRemoveServantLocator(ObjectAdapterObject* self, PyObject* args) +{ + PyObject* categoryObj; + if(!PyArg_ParseTuple(args, STRCAST("O"), &categoryObj)) + { + return 0; + } + + string category; + if(!getStringArg(categoryObj, "category", category)) + { + return 0; + } + + assert(self->adapter); + Ice::ServantLocatorPtr locator; + try + { + locator = (*self->adapter)->removeServantLocator(category); + } + catch(const Ice::Exception& ex) + { + setPythonException(ex); + return 0; + } + + if(!locator) + { + Py_INCREF(Py_None); + return Py_None; + } + + ServantLocatorWrapperPtr wrapper = ServantLocatorWrapperPtr::dynamicCast(locator); + assert(wrapper); + return wrapper->getObject(); +} + +#ifdef WIN32 +extern "C" +#endif +static PyObject* adapterFindServantLocator(ObjectAdapterObject* self, PyObject* args) { PyObject* categoryObj; @@ -1585,6 +1625,8 @@ static PyMethodDef AdapterMethods[] = PyDoc_STR(STRCAST("findDefaultServant(category) -> Ice.Object")) }, { STRCAST("addServantLocator"), reinterpret_cast<PyCFunction>(adapterAddServantLocator), METH_VARARGS, PyDoc_STR(STRCAST("addServantLocator(Ice.ServantLocator, category) -> None")) }, + { STRCAST("removeServantLocator"), reinterpret_cast<PyCFunction>(adapterRemoveServantLocator), METH_VARARGS, + PyDoc_STR(STRCAST("removeServantLocator(category) -> Ice.ServantLocator")) }, { STRCAST("findServantLocator"), reinterpret_cast<PyCFunction>(adapterFindServantLocator), METH_VARARGS, PyDoc_STR(STRCAST("findServantLocator(category) -> Ice.ServantLocator")) }, { STRCAST("createProxy"), reinterpret_cast<PyCFunction>(adapterCreateProxy), METH_VARARGS, diff --git a/py/python/Ice.py b/py/python/Ice.py index 71e4e5fa1a9..1b718e6a56a 100644 --- a/py/python/Ice.py +++ b/py/python/Ice.py @@ -432,6 +432,9 @@ class ObjectAdapterI(ObjectAdapter): def addServantLocator(self, locator, category): self._impl.addServantLocator(locator, category) + def removeServantLocator(self, category): + return self._impl.removeServantLocator(category) + def findServantLocator(self, category): return self._impl.findServantLocator(category) diff --git a/py/test/Ice/servantLocator/AllTests.py b/py/test/Ice/servantLocator/AllTests.py index 1a9039cf422..865cb30a1a7 100644 --- a/py/test/Ice/servantLocator/AllTests.py +++ b/py/test/Ice/servantLocator/AllTests.py @@ -195,4 +195,26 @@ def allTests(communicator, collocated): testExceptions(obj, collocated) print "ok" + print "testing servant locator removal...", + sys.stdout.flush() + base = communicator.stringToProxy("test/activation:default -p 12010") + activation = Test.TestActivationPrx.checkedCast(base) + activation.activateServantLocator(False) + try: + base = communicator.stringToProxy("category/finished:default -p 12010") + obj.ice_ping() + test(False) + except Ice.ObjectNotExistException: + pass + print "ok" + + print "testing servant locator addition...", + sys.stdout.flush() + activation.activateServantLocator(True) + try: + obj.ice_ping() + except: + test(False) + print "ok" + return obj diff --git a/py/test/Ice/servantLocator/Collocated.py b/py/test/Ice/servantLocator/Collocated.py index 9e996f50732..a91987ad85f 100755 --- a/py/test/Ice/servantLocator/Collocated.py +++ b/py/test/Ice/servantLocator/Collocated.py @@ -12,7 +12,7 @@ import os, sys, traceback, time import Ice Ice.loadSlice('Test.ice') -import Test, TestI, AllTests +import Test, TestI, AllTests, TestActivationI class TestServer(Ice.Application): def run(self, args): @@ -24,6 +24,7 @@ class TestServer(Ice.Application): adapter.addServantLocator(TestI.ServantLocatorI("category"), "category") adapter.addServantLocator(TestI.ServantLocatorI(""), "") adapter.add(TestI.TestI(), self.communicator().stringToIdentity("asm")) + adapter.add(TestActivationI.TestActivationI(), self.communicator().stringToIdentity("test/activation")) AllTests.allTests(self.communicator(), False) diff --git a/py/test/Ice/servantLocator/Server.py b/py/test/Ice/servantLocator/Server.py index 091db0eb4fc..a32d5328ae1 100755 --- a/py/test/Ice/servantLocator/Server.py +++ b/py/test/Ice/servantLocator/Server.py @@ -12,7 +12,7 @@ import os, sys, traceback, time import Ice Ice.loadSlice('Test.ice') -import Test, TestI +import Test, TestI, TestActivationI class TestServer(Ice.Application): def run(self, args): @@ -23,6 +23,7 @@ class TestServer(Ice.Application): adapter.addServantLocator(TestI.ServantLocatorI("category"), "category") adapter.addServantLocator(TestI.ServantLocatorI(""), "") adapter.add(TestI.TestI(), self.communicator().stringToIdentity("asm")) + adapter.add(TestActivationI.TestActivationI(), self.communicator().stringToIdentity("test/activation")) adapter.activate() adapter.waitForDeactivate() diff --git a/py/test/Ice/servantLocator/ServerAMD.py b/py/test/Ice/servantLocator/ServerAMD.py index e322497718f..9ea620e4aab 100755 --- a/py/test/Ice/servantLocator/ServerAMD.py +++ b/py/test/Ice/servantLocator/ServerAMD.py @@ -12,7 +12,7 @@ import os, sys, traceback, time import Ice Ice.loadSlice('TestAMD.ice') -import Test, TestAMDI +import Test, TestAMDI, TestActivationAMDI class TestServer(Ice.Application): def run(self, args): @@ -23,6 +23,7 @@ class TestServer(Ice.Application): adapter.addServantLocator(TestAMDI.ServantLocatorI("category"), "category") adapter.addServantLocator(TestAMDI.ServantLocatorI(""), "") adapter.add(TestAMDI.TestI(), self.communicator().stringToIdentity("asm")) + adapter.add(TestActivationAMDI.TestActivationAMDI(), self.communicator().stringToIdentity("test/activation")) adapter.activate() adapter.waitForDeactivate() diff --git a/py/test/Ice/servantLocator/Test.ice b/py/test/Ice/servantLocator/Test.ice index 0c9b0d3af51..678dbe18386 100644 --- a/py/test/Ice/servantLocator/Test.ice +++ b/py/test/Ice/servantLocator/Test.ice @@ -39,6 +39,11 @@ interface TestIntf void shutdown(); }; +interface TestActivation +{ + void activateServantLocator(bool activate); +}; + local class Cookie { ["cpp:const"] string message(); diff --git a/py/test/Ice/servantLocator/TestAMD.ice b/py/test/Ice/servantLocator/TestAMD.ice index 809b2fa8f6d..808ff84fb89 100644 --- a/py/test/Ice/servantLocator/TestAMD.ice +++ b/py/test/Ice/servantLocator/TestAMD.ice @@ -39,6 +39,11 @@ exception TestImpossibleException void shutdown(); }; +interface TestActivation +{ + void activateServantLocator(bool activate); +}; + local class Cookie { ["cpp:const"] string message(); diff --git a/py/test/Ice/servantLocator/TestI.py b/py/test/Ice/servantLocator/TestI.py index eee6e60e8e4..96c0d3c1231 100644 --- a/py/test/Ice/servantLocator/TestI.py +++ b/py/test/Ice/servantLocator/TestI.py @@ -72,7 +72,7 @@ class ServantLocatorI(Ice.ServantLocator): def __del__(self): test(self._deactivated) - + def locate(self, current): test(not self._deactivated) diff --git a/slice/Ice/ObjectAdapter.ice b/slice/Ice/ObjectAdapter.ice index 190da4650f8..d7cc2692567 100644 --- a/slice/Ice/ObjectAdapter.ice +++ b/slice/Ice/ObjectAdapter.ice @@ -484,6 +484,7 @@ local interface ObjectAdapter * not belong to any specific category. * * @see Identity + * @see removeServantLocator * @see findServantLocator * @see ServantLocator * @@ -492,6 +493,25 @@ local interface ObjectAdapter /** * + * Remove a Servant Locator installed with this object adapter. + * + * @param category The category for which the Servant Locator can + * locate servants, or an empty string if the Servant Locator does + * not belong to any specific category. + * + * @return The Servant Locator, or null if no Servant Locator was + * found for the given category. + * + * @see Identity + * @see addServantLocator + * @see findServantLocator + * @see ServantLocator + * + **/ + ServantLocator removeServantLocator(string category); + + /** + * * Find a Servant Locator installed with this object adapter. * * @param category The category for which the Servant Locator can @@ -503,6 +523,7 @@ local interface ObjectAdapter * * @see Identity * @see addServantLocator + * @see removeServantLocator * @see ServantLocator * **/ |