summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2017-02-10 12:26:16 -0500
committerBernard Normier <bernard@zeroc.com>2017-02-10 12:26:16 -0500
commitb2923da71983b0ccac196ac2d0b22b1296a153ed (patch)
tree431de1f175ba93975308627c391ace28fcba7cab
parentFixed (ICE-7577) - IllegalStateException in the IceGridGUI (diff)
downloadice-b2923da71983b0ccac196ac2d0b22b1296a153ed.tar.bz2
ice-b2923da71983b0ccac196ac2d0b22b1296a153ed.tar.xz
ice-b2923da71983b0ccac196ac2d0b22b1296a153ed.zip
ICE-7342: add setPublishedEndpoints to ObjectAdapter
-rw-r--r--cpp/src/Ice/ObjectAdapterI.cpp76
-rw-r--r--cpp/src/Ice/ObjectAdapterI.h5
-rw-r--r--cpp/test/Ice/info/AllTests.cpp6
-rw-r--r--java-compat/src/Ice/src/main/java/Ice/ObjectAdapterI.java61
-rw-r--r--java-compat/test/src/main/java/test/Ice/info/AllTests.java6
-rw-r--r--java/src/Ice/src/main/java/com/zeroc/Ice/ObjectAdapterI.java60
-rw-r--r--java/test/src/main/java/test/Ice/info/AllTests.java6
-rw-r--r--js/src/Ice/ObjectAdapterI.js11
-rw-r--r--objective-c/src/Ice/ObjectAdapterI.mm30
-rw-r--r--objective-c/test/Ice/info/AllTests.m8
-rw-r--r--python/modules/IcePy/Endpoint.cpp24
-rw-r--r--python/modules/IcePy/Endpoint.h2
-rw-r--r--python/modules/IcePy/ObjectAdapter.cpp105
-rw-r--r--python/modules/IcePy/Proxy.cpp17
-rw-r--r--python/python/Ice.py9
-rw-r--r--python/test/Ice/info/AllTests.py7
-rw-r--r--slice/Ice/ObjectAdapter.ice25
17 files changed, 353 insertions, 105 deletions
diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp
index e7c6e529095..d7998cf49a1 100644
--- a/cpp/src/Ice/ObjectAdapterI.cpp
+++ b/cpp/src/Ice/ObjectAdapterI.cpp
@@ -63,6 +63,12 @@ inline void checkServant(const ObjectPtr& servant)
throw IllegalServantException(__FILE__, __LINE__, "cannot add null servant to Object Adapter");
}
}
+
+inline EndpointIPtr toEndpointI(const EndpointPtr& endp)
+{
+ return ICE_DYNAMIC_CAST(EndpointI, endp);
+}
+
}
string
@@ -641,6 +647,24 @@ Ice::ObjectAdapterI::getLocator() const
}
}
+EndpointSeq
+Ice::ObjectAdapterI::getEndpoints() const
+{
+ IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this);
+
+ EndpointSeq endpoints;
+ transform(_incomingConnectionFactories.begin(), _incomingConnectionFactories.end(),
+ back_inserter(endpoints),
+#ifdef ICE_CPP11_MAPPING
+ [](const IncomingConnectionFactoryPtr& factory)
+ {
+ return factory->endpoint();
+ });
+#else
+ Ice::constMemFun(&IncomingConnectionFactory::endpoint));
+#endif
+ return endpoints;
+}
void
Ice::ObjectAdapterI::refreshPublishedEndpoints()
@@ -650,7 +674,6 @@ Ice::ObjectAdapterI::refreshPublishedEndpoints()
{
IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this);
-
checkForDeactivation();
oldPublishedEndpoints = _publishedEndpoints;
@@ -678,32 +701,49 @@ Ice::ObjectAdapterI::refreshPublishedEndpoints()
}
EndpointSeq
-Ice::ObjectAdapterI::getEndpoints() const
+Ice::ObjectAdapterI::getPublishedEndpoints() const
{
IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this);
EndpointSeq endpoints;
- transform(_incomingConnectionFactories.begin(), _incomingConnectionFactories.end(),
- back_inserter(endpoints),
-#ifdef ICE_CPP11_MAPPING
- [](const IncomingConnectionFactoryPtr& factory)
- {
- return factory->endpoint();
- });
-#else
- Ice::constMemFun(&IncomingConnectionFactory::endpoint));
-#endif
+ copy(_publishedEndpoints.begin(), _publishedEndpoints.end(), back_inserter(endpoints));
return endpoints;
}
-EndpointSeq
-Ice::ObjectAdapterI::getPublishedEndpoints() const
+void
+Ice::ObjectAdapterI::setPublishedEndpoints(const EndpointSeq& newEndpoints)
{
- IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this);
+ vector<EndpointIPtr> newPublishedEndpoints;
+ transform(newEndpoints.begin(), newEndpoints.end(), back_inserter(newPublishedEndpoints), toEndpointI);
- EndpointSeq endpoints;
- copy(_publishedEndpoints.begin(), _publishedEndpoints.end(), back_inserter(endpoints));
- return endpoints;
+ LocatorInfoPtr locatorInfo;
+ vector<EndpointIPtr> oldPublishedEndpoints;
+ {
+ IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this);
+ checkForDeactivation();
+
+ oldPublishedEndpoints = _publishedEndpoints;
+ _publishedEndpoints = newPublishedEndpoints;
+
+ locatorInfo = _locatorInfo;
+ }
+
+ try
+ {
+ Ice::Identity dummy;
+ dummy.name = "dummy";
+ updateLocatorRegistry(locatorInfo, createDirectProxy(dummy));
+ }
+ catch(const Ice::LocalException&)
+ {
+ IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this);
+
+ //
+ // Restore the old published endpoints.
+ //
+ _publishedEndpoints = oldPublishedEndpoints;
+ throw;
+ }
}
bool
diff --git a/cpp/src/Ice/ObjectAdapterI.h b/cpp/src/Ice/ObjectAdapterI.h
index d86ce43235c..c1a731946f0 100644
--- a/cpp/src/Ice/ObjectAdapterI.h
+++ b/cpp/src/Ice/ObjectAdapterI.h
@@ -85,10 +85,11 @@ public:
virtual void setLocator(const LocatorPrxPtr&);
virtual Ice::LocatorPrxPtr getLocator() const;
- virtual void refreshPublishedEndpoints();
-
virtual EndpointSeq getEndpoints() const;
+
+ virtual void refreshPublishedEndpoints();
virtual EndpointSeq getPublishedEndpoints() const;
+ virtual void setPublishedEndpoints(const EndpointSeq&);
bool isLocal(const ObjectPrxPtr&) const;
diff --git a/cpp/test/Ice/info/AllTests.cpp b/cpp/test/Ice/info/AllTests.cpp
index 124b5069aad..9a21a3a01b6 100644
--- a/cpp/test/Ice/info/AllTests.cpp
+++ b/cpp/test/Ice/info/AllTests.cpp
@@ -139,6 +139,12 @@ allTests(const Ice::CommunicatorPtr& communicator)
test(udpEndpoint->datagram());
test(udpEndpoint->port > 0);
+ endpoints.pop_back();
+ test(endpoints.size() == 1);
+ adapter->setPublishedEndpoints(endpoints);
+ publishedEndpoints = adapter->getPublishedEndpoints();
+ test(endpoints == publishedEndpoints);
+
adapter->destroy();
int port = getTestPort(communicator->getProperties(), 1);
diff --git a/java-compat/src/Ice/src/main/java/Ice/ObjectAdapterI.java b/java-compat/src/Ice/src/main/java/Ice/ObjectAdapterI.java
index 4b4029abbd2..fe660152615 100644
--- a/java-compat/src/Ice/src/main/java/Ice/ObjectAdapterI.java
+++ b/java-compat/src/Ice/src/main/java/Ice/ObjectAdapterI.java
@@ -611,6 +611,18 @@ public final class ObjectAdapterI implements ObjectAdapter
}
@Override
+ public synchronized Endpoint[]
+ getEndpoints()
+ {
+ List<Endpoint> endpoints = new ArrayList<Endpoint>();
+ for(IncomingConnectionFactory factory : _incomingConnectionFactories)
+ {
+ endpoints.add(factory.endpoint());
+ }
+ return endpoints.toArray(new Endpoint[0]);
+ }
+
+ @Override
public void
refreshPublishedEndpoints()
{
@@ -648,23 +660,52 @@ public final class ObjectAdapterI implements ObjectAdapter
@Override
public synchronized Endpoint[]
- getEndpoints()
+ getPublishedEndpoints()
{
- List<Endpoint> endpoints = new ArrayList<Endpoint>();
- for(IncomingConnectionFactory factory : _incomingConnectionFactories)
- {
- endpoints.add(factory.endpoint());
- }
- return endpoints.toArray(new Endpoint[0]);
+ return _publishedEndpoints.toArray(new Endpoint[0]);
}
@Override
- public synchronized Endpoint[]
- getPublishedEndpoints()
+ public void
+ setPublishedEndpoints(Endpoint[] newEndpoints)
{
- return _publishedEndpoints.toArray(new Endpoint[0]);
+ List<IceInternal.EndpointI> newPublishedEndpoints = new ArrayList<>(newEndpoints.length);
+ for(Endpoint e: newEndpoints)
+ {
+ newPublishedEndpoints.add((IceInternal.EndpointI)e);
+ }
+
+ IceInternal.LocatorInfo locatorInfo = null;
+ List<IceInternal.EndpointI> oldPublishedEndpoints;
+
+ synchronized(this)
+ {
+ checkForDeactivation();
+ oldPublishedEndpoints = _publishedEndpoints;
+ _publishedEndpoints = newPublishedEndpoints;
+ locatorInfo = _locatorInfo;
+ }
+
+ try
+ {
+ Ice.Identity dummy = new Identity();
+ dummy.name = "dummy";
+ updateLocatorRegistry(locatorInfo, createDirectProxy(dummy));
+ }
+ catch(Ice.LocalException ex)
+ {
+ synchronized(this)
+ {
+ //
+ // Restore the old published endpoints.
+ //
+ _publishedEndpoints = oldPublishedEndpoints;
+ throw ex;
+ }
+ }
}
+
public boolean
isLocal(ObjectPrx proxy)
{
diff --git a/java-compat/test/src/main/java/test/Ice/info/AllTests.java b/java-compat/test/src/main/java/test/Ice/info/AllTests.java
index a52714ac866..f91a7dd05c6 100644
--- a/java-compat/test/src/main/java/test/Ice/info/AllTests.java
+++ b/java-compat/test/src/main/java/test/Ice/info/AllTests.java
@@ -123,6 +123,12 @@ public class AllTests
test(udpEndpoint.datagram());
test(udpEndpoint.port > 0);
+ endpoints = new Ice.Endpoint[]{endpoints[0]};
+ test(endpoints.length == 1);
+ adapter.setPublishedEndpoints(endpoints);
+ publishedEndpoints = adapter.getPublishedEndpoints();
+ test(java.util.Arrays.equals(endpoints, publishedEndpoints));
+
adapter.destroy();
int port = app.getTestPort(1);
diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectAdapterI.java b/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectAdapterI.java
index 2149b60a207..2f1bcde752e 100644
--- a/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectAdapterI.java
+++ b/java/src/Ice/src/main/java/com/zeroc/Ice/ObjectAdapterI.java
@@ -611,6 +611,18 @@ public final class ObjectAdapterI implements ObjectAdapter
}
@Override
+ public synchronized Endpoint[]
+ getEndpoints()
+ {
+ List<Endpoint> endpoints = new ArrayList<>();
+ for(IncomingConnectionFactory factory : _incomingConnectionFactories)
+ {
+ endpoints.add(factory.endpoint());
+ }
+ return endpoints.toArray(new Endpoint[0]);
+ }
+
+ @Override
public void
refreshPublishedEndpoints()
{
@@ -648,21 +660,49 @@ public final class ObjectAdapterI implements ObjectAdapter
@Override
public synchronized Endpoint[]
- getEndpoints()
+ getPublishedEndpoints()
{
- List<Endpoint> endpoints = new ArrayList<>();
- for(IncomingConnectionFactory factory : _incomingConnectionFactories)
- {
- endpoints.add(factory.endpoint());
- }
- return endpoints.toArray(new Endpoint[0]);
+ return _publishedEndpoints.toArray(new Endpoint[0]);
}
@Override
- public synchronized Endpoint[]
- getPublishedEndpoints()
+ public void
+ setPublishedEndpoints(Endpoint[] newEndpoints)
{
- return _publishedEndpoints.toArray(new Endpoint[0]);
+ List<com.zeroc.IceInternal.EndpointI> newPublishedEndpoints = new ArrayList<>(newEndpoints.length);
+ for(Endpoint e: newEndpoints)
+ {
+ newPublishedEndpoints.add((com.zeroc.IceInternal.EndpointI)e);
+ }
+
+ com.zeroc.IceInternal.LocatorInfo locatorInfo = null;
+ List<com.zeroc.IceInternal.EndpointI> oldPublishedEndpoints;
+
+ synchronized(this)
+ {
+ checkForDeactivation();
+ oldPublishedEndpoints = _publishedEndpoints;
+ _publishedEndpoints = newPublishedEndpoints;
+ locatorInfo = _locatorInfo;
+ }
+
+ try
+ {
+ Identity dummy = new Identity();
+ dummy.name = "dummy";
+ updateLocatorRegistry(locatorInfo, createDirectProxy(dummy));
+ }
+ catch(LocalException ex)
+ {
+ synchronized(this)
+ {
+ //
+ // Restore the old published endpoints.
+ //
+ _publishedEndpoints = oldPublishedEndpoints;
+ throw ex;
+ }
+ }
}
public boolean
diff --git a/java/test/src/main/java/test/Ice/info/AllTests.java b/java/test/src/main/java/test/Ice/info/AllTests.java
index d22aaf55e5b..8e7e33565dc 100644
--- a/java/test/src/main/java/test/Ice/info/AllTests.java
+++ b/java/test/src/main/java/test/Ice/info/AllTests.java
@@ -136,6 +136,12 @@ public class AllTests
test(udpEndpoint.datagram());
test(udpEndpoint.port > 0);
+ endpoints = new Endpoint[]{endpoints[0]};
+ test(endpoints.length == 1);
+ adapter.setPublishedEndpoints(endpoints);
+ publishedEndpoints = adapter.getPublishedEndpoints();
+ test(java.util.Arrays.equals(endpoints, publishedEndpoints));
+
adapter.destroy();
int port = app.getTestPort(1);
diff --git a/js/src/Ice/ObjectAdapterI.js b/js/src/Ice/ObjectAdapterI.js
index 1af76bef4e8..e7c5c136b02 100644
--- a/js/src/Ice/ObjectAdapterI.js
+++ b/js/src/Ice/ObjectAdapterI.js
@@ -445,19 +445,24 @@ class ObjectAdapterI
throw new Ice.FeatureNotSupportedException("setLocator not supported");
}
+ getEndpoints()
+ {
+ return [];
+ }
+
refreshPublishedEndpoints()
{
throw new Ice.FeatureNotSupportedException("refreshPublishedEndpoints not supported");
}
- getEndpoints()
+ getPublishedEndpoints()
{
return [];
}
- getPublishedEndpoints()
+ setPublishedEndpoints(newEndpoints)
{
- return [];
+ throw new Ice.FeatureNotSupportedException("setPublishedEndpoints not supported");
}
getServantManager()
diff --git a/objective-c/src/Ice/ObjectAdapterI.mm b/objective-c/src/Ice/ObjectAdapterI.mm
index c88ca834326..09b373cfcb6 100644
--- a/objective-c/src/Ice/ObjectAdapterI.mm
+++ b/objective-c/src/Ice/ObjectAdapterI.mm
@@ -789,6 +789,24 @@ typedef IceUtil::Handle<ServantLocatorWrapper> ServantLocatorWrapperPtr;
return nil; // Keep the compiler happy.
}
+-(ICEMutableEndpointSeq*) getEndpoints
+{
+ NSException* nsex = nil;
+ try
+ {
+ return [toNSArray(OBJECTADAPTER->getEndpoints()) autorelease];
+ }
+ catch(const std::exception& ex)
+ {
+ nsex = toObjCException(ex);
+ }
+ if(nsex != nil)
+ {
+ @throw nsex;
+ }
+ return nil;
+}
+
-(void) refreshPublishedEndpoints
{
NSException* nsex = nil;
@@ -806,12 +824,12 @@ typedef IceUtil::Handle<ServantLocatorWrapper> ServantLocatorWrapperPtr;
}
}
--(ICEEndpointSeq*) getEndpoints
+-(ICEMutableEndpointSeq*) getPublishedEndpoints
{
NSException* nsex = nil;
try
{
- return [toNSArray(OBJECTADAPTER->getEndpoints()) autorelease];
+ return [toNSArray(OBJECTADAPTER->getPublishedEndpoints()) autorelease];
}
catch(const std::exception& ex)
{
@@ -824,12 +842,14 @@ typedef IceUtil::Handle<ServantLocatorWrapper> ServantLocatorWrapperPtr;
return nil;
}
--(ICEEndpointSeq*) getPublishedEndpoints
+-(void) setPublishedEndpoints:(ICEEndpointSeq*)newEndpoints
{
NSException* nsex = nil;
try
{
- return [toNSArray(OBJECTADAPTER->getPublishedEndpoints()) autorelease];
+ Ice::EndpointSeq cxxNewEndpoints;
+ fromNSArray(newEndpoints, cxxNewEndpoints);
+ OBJECTADAPTER->setPublishedEndpoints(cxxNewEndpoints);
}
catch(const std::exception& ex)
{
@@ -839,7 +859,7 @@ typedef IceUtil::Handle<ServantLocatorWrapper> ServantLocatorWrapperPtr;
{
@throw nsex;
}
- return nil;
}
+
@end
diff --git a/objective-c/test/Ice/info/AllTests.m b/objective-c/test/Ice/info/AllTests.m
index 413855c279e..bf87a784b2a 100644
--- a/objective-c/test/Ice/info/AllTests.m
+++ b/objective-c/test/Ice/info/AllTests.m
@@ -97,7 +97,7 @@ infoAllTests(id<ICECommunicator> communicator)
[[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -t 15000:udp"];
id<ICEObjectAdapter> adapter = [communicator createObjectAdapter:@"TestAdapter"];
- ICEEndpointSeq* endpoints = [adapter getEndpoints];
+ ICEMutableEndpointSeq* endpoints = [adapter getEndpoints];
test([endpoints count] == 2);
ICEEndpointSeq* publishedEndpoints = [adapter getPublishedEndpoints];
test([endpoints isEqualToArray:publishedEndpoints]);
@@ -118,6 +118,12 @@ infoAllTests(id<ICECommunicator> communicator)
test([udpEndpoint datagram]);
test(udpEndpoint.port > 0);
+ [endpoints removeLastObject];
+ test([endpoints count] == 1);
+ [adapter setPublishedEndpoints:endpoints];
+ publishedEndpoints = [adapter getPublishedEndpoints];
+ test([endpoints isEqualToArray:publishedEndpoints]);
+
[adapter destroy];
[[communicator getProperties] setProperty:@"TestAdapter.Endpoints" value:@"default -h * -p 12020"];
diff --git a/python/modules/IcePy/Endpoint.cpp b/python/modules/IcePy/Endpoint.cpp
index 4482c759d47..f2285f381ba 100644
--- a/python/modules/IcePy/Endpoint.cpp
+++ b/python/modules/IcePy/Endpoint.cpp
@@ -252,3 +252,27 @@ IcePy::createEndpoint(const Ice::EndpointPtr& endpoint)
obj->endpoint = new Ice::EndpointPtr(endpoint);
return (PyObject*)obj;
}
+
+bool
+IcePy::toEndpointSeq(PyObject* endpoints, Ice::EndpointSeq& seq)
+{
+ Py_ssize_t sz = PySequence_Fast_GET_SIZE(endpoints);
+ for(Py_ssize_t i = 0; i < sz; ++i)
+ {
+ PyObject* p = PySequence_Fast_GET_ITEM(endpoints, i);
+ PyTypeObject* type = &EndpointType; // Necessary to prevent GCC's strict-alias warnings.
+ if(!PyObject_IsInstance(p, reinterpret_cast<PyObject*>(type)))
+ {
+ PyErr_Format(PyExc_ValueError, STRCAST("expected element of type Ice.Endpoint"));
+ return false;
+ }
+ Ice::EndpointPtr endp = getEndpoint(p);
+ if(!endp)
+ {
+ return false;
+ }
+ seq.push_back(endp);
+ }
+
+ return true;
+}
diff --git a/python/modules/IcePy/Endpoint.h b/python/modules/IcePy/Endpoint.h
index 88f7db88ea4..fdd15e2e7e7 100644
--- a/python/modules/IcePy/Endpoint.h
+++ b/python/modules/IcePy/Endpoint.h
@@ -23,6 +23,8 @@ bool initEndpoint(PyObject*);
PyObject* createEndpoint(const Ice::EndpointPtr&);
Ice::EndpointPtr getEndpoint(PyObject*);
+bool toEndpointSeq(PyObject*, Ice::EndpointSeq&);
+
}
#endif
diff --git a/python/modules/IcePy/ObjectAdapter.cpp b/python/modules/IcePy/ObjectAdapter.cpp
index d2718b1ca50..336df8f0be7 100644
--- a/python/modules/IcePy/ObjectAdapter.cpp
+++ b/python/modules/IcePy/ObjectAdapter.cpp
@@ -563,7 +563,7 @@ adapterWaitForDeactivate(ObjectAdapterObject* self, PyObject* args)
self->deactivateThread = new AdapterInvokeThreadPtr(t);
t->start();
}
-
+
while(!self->deactivated)
{
bool done;
@@ -571,7 +571,7 @@ adapterWaitForDeactivate(ObjectAdapterObject* self, PyObject* args)
AllowThreads allowThreads; // Release Python's global interpreter lock during blocking calls.
done = (*self->deactivateMonitor).timedWait(IceUtil::Time::milliSeconds(timeout));
}
-
+
if(!done)
{
PyRETURN_FALSE;
@@ -1541,8 +1541,42 @@ adapterGetLocator(ObjectAdapterObject* self)
PyObject* locatorProxyType = lookupType("Ice.LocatorPrx");
assert(locatorProxyType);
return createProxy(locator, (*self->adapter)->getCommunicator(), locatorProxyType);
-}
+}
+
+#ifdef WIN32
+extern "C"
+#endif
+static PyObject*
+adapterGetEndpoints(ObjectAdapterObject* self)
+{
+ assert(self->adapter);
+
+ Ice::EndpointSeq endpoints;
+ try
+ {
+ endpoints = (*self->adapter)->getEndpoints();
+ }
+ catch(const Ice::Exception& ex)
+ {
+ setPythonException(ex);
+ return 0;
+ }
+ int count = static_cast<int>(endpoints.size());
+ PyObjectHandle result = PyTuple_New(count);
+ int i = 0;
+ for(Ice::EndpointSeq::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p, ++i)
+ {
+ PyObjectHandle endp = createEndpoint(*p);
+ if(!endp.get())
+ {
+ return 0;
+ }
+ PyTuple_SET_ITEM(result.get(), i, endp.release()); // PyTuple_SET_ITEM steals a reference.
+ }
+
+ return result.release();
+}
#ifdef WIN32
extern "C"
@@ -1570,20 +1604,20 @@ adapterRefreshPublishedEndpoints(ObjectAdapterObject* self)
extern "C"
#endif
static PyObject*
-adapterGetEndpoints(ObjectAdapterObject* self)
+adapterGetPublishedEndpoints(ObjectAdapterObject* self)
{
assert(self->adapter);
Ice::EndpointSeq endpoints;
try
{
- endpoints = (*self->adapter)->getEndpoints();
+ endpoints = (*self->adapter)->getPublishedEndpoints();
}
catch(const Ice::Exception& ex)
{
setPythonException(ex);
return 0;
- }
+ }
int count = static_cast<int>(endpoints.size());
PyObjectHandle result = PyTuple_New(count);
@@ -1603,39 +1637,46 @@ adapterGetEndpoints(ObjectAdapterObject* self)
#ifdef WIN32
extern "C"
-#endif
+#endif
static PyObject*
-adapterGetPublishedEndpoints(ObjectAdapterObject* self)
+adapterSetPublishedEndpoints(ObjectAdapterObject* self, PyObject* args)
{
assert(self->adapter);
-
- Ice::EndpointSeq endpoints;
- try
- {
- endpoints = (*self->adapter)->getPublishedEndpoints();
- }
- catch(const Ice::Exception& ex)
- {
- setPythonException(ex);
+
+ PyObject* endpoints;
+ if(!PyArg_ParseTuple(args, STRCAST("O"), &endpoints))
+ {
return 0;
}
- int count = static_cast<int>(endpoints.size());
- PyObjectHandle result = PyTuple_New(count);
- int i = 0;
- for(Ice::EndpointSeq::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p, ++i)
+ if(!PyTuple_Check(endpoints) && !PyList_Check(endpoints))
{
- PyObjectHandle endp = createEndpoint(*p);
- if(!endp.get())
- {
- return 0;
- }
- PyTuple_SET_ITEM(result.get(), i, endp.release()); // PyTuple_SET_ITEM steals a reference.
+ PyErr_Format(PyExc_ValueError, STRCAST("argument must be a tuple or list"));
+ return 0;
}
- return result.release();
+ Ice::EndpointSeq seq;
+ if(!toEndpointSeq(endpoints, seq))
+ {
+ return 0;
+ }
+
+ try
+ {
+ AllowThreads allowThreads; // Release Python's global interpreter lock during blocking calls.
+ (*self->adapter)->setPublishedEndpoints(seq);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ setPythonException(ex);
+ return 0;
+ }
+
+ Py_INCREF(Py_None);
+ return Py_None;
}
+
static PyMethodDef AdapterMethods[] =
{
{ STRCAST("getName"), reinterpret_cast<PyCFunction>(adapterGetName), METH_NOARGS,
@@ -1699,13 +1740,15 @@ static PyMethodDef AdapterMethods[] =
{ STRCAST("setLocator"), reinterpret_cast<PyCFunction>(adapterSetLocator), METH_VARARGS,
PyDoc_STR(STRCAST("setLocator(proxy) -> None")) },
{ STRCAST("getLocator"), reinterpret_cast<PyCFunction>(adapterGetLocator), METH_NOARGS,
- PyDoc_STR(STRCAST("getLocator() -> Ice.LocatorPrx")) },
- { STRCAST("refreshPublishedEndpoints"), reinterpret_cast<PyCFunction>(adapterRefreshPublishedEndpoints), METH_NOARGS,
- PyDoc_STR(STRCAST("refreshPublishedEndpoints() -> None")) },
+ PyDoc_STR(STRCAST("getLocator() -> Ice.LocatorPrx")) },
{ STRCAST("getEndpoints"), reinterpret_cast<PyCFunction>(adapterGetEndpoints), METH_NOARGS,
PyDoc_STR(STRCAST("getEndpoints() -> None")) },
+ { STRCAST("refreshPublishedEndpoints"), reinterpret_cast<PyCFunction>(adapterRefreshPublishedEndpoints), METH_NOARGS,
+ PyDoc_STR(STRCAST("refreshPublishedEndpoints() -> None")) },
{ STRCAST("getPublishedEndpoints"), reinterpret_cast<PyCFunction>(adapterGetPublishedEndpoints), METH_NOARGS,
PyDoc_STR(STRCAST("getPublishedEndpoints() -> None")) },
+ { STRCAST("setPublishedEndpoints"), reinterpret_cast<PyCFunction>(adapterSetPublishedEndpoints), METH_VARARGS,
+ PyDoc_STR(STRCAST("setPublishedEndpoints(endpoints) -> None")) },
{ 0, 0 } /* sentinel */
};
diff --git a/python/modules/IcePy/Proxy.cpp b/python/modules/IcePy/Proxy.cpp
index a001f5047a2..a9e22e5c5e9 100644
--- a/python/modules/IcePy/Proxy.cpp
+++ b/python/modules/IcePy/Proxy.cpp
@@ -795,22 +795,9 @@ proxyIceEndpoints(ProxyObject* self, PyObject* args)
assert(self->proxy);
Ice::EndpointSeq seq;
- Py_ssize_t sz = PySequence_Fast_GET_SIZE(endpoints);
- for(Py_ssize_t i = 0; i < sz; ++i)
+ if(!toEndpointSeq(endpoints, seq))
{
- PyObject* p = PySequence_Fast_GET_ITEM(endpoints, i);
- PyTypeObject* type = &EndpointType; // Necessary to prevent GCC's strict-alias warnings.
- if(!PyObject_IsInstance(p, reinterpret_cast<PyObject*>(type)))
- {
- PyErr_Format(PyExc_ValueError, STRCAST("expected element of type Ice.Endpoint"));
- return 0;
- }
- Ice::EndpointPtr endp = getEndpoint(p);
- if(!endp)
- {
- return 0;
- }
- seq.push_back(endp);
+ return 0;
}
Ice::ObjectPrx newProxy;
diff --git a/python/python/Ice.py b/python/python/Ice.py
index 9ce81306fb7..33b407b1545 100644
--- a/python/python/Ice.py
+++ b/python/python/Ice.py
@@ -1115,15 +1115,18 @@ class ObjectAdapterI(ObjectAdapter):
def getLocator(self):
return self._impl.getLocator()
- def refreshPublishedEndpoints(self):
- self._impl.refreshPublishedEndpoints()
-
def getEndpoints(self):
return self._impl.getEndpoints()
+ def refreshPublishedEndpoints(self):
+ self._impl.refreshPublishedEndpoints()
+
def getPublishedEndpoints(self):
return self._impl.getPublishedEndpoints()
+ def setPublishedEndpoints(self, newEndpoints):
+ self._impl.setPublishedEndpoints(newEndpoints)
+
#
# Logger wrapper.
#
diff --git a/python/test/Ice/info/AllTests.py b/python/test/Ice/info/AllTests.py
index a03b69ecc4d..abc90961c6e 100644
--- a/python/test/Ice/info/AllTests.py
+++ b/python/test/Ice/info/AllTests.py
@@ -96,6 +96,12 @@ def allTests(communicator):
test(udpEndpoint.datagram())
test(udpEndpoint.port > 0)
+ endpoints = (endpoints[0], )
+ test(len(endpoints) == 1)
+ adapter.setPublishedEndpoints(endpoints)
+ publishedEndpoints = adapter.getPublishedEndpoints()
+ test(endpoints == publishedEndpoints)
+
adapter.destroy()
communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -h * -p 12020")
@@ -105,6 +111,7 @@ def allTests(communicator):
endpoints = adapter.getEndpoints()
test(len(endpoints) >= 1)
publishedEndpoints = adapter.getPublishedEndpoints()
+
test(len(publishedEndpoints) == 1)
for i in range(0, len(endpoints)):
diff --git a/slice/Ice/ObjectAdapter.ice b/slice/Ice/ObjectAdapter.ice
index 95d00c2655d..52b337febc6 100644
--- a/slice/Ice/ObjectAdapter.ice
+++ b/slice/Ice/ObjectAdapter.ice
@@ -640,6 +640,17 @@ local interface ObjectAdapter
["cpp:const"] Locator* getLocator();
/**
+ *
+ * Get the set of endpoints configured with this object adapter.
+ *
+ * @return The set of endpoints.
+ *
+ * @see Endpoint
+ *
+ **/
+ ["cpp:const"] EndpointSeq getEndpoints();
+
+ /**
* Refresh the set of published endpoints. The run time re-reads
* the PublishedEndpoints property if it is set and re-reads the
* list of local interfaces if the adapter is configured to listen
@@ -652,27 +663,27 @@ local interface ObjectAdapter
/**
*
- * Get the set of endpoints configured with this object adapter.
+ * Get the set of endpoints that proxies created by this object
+ * adapter will contain.
*
- * @return The set of endpoints.
+ * @return The set of published endpoints.
*
+ * @see #refreshPublishedEndpoints
* @see Endpoint
*
**/
- ["cpp:const"] EndpointSeq getEndpoints();
+ ["cpp:const"] EndpointSeq getPublishedEndpoints();
/**
*
- * Get the set of endpoints that proxies created by this object
+ * Set of the endpoints that proxies created by this object
* adapter will contain.
*
- * @return The set of published endpoints.
- *
* @see #refreshPublishedEndpoints
* @see Endpoint
*
**/
- ["cpp:const"] EndpointSeq getPublishedEndpoints();
+ void setPublishedEndpoints(EndpointSeq newEndpoints);
};
};