diff options
author | Matthew Newhook <matthew@zeroc.com> | 2009-09-09 15:46:16 -0230 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2009-09-09 15:46:16 -0230 |
commit | d25c2d8f8156b33c78b797cd4aa4823d3ade02cc (patch) | |
tree | 65b79d47f8a470ee9d6218687a124444234c0cbf /cpp/demo/Ice/session/Client.cpp | |
parent | Removed bogus file. (diff) | |
download | ice-d25c2d8f8156b33c78b797cd4aa4823d3ade02cc.tar.bz2 ice-d25c2d8f8156b33c78b797cd4aa4823d3ade02cc.tar.xz ice-d25c2d8f8156b33c78b797cd4aa4823d3ade02cc.zip |
- cpp/demo/Ice/session now uses a timer for the periodic reaping.
- cpp/demo/Glacier2/chat now uses a custom permissions verifier,
and a timer for refresh of the Glacier2 session. Squashed commit
of the following:
commit 82732512d64b4b6782b9c96e9c558ad56ea232af
Author: Matthew Newhook <matthew@zeroc.com>
Date: Wed Sep 9 15:35:47 2009 -0230
Simplify session demo.
commit 07cf68b9d12e8d648980d4bcae354e7531411b47
Author: Matthew Newhook <matthew@zeroc.com>
Date: Wed Sep 9 14:59:15 2009 -0230
chat demo now uses a custom perissions verifier, and a timer task.
Diffstat (limited to 'cpp/demo/Ice/session/Client.cpp')
-rw-r--r-- | cpp/demo/Ice/session/Client.cpp | 59 |
1 files changed, 17 insertions, 42 deletions
diff --git a/cpp/demo/Ice/session/Client.cpp b/cpp/demo/Ice/session/Client.cpp index 380ad9f40e3..e10b7602173 100644 --- a/cpp/demo/Ice/session/Client.cpp +++ b/cpp/demo/Ice/session/Client.cpp @@ -20,59 +20,36 @@ const DWORD SIGHUP = CTRL_LOGOFF_EVENT; using namespace std; using namespace Demo; -class SessionRefreshThread : public IceUtil::Thread, public IceUtil::Monitor<IceUtil::Mutex> +class RefreshTask : public IceUtil::TimerTask { public: - SessionRefreshThread(const Ice::LoggerPtr& logger, const IceUtil::Time& timeout, const SessionPrx& session) : + RefreshTask(const Ice::LoggerPtr& logger, const SessionPrx& session) : _logger(logger), - _session(session), - _timeout(timeout), - _terminated(false) + _session(session) { } virtual void - run() + runTimerTask() { - Lock sync(*this); - while(!_terminated) + try { - timedWait(_timeout); - if(!_terminated) - { - try - { - _session->refresh(); - } - catch(const Ice::Exception& ex) - { - Ice::Warning warn(_logger); - warn << "SessionRefreshThread: " << ex; - _terminated = true; - } - } + _session->refresh(); + } + catch(const Ice::Exception& ex) + { + Ice::Warning warn(_logger); + warn << "RefreshTask: " << ex; } - } - - void - terminate() - { - Lock sync(*this); - _terminated = true; - notify(); } private: const Ice::LoggerPtr _logger; const SessionPrx _session; - const IceUtil::Time _timeout; - bool _terminated; }; -typedef IceUtil::Handle<SessionRefreshThread> SessionRefreshThreadPtr; - class SessionClient : public Ice::Application { public: @@ -90,7 +67,7 @@ private: // another so shared variables must be mutex protected. // IceUtil::Mutex _mutex; - SessionRefreshThreadPtr _refresh; + IceUtil::TimerPtr _timer; SessionPrx _session; }; @@ -139,9 +116,8 @@ SessionClient::run(int argc, char* argv[]) IceUtil::Mutex::Lock sync(_mutex); _session = factory->create(name); - _refresh = new SessionRefreshThread( - communicator()->getLogger(), IceUtil::Time::seconds(5), _session); - _refresh->start(); + _timer = new IceUtil::Timer(); + _timer->scheduleRepeated(new RefreshTask(communicator()->getLogger(), _session), IceUtil::Time::seconds(5)); } vector<HelloPrx> hellos; @@ -239,11 +215,10 @@ SessionClient::cleanup(bool destroy) // is set to 0 so that if session->destroy() raises an exception // the thread will not be re-terminated and re-joined. // - if(_refresh) + if(_timer) { - _refresh->terminate(); - _refresh->getThreadControl().join(); - _refresh = 0; + _timer->destroy(); + _timer = 0; } if(destroy && _session) |