diff options
author | Matthew Newhook <matthew@zeroc.com> | 2006-09-04 01:14:49 +0000 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2006-09-04 01:14:49 +0000 |
commit | 25aff3e218350ea323a55ca7fa4247d9da61aac7 (patch) | |
tree | 2f04fb173eacceb007dda8696414c1d370f4c442 /cpp/src | |
parent | fixing a bug with generated #include statements (diff) | |
download | ice-25aff3e218350ea323a55ca7fa4247d9da61aac7.tar.bz2 ice-25aff3e218350ea323a55ca7fa4247d9da61aac7.tar.xz ice-25aff3e218350ea323a55ca7fa4247d9da61aac7.zip |
http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=1331
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Glacier2/SessionRouterI.cpp | 21 | ||||
-rw-r--r-- | cpp/src/IceGrid/AdminSessionI.cpp | 8 | ||||
-rw-r--r-- | cpp/src/IceGrid/AdminSessionI.h | 4 | ||||
-rw-r--r-- | cpp/src/IceGrid/ReapThread.cpp | 36 | ||||
-rw-r--r-- | cpp/src/IceGrid/ReapThread.h | 8 | ||||
-rw-r--r-- | cpp/src/IceGrid/RegistryI.cpp | 67 | ||||
-rw-r--r-- | cpp/src/IceGrid/SessionI.cpp | 60 | ||||
-rw-r--r-- | cpp/src/IceGrid/SessionI.h | 23 |
8 files changed, 140 insertions, 87 deletions
diff --git a/cpp/src/Glacier2/SessionRouterI.cpp b/cpp/src/Glacier2/SessionRouterI.cpp index bfae783e728..fcc289ac542 100644 --- a/cpp/src/Glacier2/SessionRouterI.cpp +++ b/cpp/src/Glacier2/SessionRouterI.cpp @@ -29,30 +29,37 @@ class SessionControlI : public SessionControl public: SessionControlI(const SessionRouterIPtr& sessionRouter, const ConnectionPtr& connection, - const FilterManagerPtr& filterManager) : + const FilterManagerPtr& filterManager, int timeout) : _sessionRouter(sessionRouter), _connection(connection), - _filters(filterManager) + _filters(filterManager), + _timeout(timeout) { } virtual StringSetPrx - categories(const Current& current) + categories(const Current&) { return _filters->categoriesPrx(); } virtual StringSetPrx - adapterIds(const Current& current) + adapterIds(const Current&) { return _filters->adapterIdsPrx(); } virtual IdentitySetPrx - identities(const Current& current) + identities(const Current&) { return _filters->identitiesPrx(); } + + virtual int + getSessionTimeout(const Current&) + { + return _timeout; + } virtual void destroy(const Current&) @@ -66,6 +73,7 @@ private: const SessionRouterIPtr _sessionRouter; const ConnectionPtr _connection; const FilterManagerPtr _filters; + const int _timeout; }; class ClientLocator : public ServantLocator @@ -838,7 +846,8 @@ Glacier2::SessionRouterI::createSessionInternal(const string& userId, bool allow if(_adminAdapter) { control = SessionControlPrx::uncheckedCast( - _adminAdapter->addWithUUID(new SessionControlI(this, current.con, filterManager))); + _adminAdapter->addWithUUID( + new SessionControlI(this, current.con, filterManager, _sessionTimeout.toSeconds()))); controlId = control->ice_getIdentity(); } session = factory->create(control, current.ctx); diff --git a/cpp/src/IceGrid/AdminSessionI.cpp b/cpp/src/IceGrid/AdminSessionI.cpp index 8306b118074..5f98dd7cf89 100644 --- a/cpp/src/IceGrid/AdminSessionI.cpp +++ b/cpp/src/IceGrid/AdminSessionI.cpp @@ -19,9 +19,7 @@ using namespace std; using namespace IceGrid; -AdminSessionI::AdminSessionI(const string& id, - const DatabasePtr& db, - int timeout) : +AdminSessionI::AdminSessionI(const string& id, const DatabasePtr& db, int timeout) : BaseSessionI(id, "admin", db), _timeout(timeout) { @@ -190,10 +188,12 @@ AdminSessionI::destroy(const Ice::Current& current) AdminSessionFactory::AdminSessionFactory(const Ice::ObjectAdapterPtr& adapter, const DatabasePtr& database, + const ReapThreadPtr& reapThread, const RegistryIPtr& registry) : _adapter(adapter), _database(database), _timeout(registry->getSessionTimeout()), + _reapThread(reapThread), _registry(registry) { } @@ -231,6 +231,8 @@ AdminSessionFactory::createGlacier2Session(const string& sessionId, const Glacie } } + _reapThread->add(new SessionReapable(_adapter, session, s->ice_getIdentity()), ctl->getSessionTimeout()); + return s; } diff --git a/cpp/src/IceGrid/AdminSessionI.h b/cpp/src/IceGrid/AdminSessionI.h index 4feb9d50222..090137a5c1b 100644 --- a/cpp/src/IceGrid/AdminSessionI.h +++ b/cpp/src/IceGrid/AdminSessionI.h @@ -12,6 +12,7 @@ #include <IceGrid/SessionI.h> #include <IceGrid/Topics.h> +#include <IceGrid/ReapThread.h> namespace IceGrid { @@ -54,7 +55,7 @@ class AdminSessionFactory : virtual public IceUtil::Shared { public: - AdminSessionFactory(const Ice::ObjectAdapterPtr&, const DatabasePtr&, const RegistryIPtr&); + AdminSessionFactory(const Ice::ObjectAdapterPtr&, const DatabasePtr&, const ReapThreadPtr&, const RegistryIPtr&); Glacier2::SessionPrx createGlacier2Session(const std::string&, const Glacier2::SessionControlPrx&); AdminSessionIPtr createSessionServant(const std::string&); @@ -67,6 +68,7 @@ private: const DatabasePtr _database; const int _timeout; const WaitQueuePtr _waitQueue; + const ReapThreadPtr _reapThread; const RegistryIPtr _registry; }; typedef IceUtil::Handle<AdminSessionFactory> AdminSessionFactoryPtr; diff --git a/cpp/src/IceGrid/ReapThread.cpp b/cpp/src/IceGrid/ReapThread.cpp index bdda6941c7b..e8ee202ac61 100644 --- a/cpp/src/IceGrid/ReapThread.cpp +++ b/cpp/src/IceGrid/ReapThread.cpp @@ -22,7 +22,7 @@ ReapThread::ReapThread(int timeout) : void ReapThread::run() { - vector<ReapablePtr> reap; + vector<ReapableItem> reap; while(true) { { @@ -34,12 +34,12 @@ ReapThread::run() break; } - list<ReapablePtr>::iterator p = _sessions.begin(); + list<ReapableItem>::iterator p = _sessions.begin(); while(p != _sessions.end()) { try { - if((IceUtil::Time::now() - (*p)->timestamp()) > _timeout) + if((IceUtil::Time::now() - p->item->timestamp()) > p->timeout) { reap.push_back(*p); p = _sessions.erase(p); @@ -56,9 +56,9 @@ ReapThread::run() } } - for(vector<ReapablePtr>::const_iterator p = reap.begin(); p != reap.end(); ++p) + for(vector<ReapableItem>::const_iterator p = reap.begin(); p != reap.end(); ++p) { - (*p)->destroy(false); + p->item->destroy(false); } reap.clear(); } @@ -67,7 +67,7 @@ ReapThread::run() void ReapThread::terminate() { - list<ReapablePtr> reap; + list<ReapableItem> reap; { Lock sync(*this); if(_terminated) @@ -79,9 +79,9 @@ ReapThread::terminate() reap.swap(_sessions); } - for(list<ReapablePtr>::const_iterator p = reap.begin(); p != reap.end(); ++p) + for(list<ReapableItem>::const_iterator p = reap.begin(); p != reap.end(); ++p) { - (*p)->destroy(true); + p->item->destroy(true); } } @@ -93,6 +93,24 @@ ReapThread::add(const ReapablePtr& reapable) { return; } - _sessions.push_back(reapable); + ReapableItem item; + item.item = reapable; + item.timeout = _timeout; + _sessions.push_back(item); +} + +void +ReapThread::add(const ReapablePtr& reapable, int timeout) +{ + Lock sync(*this); + if(_terminated) + { + return; + } + + ReapableItem item; + item.item = reapable; + item.timeout = IceUtil::Time::seconds(timeout); + _sessions.push_back(item); } diff --git a/cpp/src/IceGrid/ReapThread.h b/cpp/src/IceGrid/ReapThread.h index 0c8f8e62e3f..d4713de7726 100644 --- a/cpp/src/IceGrid/ReapThread.h +++ b/cpp/src/IceGrid/ReapThread.h @@ -39,12 +39,18 @@ public: virtual void run(); void terminate(); void add(const ReapablePtr&); + void add(const ReapablePtr&, int); private: const IceUtil::Time _timeout; bool _terminated; - std::list<ReapablePtr> _sessions; + struct ReapableItem + { + ReapablePtr item; + IceUtil::Time timeout; + }; + std::list<ReapableItem> _sessions; }; typedef IceUtil::Handle<ReapThread> ReapThreadPtr; diff --git a/cpp/src/IceGrid/RegistryI.cpp b/cpp/src/IceGrid/RegistryI.cpp index 77bce75b660..a1907fa8982 100644 --- a/cpp/src/IceGrid/RegistryI.cpp +++ b/cpp/src/IceGrid/RegistryI.cpp @@ -55,68 +55,6 @@ using namespace IceGrid; namespace IceGrid { -class SessionReapable : public Reapable -{ -public: - - SessionReapable(const ObjectAdapterPtr& adapter, - const ObjectPtr& session, - const Identity& id) : - _adapter(adapter), - _servant(session), - _session(dynamic_cast<BaseSessionI*>(_servant.get())), - _id(id) - { - } - - virtual ~SessionReapable() - { - } - - virtual IceUtil::Time - timestamp() const - { - return _session->timestamp(); - } - - virtual void - destroy(bool destroy) - { - try - { - // - // Invoke on the servant directly instead of the - // proxy. Invoking on the proxy might not always work if the - // communicator is being shutdown/destroyed. We have to create - // a fake "current" because the session destroy methods needs - // the adapter and object identity to unregister the servant - // from the adapter. - // - Current current; - if(!destroy) - { - current.adapter = _adapter; - current.id = _id; - } - _session->destroy(current); - } - catch(const ObjectNotExistException&) - { - } - catch(const LocalException& ex) - { - Warning out(_adapter->getCommunicator()->getLogger()); - out << "unexpected exception while reaping node session:\n" << ex; - } - } - -private: - - const ObjectAdapterPtr _adapter; - const ObjectPtr _servant; - BaseSessionI* _session; - const Identity _id; -}; class NullPermissionsVerifierI : public Glacier2::PermissionsVerifier { @@ -513,7 +451,8 @@ RegistryI::setupClientSessionFactory(const Ice::ObjectAdapterPtr& registryAdapte _waitQueue = new WaitQueue(); // Used for for session allocation timeout. _waitQueue->start(); - _clientSessionFactory = new ClientSessionFactory(sessionManagerAdapter, _database, _waitQueue); + assert(_clientReaper); + _clientSessionFactory = new ClientSessionFactory(sessionManagerAdapter, _database, _waitQueue, _clientReaper); Identity clientSessionMgrId = _communicator->stringToIdentity(_instanceName + "/SessionManager"); sessionManagerAdapter->add(new ClientSessionManagerI(_clientSessionFactory), clientSessionMgrId); @@ -545,7 +484,7 @@ RegistryI::setupAdminSessionFactory(const Ice::ObjectAdapterPtr& registryAdapter const Ice::LocatorPrx& locator, bool nowarn) { - _adminSessionFactory = new AdminSessionFactory(sessionManagerAdapter, _database, this); + _adminSessionFactory = new AdminSessionFactory(sessionManagerAdapter, _database, _clientReaper, this); Identity adminSessionMgrId = _communicator->stringToIdentity(_instanceName + "/AdminSessionManager"); sessionManagerAdapter->add(new AdminSessionManagerI(_adminSessionFactory), adminSessionMgrId); diff --git a/cpp/src/IceGrid/SessionI.cpp b/cpp/src/IceGrid/SessionI.cpp index d6e608f1049..5cb8d3b42f2 100644 --- a/cpp/src/IceGrid/SessionI.cpp +++ b/cpp/src/IceGrid/SessionI.cpp @@ -13,6 +13,7 @@ #include <IceGrid/QueryI.h> #include <IceGrid/LocatorI.h> #include <IceGrid/Database.h> +#include <IceGrid/Admin.h> #include <IceSSL/Plugin.h> @@ -154,6 +155,57 @@ BaseSessionI::setServantLocator(const SessionServantLocatorIPtr& servantLocator) const_cast<SessionServantLocatorIPtr&>(_servantLocator) = servantLocator; } +SessionReapable::SessionReapable(const Ice::ObjectAdapterPtr& adapter, + const Ice::ObjectPtr& session, + const Ice::Identity& id) : + _adapter(adapter), + _servant(session), + _session(dynamic_cast<BaseSessionI*>(_servant.get())), + _id(id) +{ +} + +SessionReapable::~SessionReapable() +{ +} + +IceUtil::Time +SessionReapable::timestamp() const +{ + return _session->timestamp(); +} + +void +SessionReapable::destroy(bool destroy) +{ + try + { + // + // Invoke on the servant directly instead of the + // proxy. Invoking on the proxy might not always work if the + // communicator is being shutdown/destroyed. We have to create + // a fake "current" because the session destroy methods needs + // the adapter and object identity to unregister the servant + // from the adapter. + // + Ice::Current current; + if(!destroy) + { + current.adapter = _adapter; + current.id = _id; + } + _session->destroy(current); + } + catch(const Ice::ObjectNotExistException&) + { + } + catch(const Ice::LocalException& ex) + { + Ice::Warning out(_adapter->getCommunicator()->getLogger()); + out << "unexpected exception while reaping node session:\n" << ex; + } +} + SessionI::SessionI(const string& id, const DatabasePtr& database, const WaitQueuePtr& waitQueue, @@ -282,10 +334,12 @@ SessionI::removeAllocation(const AllocatablePtr& allocatable) ClientSessionFactory::ClientSessionFactory(const Ice::ObjectAdapterPtr& adapter, const DatabasePtr& database, - const WaitQueuePtr& waitQueue) : + const WaitQueuePtr& waitQueue, + const ReapThreadPtr& reapThread) : _adapter(adapter), _database(database), - _waitQueue(waitQueue) + _waitQueue(waitQueue), + _reapThread(reapThread) { } @@ -320,6 +374,8 @@ ClientSessionFactory::createGlacier2Session(const string& sessionId, const Glaci } } + _reapThread->add(new SessionReapable(_adapter, session, s->ice_getIdentity()), ctl->getSessionTimeout()); + return s; } diff --git a/cpp/src/IceGrid/SessionI.h b/cpp/src/IceGrid/SessionI.h index 2b42c4e8a34..1519c93576f 100644 --- a/cpp/src/IceGrid/SessionI.h +++ b/cpp/src/IceGrid/SessionI.h @@ -11,6 +11,7 @@ #define ICEGRID_SESSIONI_H #include <IceUtil/Mutex.h> +#include <IceGrid/ReapThread.h> #include <IceGrid/Session.h> #include <IceGrid/SessionServantLocatorI.h> @@ -59,11 +60,30 @@ protected: bool _destroyed; IceUtil::Time _timestamp; }; +typedef IceUtil::Handle<BaseSessionI> BaseSessionIPtr; class SessionDestroyedException { }; +class SessionReapable : public Reapable +{ +public: + + SessionReapable(const Ice::ObjectAdapterPtr&, const Ice::ObjectPtr&, const Ice::Identity&); + virtual ~SessionReapable(); + + virtual IceUtil::Time timestamp() const; + virtual void destroy(bool); + +private: + + const Ice::ObjectAdapterPtr _adapter; + const Ice::ObjectPtr _servant; + BaseSessionI* _session; + const Ice::Identity _id; +}; + class SessionI : public BaseSessionI, public Session { public: @@ -106,7 +126,7 @@ class ClientSessionFactory : virtual public IceUtil::Shared { public: - ClientSessionFactory(const Ice::ObjectAdapterPtr&, const DatabasePtr&, const WaitQueuePtr&); + ClientSessionFactory(const Ice::ObjectAdapterPtr&, const DatabasePtr&, const WaitQueuePtr&, const ReapThreadPtr&); Glacier2::SessionPrx createGlacier2Session(const std::string&, const Glacier2::SessionControlPrx&); SessionIPtr createSessionServant(const std::string&, const Glacier2::SessionControlPrx&); @@ -118,6 +138,7 @@ private: const Ice::ObjectAdapterPtr _adapter; const DatabasePtr _database; const WaitQueuePtr _waitQueue; + const ReapThreadPtr _reapThread; }; typedef IceUtil::Handle<ClientSessionFactory> ClientSessionFactoryPtr; |