summaryrefslogtreecommitdiff
path: root/cpp/demo/IceGrid/allocate/Client.cpp
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2006-08-22 09:22:44 +0000
committerMatthew Newhook <matthew@zeroc.com>2006-08-22 09:22:44 +0000
commit3c972cf0e6d4d86250fc61dea9af1dbd4fd9fad7 (patch)
treecbd731a03c77a4b3018a652dd916039c4bcafb12 /cpp/demo/IceGrid/allocate/Client.cpp
parentadded more tracing. (diff)
downloadice-3c972cf0e6d4d86250fc61dea9af1dbd4fd9fad7.tar.bz2
ice-3c972cf0e6d4d86250fc61dea9af1dbd4fd9fad7.tar.xz
ice-3c972cf0e6d4d86250fc61dea9af1dbd4fd9fad7.zip
http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=1221
Diffstat (limited to 'cpp/demo/IceGrid/allocate/Client.cpp')
-rw-r--r--cpp/demo/IceGrid/allocate/Client.cpp125
1 files changed, 64 insertions, 61 deletions
diff --git a/cpp/demo/IceGrid/allocate/Client.cpp b/cpp/demo/IceGrid/allocate/Client.cpp
index 7551adde5f3..b4df84f00c9 100644
--- a/cpp/demo/IceGrid/allocate/Client.cpp
+++ b/cpp/demo/IceGrid/allocate/Client.cpp
@@ -109,6 +109,8 @@ 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)
@@ -146,80 +148,81 @@ HelloClient::run(int argc, char* argv[])
SessionKeepAliveThreadPtr keepAlive = new SessionKeepAliveThread(session, registry->getSessionTimeout() / 2);
keepAlive->start();
- //
- // First try to retrieve object by identity, which will work if the application-single.xml
- // descriptor is used. Otherwise we retrieve object by type, which will succeed if the
- // application-multiple.xml descriptor is used.
- //
- 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&)
- {
- }
- if(!hello)
- {
- try
- {
- hello = HelloPrx::checkedCast(session->allocateObjectByType("::Demo::Hello"));
- }
- catch(const IceGrid::AllocationException& ex)
- {
- cerr << argv[0] << ": could not allocate object: " << ex.reason << endl;
- return EXIT_FAILURE;
- }
- }
-
- menu();
-
- char c;
- do
- {
+ //
+ // First try to retrieve object by identity, which will work
+ // if the application-single.xml descriptor is used. Otherwise
+ // we retrieve object by type, which will succeed if the
+ // application-multiple.xml descriptor is used.
+ //
+ HelloPrx hello;
try
{
- cout << "==> ";
- cin >> c;
- if(c == 't')
- {
- hello->sayHello();
- }
- else if(c == 's')
- {
- hello->shutdown();
- }
- else if(c == 'x')
- {
- // Nothing to do
- }
- else if(c == '?')
+ hello = HelloPrx::checkedCast(session->allocateObjectById(communicator()->stringToIdentity("hello")));
+ }
+ catch(const IceGrid::ObjectNotRegisteredException&)
+ {
+ hello = HelloPrx::checkedCast(session->allocateObjectByType("::Demo::Hello"));
+ }
+
+ menu();
+
+ char c;
+ do
+ {
+ try
{
- menu();
+ cout << "==> ";
+ cin >> c;
+ if(c == 't')
+ {
+ hello->sayHello();
+ }
+ else if(c == 's')
+ {
+ hello->shutdown();
+ }
+ 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(...)
+ {
+ 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;
}