diff options
author | Matthew Newhook <matthew@zeroc.com> | 2005-04-19 00:24:08 +0000 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2005-04-19 00:24:08 +0000 |
commit | 985f18404d3b00ef445ea44619fad548da549ff0 (patch) | |
tree | 383f58b121b52227cd05cfb0851205656acc5443 /cpp/demo/Ice/session/SessionFactoryI.cpp | |
parent | fix for bug 243: python demos lack mutex protection (diff) | |
download | ice-985f18404d3b00ef445ea44619fad548da549ff0.tar.bz2 ice-985f18404d3b00ef445ea44619fad548da549ff0.tar.xz ice-985f18404d3b00ef445ea44619fad548da549ff0.zip |
addressed comments added by Marc.
Diffstat (limited to 'cpp/demo/Ice/session/SessionFactoryI.cpp')
-rwxr-xr-x | cpp/demo/Ice/session/SessionFactoryI.cpp | 103 |
1 files changed, 5 insertions, 98 deletions
diff --git a/cpp/demo/Ice/session/SessionFactoryI.cpp b/cpp/demo/Ice/session/SessionFactoryI.cpp index 13bd2f94c5d..72fe47e5af1 100755 --- a/cpp/demo/Ice/session/SessionFactoryI.cpp +++ b/cpp/demo/Ice/session/SessionFactoryI.cpp @@ -13,55 +13,13 @@ using namespace std; using namespace Demo; -// XXX Why does the reaper thread have to know the factory? -ReapThread::ReapThread(const SessionFactoryIPtr& factory, const IceUtil::Time& timeout) : - _terminated(false), - _timeout(timeout), - _factory(factory) +SessionFactoryI::SessionFactoryI(const ReapThreadPtr& reapThread) : + _reapThread(reapThread) { } -ReapThread::~ReapThread() -{ - cout << "~ReapThread" << endl; -} - -void -ReapThread::run() -{ - Lock sync(*this); - while(!_terminated) - { - timedWait(_timeout); - if(!_terminated) - { - assert(_factory); - _factory->reap(); - } - } -} - -void -ReapThread::terminate() -{ - Lock sync(*this); - _terminated = true; - notify(); - // Drop the cyclic reference count. - _factory = 0; -} - -SessionFactoryI::SessionFactoryI(const Ice::ObjectAdapterPtr& adapter) : - _adapter(adapter), - _timeout(IceUtil::Time::seconds(10)), - _reapThread(new ReapThread(this, _timeout)) -{ - _reapThread->start(); -} - SessionFactoryI::~SessionFactoryI() { - cout << "~SessionFactoryI" << endl; } SessionPrx @@ -69,9 +27,9 @@ SessionFactoryI::create(const Ice::Current& c) { Lock sync(*this); - SessionIPtr session = new SessionI(_adapter, _timeout); - SessionPrx proxy = SessionPrx::uncheckedCast(_adapter->addWithUUID(session)); - _sessions.push_back(SessionId(session, proxy->ice_getIdentity())); + SessionIPtr session = new SessionI; + SessionPrx proxy = SessionPrx::uncheckedCast(c.adapter->addWithUUID(session)); + _reapThread->add(proxy, session); return proxy; } @@ -81,54 +39,3 @@ SessionFactoryI::shutdown(const ::Ice::Current& c) cout << "Shutting down..." << endl; c.adapter->getCommunicator()->shutdown(); } - -void -SessionFactoryI::reap() -{ - Lock sync(*this); - - list<SessionId>::iterator p = _sessions.begin(); - while(p != _sessions.end()) - { - if(p->session->destroyed()) - { - p->session->destroyCallback(); - try - { - _adapter->remove(p->id); - } - catch(const Ice::ObjectAdapterDeactivatedException&) - { - // This method can be called while the server is - // shutting down, in which case this exception is - // expected. - } - p = _sessions.erase(p); - } - else - { - ++p; - } - } -} - -void -SessionFactoryI::destroy() -{ - Lock sync(*this); - - // XXX When _reapThread is out of this class, simply place this code after the waitForShutdown(). - _reapThread->terminate(); - _reapThread->getThreadControl().join(); - _reapThread = 0; - - for(list<SessionId>::const_iterator p = _sessions.begin(); p != _sessions.end(); ++p) - { - p->session->destroyCallback(); - - // When the session factory is destroyed the OA is deactivated - // and all servants have been removed so calling remove on the - // OA is not necessary. - } - _sessions.clear(); -} |