summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorMarc Laukien <marc@zeroc.com>2002-01-14 22:39:58 +0000
committerMarc Laukien <marc@zeroc.com>2002-01-14 22:39:58 +0000
commitc0c6c0b98b0819f63cc6927a7041034ee48f481d (patch)
tree4b81109e1b222055020bec10ad4e2f2841454982 /cpp/src
parentglacier integration (diff)
downloadice-c0c6c0b98b0819f63cc6927a7041034ee48f481d.tar.bz2
ice-c0c6c0b98b0819f63cc6927a7041034ee48f481d.tar.xz
ice-c0c6c0b98b0819f63cc6927a7041034ee48f481d.zip
router fixes
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Glacier/ClientBlobject.cpp15
-rw-r--r--cpp/src/Glacier/ClientBlobject.h1
-rw-r--r--cpp/src/Glacier/GlacierRouter.cpp18
-rw-r--r--cpp/src/Glacier/RouterI.cpp37
-rw-r--r--cpp/src/Glacier/RouterI.h18
-rw-r--r--cpp/src/Glacier/ServerBlobject.cpp31
-rw-r--r--cpp/src/Glacier/ServerBlobject.h1
-rw-r--r--cpp/src/Ice/ObjectAdapterI.cpp2
-rw-r--r--cpp/src/Ice/Reference.cpp59
-rw-r--r--cpp/src/Ice/ReferenceFactory.cpp4
-rw-r--r--cpp/src/Ice/RouterInfo.cpp10
11 files changed, 174 insertions, 22 deletions
diff --git a/cpp/src/Glacier/ClientBlobject.cpp b/cpp/src/Glacier/ClientBlobject.cpp
index bff9072f25a..5d956bb984a 100644
--- a/cpp/src/Glacier/ClientBlobject.cpp
+++ b/cpp/src/Glacier/ClientBlobject.cpp
@@ -25,6 +25,11 @@ Glacier::ClientBlobject::ClientBlobject(const CommunicatorPtr& communicator,
_traceLevel = atoi(properties->getProperty("Glacier.Trace.Client").c_str());
}
+Glacier::ClientBlobject::~ClientBlobject()
+{
+ assert(!_communicator);
+}
+
void
Glacier::ClientBlobject::destroy()
{
@@ -60,6 +65,16 @@ Glacier::ClientBlobject::ice_invoke(const std::vector<Byte>& inParams, std::vect
proxy = proxy->ice_oneway();
}
+ if (_traceLevel >= 2)
+ {
+ ostringstream s;
+ s << "routing to:\n"
+ << "proxy = " << _communicator->proxyToString(proxy) << '\n'
+ << "operation = " << current.operation << '\n'
+ << "nonmutating = " << (current.nonmutating ? "true" : "false");
+ _logger->trace("Glacier", s.str());
+ }
+
proxy->ice_invoke(current.operation, current.nonmutating, inParams, outParams, current.context);
}
catch (const Exception& ex)
diff --git a/cpp/src/Glacier/ClientBlobject.h b/cpp/src/Glacier/ClientBlobject.h
index e9a4b39104a..ef173688909 100644
--- a/cpp/src/Glacier/ClientBlobject.h
+++ b/cpp/src/Glacier/ClientBlobject.h
@@ -22,6 +22,7 @@ class ClientBlobject : public Ice::Blobject
public:
ClientBlobject(const Ice::CommunicatorPtr&, const IceInternal::RoutingTablePtr&);
+ virtual ~ClientBlobject();
void destroy();
virtual void ice_invoke(const std::vector<Ice::Byte>&, std::vector<Ice::Byte>&, const Ice::Current&);
diff --git a/cpp/src/Glacier/GlacierRouter.cpp b/cpp/src/Glacier/GlacierRouter.cpp
index b1762e6d46b..ff3c496fce8 100644
--- a/cpp/src/Glacier/GlacierRouter.cpp
+++ b/cpp/src/Glacier/GlacierRouter.cpp
@@ -134,8 +134,8 @@ Glacier::Router::run(int argc, char* argv[])
return EXIT_FAILURE;
}
- ObjectAdapterPtr clientAdapter =
- communicator()->createObjectAdapterFromProperty("Client", clientEndpointsProperty);
+ ObjectAdapterPtr clientAdapter = communicator()->createObjectAdapterFromProperty("Client",
+ clientEndpointsProperty);
clientAdapter->activate();
//
@@ -146,8 +146,7 @@ Glacier::Router::run(int argc, char* argv[])
ObjectAdapterPtr serverAdapter;
if (!serverEndpoints.empty())
{
- ObjectAdapterPtr serverAdapter =
- communicator()->createObjectAdapterFromProperty("Server", serverEndpointsProperty);
+ serverAdapter = communicator()->createObjectAdapterFromProperty("Server", serverEndpointsProperty);
serverAdapter->activate();
}
@@ -186,7 +185,8 @@ Glacier::Router::run(int argc, char* argv[])
ObjectAdapterPtr routerAdapter =
communicator()->createObjectAdapterFromProperty("Router", routerEndpointsProperty);
- routerAdapter->add(new RouterI(clientAdapter, serverAdapter, routingTable), stringToIdentity(routerIdentity));
+ RouterPtr router = new RouterI(clientAdapter, serverAdapter, routingTable);
+ routerAdapter->add(router, stringToIdentity(routerIdentity));
routerAdapter->activate();
//
@@ -194,6 +194,14 @@ Glacier::Router::run(int argc, char* argv[])
//
communicator()->waitForShutdown();
return EXIT_SUCCESS;
+
+ //
+ // Destroy the router. The client and server blobjects get
+ // destroyed by ServantLocator::deactivate.
+ //
+ RouterI* rtr = dynamic_cast<RouterI*>(router.get());
+ assert(rtr);
+ rtr->destroy();
}
int
diff --git a/cpp/src/Glacier/RouterI.cpp b/cpp/src/Glacier/RouterI.cpp
index 8c15ecc3953..00f04a5424b 100644
--- a/cpp/src/Glacier/RouterI.cpp
+++ b/cpp/src/Glacier/RouterI.cpp
@@ -20,24 +20,59 @@ Glacier::RouterI::RouterI(const ObjectAdapterPtr& clientAdapter,
const ::IceInternal::RoutingTablePtr& routingTable) :
_clientAdapter(clientAdapter),
_serverAdapter(serverAdapter),
+ _logger(_clientAdapter->getCommunicator()->getLogger()),
_routingTable(routingTable)
{
+ PropertiesPtr properties = _clientAdapter->getCommunicator()->getProperties();
+ _routingTableTraceLevel = atoi(properties->getProperty("Glacier.Trace.RoutingTable").c_str());
+}
+
+Glacier::RouterI::~RouterI()
+{
+ assert(!_clientAdapter == 0);
+}
+
+void
+Glacier::RouterI::destroy()
+{
+ // No mutex protection necessary, destroy is only called after all
+ // object adapters have shut down.
+ _clientAdapter = 0;
+ _serverAdapter = 0;
+ _logger = 0;
+ _routingTable = 0;
}
ObjectPrx
Glacier::RouterI::getClientProxy(const Current&)
{
+ assert(_clientAdapter);
return _clientAdapter->createProxy(stringToIdentity("dummy"));
}
ObjectPrx
Glacier::RouterI::getServerProxy(const Current&)
{
- return _serverAdapter->createProxy(stringToIdentity("dummy"));
+ if (_serverAdapter)
+ {
+ return _serverAdapter->createProxy(stringToIdentity("dummy"));
+ }
+ else
+ {
+ return 0;
+ }
}
void
Glacier::RouterI::addProxy(const ObjectPrx& proxy, const Current&)
{
+ if (_routingTableTraceLevel)
+ {
+ ostringstream s;
+ s << "adding proxy to routing table:\n"
+ << _clientAdapter->getCommunicator()->proxyToString(proxy);
+ _logger->trace("Glacier", s.str());
+ }
+
_routingTable->add(proxy);
}
diff --git a/cpp/src/Glacier/RouterI.h b/cpp/src/Glacier/RouterI.h
index f15acf29153..53e0e582041 100644
--- a/cpp/src/Glacier/RouterI.h
+++ b/cpp/src/Glacier/RouterI.h
@@ -18,21 +18,25 @@
namespace Glacier
{
-class RouterI : public ::Ice::Router
+class RouterI : public Ice::Router
{
public:
- RouterI(const ::Ice::ObjectAdapterPtr&, const ::Ice::ObjectAdapterPtr&, const ::IceInternal::RoutingTablePtr&);
+ RouterI(const Ice::ObjectAdapterPtr&, const Ice::ObjectAdapterPtr&, const ::IceInternal::RoutingTablePtr&);
+ virtual ~RouterI();
- virtual ::Ice::ObjectPrx getClientProxy(const ::Ice::Current&);
- virtual ::Ice::ObjectPrx getServerProxy(const ::Ice::Current&);
- virtual void addProxy(const ::Ice::ObjectPrx&, const ::Ice::Current&);
+ void destroy();
+ virtual Ice::ObjectPrx getClientProxy(const Ice::Current&);
+ virtual Ice::ObjectPrx getServerProxy(const Ice::Current&);
+ virtual void addProxy(const Ice::ObjectPrx&, const Ice::Current&);
private:
- ::Ice::ObjectAdapterPtr _clientAdapter;
- ::Ice::ObjectAdapterPtr _serverAdapter;
+ Ice::ObjectAdapterPtr _clientAdapter;
+ Ice::ObjectAdapterPtr _serverAdapter;
+ Ice::LoggerPtr _logger;
::IceInternal::RoutingTablePtr _routingTable;
+ int _routingTableTraceLevel;
};
}
diff --git a/cpp/src/Glacier/ServerBlobject.cpp b/cpp/src/Glacier/ServerBlobject.cpp
index 8ad293e6e2e..cf9055387a2 100644
--- a/cpp/src/Glacier/ServerBlobject.cpp
+++ b/cpp/src/Glacier/ServerBlobject.cpp
@@ -23,6 +23,11 @@ Glacier::ServerBlobject::ServerBlobject(const ObjectAdapterPtr& clientAdapter) :
_traceLevel = atoi(properties->getProperty("Glacier.Trace.Server").c_str());
}
+Glacier::ServerBlobject::~ServerBlobject()
+{
+ assert(!_clientAdapter);
+}
+
void
Glacier::ServerBlobject::destroy()
{
@@ -40,8 +45,30 @@ Glacier::ServerBlobject::ice_invoke(const std::vector<Byte>& inParams, std::vect
try
{
- ObjectPrx reverseProxy = _clientAdapter->createReverseProxy(current.identity);
- reverseProxy->ice_invoke(current.operation, current.nonmutating, inParams, outParams, current.context);
+ ObjectPrx proxy = _clientAdapter->createReverseProxy(current.identity);
+ assert(proxy);
+
+ if (!current.facet.empty())
+ {
+ proxy = proxy->ice_newFacet(current.facet);
+ }
+
+ if (!current.response)
+ {
+ proxy = proxy->ice_oneway();
+ }
+
+ if (_traceLevel >= 2)
+ {
+ ostringstream s;
+ s << "reverse routing to:\n"
+ << "proxy = " << _clientAdapter->getCommunicator()->proxyToString(proxy) << '\n'
+ << "operation = " << current.operation << '\n'
+ << "nonmutating = " << (current.nonmutating ? "true" : "false");
+ _logger->trace("Glacier", s.str());
+ }
+
+ proxy->ice_invoke(current.operation, current.nonmutating, inParams, outParams, current.context);
}
catch (const Exception& ex)
{
diff --git a/cpp/src/Glacier/ServerBlobject.h b/cpp/src/Glacier/ServerBlobject.h
index 144440dae9c..d84637d0136 100644
--- a/cpp/src/Glacier/ServerBlobject.h
+++ b/cpp/src/Glacier/ServerBlobject.h
@@ -22,6 +22,7 @@ class ServerBlobject : public Ice::Blobject
public:
ServerBlobject(const Ice::ObjectAdapterPtr&);
+ virtual ~ServerBlobject();
void destroy();
virtual void ice_invoke(const std::vector<Ice::Byte>&, std::vector<Ice::Byte>&, const Ice::Current&);
diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp
index 232fb1adfd1..57b253b67da 100644
--- a/cpp/src/Ice/ObjectAdapterI.cpp
+++ b/cpp/src/Ice/ObjectAdapterI.cpp
@@ -332,7 +332,7 @@ Ice::ObjectAdapterI::addRouter(const RouterPrx& router)
// Add the router's server proxy endpoints to this object
// adapter.
//
- ObjectPrx proxy = routerInfo->getClientProxy();
+ ObjectPrx proxy = routerInfo->getServerProxy();
copy(proxy->__reference()->endpoints.begin(), proxy->__reference()->endpoints.end(),
back_inserter(_routerEndpoints));
sort(_routerEndpoints.begin(), _routerEndpoints.end()); // Must be sorted.
diff --git a/cpp/src/Ice/Reference.cpp b/cpp/src/Ice/Reference.cpp
index 454d39f9bd9..c40c30567a7 100644
--- a/cpp/src/Ice/Reference.cpp
+++ b/cpp/src/Ice/Reference.cpp
@@ -205,8 +205,52 @@ string
IceInternal::Reference::toString() const
{
ostringstream s;
+
s << identity;
+ if (!facet.empty())
+ {
+ s << " -f " << facet;
+ }
+
+ switch (mode)
+ {
+ case ModeTwoway:
+ {
+ s << " -t";
+ break;
+ }
+
+ case ModeOneway:
+ {
+ s << " -o";
+ break;
+ }
+
+ case ModeBatchOneway:
+ {
+ s << " -O";
+ break;
+ }
+
+ case ModeDatagram:
+ {
+ s << " -d";
+ break;
+ }
+
+ case ModeBatchDatagram:
+ {
+ s << " -D";
+ break;
+ }
+ }
+
+ if (secure)
+ {
+ s << " -s";
+ }
+
vector<EndpointPtr>::const_iterator p;
for (p = origEndpoints.begin(); p != origEndpoints.end(); ++p)
@@ -283,10 +327,17 @@ IceInternal::Reference::changeTimeout(int timeout) const
RouterInfoPtr newRouterInfo;
if (routerInfo)
{
- RouterPrx newRouter = RouterPrx::uncheckedCast(routerInfo->getRouter()->ice_timeout(timeout));
- ObjectPrx newClientProxy = routerInfo->getClientProxy()->ice_timeout(timeout);
- newRouterInfo = instance->routerManager()->get(newRouter);
- newRouterInfo->setClientProxy(newClientProxy);
+ try
+ {
+ RouterPrx newRouter = RouterPrx::uncheckedCast(routerInfo->getRouter()->ice_timeout(timeout));
+ ObjectPrx newClientProxy = routerInfo->getClientProxy()->ice_timeout(timeout);
+ newRouterInfo = instance->routerManager()->get(newRouter);
+ newRouterInfo->setClientProxy(newClientProxy);
+ }
+ catch (const NoEndpointException&)
+ {
+ // Ignore non-existing client proxies.
+ }
}
return instance->referenceFactory()->create(identity, facet, mode, secure,
diff --git a/cpp/src/Ice/ReferenceFactory.cpp b/cpp/src/Ice/ReferenceFactory.cpp
index e784c54ad8b..d1fa68f4116 100644
--- a/cpp/src/Ice/ReferenceFactory.cpp
+++ b/cpp/src/Ice/ReferenceFactory.cpp
@@ -174,6 +174,10 @@ IceInternal::ReferenceFactory::create(const string& str)
argument = str.substr(beg, end - beg);
}
+ //
+ // If any new options are added here,
+ // IceInternal::Reference::toString() must be updated as well.
+ //
switch (option[1])
{
case 'f':
diff --git a/cpp/src/Ice/RouterInfo.cpp b/cpp/src/Ice/RouterInfo.cpp
index 70cad21fbd6..267242e7273 100644
--- a/cpp/src/Ice/RouterInfo.cpp
+++ b/cpp/src/Ice/RouterInfo.cpp
@@ -117,7 +117,10 @@ IceInternal::RouterInfo::getClientProxy()
if (!_clientProxy) // Lazy initialization.
{
_clientProxy = _router->getClientProxy();
- assert(_clientProxy);
+ if (!_clientProxy)
+ {
+ throw NoEndpointException(__FILE__, __LINE__);
+ }
_clientProxy = _clientProxy->ice_router(0); // The client proxy cannot be routed.
}
@@ -139,7 +142,10 @@ IceInternal::RouterInfo::getServerProxy()
if (!_serverProxy) // Lazy initialization.
{
_serverProxy = _router->getServerProxy();
- assert(_serverProxy);
+ if (!_serverProxy)
+ {
+ throw NoEndpointException(__FILE__, __LINE__);
+ }
_serverProxy = _serverProxy->ice_router(0); // The server proxy cannot be routed.
}