summaryrefslogtreecommitdiff
path: root/cpp/demo/IceGrid/sessionActivation/Client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/demo/IceGrid/sessionActivation/Client.cpp')
-rw-r--r--cpp/demo/IceGrid/sessionActivation/Client.cpp95
1 files changed, 54 insertions, 41 deletions
diff --git a/cpp/demo/IceGrid/sessionActivation/Client.cpp b/cpp/demo/IceGrid/sessionActivation/Client.cpp
index 07fb4c85d58..d8fc48e65dc 100644
--- a/cpp/demo/IceGrid/sessionActivation/Client.cpp
+++ b/cpp/demo/IceGrid/sessionActivation/Client.cpp
@@ -108,6 +108,7 @@ HelloClient::trim(const string& s)
int
HelloClient::run(int argc, char* argv[])
{
+ int status = EXIT_SUCCESS;
IceGrid::RegistryPrx registry =
IceGrid::RegistryPrx::checkedCast(communicator()->stringToProxy("DemoIceGrid/Registry"));
if(!registry)
@@ -145,62 +146,74 @@ HelloClient::run(int argc, char* argv[])
SessionKeepAliveThreadPtr keepAlive = new SessionKeepAliveThread(session, registry->getSessionTimeout() / 2);
keepAlive->start();
- HelloPrx hello;
try
{
- hello = HelloPrx::checkedCast(session->allocateObjectById(communicator()->stringToIdentity("hello")));
- }
- catch(const IceGrid::AllocationException& ex)
- {
- cerr << argv[0] << ": could not allocate object: " << ex.reason << endl;
- return EXIT_FAILURE;
- }
- catch(const IceGrid::ObjectNotRegisteredException&)
- {
- cerr << argv[0] << ": object not registered with registry" << endl;
- return EXIT_FAILURE;
- }
+ HelloPrx hello = HelloPrx::checkedCast(session->allocateObjectById(communicator()->stringToIdentity("hello")));
- menu();
+ menu();
- char c;
- do
- {
- try
+ char c;
+ do
{
- cout << "==> ";
- cin >> c;
- if(c == 't')
- {
- hello->sayHello();
- }
- else if(c == 'x')
- {
- // Nothing to do
- }
- else if(c == '?')
+ try
{
- menu();
+ cout << "==> ";
+ cin >> c;
+ if(c == 't')
+ {
+ hello->sayHello();
+ }
+ else if(c == 'x')
+ {
+ // Nothing to do
+ }
+ else if(c == '?')
+ {
+ menu();
+ }
+ else
+ {
+ cout << "unknown command `" << c << "'" << endl;
+ menu();
+ }
}
- else
+ catch(const Ice::Exception& ex)
{
- cout << "unknown command `" << c << "'" << endl;
- menu();
+ cerr << ex << endl;
}
}
- catch(const Ice::Exception& ex)
- {
- cerr << ex << endl;
- }
+ while(cin.good() && c != 'x');
+ }
+ catch(const IceGrid::AllocationException& ex)
+ {
+ cerr << argv[0] << ": could not allocate object: " << ex.reason << endl;
+ status = EXIT_FAILURE;
+ }
+ catch(const IceGrid::ObjectNotRegisteredException&)
+ {
+ cerr << argv[0] << ": object not registered with registry" << endl;
+ status = EXIT_FAILURE;
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ status = EXIT_FAILURE;
+ }
+ catch(...)
+ {
+ cerr << "unexpected exception" << endl;
+ status = EXIT_FAILURE;
}
- while(cin.good() && c != 'x');
+ //
+ // 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->releaseObject(hello->ice_getIdentity());
session->destroy();
- return EXIT_SUCCESS;
+ return status;
}