summaryrefslogtreecommitdiff
path: root/cpp/demo/Ice
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2006-12-22 18:52:53 +0000
committerMatthew Newhook <matthew@zeroc.com>2006-12-22 18:52:53 +0000
commit84d9f5c369fceccfa16401ed50783ed2ad209559 (patch)
tree689d30c8707629f1db8155edadb47ce1bce363ad /cpp/demo/Ice
parentAdded autoflushing of batches (diff)
downloadice-84d9f5c369fceccfa16401ed50783ed2ad209559.tar.bz2
ice-84d9f5c369fceccfa16401ed50783ed2ad209559.tar.xz
ice-84d9f5c369fceccfa16401ed50783ed2ad209559.zip
http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=1391.
Diffstat (limited to 'cpp/demo/Ice')
-rw-r--r--cpp/demo/Ice/callback/Client.cpp25
-rw-r--r--cpp/demo/Ice/converter/Client.cpp5
-rw-r--r--cpp/demo/Ice/hello/Client.cpp25
-rw-r--r--cpp/demo/Ice/invoke/Client.cpp25
-rw-r--r--cpp/demo/Ice/nested/Client.cpp32
-rwxr-xr-xcpp/demo/Ice/session/Client.cpp96
-rw-r--r--cpp/demo/Ice/throughput/Client.cpp25
-rw-r--r--cpp/demo/Ice/value/Client.cpp25
8 files changed, 236 insertions, 22 deletions
diff --git a/cpp/demo/Ice/callback/Client.cpp b/cpp/demo/Ice/callback/Client.cpp
index 8a6b237b415..0f40c0371a1 100644
--- a/cpp/demo/Ice/callback/Client.cpp
+++ b/cpp/demo/Ice/callback/Client.cpp
@@ -28,6 +28,7 @@ class CallbackClient : public Ice::Application
public:
virtual int run(int, char*[]);
+ virtual void interruptCallback(int);
private:
@@ -44,6 +45,12 @@ main(int argc, char* argv[])
int
CallbackClient::run(int argc, char* argv[])
{
+ //
+ // Since this is an interactive demo we want the custom interrupt
+ // callback to be called when the process is interrupted.
+ //
+ userCallbackOnInterrupt();
+
CallbackSenderPrx twoway = CallbackSenderPrx::checkedCast(
communicator()->propertyToProxy("Callback.Client.CallbackServer")->
ice_twoway()->ice_timeout(-1)->ice_secure(false));
@@ -169,6 +176,24 @@ CallbackClient::run(int argc, char* argv[])
}
void
+CallbackClient::interruptCallback(int)
+{
+ try
+ {
+ communicator()->destroy();
+ }
+ catch(const IceUtil::Exception& ex)
+ {
+ cerr << appName() << ": " << ex << endl;
+ }
+ catch(...)
+ {
+ cerr << appName() << ": unknown exception" << endl;
+ }
+ exit(EXIT_SUCCESS);
+}
+
+void
CallbackClient::menu()
{
cout <<
diff --git a/cpp/demo/Ice/converter/Client.cpp b/cpp/demo/Ice/converter/Client.cpp
index 8864838bf69..e833dbc3b48 100644
--- a/cpp/demo/Ice/converter/Client.cpp
+++ b/cpp/demo/Ice/converter/Client.cpp
@@ -113,7 +113,10 @@ main(int argc, char* argv[])
initData.properties->load("config.client");
communicator1 = Ice::initialize(argc, argv, initData);
- communicator2 = Ice::initialize(argc, argv);
+ Ice::InitializationData initData2;
+ initData2.properties = Ice::createProperties();
+ initData2.properties->load("config.client");
+ communicator2 = Ice::initialize(argc, argv, initData2);
status = run(argc, argv, communicator1, communicator2);
}
diff --git a/cpp/demo/Ice/hello/Client.cpp b/cpp/demo/Ice/hello/Client.cpp
index 3aca8c3d934..f2de173ada6 100644
--- a/cpp/demo/Ice/hello/Client.cpp
+++ b/cpp/demo/Ice/hello/Client.cpp
@@ -18,6 +18,7 @@ class HelloClient : public Ice::Application
public:
virtual int run(int, char*[]);
+ virtual void interruptCallback(int);
private:
@@ -34,6 +35,12 @@ main(int argc, char* argv[])
int
HelloClient::run(int argc, char* argv[])
{
+ //
+ // Since this is an interactive demo we want the custom interrupt
+ // callback to be called when the process is interrupted.
+ //
+ userCallbackOnInterrupt();
+
HelloPrx twoway = HelloPrx::checkedCast(
communicator()->propertyToProxy("Hello.Proxy")->ice_twoway()->ice_timeout(-1)->ice_secure(false));
if(!twoway)
@@ -189,6 +196,24 @@ HelloClient::run(int argc, char* argv[])
}
void
+HelloClient::interruptCallback(int)
+{
+ try
+ {
+ communicator()->destroy();
+ }
+ catch(const IceUtil::Exception& ex)
+ {
+ cerr << appName() << ": " << ex << endl;
+ }
+ catch(...)
+ {
+ cerr << appName() << ": unknown exception" << endl;
+ }
+ exit(EXIT_SUCCESS);
+}
+
+void
HelloClient::menu()
{
cout <<
diff --git a/cpp/demo/Ice/invoke/Client.cpp b/cpp/demo/Ice/invoke/Client.cpp
index 3a687a5e29f..0bfe715f5d1 100644
--- a/cpp/demo/Ice/invoke/Client.cpp
+++ b/cpp/demo/Ice/invoke/Client.cpp
@@ -18,6 +18,7 @@ class InvokeClient : public Ice::Application
public:
virtual int run(int, char*[]);
+ virtual void interruptCallback(int);
private:
@@ -52,6 +53,12 @@ operator<<(ostream& out, Demo::Color c)
int
InvokeClient::run(int argc, char* argv[])
{
+ //
+ // Since this is an interactive demo we want the custom interrupt
+ // callback to be called when the process is interrupted.
+ //
+ userCallbackOnInterrupt();
+
Ice::ObjectPrx obj = communicator()->propertyToProxy("Printer.Proxy");
menu();
@@ -293,6 +300,24 @@ InvokeClient::run(int argc, char* argv[])
}
void
+InvokeClient::interruptCallback(int)
+{
+ try
+ {
+ communicator()->destroy();
+ }
+ catch(const IceUtil::Exception& ex)
+ {
+ cerr << appName() << ": " << ex << endl;
+ }
+ catch(...)
+ {
+ cerr << appName() << ": unknown exception" << endl;
+ }
+ exit(EXIT_SUCCESS);
+}
+
+void
InvokeClient::menu()
{
cout <<
diff --git a/cpp/demo/Ice/nested/Client.cpp b/cpp/demo/Ice/nested/Client.cpp
index 53d9ae26547..bc10109a1fe 100644
--- a/cpp/demo/Ice/nested/Client.cpp
+++ b/cpp/demo/Ice/nested/Client.cpp
@@ -13,11 +13,13 @@
using namespace std;
using namespace Demo;
+
class NestedClient : public Ice::Application
{
public:
virtual int run(int, char*[]);
+ virtual void interruptCallback(int);
};
int
@@ -30,6 +32,12 @@ main(int argc, char* argv[])
int
NestedClient::run(int argc, char* argv[])
{
+ //
+ // Since this is an interactive demo we want the custom interrupt
+ // callback to be called when the process is interrupted.
+ //
+ userCallbackOnInterrupt();
+
NestedPrx nested = NestedPrx::checkedCast(communicator()->propertyToProxy("Nested.Client.NestedServer"));
if(!nested)
{
@@ -70,3 +78,27 @@ NestedClient::run(int argc, char* argv[])
return EXIT_SUCCESS;
}
+
+void
+NestedClient::interruptCallback(int)
+{
+/*
+ * For this demo we won't destroy the communicator since it has to
+ * wait for any outstanding invocations to complete which may take
+ * some time if the nesting level is exceeded.
+ *
+ try
+ {
+ communicator()->destroy();
+ }
+ catch(const IceUtil::Exception& ex)
+ {
+ cerr << appName() << ": " << ex << endl;
+ }
+ catch(...)
+ {
+ cerr << appName() << ": unknown exception" << endl;
+ }
+*/
+ exit(EXIT_SUCCESS);
+}
diff --git a/cpp/demo/Ice/session/Client.cpp b/cpp/demo/Ice/session/Client.cpp
index fc78b4dee0c..e0be25f7d61 100755
--- a/cpp/demo/Ice/session/Client.cpp
+++ b/cpp/demo/Ice/session/Client.cpp
@@ -72,10 +72,20 @@ class SessionClient : public Ice::Application
public:
virtual int run(int, char*[]);
+ virtual void interruptCallback(int);
private:
void menu();
+ void cleanup(bool);
+
+ //
+ // The interrupt callback and main can run concurrently with one
+ // another so shared variables must be mutex protected.
+ //
+ IceUtil::Mutex _mutex;
+ SessionRefreshThreadPtr _refresh;
+ SessionPrx _session;
};
int
@@ -88,6 +98,12 @@ main(int argc, char* argv[])
int
SessionClient::run(int argc, char* argv[])
{
+ //
+ // Since this is an interactive demo we want the custom interrupt
+ // callback to be called when the process is interrupted.
+ //
+ userCallbackOnInterrupt();
+
string name;
cout << "Please enter your name ==> ";
cin >> name;
@@ -104,11 +120,14 @@ SessionClient::run(int argc, char* argv[])
return EXIT_FAILURE;
}
- SessionPrx session = factory->create(name);
-
- SessionRefreshThreadPtr refresh = new SessionRefreshThread(
- communicator()->getLogger(), IceUtil::Time::seconds(5), session);
- refresh->start();
+ {
+ IceUtil::Mutex::Lock sync(_mutex);
+ _session = factory->create(name);
+
+ _refresh = new SessionRefreshThread(
+ communicator()->getLogger(), IceUtil::Time::seconds(5), _session);
+ _refresh->start();
+ }
vector<HelloPrx> hellos;
@@ -144,7 +163,7 @@ SessionClient::run(int argc, char* argv[])
}
else if(c == 'c')
{
- hellos.push_back(session->createHello());
+ hellos.push_back(_session->createHello());
cout << "Created hello object " << hellos.size() - 1 << endl;
}
else if(c == 's')
@@ -179,14 +198,7 @@ SessionClient::run(int argc, char* argv[])
// is set to 0 so that if session->destroy() raises an exception
// the thread will not be re-terminated and re-joined.
//
- refresh->terminate();
- refresh->getThreadControl().join();
- refresh = 0;
-
- if(destroy)
- {
- session->destroy();
- }
+ cleanup(destroy);
if(shutdown)
{
factory->shutdown();
@@ -194,14 +206,12 @@ SessionClient::run(int argc, char* argv[])
}
catch(...)
{
- //
- // The refresher thread must be terminated in the event of a
- // failure.
- //
- if(refresh)
+ try
+ {
+ cleanup(true);
+ }
+ catch(...)
{
- refresh->terminate();
- refresh->getThreadControl().join();
}
throw;
}
@@ -210,6 +220,50 @@ SessionClient::run(int argc, char* argv[])
}
void
+SessionClient::interruptCallback(int)
+{
+ //
+ // Terminate the refresh thread, destroy the session and then
+ // destroy the communicator, followed by an exit. We have to call
+ // exit because main may be blocked in a cin >> s call which
+ // cannot be interrupted portably.
+ //
+ cleanup(true);
+
+ try
+ {
+ communicator()->destroy();
+ }
+ catch(const IceUtil::Exception& ex)
+ {
+ cerr << appName() << ": " << ex << endl;
+ }
+ catch(...)
+ {
+ cerr << appName() << ": unknown exception" << endl;
+ }
+ exit(EXIT_SUCCESS);
+}
+
+void
+SessionClient::cleanup(bool destroy)
+{
+ IceUtil::Mutex::Lock sync(_mutex);
+ if(_refresh)
+ {
+ _refresh->terminate();
+ _refresh->getThreadControl().join();
+ _refresh = 0;
+ }
+
+ if(destroy && _session)
+ {
+ _session->destroy();
+ _session = 0;
+ }
+}
+
+void
SessionClient::menu()
{
cout <<
diff --git a/cpp/demo/Ice/throughput/Client.cpp b/cpp/demo/Ice/throughput/Client.cpp
index 03bfd13aeec..a2c00c008a3 100644
--- a/cpp/demo/Ice/throughput/Client.cpp
+++ b/cpp/demo/Ice/throughput/Client.cpp
@@ -20,6 +20,7 @@ class ThroughputClient : public Ice::Application
public:
virtual int run(int, char*[]);
+ virtual void interruptCallback(int);
private:
@@ -36,6 +37,12 @@ main(int argc, char* argv[])
int
ThroughputClient::run(int argc, char* argv[])
{
+ //
+ // Since this is an interactive demo we want the custom interrupt
+ // callback to be called when the process is interrupted.
+ //
+ userCallbackOnInterrupt();
+
Ice::ObjectPrx base = communicator()->propertyToProxy("Throughput.Throughput");
ThroughputPrx throughput = ThroughputPrx::checkedCast(base);
if(!throughput)
@@ -378,6 +385,24 @@ ThroughputClient::run(int argc, char* argv[])
}
void
+ThroughputClient::interruptCallback(int)
+{
+ try
+ {
+ communicator()->destroy();
+ }
+ catch(const IceUtil::Exception& ex)
+ {
+ cerr << appName() << ": " << ex << endl;
+ }
+ catch(...)
+ {
+ cerr << appName() << ": unknown exception" << endl;
+ }
+ exit(EXIT_SUCCESS);
+}
+
+void
ThroughputClient::menu()
{
cout <<
diff --git a/cpp/demo/Ice/value/Client.cpp b/cpp/demo/Ice/value/Client.cpp
index a375da519de..de4885f7f79 100644
--- a/cpp/demo/Ice/value/Client.cpp
+++ b/cpp/demo/Ice/value/Client.cpp
@@ -19,6 +19,7 @@ class ValueClient : public Ice::Application
public:
virtual int run(int, char*[]);
+ virtual void interruptCallback(int);
};
int
@@ -31,6 +32,12 @@ main(int argc, char* argv[])
int
ValueClient::run(int argc, char* argv[])
{
+ //
+ // Since this is an interactive demo we want the custom interrupt
+ // callback to be called when the process is interrupted.
+ //
+ userCallbackOnInterrupt();
+
Ice::ObjectPrx base = communicator()->propertyToProxy("Value.Initial");
InitialPrx initial = InitialPrx::checkedCast(base);
if(!initial)
@@ -174,3 +181,21 @@ ValueClient::run(int argc, char* argv[])
return EXIT_SUCCESS;
}
+
+void
+ValueClient::interruptCallback(int)
+{
+ try
+ {
+ communicator()->destroy();
+ }
+ catch(const IceUtil::Exception& ex)
+ {
+ cerr << appName() << ": " << ex << endl;
+ }
+ catch(...)
+ {
+ cerr << appName() << ": unknown exception" << endl;
+ }
+ exit(EXIT_SUCCESS);
+}