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/Glacier2/chat/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/Glacier2/chat/Client.cpp')
-rw-r--r-- | cpp/demo/Glacier2/chat/Client.cpp | 66 |
1 files changed, 24 insertions, 42 deletions
diff --git a/cpp/demo/Glacier2/chat/Client.cpp b/cpp/demo/Glacier2/chat/Client.cpp index 48376244329..7b4b375303d 100644 --- a/cpp/demo/Glacier2/chat/Client.cpp +++ b/cpp/demo/Glacier2/chat/Client.cpp @@ -15,54 +15,31 @@ using namespace std; using namespace Demo; -class SessionPingThread : public IceUtil::Thread, public IceUtil::Monitor<IceUtil::Mutex> +class PingTask : public IceUtil::TimerTask { public: - SessionPingThread(const Glacier2::SessionPrx& session, long timeout) : - _session(session), - _timeout(IceUtil::Time::seconds(timeout)), - _destroy(false) + PingTask(const Glacier2::SessionPrx& session) : + _session(session) { } - virtual void - run() + virtual void runTimerTask() { - Lock sync(*this); - while(!_destroy) + try { - timedWait(_timeout); - if(_destroy) - { - break; - } - try - { - _session->ice_ping(); - } - catch(const Ice::Exception&) - { - break; - } + _session->ice_ping(); + } + catch(const Ice::Exception&) + { + // Ignore } - } - - void - destroy() - { - Lock sync(*this); - _destroy = true; - notify(); } private: const Glacier2::SessionPrx _session; - const IceUtil::Time _timeout; - bool _destroy; }; -typedef IceUtil::Handle<SessionPingThread> SessionPingThreadPtr; class ChatCallbackI : public ChatCallback { @@ -152,8 +129,9 @@ public: } } - _ping = new SessionPingThread(session, (long)_router->getSessionTimeout() / 2); - _ping->start(); + _timer = new IceUtil::Timer(); + _timer->scheduleRepeated(new PingTask(session), IceUtil::Time::milliSeconds( + _router->getSessionTimeout() * 500)); Ice::Identity callbackReceiverIdent; callbackReceiverIdent.name = "callbackReceiver"; @@ -212,6 +190,16 @@ private: void cleanup() { + // + // Destroy the timer before the router session is destroyed, + // otherwise it might get a spurious ObjectNotExistException. + // + if(_timer) + { + _timer->destroy(); + _timer = 0; + } + if(_router) { try @@ -226,12 +214,6 @@ private: } _router = 0; } - if(_ping) - { - _ping->destroy(); - _ping->getThreadControl().join(); - _ping = 0; - } } void @@ -253,7 +235,7 @@ private: } Glacier2::RouterPrx _router; - SessionPingThreadPtr _ping; + IceUtil::TimerPtr _timer; }; int |