diff options
Diffstat (limited to 'cpp/src')
34 files changed, 590 insertions, 545 deletions
diff --git a/cpp/src/Glacier/Request.cpp b/cpp/src/Glacier/Request.cpp index a9054e114d1..3dd7a552577 100644 --- a/cpp/src/Glacier/Request.cpp +++ b/cpp/src/Glacier/Request.cpp @@ -162,6 +162,7 @@ Glacier::RequestQueue::run() { while(true) { + CommunicatorPtr communicator; vector<RequestPtr> requests; vector<RequestPtr> missives; @@ -182,15 +183,9 @@ Glacier::RequestQueue::run() return; } - if(!_requests.empty()) - { - _requests.swap(requests); - } - - if(!_missives.empty()) - { - _missives.swap(missives); - } + communicator = _communicator; + requests.swap(_requests); + missives.swap(_missives); } // @@ -214,8 +209,8 @@ Glacier::RequestQueue::run() { out << "reverse "; } - out << "routing to:\n" - << "\nproxy = " << _communicator->proxyToString(proxy) + out << "routing to:" + << "\nproxy = " << communicator->proxyToString(proxy) << "\noperation = " << current.operation; } @@ -254,7 +249,7 @@ Glacier::RequestQueue::run() } out << "batch routing to:" - << "\nproxy = " << _communicator->proxyToString(proxy) + << "\nproxy = " << communicator->proxyToString(proxy) << "\noperation = " << current.operation; } @@ -264,7 +259,7 @@ Glacier::RequestQueue::run() // // This sends all batched missives. // - _communicator->flushBatchRequests(); + communicator->flushBatchRequests(); } catch(const Ice::Exception& ex) { diff --git a/cpp/src/Glacier/RouterI.cpp b/cpp/src/Glacier/RouterI.cpp index 9d08816afdb..44e7448d0b0 100644 --- a/cpp/src/Glacier/RouterI.cpp +++ b/cpp/src/Glacier/RouterI.cpp @@ -26,9 +26,9 @@ Glacier::RouterI::RouterI(const ObjectAdapterPtr& clientAdapter, _serverAdapter(serverAdapter), _logger(_clientAdapter->getCommunicator()->getLogger()), _routingTable(routingTable), - _sessionManager(sessionManager), - _userId(userId) -{ + _userId(userId), + _sessionManager(sessionManager) + { PropertiesPtr properties = _clientAdapter->getCommunicator()->getProperties(); _routingTableTraceLevel = properties->getPropertyAsInt("Glacier.Router.Trace.RoutingTable"); } @@ -36,7 +36,7 @@ Glacier::RouterI::RouterI(const ObjectAdapterPtr& clientAdapter, Glacier::RouterI::~RouterI() { assert(!_clientAdapter); - assert(_sessions.empty()); + assert(!_session); } void @@ -50,18 +50,19 @@ Glacier::RouterI::destroy() _serverAdapter = 0; _logger = 0; _routingTable = 0; - for(vector<SessionPrx>::const_iterator p = _sessions.begin(); p != _sessions.end(); ++p) + { + IceUtil::Mutex::Lock lock(_sessionMutex); try { - (*p)->destroy(); + _session->destroy(); } catch(...) { // Ignore all exceptions. } + _session = 0; } - _sessions.clear(); } ObjectPrx @@ -116,14 +117,16 @@ Glacier::RouterI::createSession(const Current&) assert(_clientAdapter); // Destroyed? IceUtil::Mutex::Lock lock(_sessionMutex); - if(!_sessionManager) + + if(!_session) { - throw NoSessionManagerException(); + if(!_sessionManager) + { + throw NoSessionManagerException(); + } + + _session = _sessionManager->create(_userId); } - SessionPrx session = _sessionManager->create(_userId); - _sessions.push_back(session); - - return session; + return _session; } - diff --git a/cpp/src/Glacier/RouterI.h b/cpp/src/Glacier/RouterI.h index ac075232429..5f865cce3af 100644 --- a/cpp/src/Glacier/RouterI.h +++ b/cpp/src/Glacier/RouterI.h @@ -14,6 +14,7 @@ #include <Ice/Ice.h> #include <Glacier/Router.h> #include <Glacier/SessionManagerF.h> +#include <Glacier/SessionF.h> namespace Glacier { @@ -22,7 +23,7 @@ class RouterI : public Router { public: - RouterI(const Ice::ObjectAdapterPtr&, const Ice::ObjectAdapterPtr&, const ::IceInternal::RoutingTablePtr&, + RouterI(const Ice::ObjectAdapterPtr&, const Ice::ObjectAdapterPtr&, const IceInternal::RoutingTablePtr&, const SessionManagerPrx&, const std::string&); virtual ~RouterI(); @@ -40,13 +41,13 @@ private: Ice::ObjectAdapterPtr _clientAdapter; Ice::ObjectAdapterPtr _serverAdapter; Ice::LoggerPtr _logger; - ::IceInternal::RoutingTablePtr _routingTable; + IceInternal::RoutingTablePtr _routingTable; int _routingTableTraceLevel; - IceUtil::Mutex _sessionMutex; - SessionManagerPrx _sessionManager; - std::vector<SessionPrx> _sessions; std::string _userId; + SessionManagerPrx _sessionManager; + SessionPrx _session; + IceUtil::Mutex _sessionMutex; }; } diff --git a/cpp/src/Glacier/ServerBlobject.cpp b/cpp/src/Glacier/ServerBlobject.cpp index 09cd4044a06..3f349ba84f9 100644 --- a/cpp/src/Glacier/ServerBlobject.cpp +++ b/cpp/src/Glacier/ServerBlobject.cpp @@ -37,7 +37,7 @@ Glacier::ServerBlobject::ice_invoke_async(const Ice::AMD_Object_ice_invokePtr& a { assert(_clientAdapter); // Destroyed? - ObjectPrx proxy = _clientAdapter->createReverseProxy(current.id); + ObjectPrx proxy = _clientAdapter->createReverseProxy(current.id, 0); assert(proxy); invoke(proxy, amdCB, inParams, current); diff --git a/cpp/src/Glacier2/.depend b/cpp/src/Glacier2/.depend new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/cpp/src/Glacier2/.depend diff --git a/cpp/src/Glacier2/Blobject.cpp b/cpp/src/Glacier2/Blobject.cpp index 3a860404755..348a7004f59 100644 --- a/cpp/src/Glacier2/Blobject.cpp +++ b/cpp/src/Glacier2/Blobject.cpp @@ -13,83 +13,6 @@ using namespace std; using namespace Ice; using namespace Glacier; -Glacier::TwowayThrottle::TwowayThrottle(const CommunicatorPtr& communicator, bool reverse) : - _communicator(communicator), - _reverse(reverse), - _properties(_communicator->getProperties()), - _logger(_communicator->getLogger()), - _traceLevel(_properties->getPropertyAsInt("Glacier.Router.Trace.Throttle")), - _max(_reverse ? - _properties->getPropertyAsInt("Glacier.Router.Server.Throttle.Twoways") : - _properties->getPropertyAsInt("Glacier.Router.Client.Throttle.Twoways")), - _count(0) -{ -} - -Glacier::TwowayThrottle::~TwowayThrottle() -{ - assert(_count == 0); -} - -void -Glacier::TwowayThrottle::twowayStarted(const Ice::ObjectPrx& proxy, const Ice::Current& current) -{ - if(_max <= 0) - { - return; - } - - { - IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this); - - assert(_count <= _max); - - while(_count == _max) - { - if(_traceLevel >= 1) - { - Trace out(_logger, "Glacier"); - out << "throttling "; - if(_reverse) - { - out << "reverse "; - } - out << "twoway call:"; - out << "\nnumber of calls = " << _count; - out << "\nproxy = " << _communicator->proxyToString(proxy); - out << "\noperation = " << current.operation; - } - - wait(); - } - - ++_count; - } -} - -void -Glacier::TwowayThrottle::twowayFinished() -{ - if(_max <= 0) - { - return; - } - - { - IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this); - - assert(_count <= _max); - - if(_count == _max) - { - notifyAll(); - } - - --_count; - } -} - - #ifdef __HP_aCC // // Compiler bug! @@ -99,14 +22,14 @@ Glacier::TwowayThrottle::twowayFinished() // The work around is to use static strings: // -static const string traceServer = "Glacier.Router.Trace.Server"; -static const string traceClient = "Glacier.Router.Trace.Client"; +static const string traceServer = "Glacier2.Trace.Server"; +static const string traceClient = "Glacier2.Trace.Client"; -static const string serverForwardContext = "Glacier.Router.Server.ForwardContext"; -static const string clientForwardContext = "Glacier.Router.Client.ForwardContext"; +static const string serverForwardContext = "Glacier2.Server.ForwardContext"; +static const string clientForwardContext = "Glacier2.Client.ForwardContext"; -static const string serverSleepTime = "Glacier.Router.Server.SleepTime"; -static const string clientSleepTime = "Glacier.Router.Client.SleepTime"; +static const string serverSleepTime = "Glacier2.Server.SleepTime"; +static const string clientSleepTime = "Glacier2.Client.SleepTime"; #endif Glacier::Blobject::Blobject(const CommunicatorPtr& communicator, bool reverse) : @@ -127,21 +50,19 @@ Glacier::Blobject::Blobject(const CommunicatorPtr& communicator, bool reverse) : _properties->getPropertyAsInt(clientForwardContext) > 0), _sleepTime(_reverse ? IceUtil::Time::milliSeconds(_properties->getPropertyAsInt(serverSleepTime)) : - IceUtil::Time::milliSeconds(_properties->getPropertyAsInt(clientSleepTime))), + IceUtil::Time::milliSeconds(_properties->getPropertyAsInt(clientSleepTime))) #else _traceLevel(_reverse ? - _properties->getPropertyAsInt("Glacier.Router.Trace.Server") : - _properties->getPropertyAsInt("Glacier.Router.Trace.Client")), + _properties->getPropertyAsInt("Glacier2.Trace.Server") : + _properties->getPropertyAsInt("Glacier2.Trace.Client")), _forwardContext(_reverse ? - _properties->getPropertyAsInt("Glacier.Router.Server.ForwardContext") > 0 : - _properties->getPropertyAsInt("Glacier.Router.Client.ForwardContext") > 0), + _properties->getPropertyAsInt("Glacier2.Server.ForwardContext") > 0 : + _properties->getPropertyAsInt("Glacier2.Client.ForwardContext") > 0), _sleepTime(_reverse ? - IceUtil::Time::milliSeconds(_properties->getPropertyAsInt("Glacier.Router.Server.SleepTime")) : - IceUtil::Time::milliSeconds(_properties->getPropertyAsInt("Glacier.Router.Client.SleepTime"))), + IceUtil::Time::milliSeconds(_properties->getPropertyAsInt("Glacier2.Server.SleepTime")) : + IceUtil::Time::milliSeconds(_properties->getPropertyAsInt("Glacier2.Client.SleepTime"))) #endif - - _twowayThrottle(_communicator, _reverse) { _requestQueue = new RequestQueue(_communicator, _traceLevel, _reverse, _sleepTime); _requestQueueControl = _requestQueue->start(); @@ -171,26 +92,19 @@ class GlacierCB : public AMI_Object_ice_invoke { public: - GlacierCB(const AMD_Object_ice_invokePtr& cb, TwowayThrottle& twowayThrottle) : - _cb(cb), - _twowayThrottle(twowayThrottle) + GlacierCB(const AMD_Object_ice_invokePtr& cb) : + _cb(cb) { } - virtual - ~GlacierCB() - { - _twowayThrottle.twowayFinished(); - } - virtual void - ice_response(bool ok, const ::std::vector< ::Ice::Byte>& outParams) + ice_response(bool ok, const vector<Byte>& outParams) { _cb->ice_response(ok, outParams); } virtual void - ice_exception(const ::IceUtil::Exception& ex) + ice_exception(const Exception& ex) { _cb->ice_exception(ex); } @@ -198,7 +112,6 @@ public: private: AMD_Object_ice_invokePtr _cb; - TwowayThrottle& _twowayThrottle; }; void @@ -207,31 +120,18 @@ Glacier::Blobject::invoke(ObjectPrx& proxy, const AMD_Object_ice_invokePtr& amdC { try { - bool missive = modifyProxy(proxy, current); + modifyProxy(proxy, current); - if(missive) // Batch routing? + if(proxy->ice_isTwoway()) { - vector<Byte> dummy; - amdCB->ice_response(true, dummy); - - _requestQueue->addMissive(new Request(proxy, inParams, current, _forwardContext)); + AMI_Object_ice_invokePtr amiCB = new GlacierCB(amdCB); + _requestQueue->addRequest(new Request(proxy, inParams, current, _forwardContext, amiCB)); } - else // Regular routing. + else { - AMI_Object_ice_invokePtr amiCB; - - if(proxy->ice_isTwoway()) - { - amiCB = new GlacierCB(amdCB, _twowayThrottle); - _twowayThrottle.twowayStarted(proxy, current); - } - else - { - vector<Byte> dummy; - amdCB->ice_response(true, dummy); - } - - _requestQueue->addRequest(new Request(proxy, inParams, current, _forwardContext, amiCB)); + vector<Byte> dummy; + amdCB->ice_response(true, dummy); + _requestQueue->addRequest(new Request(proxy, inParams, current, _forwardContext, 0)); } } catch(const Exception& ex) @@ -252,15 +152,15 @@ Glacier::Blobject::invoke(ObjectPrx& proxy, const AMD_Object_ice_invokePtr& amdC return; } -bool -Glacier::Blobject::modifyProxy(ObjectPrx& proxy, const Current& current) +void +Glacier::Blobject::modifyProxy(ObjectPrx& proxy, const Current& current) const { if(!current.facet.empty()) { proxy = proxy->ice_newFacet(current.facet); } - bool missive = false; + bool batch = false; Context::const_iterator p = current.ctx.find("_fwd"); if(p != current.ctx.end()) @@ -273,35 +173,35 @@ Glacier::Blobject::modifyProxy(ObjectPrx& proxy, const Current& current) case 't': { proxy = proxy->ice_twoway(); - missive = false; + batch = false; break; } case 'o': { proxy = proxy->ice_oneway(); - missive = false; + batch = false; break; } case 'd': { proxy = proxy->ice_datagram(); - missive = false; + batch = false; break; } case 'O': { proxy = proxy->ice_batchOneway(); - missive = true; + batch = true; break; } case 'D': { proxy = proxy->ice_batchDatagram(); - missive = true; + batch = true; break; } @@ -326,6 +226,4 @@ Glacier::Blobject::modifyProxy(ObjectPrx& proxy, const Current& current) } } } - - return missive; } diff --git a/cpp/src/Glacier2/Blobject.h b/cpp/src/Glacier2/Blobject.h index 3355d66bf8e..e4f462223dd 100644 --- a/cpp/src/Glacier2/Blobject.h +++ b/cpp/src/Glacier2/Blobject.h @@ -50,7 +50,6 @@ public: void destroy(); void invoke(Ice::ObjectPrx&, const Ice::AMD_Object_ice_invokePtr&, const std::vector<Ice::Byte>&, const Ice::Current&); - bool modifyProxy(Ice::ObjectPrx&, const Ice::Current&); protected: @@ -63,13 +62,13 @@ protected: private: + void modifyProxy(Ice::ObjectPrx&, const Ice::Current&) const; + const bool _forwardContext; const IceUtil::Time _sleepTime; RequestQueuePtr _requestQueue; IceUtil::ThreadControl _requestQueueControl; - - TwowayThrottle _twowayThrottle; }; } diff --git a/cpp/src/Glacier2/ClientServantLocator.cpp b/cpp/src/Glacier2/ClientServantLocator.cpp deleted file mode 100644 index 91d62bb14be..00000000000 --- a/cpp/src/Glacier2/ClientServantLocator.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2004 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -#include <Ice/RoutingTable.h> -#include <Glacier2/ClientServantLocator.h> -#include <Glacier2/RouterI.h> - -using namespace std; -using namespace Ice; -using namespace Glacier; - -Glacier::ClientServantLocator::ClientServantLocator(const ObjectAdapterPtr& clientAdapter, - const ObjectAdapterPtr& serverAdapter, - const SessionManagerPrx& sessionManager) : - _routingTable(new IceInternal::RoutingTable), - _routerId(stringToIdentity(clientAdapter->getCommunicator()->getProperties()->getPropertyWithDefault( - "Glacier.Router.Identity", "Glacier/router"))), - _router(new RouterI(clientAdapter, serverAdapter, _routingTable, sessionManager, "todo")), - _blobject(new ClientBlobject(clientAdapter->getCommunicator(), _routingTable, "")) -{ -} - -ObjectPtr -Glacier::ClientServantLocator::locate(const Current& current, LocalObjectPtr&) -{ - if(current.id == _routerId) - { - return _router; - } - else - { - return _blobject; - } -} - -void -Glacier::ClientServantLocator::finished(const Current&, const ObjectPtr&, const LocalObjectPtr&) -{ - // Nothing to do -} - -void -Glacier::ClientServantLocator::deactivate(const string&) -{ - assert(_blobject); - _blobject->destroy(); - _blobject = 0; - - assert(_router); - RouterI* router = dynamic_cast<RouterI*>(_router.get()); - assert(router); - router->destroy(); - _router = 0; -} diff --git a/cpp/src/Glacier2/ClientServantLocator.h b/cpp/src/Glacier2/ClientServantLocator.h deleted file mode 100644 index 4707ac2bc94..00000000000 --- a/cpp/src/Glacier2/ClientServantLocator.h +++ /dev/null @@ -1,36 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2004 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -#include <Glacier/SessionManagerF.h> -#include <Glacier2/ClientBlobject.h> - -namespace Glacier -{ - -class ClientServantLocator : public Ice::ServantLocator -{ -public: - - ClientServantLocator(const Ice::ObjectAdapterPtr&, - const Ice::ObjectAdapterPtr&, - const Glacier::SessionManagerPrx&); - - virtual Ice::ObjectPtr locate(const Ice::Current&, Ice::LocalObjectPtr&); - virtual void finished(const Ice::Current&, const Ice::ObjectPtr&, const Ice::LocalObjectPtr&); - virtual void deactivate(const std::string&); - -private: - - IceInternal::RoutingTablePtr _routingTable; - Ice::Identity _routerId; - Ice::RouterPtr _router; - Glacier::ClientBlobjectPtr _blobject; -}; - -} diff --git a/cpp/src/Glacier2/Glacier2.cpp b/cpp/src/Glacier2/Glacier2.cpp index 0108380a847..a0f87e8c7d1 100644 --- a/cpp/src/Glacier2/Glacier2.cpp +++ b/cpp/src/Glacier2/Glacier2.cpp @@ -11,9 +11,7 @@ #include <Ice/Application.h> #include <IceSSL/CertificateVerifierF.h> #include <IceSSL/Plugin.h> -#include <Glacier/SessionManager.h> -#include <Glacier2/ClientServantLocator.h> -#include <Glacier2/ServerServantLocator.h> +#include <Glacier2/ServantLocator.h> using namespace std; using namespace Ice; @@ -93,7 +91,7 @@ Glacier::RouterApp::run(int argc, char* argv[]) sslPlugin->configure(contextType); // If we have been told only to only accept a single certificate. - string clientCertBase64 = properties->getProperty("Glacier.Router.AcceptCert"); + string clientCertBase64 = properties->getProperty("Glacier2.AcceptCert"); if(!clientCertBase64.empty()) { // Install a Certificate Verifier that only accepts indicated certificate. @@ -106,59 +104,23 @@ Glacier::RouterApp::run(int argc, char* argv[]) } // - // Get the session manager. + // Initialize the client object adapter and servant locator. // - const char* sessionManagerProperty = "Glacier.Router.SessionManager"; - string sessionManager = properties->getProperty(sessionManagerProperty); - SessionManagerPrx sessionManagerPrx; - if(!sessionManager.empty()) - { - sessionManagerPrx = SessionManagerPrx::checkedCast(communicator()->stringToProxy(sessionManager)); - } - - // - // Initialize the client object adapter. - // - const char* clientEndpointsProperty = "Glacier.Router.Client.Endpoints"; + const char* clientEndpointsProperty = "Glacier2.Client.Endpoints"; if(properties->getProperty(clientEndpointsProperty).empty()) { cerr << appName() << ": property `" << clientEndpointsProperty << "' is not set" << endl; return EXIT_FAILURE; } - ObjectAdapterPtr clientAdapter = communicator()->createObjectAdapter("Glacier.Router.Client"); - - // - // Initialize the server object adapter. - // - ObjectAdapterPtr serverAdapter; - if(!properties->getProperty("Glacier.Router.Server.Endpoints").empty()) - { - serverAdapter = communicator()->createObjectAdapter("Glacier.Router.Server"); - } - - // - // Create and add the servant locators. - // - Ice::ServantLocatorPtr clientServantLocator = new ClientServantLocator(clientAdapter, - serverAdapter, - sessionManagerPrx); - clientAdapter->addServantLocator(clientServantLocator, ""); - - if(serverAdapter) - { - Ice::ServantLocatorPtr serverServantLocator = new ServerServantLocator(clientAdapter); - serverAdapter->addServantLocator(serverServantLocator, ""); - } + ObjectAdapterPtr adapter = communicator()->createObjectAdapter("Glacier2.Client"); + ServantLocatorPtr locator = new ClientServantLocator(adapter); + adapter->addServantLocator(locator, ""); // // Everything ok, let's go. // shutdownOnInterrupt(); - clientAdapter->activate(); - if(serverAdapter) - { - serverAdapter->activate(); - } + adapter->activate(); communicator()->waitForShutdown(); ignoreInterrupt(); @@ -168,13 +130,39 @@ Glacier::RouterApp::run(int argc, char* argv[]) int main(int argc, char* argv[]) { - // - // Make sure that this process doesn't use a router. - // try { PropertiesPtr defaultProperties = getDefaultProperties(argc, argv); + + // + // Make sure that Glacier2 doesn't use a router. + // defaultProperties->setProperty("Ice.Default.Router", ""); + + // + // No active connection management is permitted with + // Glacier2. Connections must remain established. + // + defaultProperties->setProperty("Ice.ConnectionIdleTime", "0"); + + // + // Ice.MonitorConnections defaults to Ice.ConnectionIdleTime, + // which we set to 0 above. However, we still want the + // connection monitor thread for AMI timeouts. We only set + // this value if it hasn't been set explicitly already. + // + if(defaultProperties->getProperty("Ice.MonitorConnections").empty()) + { + defaultProperties->setProperty("Ice.MonitorConnections", "60"); + } + + // + // We do not need to set Ice.RetryIntervals to -1, i.e., we do + // not have to disable connection retry. It is safe for + // Glacier2 to retry outgoing connections to servers. Retry + // for incoming connections from clients must be disabled in + // the clients. + // } catch(const Exception& e) { diff --git a/cpp/src/Glacier2/Request.cpp b/cpp/src/Glacier2/Request.cpp index 2a2d7ef4543..1a04116692c 100644 --- a/cpp/src/Glacier2/Request.cpp +++ b/cpp/src/Glacier2/Request.cpp @@ -31,7 +31,6 @@ Glacier::Request::Request(const ObjectPrx& proxy, const vector<Byte>& inParams, void Glacier::Request::invoke() { - if(_proxy->ice_isTwoway()) { assert(_amiCB); @@ -68,11 +67,31 @@ Glacier::Request::invoke() bool Glacier::Request::override(const RequestPtr& other) { + // + // Both override values have to be non-empty. + // if(_override.empty() || other->_override.empty()) { return false; } + // + // Override does not work for twoways, because a response is + // expected for each request. + // + if(_proxy->ice_isTwoway() || other->_proxy->ice_isTwoway()) + { + return false; + } + + // + // We cannot override if the proxies differ. + // + if(_proxy != other->_proxy) + { + return false; + } + return _override == other->_override; } @@ -102,7 +121,6 @@ Glacier::RequestQueue::RequestQueue(const Ice::CommunicatorPtr& communicator, in Glacier::RequestQueue::~RequestQueue() { assert(_destroy); - assert(_missives.empty()); assert(_requests.empty()); assert(!_communicator); } @@ -113,7 +131,6 @@ Glacier::RequestQueue::destroy() IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this); _destroy = true; - _missives.clear(); _requests.clear(); _communicator = 0; @@ -121,38 +138,24 @@ Glacier::RequestQueue::destroy() } void -Glacier::RequestQueue::addMissive(const RequestPtr& missive) +Glacier::RequestQueue::addRequest(const RequestPtr& request) { - assert(missive); + assert(request); IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this); assert(!_destroy); - for(vector<RequestPtr>::iterator p = _missives.begin(); p != _missives.end(); ++p) + for(vector<RequestPtr>::iterator p = _requests.begin(); p != _requests.end(); ++p) { - if(missive->override(*p)) + if(request->override(*p)) { - *p = missive; // Replace old missive if this is an override. + *p = request; // Replace old request if this is an override. return; } } - _missives.push_back(missive); // No override, add new missive. - - notify(); -} - -void -Glacier::RequestQueue::addRequest(const RequestPtr& request) -{ - assert(request); - - IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this); - - assert(!_destroy); - - _requests.push_back(request); + _requests.push_back(request); // No override, add new request. notify(); } @@ -162,17 +165,16 @@ Glacier::RequestQueue::run() { while(true) { + CommunicatorPtr communicator; vector<RequestPtr> requests; - vector<RequestPtr> missives; { IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this); // - // Wait indefinitely if there's no requests or missive to - // send. + // Wait indefinitely if there's no requests to send. // - while(!_destroy && _requests.empty() && _missives.empty()) + while(!_destroy && _requests.empty()) { wait(); } @@ -182,21 +184,14 @@ Glacier::RequestQueue::run() return; } - if(!_requests.empty()) - { - _requests.swap(requests); - } - - if(!_missives.empty()) - { - _missives.swap(missives); - } + communicator = _communicator; + requests.swap(_requests); } // - // Send requests and missives, flush batch requests, and sleep - // outside the thread synchronization, so that new messages - // can be added while this is being done. + // Send requests, flush batch requests, and sleep outside the + // thread synchronization, so that new messages can be added + // while this is being done. // try @@ -214,8 +209,8 @@ Glacier::RequestQueue::run() { out << "reverse "; } - out << "routing to:\n" - << "\nproxy = " << _communicator->proxyToString(proxy) + out << "routing to:" + << "\nproxy = " << communicator->proxyToString(proxy) << "\noperation = " << current.operation; } @@ -239,32 +234,10 @@ Glacier::RequestQueue::run() try { - for(vector<RequestPtr>::const_iterator p = missives.begin(); p != missives.end(); ++p) - { - if(_traceLevel >= 2) - { - const ObjectPrx& proxy = (*p)->getProxy(); - const Current& current = (*p)->getCurrent(); - - Trace out(_logger, "Glacier"); - - if(_reverse) - { - out << "reverse "; - } - - out << "batch routing to:" - << "\nproxy = " << _communicator->proxyToString(proxy) - << "\noperation = " << current.operation; - } - - (*p)->invoke(); - } - // - // This sends all batched missives. + // This sends all batched requests. // - _communicator->flushBatchRequests(); + communicator->flushBatchRequests(); } catch(const Ice::Exception& ex) { diff --git a/cpp/src/Glacier2/Request.h b/cpp/src/Glacier2/Request.h index 7eecda78f00..54667fdff79 100644 --- a/cpp/src/Glacier2/Request.h +++ b/cpp/src/Glacier2/Request.h @@ -7,8 +7,8 @@ // // ********************************************************************** -#ifndef MISSIVE_H -#define MISSIVE_H +#ifndef REQUEST_H +#define REQUEST_H #include <Ice/Ice.h> #include <IceUtil/Thread.h> @@ -25,7 +25,7 @@ class Request : virtual public IceUtil::Shared public: Request(const Ice::ObjectPrx&, const std::vector<Ice::Byte>&, const Ice::Current&, bool, - const Ice::AMI_Object_ice_invokePtr& = 0); + const Ice::AMI_Object_ice_invokePtr&); void invoke(); bool override(const RequestPtr&); @@ -53,8 +53,8 @@ public: virtual ~RequestQueue(); void destroy(); - void addMissive(const RequestPtr&); void addRequest(const RequestPtr&); + void addBatchRequest(const RequestPtr&); virtual void run(); @@ -66,8 +66,8 @@ private: const bool _reverse; const IceUtil::Time _sleepTime; - std::vector<RequestPtr> _missives; std::vector<RequestPtr> _requests; + std::vector<RequestPtr> _batchRequests; bool _destroy; }; diff --git a/cpp/src/Glacier2/RouterI.cpp b/cpp/src/Glacier2/RouterI.cpp index 30423eda8c2..c0c5fa8aab1 100644 --- a/cpp/src/Glacier2/RouterI.cpp +++ b/cpp/src/Glacier2/RouterI.cpp @@ -8,9 +8,9 @@ // ********************************************************************** #include <Ice/RoutingTable.h> -#include <Glacier2/RouterI.h> #include <Glacier/Session.h> #include <Glacier/SessionManager.h> +#include <Glacier2/RouterI.h> #include <iostream> using namespace std; @@ -19,24 +19,29 @@ using namespace Glacier; Glacier::RouterI::RouterI(const ObjectAdapterPtr& clientAdapter, const ObjectAdapterPtr& serverAdapter, - const ::IceInternal::RoutingTablePtr& routingTable, - const SessionManagerPrx& sessionManager, - const string& userId) : + const IceInternal::RoutingTablePtr& routingTable) : _clientAdapter(clientAdapter), _serverAdapter(serverAdapter), _logger(_clientAdapter->getCommunicator()->getLogger()), _routingTable(routingTable), - _sessionManager(sessionManager), - _userId(userId) + _userId("todo") { - PropertiesPtr properties = _clientAdapter->getCommunicator()->getProperties(); - _routingTableTraceLevel = properties->getPropertyAsInt("Glacier.Router.Trace.RoutingTable"); + CommunicatorPtr communicator = _clientAdapter->getCommunicator(); + PropertiesPtr properties = communicator->getProperties(); + + _routingTableTraceLevel = properties->getPropertyAsInt("Glacier2.Trace.RoutingTable"); + + // + // If the property is empty, _sessionManager is null. + // + _sessionManager = SessionManagerPrx::checkedCast( + communicator->stringToProxy(properties->getProperty("Glacier2.SessionManager"))); } Glacier::RouterI::~RouterI() { assert(!_clientAdapter); - assert(_sessions.empty()); + assert(!_session); } void @@ -50,18 +55,19 @@ Glacier::RouterI::destroy() _serverAdapter = 0; _logger = 0; _routingTable = 0; - for(vector<SessionPrx>::const_iterator p = _sessions.begin(); p != _sessions.end(); ++p) + { + IceUtil::Mutex::Lock lock(_sessionMutex); try { - (*p)->destroy(); + _session->destroy(); } catch(...) { // Ignore all exceptions. } + _session = 0; } - _sessions.clear(); } ObjectPrx @@ -116,14 +122,17 @@ Glacier::RouterI::createSession(const Current&) assert(_clientAdapter); // Destroyed? IceUtil::Mutex::Lock lock(_sessionMutex); - if(!_sessionManager) + + if(!_session) { - throw NoSessionManagerException(); + if(!_sessionManager) + { + throw NoSessionManagerException(); + } + + _session = _sessionManager->create(_userId); } - SessionPrx session = _sessionManager->create(_userId); - _sessions.push_back(session); - - return session; + return _session; } diff --git a/cpp/src/Glacier2/RouterI.h b/cpp/src/Glacier2/RouterI.h index b23b5b7dae0..6c9dfc8a336 100644 --- a/cpp/src/Glacier2/RouterI.h +++ b/cpp/src/Glacier2/RouterI.h @@ -14,6 +14,7 @@ #include <Ice/Ice.h> #include <Glacier/Router.h> #include <Glacier/SessionManagerF.h> +#include <Glacier/SessionF.h> namespace Glacier { @@ -22,8 +23,7 @@ class RouterI : public Router { public: - RouterI(const Ice::ObjectAdapterPtr&, const Ice::ObjectAdapterPtr&, const IceInternal::RoutingTablePtr&, - const SessionManagerPrx&, const std::string&); + RouterI(const Ice::ObjectAdapterPtr&, const Ice::ObjectAdapterPtr&, const IceInternal::RoutingTablePtr&); virtual ~RouterI(); @@ -43,10 +43,10 @@ private: IceInternal::RoutingTablePtr _routingTable; int _routingTableTraceLevel; - IceUtil::Mutex _sessionMutex; - SessionManagerPrx _sessionManager; - std::vector<SessionPrx> _sessions; std::string _userId; + SessionManagerPrx _sessionManager; + SessionPrx _session; + IceUtil::Mutex _sessionMutex; }; } diff --git a/cpp/src/Glacier2/ServantLocator.cpp b/cpp/src/Glacier2/ServantLocator.cpp new file mode 100644 index 00000000000..32e8bf20249 --- /dev/null +++ b/cpp/src/Glacier2/ServantLocator.cpp @@ -0,0 +1,155 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2004 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <Ice/RoutingTable.h> +#include <Glacier2/ServantLocator.h> +#include <Glacier2/RouterI.h> + +using namespace std; +using namespace Ice; +using namespace Glacier; + +Glacier::ClientServantLocator::ClientServantLocator(const ObjectAdapterPtr& clientAdapter) : + _communicator(clientAdapter->getCommunicator()), + _properties(_communicator->getProperties()), + _logger(_communicator->getLogger()), + _clientAdapter(clientAdapter), + _routerId(stringToIdentity(_properties->getPropertyWithDefault("Glacier2.Identity", "Glacier/router"))), + _serverEndpoints(_properties->getProperty("Glacier2.Server.Endpoints")), + _traceLevel(_properties->getPropertyAsInt("Glacier2.Trace.Session")), + _serverAdapterCount(0), + _clientMapHint(_clientMap.end()) +{ +} + +ObjectPtr +Glacier::ClientServantLocator::locate(const Current& current, LocalObjectPtr&) +{ + IceUtil::Mutex::Lock sync(*this); + + assert(current.transport); + + map<TransportInfoPtr, Client>::iterator p = _clientMap.end(); + + if(_clientMapHint != _clientMap.end() && _clientMapHint->first == current.transport) + { + p = _clientMapHint; + } + else + { + p = _clientMap.find(current.transport); + + if(p == _clientMap.end()) + { + // + // Create a server object adapter and related objects if + // server endpoints are defined. + // + ObjectAdapterPtr adapter; + CommunicatorPtr communicator = _clientAdapter->getCommunicator(); + PropertiesPtr properties = communicator->getProperties(); + string endpoints = properties->getProperty("Glacier2.Server.Endpoints"); + if(!endpoints.empty()) + { + ostringstream name; + name << "Glacier2.Server." << _serverAdapterCount++; + adapter = communicator->createObjectAdapterWithEndpoints(name.str(), endpoints); + ServerBlobjectPtr blobject = new ServerBlobject(_clientAdapter, current.transport); + ServantLocatorPtr locator = new ServerServantLocator(blobject); + adapter->addServantLocator(locator, ""); + adapter->activate(); + } + + // + // Add a new client to our client map. + // + Client client; + IceInternal::RoutingTablePtr routingTable = new IceInternal::RoutingTable; + client.router = new RouterI(_clientAdapter, adapter, routingTable); + client.clientBlobject = new ClientBlobject(_clientAdapter->getCommunicator(), routingTable, ""); + client.serverAdapter = adapter; + p = _clientMap.insert(_clientMapHint, pair<const TransportInfoPtr, Client>(current.transport, client)); + + if(_traceLevel >= 1) + { + Trace out(_logger, "Glacier"); + out << "added session for:\n"; + out << current.transport->toString(); + if(client.serverAdapter) + { + Identity ident; + ident.name = "dummy"; + string endpts = communicator->proxyToString(client.serverAdapter->createProxy(ident)); + endpts.erase(0, endpts.find(':') + 1); + out << "\nserver adapter endpoints: " << endpts; + } + } + } + + _clientMapHint = p; + } + + if(current.id == _routerId) + { + return p->second.router; + } + else + { + return p->second.clientBlobject; + } +} + +void +Glacier::ClientServantLocator::finished(const Current&, const ObjectPtr&, const LocalObjectPtr&) +{ + // Nothing to do +} + +void +Glacier::ClientServantLocator::deactivate(const string&) +{ + IceUtil::Mutex::Lock sync(*this); + + for(map<TransportInfoPtr, Client>::iterator p = _clientMap.begin(); p != _clientMap.end(); ++p) + { + p->second.clientBlobject->destroy(); + RouterI* router = dynamic_cast<RouterI*>(p->second.router.get()); + router->destroy(); + if(p->second.serverAdapter) + { + p->second.serverAdapter->deactivate(); + } + }; + _clientMap.clear(); + _clientMapHint = _clientMap.end(); +} + +Glacier::ServerServantLocator::ServerServantLocator(const ServerBlobjectPtr& serverBlobject) : + _serverBlobject(serverBlobject) +{ +} + +ObjectPtr +Glacier::ServerServantLocator::locate(const Current& current, LocalObjectPtr&) +{ + return _serverBlobject; +} + +void +Glacier::ServerServantLocator::finished(const Current&, const ObjectPtr&, const LocalObjectPtr&) +{ + // Nothing to do +} + +void +Glacier::ServerServantLocator::deactivate(const string&) +{ + _serverBlobject->destroy(); + _serverBlobject = 0; +} diff --git a/cpp/src/Glacier2/ServantLocator.h b/cpp/src/Glacier2/ServantLocator.h new file mode 100644 index 00000000000..d18ad6e95c5 --- /dev/null +++ b/cpp/src/Glacier2/ServantLocator.h @@ -0,0 +1,64 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2004 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <Glacier2/ClientBlobject.h> +#include <Glacier2/ServerBlobject.h> + +namespace Glacier +{ + +class ClientServantLocator : public Ice::ServantLocator, public IceUtil::Mutex +{ +public: + + ClientServantLocator(const Ice::ObjectAdapterPtr&); + + virtual Ice::ObjectPtr locate(const Ice::Current&, Ice::LocalObjectPtr&); + virtual void finished(const Ice::Current&, const Ice::ObjectPtr&, const Ice::LocalObjectPtr&); + virtual void deactivate(const std::string&); + +private: + + const Ice::CommunicatorPtr _communicator; + const Ice::PropertiesPtr _properties; + const Ice::LoggerPtr _logger; + const Ice::ObjectAdapterPtr _clientAdapter; + const Ice::Identity _routerId; + const std::string _serverEndpoints; + const int _traceLevel; + + struct Client + { + Ice::RouterPtr router; + Glacier::ClientBlobjectPtr clientBlobject; + Ice::ObjectAdapterPtr serverAdapter; + }; + + int _serverAdapterCount; + + std::map<Ice::TransportInfoPtr, Client> _clientMap; + std::map<Ice::TransportInfoPtr, Client>::iterator _clientMapHint; +}; + +class ServerServantLocator : public Ice::ServantLocator +{ +public: + + ServerServantLocator(const Glacier::ServerBlobjectPtr&); + + virtual Ice::ObjectPtr locate(const Ice::Current&, Ice::LocalObjectPtr&); + virtual void finished(const Ice::Current&, const Ice::ObjectPtr&, const Ice::LocalObjectPtr&); + virtual void deactivate(const std::string&); + +private: + + Glacier::ServerBlobjectPtr _serverBlobject; +}; + +} diff --git a/cpp/src/Glacier2/ServerBlobject.cpp b/cpp/src/Glacier2/ServerBlobject.cpp index 0e1f1792b68..965a63393d2 100644 --- a/cpp/src/Glacier2/ServerBlobject.cpp +++ b/cpp/src/Glacier2/ServerBlobject.cpp @@ -14,9 +14,10 @@ using namespace std; using namespace Ice; using namespace Glacier; -Glacier::ServerBlobject::ServerBlobject(const ObjectAdapterPtr& clientAdapter) : +Glacier::ServerBlobject::ServerBlobject(const ObjectAdapterPtr& clientAdapter, const TransportInfoPtr& transport) : Glacier::Blobject(clientAdapter->getCommunicator(), true), - _clientAdapter(clientAdapter) + _clientAdapter(clientAdapter), + _transport(transport) { } @@ -28,6 +29,7 @@ Glacier::ServerBlobject::destroy() // object adapters have shut down. // _clientAdapter = 0; + _transport = 0; Blobject::destroy(); } @@ -37,7 +39,7 @@ Glacier::ServerBlobject::ice_invoke_async(const Ice::AMD_Object_ice_invokePtr& a { assert(_clientAdapter); // Destroyed? - ObjectPrx proxy = _clientAdapter->createReverseProxy(current.id); + ObjectPrx proxy = _clientAdapter->createReverseProxy(current.id, _transport); assert(proxy); invoke(proxy, amdCB, inParams, current); diff --git a/cpp/src/Glacier2/ServerBlobject.h b/cpp/src/Glacier2/ServerBlobject.h index aee22cdb1f3..e941a6b021a 100644 --- a/cpp/src/Glacier2/ServerBlobject.h +++ b/cpp/src/Glacier2/ServerBlobject.h @@ -22,7 +22,7 @@ class ServerBlobject : public Glacier::Blobject { public: - ServerBlobject(const Ice::ObjectAdapterPtr&); + ServerBlobject(const Ice::ObjectAdapterPtr&, const Ice::TransportInfoPtr&); void destroy(); virtual void ice_invoke_async(const Ice::AMD_Object_ice_invokePtr&, const std::vector<Ice::Byte>&, @@ -31,6 +31,7 @@ public: private: Ice::ObjectAdapterPtr _clientAdapter; + Ice::TransportInfoPtr _transport; }; } diff --git a/cpp/src/Glacier2/ServerServantLocator.cpp b/cpp/src/Glacier2/ServerServantLocator.cpp deleted file mode 100644 index b44c842abd9..00000000000 --- a/cpp/src/Glacier2/ServerServantLocator.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2004 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -#include <Glacier2/ServerServantLocator.h> - -using namespace std; -using namespace Ice; -using namespace Glacier; - -Glacier::ServerServantLocator::ServerServantLocator(const ObjectAdapterPtr& clientAdapter) : - _blobject(new ServerBlobject(clientAdapter)) -{ -} - -ObjectPtr -Glacier::ServerServantLocator::locate(const Current& current, LocalObjectPtr&) -{ - return _blobject; -} - -void -Glacier::ServerServantLocator::finished(const Current&, const ObjectPtr&, const LocalObjectPtr&) -{ - // Nothing to do -} - -void -Glacier::ServerServantLocator::deactivate(const string&) -{ - assert(_blobject); - _blobject->destroy(); - _blobject = 0; -} diff --git a/cpp/src/Glacier2/ServerServantLocator.h b/cpp/src/Glacier2/ServerServantLocator.h deleted file mode 100644 index 308d59092c2..00000000000 --- a/cpp/src/Glacier2/ServerServantLocator.h +++ /dev/null @@ -1,30 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2004 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -#include <Glacier2/ServerBlobject.h> - -namespace Glacier -{ - -class ServerServantLocator : public Ice::ServantLocator -{ -public: - - ServerServantLocator(const Ice::ObjectAdapterPtr&); - - virtual Ice::ObjectPtr locate(const Ice::Current&, Ice::LocalObjectPtr&); - virtual void finished(const Ice::Current&, const Ice::ObjectPtr&, const Ice::LocalObjectPtr&); - virtual void deactivate(const std::string&); - -private: - - Glacier::ServerBlobjectPtr _blobject; -}; - -} diff --git a/cpp/src/Glacier2/glacier2.dsp b/cpp/src/Glacier2/glacier2.dsp index 3fda9de09b7..a83915da61e 100755 --- a/cpp/src/Glacier2/glacier2.dsp +++ b/cpp/src/Glacier2/glacier2.dsp @@ -111,10 +111,6 @@ SOURCE=.\ClientBlobject.cpp # End Source File
# Begin Source File
-SOURCE=.\ClientServantLocator.cpp
-# End Source File
-# Begin Source File
-
SOURCE=.\Glacier2.cpp
# End Source File
# Begin Source File
@@ -127,11 +123,11 @@ SOURCE=.\RouterI.cpp # End Source File
# Begin Source File
-SOURCE=.\ServerBlobject.cpp
+SOURCE=.\ServantLocator.cpp
# End Source File
# Begin Source File
-SOURCE=.\ServerServantLocator.cpp
+SOURCE=.\ServerBlobject.cpp
# End Source File
# End Group
# Begin Group "Header Files"
@@ -147,10 +143,6 @@ SOURCE=.\ClientBlobject.h # End Source File
# Begin Source File
-SOURCE=.\ClientServantLocator.h
-# End Source File
-# Begin Source File
-
SOURCE=.\Request.h
# End Source File
# Begin Source File
@@ -159,11 +151,11 @@ SOURCE=.\RouterI.h # End Source File
# Begin Source File
-SOURCE=.\ServerBlobject.h
+SOURCE=.\ServantLocator.h
# End Source File
# Begin Source File
-SOURCE=.\ServerServantLocator.h
+SOURCE=.\ServerBlobject.h
# End Source File
# End Group
# Begin Group "Resource Files"
diff --git a/cpp/src/Ice/Connection.cpp b/cpp/src/Ice/Connection.cpp index 39067125e4f..df87a9678b3 100644 --- a/cpp/src/Ice/Connection.cpp +++ b/cpp/src/Ice/Connection.cpp @@ -1015,15 +1015,13 @@ IceInternal::Connection::sendNoResponse() int IceInternal::Connection::timeout() const { - // No mutex protection necessary, _endpoint is immutable. - return _endpoint->timeout(); + return _endpoint->timeout(); // No mutex protection necessary, _endpoint is immutable. } EndpointPtr IceInternal::Connection::endpoint() const { - // No mutex protection necessary, _endpoint is immutable. - return _endpoint; + return _endpoint; // No mutex protection necessary, _endpoint is immutable. } void @@ -1075,10 +1073,16 @@ IceInternal::Connection::getAdapter() const return _adapter; } +TransportInfoPtr +IceInternal::Connection::getTransportInfo() const +{ + return _info; // No mutex lock, _info is immutable. +} + bool IceInternal::Connection::datagram() const { - return _endpoint->datagram(); + return _endpoint->datagram(); // No mutex protection necessary, _endpoint is immutable. } bool @@ -1949,3 +1953,38 @@ IceInternal::Connection::doUncompress(BasicStream& compressed, BasicStream& unco copy(compressed.b.begin(), compressed.b.begin() + headerSize, uncompressed.b.begin()); } + +/* +void +Ice::ConnectionHandleI::flushBatchRequests() +{ + IceUtil::Mutex::Lock sync(*this); + if(_connection) + { + _connection->flushBatchRequest(); + } +} + +TransportInfoPtr +Ice::ConnectionHandleI::getTransportInfo() const +{ + // + // No mutex lock necessary, _info is immutable; + // + return _info; +} + +Ice::ConnectionHandleI::ConnectionHandleI(const ConnectionPtr& connection, const TransportInfoPtr& info) : + _connection(connection), + _info(info) +{ +} + +void +Ice::ConnectionHandleI::destroy() +{ + IceUtil::Mutex::Lock sync(*this); + assert(_connection); + _connection = 0; +} +*/ diff --git a/cpp/src/Ice/Connection.h b/cpp/src/Ice/Connection.h index 131f379bb54..ba1da1e7880 100644 --- a/cpp/src/Ice/Connection.h +++ b/cpp/src/Ice/Connection.h @@ -78,6 +78,8 @@ public: void setAdapter(const Ice::ObjectAdapterPtr&); Ice::ObjectAdapterPtr getAdapter() const; + Ice::TransportInfoPtr getTransportInfo() const; + // // Operations from EventHandler // @@ -90,7 +92,7 @@ public: virtual std::string toString() const; // - // Compare endpoints for sorting purposes. + // Compare connections for sorting purposes. // virtual bool operator==(const Connection&) const; virtual bool operator!=(const Connection&) const; diff --git a/cpp/src/Ice/IncomingAsync.cpp b/cpp/src/Ice/IncomingAsync.cpp index 7624c20200f..996dbd3c1c2 100644 --- a/cpp/src/Ice/IncomingAsync.cpp +++ b/cpp/src/Ice/IncomingAsync.cpp @@ -253,7 +253,7 @@ IceAsync::Ice::AMD_Object_ice_invoke::AMD_Object_ice_invoke(Incoming& in) : } void -IceAsync::Ice::AMD_Object_ice_invoke::ice_response(bool ok, const ::std::vector< ::Ice::Byte>& outParams) +IceAsync::Ice::AMD_Object_ice_invoke::ice_response(bool ok, const vector<Byte>& outParams) { try { diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp index 0ce1f2ed719..201cb830ecf 100644 --- a/cpp/src/Ice/Instance.cpp +++ b/cpp/src/Ice/Instance.cpp @@ -503,7 +503,7 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Prope } { - Int num = _properties->getPropertyAsIntWithDefault("Ice.ConnectionIdleTime", 60); + Int num = _properties->getPropertyAsIntWithDefault("Ice.ConnectiondleTime", 60); if(num < 0) { const_cast<Int&>(_connectionIdleTime) = 0; diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp index a3966c6870d..a5c62cbfe95 100644 --- a/cpp/src/Ice/ObjectAdapterI.cpp +++ b/cpp/src/Ice/ObjectAdapterI.cpp @@ -443,7 +443,7 @@ Ice::ObjectAdapterI::createDirectProxy(const Identity& ident) } ObjectPrx -Ice::ObjectAdapterI::createReverseProxy(const Identity& ident) +Ice::ObjectAdapterI::createReverseProxy(const Identity& ident, const TransportInfoPtr& transport) { IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); @@ -456,7 +456,7 @@ Ice::ObjectAdapterI::createReverseProxy(const Identity& ident) // vector<EndpointPtr> endpoints; ReferencePtr ref = _instance->referenceFactory()->create(ident, Context(), "", Reference::ModeTwoway, - false, "", endpoints, 0, 0, this, true); + false, "", endpoints, 0, 0, this, transport, true); return _instance->proxyFactory()->referenceToProxy(ref); } @@ -792,7 +792,7 @@ Ice::ObjectAdapterI::newProxy(const Identity& ident) const vector<EndpointPtr> endpoints; ReferencePtr ref = _instance->referenceFactory()->create(ident, Context(), "", Reference::ModeTwoway, false, _id, - endpoints, 0, _locatorInfo, 0, true); + endpoints, 0, _locatorInfo, 0, 0, true); // // Return a proxy for the reference. @@ -824,7 +824,7 @@ Ice::ObjectAdapterI::newDirectProxy(const Identity& ident) const // Create a reference and return a proxy for this reference. // ReferencePtr ref = _instance->referenceFactory()->create(ident, Context(), "", Reference::ModeTwoway, - false, "", endpoints, 0, _locatorInfo, 0, true); + false, "", endpoints, 0, _locatorInfo, 0, 0, true); return _instance->proxyFactory()->referenceToProxy(ref); } diff --git a/cpp/src/Ice/ObjectAdapterI.h b/cpp/src/Ice/ObjectAdapterI.h index 03f6d7b3bb4..4176c12ddba 100644 --- a/cpp/src/Ice/ObjectAdapterI.h +++ b/cpp/src/Ice/ObjectAdapterI.h @@ -65,7 +65,7 @@ public: virtual ObjectPrx createProxy(const Identity&); virtual ObjectPrx createDirectProxy(const Identity&); - virtual ObjectPrx createReverseProxy(const Identity&); + virtual ObjectPrx createReverseProxy(const Identity&, const TransportInfoPtr&); virtual void addRouter(const RouterPrx&); diff --git a/cpp/src/Ice/Proxy.cpp b/cpp/src/Ice/Proxy.cpp index 64ed2612736..4ee1e1b0dad 100644 --- a/cpp/src/Ice/Proxy.cpp +++ b/cpp/src/Ice/Proxy.cpp @@ -21,6 +21,7 @@ #include <Ice/LocatorInfo.h> #include <Ice/BasicStream.h> #include <Ice/LocalException.h> +#include <Ice/Connection.h> // For __connection->getTransportInfo(); using namespace std; using namespace Ice; @@ -562,6 +563,24 @@ IceProxy::Ice::Object::ice_default() const } } +TransportInfoPtr +IceProxy::Ice::Object::ice_getTransportInfo() +{ + int __cnt = 0; + while(true) + { + try + { + Handle< ::IceDelegate::Ice::Object> __del = __getDelegate(); + return __del->ice_getTransportInfo(); + } + catch(const LocalException& __ex) + { + __handleException(__ex, __cnt); + } + } +} + ReferencePtr IceProxy::Ice::Object::__reference() const { @@ -858,6 +877,12 @@ IceDelegateM::Ice::Object::ice_invoke(const string& operation, return ok; } +TransportInfoPtr +IceDelegateM::Ice::Object::ice_getTransportInfo() +{ + return __connection->getTransportInfo(); +} + void IceDelegateM::Ice::Object::__copyFrom(const ::IceInternal::Handle< ::IceDelegateM::Ice::Object>& from) { @@ -956,6 +981,12 @@ IceDelegateD::Ice::Object::ice_invoke(const string&, throw CollocationOptimizationException(__FILE__, __LINE__); } +TransportInfoPtr +IceDelegateD::Ice::Object::ice_getTransportInfo() +{ + throw CollocationOptimizationException(__FILE__, __LINE__); +} + void IceDelegateD::Ice::Object::__copyFrom(const ::IceInternal::Handle< ::IceDelegateD::Ice::Object>& from) { diff --git a/cpp/src/Ice/Reference.cpp b/cpp/src/Ice/Reference.cpp index e8df567dede..93bfb1d602e 100644 --- a/cpp/src/Ice/Reference.cpp +++ b/cpp/src/Ice/Reference.cpp @@ -91,6 +91,11 @@ IceInternal::Reference::operator==(const Reference& r) const return false; } + if(reverseTransport != r.reverseTransport) + { + return false; + } + if(collocationOptimization != r.collocationOptimization) { return false; @@ -203,6 +208,15 @@ IceInternal::Reference::operator<(const Reference& r) const return false; } + if(reverseTransport < r.reverseTransport) + { + return true; + } + else if(r.reverseTransport < reverseTransport) + { + return false; + } + if(!collocationOptimization && r.collocationOptimization) { return true; @@ -385,7 +399,7 @@ IceInternal::Reference::changeIdentity(const Identity& newIdentity) const { return instance->referenceFactory()->create(newIdentity, context, facet, mode, secure, adapterId, endpoints, routerInfo, locatorInfo, reverseAdapter, - collocationOptimization); + reverseTransport, collocationOptimization); } } @@ -400,7 +414,7 @@ IceInternal::Reference::changeContext(const Context& newContext) const { return instance->referenceFactory()->create(identity, newContext, facet, mode, secure, adapterId, endpoints, routerInfo, locatorInfo, reverseAdapter, - collocationOptimization); + reverseTransport, collocationOptimization); } } @@ -415,7 +429,7 @@ IceInternal::Reference::changeFacet(const string& newFacet) const { return instance->referenceFactory()->create(identity, context, newFacet, mode, secure, adapterId, endpoints, routerInfo, locatorInfo, reverseAdapter, - collocationOptimization); + reverseTransport, collocationOptimization); } } @@ -466,7 +480,7 @@ IceInternal::Reference::changeTimeout(int newTimeout) const return instance->referenceFactory()->create(identity, context, facet, mode, secure, adapterId, newEndpoints, newRouterInfo, newLocatorInfo, reverseAdapter, - collocationOptimization); + reverseTransport, collocationOptimization); } ReferencePtr @@ -480,7 +494,7 @@ IceInternal::Reference::changeMode(Mode newMode) const { return instance->referenceFactory()->create(identity, context, facet, newMode, secure, adapterId, endpoints, routerInfo, locatorInfo, reverseAdapter, - collocationOptimization); + reverseTransport, collocationOptimization); } } @@ -495,7 +509,7 @@ IceInternal::Reference::changeSecure(bool newSecure) const { return instance->referenceFactory()->create(identity, context, facet, mode, newSecure, adapterId, endpoints, routerInfo, locatorInfo, reverseAdapter, - collocationOptimization); + reverseTransport, collocationOptimization); } } @@ -546,7 +560,7 @@ IceInternal::Reference::changeCompress(bool newCompress) const return instance->referenceFactory()->create(identity, context, facet, mode, secure, adapterId, newEndpoints, newRouterInfo, newLocatorInfo, reverseAdapter, - collocationOptimization); + reverseTransport, collocationOptimization); } ReferencePtr @@ -560,7 +574,7 @@ IceInternal::Reference::changeAdapterId(const string& newAdapterId) const { return instance->referenceFactory()->create(identity, context, facet, mode, secure, newAdapterId, endpoints, routerInfo, locatorInfo, reverseAdapter, - collocationOptimization); + reverseTransport, collocationOptimization); } } @@ -575,7 +589,7 @@ IceInternal::Reference::changeEndpoints(const vector<EndpointPtr>& newEndpoints) { return instance->referenceFactory()->create(identity, context, facet, mode, secure, adapterId, newEndpoints, routerInfo, locatorInfo, reverseAdapter, - collocationOptimization); + reverseTransport, collocationOptimization); } } @@ -592,7 +606,7 @@ IceInternal::Reference::changeRouter(const RouterPrx& newRouter) const { return instance->referenceFactory()->create(identity, context, facet, mode, secure, adapterId, endpoints, newRouterInfo, locatorInfo, reverseAdapter, - collocationOptimization); + reverseTransport, collocationOptimization); } } @@ -609,7 +623,7 @@ IceInternal::Reference::changeLocator(const LocatorPrx& newLocator) const { return instance->referenceFactory()->create(identity, context, facet, mode, secure, adapterId, endpoints, routerInfo, newLocatorInfo, reverseAdapter, - collocationOptimization); + reverseTransport, collocationOptimization); } } @@ -624,7 +638,7 @@ IceInternal::Reference::changeCollocationOptimization(bool newCollocationOptimiz { return instance->referenceFactory()->create(identity, context, facet, mode, secure, adapterId, endpoints, routerInfo, locatorInfo, reverseAdapter, - newCollocationOptimization); + reverseTransport, newCollocationOptimization); } } @@ -637,7 +651,7 @@ IceInternal::Reference::changeDefault() const get(instance->referenceFactory()->getDefaultLocator()); return instance->referenceFactory()->create(identity, context, "", ModeTwoway, false, adapterId, - endpoints, defaultRouterInfo, defaultLocatorInfo, 0, true); + endpoints, defaultRouterInfo, defaultLocatorInfo, 0, 0, true); } ConnectionPtr @@ -653,32 +667,64 @@ IceInternal::Reference::getConnection(bool& compress) const // ObjectAdapterIPtr adapter = ObjectAdapterIPtr::dynamicCast(reverseAdapter); assert(adapter); + list<ConnectionPtr> connections = adapter->getIncomingConnections(); + list<ConnectionPtr>::iterator p; - vector<EndpointPtr> endpts; - endpts.reserve(connections.size()); - transform(connections.begin(), connections.end(), back_inserter(endpts), - ::Ice::constMemFun(&Connection::endpoint)); - endpts = filterEndpoints(endpts); - - if(endpts.empty()) + // + // If we have a reverse transport, then we only use the + // incoming connection that corresponds to this + // transport. Otherwise we use the first suitable incoming + // connections. + // + if(reverseTransport) { - NoEndpointException ex(__FILE__, __LINE__); - ex.proxy = toString(); - throw ex; - } + // + // TODO: This doesn't scale if we have many connections!! + // + for(p = connections.begin(); p != connections.end(); ++p) + { + if((*p)->getTransportInfo() == reverseTransport) + { + break; + } + } - list<ConnectionPtr>::iterator p; - for(p = connections.begin(); p != connections.end(); ++p) + if(p == connections.end()) + { + NoEndpointException ex(__FILE__, __LINE__); + ex.proxy = toString(); + throw ex; + } + } + else { - if((*p)->endpoint() == endpts.front()) + vector<EndpointPtr> endpts; + endpts.reserve(connections.size()); + transform(connections.begin(), connections.end(), back_inserter(endpts), + ::Ice::constMemFun(&Connection::endpoint)); + + endpts = filterEndpoints(endpts); + + if(endpts.empty()) { - break; + NoEndpointException ex(__FILE__, __LINE__); + ex.proxy = toString(); + throw ex; + } + + for(p = connections.begin(); p != connections.end(); ++p) + { + if((*p)->endpoint() == endpts.front()) + { + break; + } } + assert(p != connections.end()); } - assert(p != connections.end()); + connection = *p; - compress = (*p)->endpoint()->compress(); + compress = connection->endpoint()->compress(); } else { @@ -842,7 +888,8 @@ IceInternal::Reference::Reference(const InstancePtr& inst, const RouterInfoPtr& rtrInfo, const LocatorInfoPtr& locInfo, const ObjectAdapterPtr& rvAdapter, - bool collocationOptimization) : + const TransportInfoPtr& rvTransport, + bool collocationOpt) : instance(inst), identity(ident), context(ctx), @@ -854,7 +901,8 @@ IceInternal::Reference::Reference(const InstancePtr& inst, routerInfo(rtrInfo), locatorInfo(locInfo), reverseAdapter(rvAdapter), - collocationOptimization(collocationOptimization), + reverseTransport(rvTransport), + collocationOptimization(collocationOpt), hashValue(0) { // diff --git a/cpp/src/Ice/Reference.h b/cpp/src/Ice/Reference.h index 64f6cfde9ec..831f7a648d7 100644 --- a/cpp/src/Ice/Reference.h +++ b/cpp/src/Ice/Reference.h @@ -20,6 +20,7 @@ #include <Ice/RouterInfoF.h> #include <Ice/LocatorInfoF.h> #include <Ice/ObjectAdapterF.h> +#include <Ice/TransportInfoF.h> #include <Ice/ConnectionF.h> #include <Ice/Identity.h> @@ -70,6 +71,7 @@ public: const RouterInfoPtr routerInfo; // Null if no router is used. const LocatorInfoPtr locatorInfo; // Null if no locator is used. const Ice::ObjectAdapterPtr reverseAdapter; // For reverse communications using the adapter's incoming connections. + const Ice::TransportInfoPtr reverseTransport; // If not null, use this transport for reverse communications. const bool collocationOptimization; const Ice::Int hashValue; @@ -105,7 +107,8 @@ private: Reference(const InstancePtr&, const Ice::Identity&, const Ice::Context&, const std::string&, Mode, bool, const std::string&, const std::vector<EndpointPtr>&, - const RouterInfoPtr&, const LocatorInfoPtr&, const Ice::ObjectAdapterPtr&, bool); + const RouterInfoPtr&, const LocatorInfoPtr&, const Ice::ObjectAdapterPtr&, const Ice::TransportInfoPtr&, + bool); friend class ReferenceFactory; }; diff --git a/cpp/src/Ice/ReferenceFactory.cpp b/cpp/src/Ice/ReferenceFactory.cpp index 2c5e9c0c4dd..d50672ab0f3 100644 --- a/cpp/src/Ice/ReferenceFactory.cpp +++ b/cpp/src/Ice/ReferenceFactory.cpp @@ -36,6 +36,7 @@ IceInternal::ReferenceFactory::create(const Identity& ident, const RouterInfoPtr& routerInfo, const LocatorInfoPtr& locatorInfo, const ObjectAdapterPtr& reverseAdapter, + const TransportInfoPtr& reverseTransport, bool collocationOptimization) { Mutex::Lock sync(*this); @@ -54,7 +55,8 @@ IceInternal::ReferenceFactory::create(const Identity& ident, // Create new reference // ReferencePtr ref = new Reference(_instance, ident, context, facet, mode, secure, adapterId, - endpoints, routerInfo, locatorInfo, reverseAdapter, collocationOptimization); + endpoints, routerInfo, locatorInfo, reverseAdapter, reverseTransport, + collocationOptimization); // @@ -453,7 +455,7 @@ IceInternal::ReferenceFactory::create(const string& str) RouterInfoPtr routerInfo = _instance->routerManager()->get(getDefaultRouter()); LocatorInfoPtr locatorInfo = _instance->locatorManager()->get(getDefaultLocator()); - return create(ident, Context(), facet, mode, secure, adapter, endpoints, routerInfo, locatorInfo, 0, true); + return create(ident, Context(), facet, mode, secure, adapter, endpoints, routerInfo, locatorInfo, 0, 0, true); } ReferencePtr @@ -517,7 +519,7 @@ IceInternal::ReferenceFactory::create(const Identity& ident, BasicStream* s) RouterInfoPtr routerInfo = _instance->routerManager()->get(getDefaultRouter()); LocatorInfoPtr locatorInfo = _instance->locatorManager()->get(getDefaultLocator()); - return create(ident, Context(), facet, mode, secure, adapterId, endpoints, routerInfo, locatorInfo, 0, true); + return create(ident, Context(), facet, mode, secure, adapterId, endpoints, routerInfo, locatorInfo, 0, 0, true); } void diff --git a/cpp/src/Ice/ReferenceFactory.h b/cpp/src/Ice/ReferenceFactory.h index 6857963bf65..94b0d5fee32 100644 --- a/cpp/src/Ice/ReferenceFactory.h +++ b/cpp/src/Ice/ReferenceFactory.h @@ -25,7 +25,8 @@ public: ReferencePtr create(const Ice::Identity&, const Ice::Context&, const std::string&, Reference::Mode, bool, const std::string&, const std::vector<EndpointPtr>&, - const RouterInfoPtr&, const LocatorInfoPtr&, const Ice::ObjectAdapterPtr&, bool); + const RouterInfoPtr&, const LocatorInfoPtr&, const Ice::ObjectAdapterPtr&, + const Ice::TransportInfoPtr&, bool); ReferencePtr create(const std::string&); ReferencePtr create(const Ice::Identity&, BasicStream*); diff --git a/cpp/src/Ice/RouterInfo.cpp b/cpp/src/Ice/RouterInfo.cpp index 3296f357765..41c3f3b4892 100644 --- a/cpp/src/Ice/RouterInfo.cpp +++ b/cpp/src/Ice/RouterInfo.cpp @@ -137,7 +137,7 @@ IceInternal::RouterInfo::getClientProxy() } _clientProxy = _clientProxy->ice_router(0); // The client proxy cannot be routed. } - + return _clientProxy; } diff --git a/cpp/src/IcePack/icepacknode.dsp b/cpp/src/IcePack/icepacknode.dsp index ba67a8015a5..04916529126 100755 --- a/cpp/src/IcePack/icepacknode.dsp +++ b/cpp/src/IcePack/icepacknode.dsp @@ -463,6 +463,7 @@ SOURCE=.\dummy4.ice !IF "$(CFG)" == "IcePackNode - Win32 Release"
+USERDEP__DUMMY4="..\..\bin\slice2freeze.exe" "..\..\lib\slice.lib"
# Begin Custom Build
InputPath=.\dummy4.ice
@@ -478,6 +479,7 @@ BuildCmds= \ !ELSEIF "$(CFG)" == "IcePackNode - Win32 Debug"
+USERDEP__DUMMY4="..\..\bin\slice2freeze.exe" "..\..\lib\sliced.lib"
# Begin Custom Build
InputPath=.\dummy4.ice
@@ -500,6 +502,7 @@ SOURCE=.\dummy5.ice !IF "$(CFG)" == "IcePackNode - Win32 Release"
+USERDEP__DUMMY5="..\..\bin\slice2freeze.exe" "..\..\lib\slice.lib"
# Begin Custom Build
InputPath=.\dummy5.ice
@@ -515,6 +518,7 @@ BuildCmds= \ !ELSEIF "$(CFG)" == "IcePackNode - Win32 Debug"
+USERDEP__DUMMY5="..\..\bin\slice2freeze.exe" "..\..\lib\sliced.lib"
# Begin Custom Build
InputPath=.\dummy5.ice
|