From d25c2d8f8156b33c78b797cd4aa4823d3ade02cc Mon Sep 17 00:00:00 2001 From: Matthew Newhook Date: Wed, 9 Sep 2009 15:46:16 -0230 Subject: - 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 Date: Wed Sep 9 15:35:47 2009 -0230 Simplify session demo. commit 07cf68b9d12e8d648980d4bcae354e7531411b47 Author: Matthew Newhook Date: Wed Sep 9 14:59:15 2009 -0230 chat demo now uses a custom perissions verifier, and a timer task. --- cpp/demo/Ice/session/Client.cpp | 59 ++++++++++++----------------------------- 1 file changed, 17 insertions(+), 42 deletions(-) (limited to 'cpp/demo/Ice/session/Client.cpp') 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 +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 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 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) -- cgit v1.2.3