summaryrefslogtreecommitdiff
path: root/cpp/demo/IceGrid/allocate/Client.cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2014-05-23 11:59:44 +0200
committerBenoit Foucher <benoit@zeroc.com>2014-05-23 11:59:44 +0200
commitd81701ca8182942b7936f9fd84a019b695e9c890 (patch)
treedc036c9d701fbbe1afad67782bd78572c0f61974 /cpp/demo/IceGrid/allocate/Client.cpp
parentFixed bug ICE-5543: stringToIdentity bug with escaped escapes (diff)
downloadice-d81701ca8182942b7936f9fd84a019b695e9c890.tar.bz2
ice-d81701ca8182942b7936f9fd84a019b695e9c890.tar.xz
ice-d81701ca8182942b7936f9fd84a019b695e9c890.zip
Added support for invocation timeouts and ACM heartbeats
Diffstat (limited to 'cpp/demo/IceGrid/allocate/Client.cpp')
-rw-r--r--cpp/demo/IceGrid/allocate/Client.cpp65
1 files changed, 5 insertions, 60 deletions
diff --git a/cpp/demo/IceGrid/allocate/Client.cpp b/cpp/demo/IceGrid/allocate/Client.cpp
index daf73ac19d3..8e9c1a28462 100644
--- a/cpp/demo/IceGrid/allocate/Client.cpp
+++ b/cpp/demo/IceGrid/allocate/Client.cpp
@@ -15,56 +15,6 @@
using namespace std;
using namespace Demo;
-class SessionKeepAliveThread : public IceUtil::Thread, public IceUtil::Monitor<IceUtil::Mutex>
-{
-public:
-
- SessionKeepAliveThread(const IceGrid::SessionPrx& session, long timeout) :
- _session(session),
- _timeout(IceUtil::Time::seconds(timeout)),
- _destroy(false)
- {
- }
-
- virtual void
- run()
- {
- Lock sync(*this);
- while(!_destroy)
- {
- timedWait(_timeout);
- if(_destroy)
- {
- break;
- }
- try
- {
- _session->keepAlive();
- }
- catch(const Ice::Exception&)
- {
- break;
- }
- }
- }
-
- void
- destroy()
- {
- Lock sync(*this);
- _destroy = true;
- notify();
- }
-
-private:
-
- const IceGrid::SessionPrx _session;
- const IceUtil::Time _timeout;
- bool _destroy;
-};
-
-typedef IceUtil::Handle<SessionKeepAliveThread> SessionKeepAliveThreadPtr;
-
class HelloClient : public Ice::Application
{
public:
@@ -141,8 +91,11 @@ HelloClient::run(int argc, char* argv[])
}
}
- SessionKeepAliveThreadPtr keepAlive = new SessionKeepAliveThread(session, registry->getSessionTimeout() / 2);
- keepAlive->start();
+ //
+ // Enable heartbeats on the session connection to maintain the
+ // connection alive even if idle.
+ //
+ session->ice_getConnection()->setACM(registry->getACMTimeout(), IceUtil::None, Ice::HeartbeatAlways);
try
{
@@ -211,14 +164,6 @@ HelloClient::run(int argc, char* argv[])
status = EXIT_FAILURE;
}
- //
- // Destroy the keepAlive thread and the sesion object otherwise
- // the session will be kept allocated until the timeout occurs.
- // Destroying the session will release all allocated objects.
- //
- keepAlive->destroy();
- keepAlive->getThreadControl().join();
-
session->destroy();
return status;