diff options
115 files changed, 2834 insertions, 2691 deletions
diff --git a/cpp/demo/Ice/bidir/CallbackI.h b/cpp/demo/Ice/bidir/CallbackI.h index 0990b911f04..7d32a84f64a 100644 --- a/cpp/demo/Ice/bidir/CallbackI.h +++ b/cpp/demo/Ice/bidir/CallbackI.h @@ -59,11 +59,10 @@ private: private: - CallbackSenderIPtr _callbackSender; + const CallbackSenderIPtr _callbackSender; }; IceUtil::ThreadPtr _callbackSenderThread; - }; #endif diff --git a/cpp/demo/Ice/callback/Client.cpp b/cpp/demo/Ice/callback/Client.cpp index 28f6e401acd..b0bff93ca3a 100644 --- a/cpp/demo/Ice/callback/Client.cpp +++ b/cpp/demo/Ice/callback/Client.cpp @@ -53,8 +53,8 @@ CallbackClient::run(int argc, char* argv[]) return EXIT_FAILURE; } - Ice::ObjectPrx base = communicator()->stringToProxy(proxy); - CallbackSenderPrx twoway = CallbackSenderPrx::checkedCast(base->ice_twoway()->ice_timeout(-1)->ice_secure(false)); + CallbackSenderPrx twoway = CallbackSenderPrx::checkedCast( + communicator()->stringToProxy(proxy)->ice_twoway()->ice_timeout(-1)->ice_secure(false)); if(!twoway) { cerr << appName() << ": invalid proxy" << endl; diff --git a/cpp/demo/Ice/hello/Client.cpp b/cpp/demo/Ice/hello/Client.cpp index 7fbb8d0053d..e6246f75c0c 100644 --- a/cpp/demo/Ice/hello/Client.cpp +++ b/cpp/demo/Ice/hello/Client.cpp @@ -43,8 +43,8 @@ HelloClient::run(int argc, char* argv[]) return EXIT_FAILURE; } - Ice::ObjectPrx base = communicator()->stringToProxy(proxy); - HelloPrx twoway = HelloPrx::checkedCast(base->ice_twoway()->ice_timeout(-1)->ice_secure(false)); + HelloPrx twoway = HelloPrx::checkedCast( + communicator()->stringToProxy(proxy)->ice_twoway()->ice_timeout(-1)->ice_secure(false)); if(!twoway) { cerr << argv[0] << ": invalid proxy" << endl; diff --git a/cpp/demo/Ice/nested/Client.cpp b/cpp/demo/Ice/nested/Client.cpp index 38f419b9e6e..29c78d31e35 100644 --- a/cpp/demo/Ice/nested/Client.cpp +++ b/cpp/demo/Ice/nested/Client.cpp @@ -39,8 +39,7 @@ NestedClient::run(int argc, char* argv[]) return EXIT_FAILURE; } - Ice::ObjectPrx base = communicator()->stringToProxy(proxy); - NestedPrx nested = NestedPrx::checkedCast(base); + NestedPrx nested = NestedPrx::checkedCast(communicator()->stringToProxy(proxy)); if(!nested) { cerr << appName() << ": invalid proxy" << endl; diff --git a/cpp/demo/IceBox/hello/Client.cpp b/cpp/demo/IceBox/hello/Client.cpp index 8366704983f..4017a29e8c5 100644 --- a/cpp/demo/IceBox/hello/Client.cpp +++ b/cpp/demo/IceBox/hello/Client.cpp @@ -60,8 +60,8 @@ HelloClient::run(int argc, char* argv[]) return EXIT_FAILURE; } - Ice::ObjectPrx base = communicator()->stringToProxy(proxy); - HelloPrx twoway = HelloPrx::checkedCast(base->ice_twoway()->ice_timeout(-1)->ice_secure(false)); + HelloPrx twoway = HelloPrx::checkedCast( + communicator()->stringToProxy(proxy)->ice_twoway()->ice_timeout(-1)->ice_secure(false)); if(!twoway) { cerr << argv[0] << ": invalid proxy" << endl; diff --git a/cpp/demo/IcePack/simple/Client.cpp b/cpp/demo/IcePack/simple/Client.cpp index 44619a15a41..7853d89541b 100644 --- a/cpp/demo/IcePack/simple/Client.cpp +++ b/cpp/demo/IcePack/simple/Client.cpp @@ -14,8 +14,26 @@ using namespace std; using namespace Demo; +class HelloClient : public Ice::Application +{ +public: + + virtual int run(int, char*[]); + +private: + + void menu(); +}; + +int +main(int argc, char* argv[]) +{ + HelloClient app; + return app.main(argc, argv, "config"); +} + void -menu() +HelloClient::menu() { cout << "usage:\n" @@ -33,11 +51,11 @@ menu() } int -run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) +HelloClient::run(int argc, char* argv[]) { - Ice::PropertiesPtr properties = communicator->getProperties(); + Ice::PropertiesPtr properties = communicator()->getProperties(); - IcePack::QueryPrx query = IcePack::QueryPrx::checkedCast(communicator->stringToProxy("IcePack/Query")); + IcePack::QueryPrx query = IcePack::QueryPrx::checkedCast(communicator()->stringToProxy("IcePack/Query")); Ice::ObjectPrx base = query->findObjectByType("::Demo::Hello"); HelloPrx twoway = HelloPrx::checkedCast(base->ice_twoway()->ice_timeout(-1)->ice_secure(false)); @@ -99,7 +117,7 @@ run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) } else if(c == 'f') { - communicator->flushBatchRequests(); + communicator()->flushBatchRequests(); } else if(c == 'T') { @@ -172,37 +190,3 @@ run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) return EXIT_SUCCESS; } -int -main(int argc, char* argv[]) -{ - int status; - Ice::CommunicatorPtr communicator; - - try - { - Ice::PropertiesPtr properties = Ice::createProperties(); - properties->load("config"); - communicator = Ice::initializeWithProperties(argc, argv, properties); - status = run(argc, argv, communicator); - } - catch(const Ice::Exception& ex) - { - cerr << ex << endl; - status = EXIT_FAILURE; - } - - if(communicator) - { - try - { - communicator->destroy(); - } - catch(const Ice::Exception& ex) - { - cerr << ex << endl; - status = EXIT_FAILURE; - } - } - - return status; -} diff --git a/cpp/demo/IcePack/simple/Server.cpp b/cpp/demo/IcePack/simple/Server.cpp index c3666ffc5d4..820e88a7051 100644 --- a/cpp/demo/IcePack/simple/Server.cpp +++ b/cpp/demo/IcePack/simple/Server.cpp @@ -21,22 +21,21 @@ public: }; int +main(int argc, char* argv[]) +{ + Server app; + int status = app.main(argc, argv); + return status; +} + +int Server::run(int argc, char* argv[]) { Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("Hello"); string id = communicator()->getProperties()->getProperty("Identity"); - Ice::ObjectPtr object = new HelloI; - adapter->add(object, Ice::stringToIdentity(id)); + adapter->add(new HelloI(), Ice::stringToIdentity(id)); adapter->activate(); communicator()->waitForShutdown(); return EXIT_SUCCESS; } - -int -main(int argc, char* argv[]) -{ - Server app; - int status = app.main(argc, argv); - return status; -} diff --git a/cpp/src/IceUtil/ThreadException.cpp b/cpp/src/IceUtil/ThreadException.cpp index abaa79f26a6..8a9bb039d39 100644 --- a/cpp/src/IceUtil/ThreadException.cpp +++ b/cpp/src/IceUtil/ThreadException.cpp @@ -15,6 +15,7 @@ IceUtil::ThreadSyscallException::ThreadSyscallException(const char* file, int li Exception(file, line), _error(err) { + abort(); //XXX: } const char* IceUtil::ThreadSyscallException::_name = "IceUtil::ThreadSyscallException"; diff --git a/cs/demo/Glacier2/callback/CallbackClient.cs b/cs/demo/Glacier2/callback/CallbackClient.cs deleted file mode 100644 index 3293153e8d3..00000000000 --- a/cs/demo/Glacier2/callback/CallbackClient.cs +++ /dev/null @@ -1,226 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -using Demo; -using System; -using System.Collections; - -class CallbackClient : Ice.Application -{ - private static void menu() - { - Console.WriteLine( - "usage:\n" + - "t: send callback as twoway\n" + - "o: send callback as oneway\n" + - "O: send callback as batch oneway\n" + - "f: flush all batch requests\n" + - "v: set/reset override context field\n" + - "F: set/reset fake category\n" + - "s: shutdown server\n" + - "x: exit\n" + - "?: help\n"); - } - - public override int run(string[] args) - { - Ice.RouterPrx defaultRouter = communicator().getDefaultRouter(); - if(defaultRouter == null) - { - Console.Error.WriteLine("no default router set"); - return 1; - } - - Glacier2.RouterPrx router = Glacier2.RouterPrxHelper.checkedCast(defaultRouter); - if(router == null) - { - Console.Error.WriteLine("configured router is not a Glacier2 router"); - return 1; - } - - while(true) - { - Console.WriteLine("This demo accepts any user-id / password combination."); - - try - { - String id; - Console.Write("user id: "); - Console.Out.Flush(); - id = Console.In.ReadLine(); - - String pw; - Console.Write("password: "); - Console.Out.Flush(); - pw = Console.In.ReadLine(); - - try - { - router.createSession(id, pw); - break; - } - catch(Glacier2.PermissionDeniedException ex) - { - Console.Write("permission denied:\n" + ex.reason); - } - catch(Glacier2.CannotCreateSessionException ex) - { - Console.Write("cannot create session:\n" + ex.reason); - } - } - catch(System.Exception ex) - { - Console.Error.WriteLine(ex); - } - } - - String category = router.getServerProxy().ice_getIdentity().category; - Ice.Identity callbackReceiverIdent = new Ice.Identity(); - callbackReceiverIdent.name = "callbackReceiver"; - callbackReceiverIdent.category = category; - Ice.Identity callbackReceiverFakeIdent = new Ice.Identity(); - callbackReceiverFakeIdent.name = "callbackReceiver"; - callbackReceiverFakeIdent.category = "fake"; - - Ice.Properties properties = communicator().getProperties(); - const string proxyProperty = "Callback.Proxy"; - String proxy = properties.getProperty(proxyProperty); - if(proxy.Length == 0) - { - Console.Error.WriteLine("property `" + proxyProperty + "' not set"); - return 1; - } - - Ice.ObjectPrx @base = communicator().stringToProxy(proxy); - CallbackPrx twoway = CallbackPrxHelper.checkedCast(@base); - CallbackPrx oneway = CallbackPrxHelper.uncheckedCast(twoway.ice_oneway()); - CallbackPrx batchOneway = CallbackPrxHelper.uncheckedCast(twoway.ice_batchOneway()); - - Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Client"); - adapter.add(new CallbackReceiverI(), callbackReceiverIdent); - adapter.add(new CallbackReceiverI(), callbackReceiverFakeIdent); - adapter.activate(); - - CallbackReceiverPrx twowayR = CallbackReceiverPrxHelper.uncheckedCast( - adapter.createProxy(callbackReceiverIdent)); - CallbackReceiverPrx onewayR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_oneway()); - - menu(); - - string line = null; - string @override = null; - bool fake = false; - do - { - try - { - Console.Write("==> "); - Console.Out.Flush(); - line = Console.In.ReadLine(); - if(line == null) - { - break; - } - if(line.Equals("t")) - { - Ice.Context context = new Ice.Context(); - context["_fwd"] = "t"; - if(@override != null) - { - context["_ovrd"] = @override; - } - twoway.initiateCallback(twowayR, context); - } - else if(line.Equals("o")) - { - Ice.Context context = new Ice.Context(); - context["_fwd"] = "o"; - if(@override != null) - { - context["_ovrd"] = @override; - } - oneway.initiateCallback(onewayR, context); - } - else if(line.Equals("O")) - { - Ice.Context context = new Ice.Context(); - context["_fwd"] = "O"; - if(@override != null) - { - context["_ovrd"] = @override; - } - batchOneway.initiateCallback(onewayR, context); - } - else if(line.Equals("f")) - { - communicator().flushBatchRequests(); - } - else if(line.Equals("v")) - { - if(@override == null) - { - @override = "some_value"; - Console.WriteLine("override context field is now `" + @override + "'"); - } - else - { - @override = null; - Console.WriteLine("override context field is empty"); - } - } - else if(line.Equals("F")) - { - fake = !fake; - - if(fake) - { - twowayR = CallbackReceiverPrxHelper.uncheckedCast( - twowayR.ice_newIdentity(callbackReceiverFakeIdent)); - onewayR = CallbackReceiverPrxHelper.uncheckedCast( - onewayR.ice_newIdentity(callbackReceiverFakeIdent)); - } - else - { - twowayR = CallbackReceiverPrxHelper.uncheckedCast( - twowayR.ice_newIdentity(callbackReceiverIdent)); - onewayR = CallbackReceiverPrxHelper.uncheckedCast( - onewayR.ice_newIdentity(callbackReceiverIdent)); - } - - Console.WriteLine("callback receiver identity: " + - Ice.Util.identityToString(twowayR.ice_getIdentity())); - } - else if(line.Equals("s")) - { - twoway.shutdown(); - } - else if(line.Equals("x")) - { - // Nothing to do - } - else if(line.Equals("?")) - { - menu(); - } - else - { - Console.WriteLine("unknown command `" + line + "'"); - menu(); - } - } - catch(System.Exception ex) - { - Console.Error.WriteLine(ex); - } - } - while(!line.Equals("x")); - - return 0; - } -} diff --git a/cs/demo/Glacier2/callback/Client.cs b/cs/demo/Glacier2/callback/Client.cs index a161937c7d0..a9772e94107 100644 --- a/cs/demo/Glacier2/callback/Client.cs +++ b/cs/demo/Glacier2/callback/Client.cs @@ -7,11 +7,226 @@ // // ********************************************************************** -public class Client +using Demo; +using System; +using System.Collections; + +public class Client : Ice.Application { + private static void menu() + { + Console.WriteLine( + "usage:\n" + + "t: send callback as twoway\n" + + "o: send callback as oneway\n" + + "O: send callback as batch oneway\n" + + "f: flush all batch requests\n" + + "v: set/reset override context field\n" + + "F: set/reset fake category\n" + + "s: shutdown server\n" + + "x: exit\n" + + "?: help\n"); + } + + public override int run(string[] args) + { + Ice.RouterPrx defaultRouter = communicator().getDefaultRouter(); + if(defaultRouter == null) + { + Console.Error.WriteLine("no default router set"); + return 1; + } + + Glacier2.RouterPrx router = Glacier2.RouterPrxHelper.checkedCast(defaultRouter); + if(router == null) + { + Console.Error.WriteLine("configured router is not a Glacier2 router"); + return 1; + } + + while(true) + { + Console.WriteLine("This demo accepts any user-id / password combination."); + + try + { + String id; + Console.Write("user id: "); + Console.Out.Flush(); + id = Console.In.ReadLine(); + + String pw; + Console.Write("password: "); + Console.Out.Flush(); + pw = Console.In.ReadLine(); + + try + { + router.createSession(id, pw); + break; + } + catch(Glacier2.PermissionDeniedException ex) + { + Console.Write("permission denied:\n" + ex.reason); + } + catch(Glacier2.CannotCreateSessionException ex) + { + Console.Write("cannot create session:\n" + ex.reason); + } + } + catch(System.Exception ex) + { + Console.Error.WriteLine(ex); + } + } + + String category = router.getServerProxy().ice_getIdentity().category; + Ice.Identity callbackReceiverIdent = new Ice.Identity(); + callbackReceiverIdent.name = "callbackReceiver"; + callbackReceiverIdent.category = category; + Ice.Identity callbackReceiverFakeIdent = new Ice.Identity(); + callbackReceiverFakeIdent.name = "callbackReceiver"; + callbackReceiverFakeIdent.category = "fake"; + + Ice.Properties properties = communicator().getProperties(); + const string proxyProperty = "Callback.Proxy"; + String proxy = properties.getProperty(proxyProperty); + if(proxy.Length == 0) + { + Console.Error.WriteLine("property `" + proxyProperty + "' not set"); + return 1; + } + + Ice.ObjectPrx @base = communicator().stringToProxy(proxy); + CallbackPrx twoway = CallbackPrxHelper.checkedCast(@base); + CallbackPrx oneway = CallbackPrxHelper.uncheckedCast(twoway.ice_oneway()); + CallbackPrx batchOneway = CallbackPrxHelper.uncheckedCast(twoway.ice_batchOneway()); + + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Client"); + adapter.add(new CallbackReceiverI(), callbackReceiverIdent); + adapter.add(new CallbackReceiverI(), callbackReceiverFakeIdent); + adapter.activate(); + + CallbackReceiverPrx twowayR = CallbackReceiverPrxHelper.uncheckedCast( + adapter.createProxy(callbackReceiverIdent)); + CallbackReceiverPrx onewayR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_oneway()); + + menu(); + + string line = null; + string @override = null; + bool fake = false; + do + { + try + { + Console.Write("==> "); + Console.Out.Flush(); + line = Console.In.ReadLine(); + if(line == null) + { + break; + } + if(line.Equals("t")) + { + Ice.Context context = new Ice.Context(); + context["_fwd"] = "t"; + if(@override != null) + { + context["_ovrd"] = @override; + } + twoway.initiateCallback(twowayR, context); + } + else if(line.Equals("o")) + { + Ice.Context context = new Ice.Context(); + context["_fwd"] = "o"; + if(@override != null) + { + context["_ovrd"] = @override; + } + oneway.initiateCallback(onewayR, context); + } + else if(line.Equals("O")) + { + Ice.Context context = new Ice.Context(); + context["_fwd"] = "O"; + if(@override != null) + { + context["_ovrd"] = @override; + } + batchOneway.initiateCallback(onewayR, context); + } + else if(line.Equals("f")) + { + communicator().flushBatchRequests(); + } + else if(line.Equals("v")) + { + if(@override == null) + { + @override = "some_value"; + Console.WriteLine("override context field is now `" + @override + "'"); + } + else + { + @override = null; + Console.WriteLine("override context field is empty"); + } + } + else if(line.Equals("F")) + { + fake = !fake; + + if(fake) + { + twowayR = CallbackReceiverPrxHelper.uncheckedCast( + twowayR.ice_newIdentity(callbackReceiverFakeIdent)); + onewayR = CallbackReceiverPrxHelper.uncheckedCast( + onewayR.ice_newIdentity(callbackReceiverFakeIdent)); + } + else + { + twowayR = CallbackReceiverPrxHelper.uncheckedCast( + twowayR.ice_newIdentity(callbackReceiverIdent)); + onewayR = CallbackReceiverPrxHelper.uncheckedCast( + onewayR.ice_newIdentity(callbackReceiverIdent)); + } + + Console.WriteLine("callback receiver identity: " + + Ice.Util.identityToString(twowayR.ice_getIdentity())); + } + else if(line.Equals("s")) + { + twoway.shutdown(); + } + else if(line.Equals("x")) + { + // Nothing to do + } + else if(line.Equals("?")) + { + menu(); + } + else + { + Console.WriteLine("unknown command `" + line + "'"); + menu(); + } + } + catch(System.Exception ex) + { + Console.Error.WriteLine(ex); + } + } + while(!line.Equals("x")); + + return 0; + } + public static void Main(string[] args) { - CallbackClient app = new CallbackClient(); + Client app = new Client(); int status = app.main(args, "config"); System.Environment.Exit(status); } diff --git a/cs/demo/Glacier2/callback/Makefile b/cs/demo/Glacier2/callback/Makefile index 5972fdeb91f..6b8fcbd8b36 100644 --- a/cs/demo/Glacier2/callback/Makefile +++ b/cs/demo/Glacier2/callback/Makefile @@ -11,8 +11,8 @@ top_srcdir = ../../.. TARGETS = client.exe server.exe sessionserver.exe -C_SRCS = CallbackClient.cs CallbackReceiverI.cs Client.cs -S_SRCS = CallbackI.cs CallbackServer.cs Server.cs +C_SRCS = CallbackReceiverI.cs Client.cs +S_SRCS = CallbackI.cs Server.cs SS_SRCS = SessionI.cs SessionManagerI.cs SessionServer.cs SLICE_SRCS = $(SDIR)/Callback.ice diff --git a/cs/demo/Glacier2/callback/Server.cs b/cs/demo/Glacier2/callback/Server.cs index ae91017e4b9..80527dd63d8 100644 --- a/cs/demo/Glacier2/callback/Server.cs +++ b/cs/demo/Glacier2/callback/Server.cs @@ -7,11 +7,22 @@ // // ********************************************************************** -public class Server +using Demo; + +public class Server : Ice.Application { + public override int run(string[] args) + { + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Server"); + adapter.add(new CallbackI(), Ice.Util.stringToIdentity("callback")); + adapter.activate(); + communicator().waitForShutdown(); + return 0; + } + public static void Main(string[] args) { - CallbackServer app = new CallbackServer(); + Server app = new Server(); int status = app.main(args, "config.server"); System.Environment.Exit(status); } diff --git a/cs/demo/Glacier2/callback/SessionServer.cs b/cs/demo/Glacier2/callback/SessionServer.cs index 782362728d0..f2b75fa9174 100644 --- a/cs/demo/Glacier2/callback/SessionServer.cs +++ b/cs/demo/Glacier2/callback/SessionServer.cs @@ -9,7 +9,7 @@ using System; -public class SessionServer +public class SessionServer : Ice.Application { sealed class DummyPermissionVerifierI : Glacier2._PermissionsVerifierDisp { @@ -21,22 +21,19 @@ public class SessionServer } }; - class Application : Ice.Application + public override int run(string[] args) { - public override int run(string[] args) - { - Ice.ObjectAdapter adapter = communicator().createObjectAdapter("SessionServer"); - adapter.add(new DummyPermissionVerifierI(), Ice.Util.stringToIdentity("verifier")); - adapter.add(new SessionManagerI(), Ice.Util.stringToIdentity("sessionmanager")); - adapter.activate(); - communicator().waitForShutdown(); - return 0; - } - }; + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("SessionServer"); + adapter.add(new DummyPermissionVerifierI(), Ice.Util.stringToIdentity("verifier")); + adapter.add(new SessionManagerI(), Ice.Util.stringToIdentity("sessionmanager")); + adapter.activate(); + communicator().waitForShutdown(); + return 0; + } public static void Main(string[] args) { - Application app = new Application(); + SessionServer app = new SessionServer(); int status = app.main(args, "config.sessionserver"); Environment.Exit(status); } diff --git a/cs/demo/Ice/Makefile b/cs/demo/Ice/Makefile index 9c608ddfd67..c80944b6584 100644 --- a/cs/demo/Ice/Makefile +++ b/cs/demo/Ice/Makefile @@ -11,7 +11,16 @@ top_srcdir = ../.. include $(top_srcdir)/config/Make.rules.cs -SUBDIRS = bidir callback hello invoke latency nested session throughput value +SUBDIRS = bidir \ + callback \ + hello \ + invoke \ + latency \ + minimal \ + nested \ + session \ + throughput \ + value $(EVERYTHING):: @for subdir in $(SUBDIRS); \ diff --git a/cs/demo/Ice/README b/cs/demo/Ice/README index e9c6ea12b20..90165ee7ca2 100644 --- a/cs/demo/Ice/README +++ b/cs/demo/Ice/README @@ -1,5 +1,9 @@ Demos in this directory: +- minimal + + This demo illustrates a minimal Ice application. + - bidir This demo shows how to use bi-directional connections for diff --git a/cs/demo/Ice/bidir/CallbackClient.cs b/cs/demo/Ice/bidir/CallbackClient.cs deleted file mode 100755 index 585308cde9c..00000000000 --- a/cs/demo/Ice/bidir/CallbackClient.cs +++ /dev/null @@ -1,45 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -using Demo; - -class CallbackClient : Ice.Application -{ - public override int run(string[] args) - { - Ice.Properties properties = communicator().getProperties(); - string proxyProperty = "Callback.Client.CallbackServer"; - string proxy = properties.getProperty(proxyProperty); - if(proxy.Length == 0) - { - System.Console.Error.WriteLine("property `" + proxyProperty + "' not set"); - return 1; - } - - Ice.ObjectPrx @base = communicator().stringToProxy(proxy); - CallbackSenderPrx server = CallbackSenderPrxHelper.checkedCast(@base); - if(server == null) - { - System.Console.Error.WriteLine("invalid proxy"); - return 1; - } - - Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Client"); - Ice.Identity ident = new Ice.Identity(); - ident.name = Ice.Util.generateUUID(); - ident.category = ""; - adapter.add(new CallbackReceiverI(), ident); - adapter.activate(); - server.ice_connection().setAdapter(adapter); - server.addClient(ident); - communicator().waitForShutdown(); - - return 0; - } -} diff --git a/cs/demo/Ice/bidir/CallbackServer.cs b/cs/demo/Ice/bidir/CallbackServer.cs deleted file mode 100755 index b75887a442f..00000000000 --- a/cs/demo/Ice/bidir/CallbackServer.cs +++ /dev/null @@ -1,37 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** -
-using Demo;
-using System.Threading;
-
-class CallbackServer : Ice.Application
-{
- public override int run(string[] args)
- {
- Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Server");
- CallbackSenderI sender = new CallbackSenderI();
- adapter.add(sender, Ice.Util.stringToIdentity("sender"));
- adapter.activate();
-
- Thread t = new Thread(new ThreadStart(sender.Run));
- t.Start();
-
- try
- {
- communicator().waitForShutdown();
- }
- finally
- {
- sender.destroy();
- t.Join();
- }
-
- return 0;
- }
-}
diff --git a/cs/demo/Ice/bidir/Client.cs b/cs/demo/Ice/bidir/Client.cs index a161937c7d0..eb889f61ad0 100755 --- a/cs/demo/Ice/bidir/Client.cs +++ b/cs/demo/Ice/bidir/Client.cs @@ -7,11 +7,44 @@ // // ********************************************************************** -public class Client +using Demo; + +public class Client : Ice.Application { + public override int run(string[] args) + { + Ice.Properties properties = communicator().getProperties(); + string proxyProperty = "Callback.Client.CallbackServer"; + string proxy = properties.getProperty(proxyProperty); + if(proxy.Length == 0) + { + System.Console.Error.WriteLine("property `" + proxyProperty + "' not set"); + return 1; + } + + CallbackSenderPrx server = CallbackSenderPrxHelper.checkedCast(communicator().stringToProxy(proxy)); + if(server == null) + { + System.Console.Error.WriteLine("invalid proxy"); + return 1; + } + + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Client"); + Ice.Identity ident = new Ice.Identity(); + ident.name = Ice.Util.generateUUID(); + ident.category = ""; + adapter.add(new CallbackReceiverI(), ident); + adapter.activate(); + server.ice_connection().setAdapter(adapter); + server.addClient(ident); + communicator().waitForShutdown(); + + return 0; + } + public static void Main(string[] args) { - CallbackClient app = new CallbackClient(); + Client app = new Client(); int status = app.main(args, "config"); System.Environment.Exit(status); } diff --git a/cs/demo/Ice/bidir/Makefile b/cs/demo/Ice/bidir/Makefile index f9026806f54..223bde08f79 100644 --- a/cs/demo/Ice/bidir/Makefile +++ b/cs/demo/Ice/bidir/Makefile @@ -11,8 +11,8 @@ top_srcdir = ../../.. TARGETS = client.exe server.exe -C_SRCS = CallbackClient.cs CallbackReceiverI.cs Client.cs -S_SRCS = CallbackSenderI.cs CallbackServer.cs Server.cs +C_SRCS = CallbackReceiverI.cs Client.cs +S_SRCS = CallbackSenderI.cs Server.cs SLICE_SRCS = $(SDIR)/Callback.ice diff --git a/cs/demo/Ice/bidir/README b/cs/demo/Ice/bidir/README new file mode 100644 index 00000000000..abce6080ba5 --- /dev/null +++ b/cs/demo/Ice/bidir/README @@ -0,0 +1,12 @@ +This demo shows how to use bi-directional connections for +callbacks. This is typically used if the server cannot open a +connection to the client to send callbacks, for example, because +firewalls block incoming connections to the client. + +To run the demo, first start the server: + +$ server + +In a separate window, start the client: + +$ client diff --git a/cs/demo/Ice/bidir/Server.cs b/cs/demo/Ice/bidir/Server.cs index d72362bfb2c..be7c493caad 100755 --- a/cs/demo/Ice/bidir/Server.cs +++ b/cs/demo/Ice/bidir/Server.cs @@ -7,11 +7,37 @@ // // ********************************************************************** -public class Server +using Demo; +using System.Threading; + +public class Server : Ice.Application { + public override int run(string[] args) + { + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Server"); + CallbackSenderI sender = new CallbackSenderI(); + adapter.add(sender, Ice.Util.stringToIdentity("sender")); + adapter.activate(); + + Thread t = new Thread(new ThreadStart(sender.Run)); + t.Start(); + + try + { + communicator().waitForShutdown(); + } + finally + { + sender.destroy(); + t.Join(); + } + + return 0; + } + public static void Main(string[] args) { - CallbackServer app = new CallbackServer(); + Server app = new Server(); int status = app.main(args, "config"); System.Environment.Exit(status); } diff --git a/cs/demo/Ice/callback/CallbackClient.cs b/cs/demo/Ice/callback/CallbackClient.cs deleted file mode 100755 index 9a17857f372..00000000000 --- a/cs/demo/Ice/callback/CallbackClient.cs +++ /dev/null @@ -1,128 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -using System; -using Demo; - -class CallbackClient : Ice.Application -{ - private static void menu() - { - Console.Out.WriteLine("usage:\n" - + "t: send callback as twoway\n" - + "o: send callback as oneway\n" - + "O: send callback as batch oneway\n" - + "d: send callback as datagram\n" - + "D: send callback as batch datagram\n" - + "f: flush all batch requests\n" - + "s: shutdown server\n" - + "x: exit\n" - + "?: help\n"); - } - - public override int run(string[] args) - { - Ice.Properties properties = communicator().getProperties(); - string proxyProperty = "Callback.Client.CallbackServer"; - string proxy = properties.getProperty(proxyProperty); - if(proxy.Length == 0) - { - Console.Error.WriteLine("property `" + proxyProperty + "' not set"); - return 1; - } - - Ice.ObjectPrx @base = communicator().stringToProxy(proxy); - CallbackSenderPrx twoway = - CallbackSenderPrxHelper.checkedCast(@base.ice_twoway().ice_timeout(-1).ice_secure(false)); - if(twoway == null) - { - Console.Error.WriteLine("invalid proxy"); - return 1; - } - CallbackSenderPrx oneway = CallbackSenderPrxHelper.uncheckedCast(twoway.ice_oneway()); - CallbackSenderPrx batchOneway = CallbackSenderPrxHelper.uncheckedCast(twoway.ice_batchOneway()); - CallbackSenderPrx datagram = CallbackSenderPrxHelper.uncheckedCast(twoway.ice_datagram()); - CallbackSenderPrx batchDatagram = CallbackSenderPrxHelper.uncheckedCast(twoway.ice_batchDatagram()); - - Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Client"); - adapter.add(new CallbackReceiverI(), Ice.Util.stringToIdentity("callbackReceiver")); - adapter.activate(); - - CallbackReceiverPrx twowayR = CallbackReceiverPrxHelper.uncheckedCast( - adapter.createProxy(Ice.Util.stringToIdentity("callbackReceiver"))); - CallbackReceiverPrx onewayR = CallbackReceiverPrxHelper.uncheckedCast( - twowayR.ice_oneway()); - CallbackReceiverPrx datagramR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_datagram()); - - menu(); - - string line = null; - do - { - try - { - Console.Out.Write("==> "); - Console.Out.Flush(); - line = Console.In.ReadLine(); - if(line == null) - { - break; - } - if(line.Equals("t")) - { - twoway.initiateCallback(twowayR); - } - else if(line.Equals("o")) - { - oneway.initiateCallback(onewayR); - } - else if(line.Equals("O")) - { - batchOneway.initiateCallback(onewayR); - } - else if(line.Equals("d")) - { - datagram.initiateCallback(datagramR); - } - else if(line.Equals("D")) - { - batchDatagram.initiateCallback(datagramR); - } - else if(line.Equals("f")) - { - communicator().flushBatchRequests(); - } - else if(line.Equals("s")) - { - twoway.shutdown(); - } - else if(line.Equals("x")) - { - // Nothing to do - } - else if(line.Equals("?")) - { - menu(); - } - else - { - Console.Out.WriteLine("unknown command `" + line + "'"); - menu(); - } - } - catch(System.Exception ex) - { - Console.Error.WriteLine(ex); - } - } - while(!line.Equals("x")); - - return 0; - } -} diff --git a/cs/demo/Ice/callback/CallbackServer.cs b/cs/demo/Ice/callback/CallbackServer.cs deleted file mode 100755 index 75f73e76485..00000000000 --- a/cs/demo/Ice/callback/CallbackServer.cs +++ /dev/null @@ -1,22 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -using Demo; - -class CallbackServer : Ice.Application -{ - public override int run(string[] args) - { - Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Server"); - adapter.add(new CallbackSenderI(), Ice.Util.stringToIdentity("callback")); - adapter.activate(); - communicator().waitForShutdown(); - return 0; - } -} diff --git a/cs/demo/Ice/callback/Client.cs b/cs/demo/Ice/callback/Client.cs index a161937c7d0..7e863507068 100755 --- a/cs/demo/Ice/callback/Client.cs +++ b/cs/demo/Ice/callback/Client.cs @@ -7,11 +7,127 @@ // // ********************************************************************** -public class Client +using System; +using Demo; + +public class Client : Ice.Application { + private static void menu() + { + Console.Out.WriteLine("usage:\n" + + "t: send callback as twoway\n" + + "o: send callback as oneway\n" + + "O: send callback as batch oneway\n" + + "d: send callback as datagram\n" + + "D: send callback as batch datagram\n" + + "f: flush all batch requests\n" + + "s: shutdown server\n" + + "x: exit\n" + + "?: help\n"); + } + + public override int run(string[] args) + { + Ice.Properties properties = communicator().getProperties(); + string proxyProperty = "Callback.Client.CallbackServer"; + string proxy = properties.getProperty(proxyProperty); + if(proxy.Length == 0) + { + Console.Error.WriteLine("property `" + proxyProperty + "' not set"); + return 1; + } + + CallbackSenderPrx twoway = CallbackSenderPrxHelper.checkedCast( + communicator().stringToProxy(proxy).ice_twoway().ice_timeout(-1).ice_secure(false)); + if(twoway == null) + { + Console.Error.WriteLine("invalid proxy"); + return 1; + } + CallbackSenderPrx oneway = CallbackSenderPrxHelper.uncheckedCast(twoway.ice_oneway()); + CallbackSenderPrx batchOneway = CallbackSenderPrxHelper.uncheckedCast(twoway.ice_batchOneway()); + CallbackSenderPrx datagram = CallbackSenderPrxHelper.uncheckedCast(twoway.ice_datagram()); + CallbackSenderPrx batchDatagram = CallbackSenderPrxHelper.uncheckedCast(twoway.ice_batchDatagram()); + + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Client"); + adapter.add(new CallbackReceiverI(), Ice.Util.stringToIdentity("callbackReceiver")); + adapter.activate(); + + CallbackReceiverPrx twowayR = CallbackReceiverPrxHelper.uncheckedCast( + adapter.createProxy(Ice.Util.stringToIdentity("callbackReceiver"))); + CallbackReceiverPrx onewayR = CallbackReceiverPrxHelper.uncheckedCast( + twowayR.ice_oneway()); + CallbackReceiverPrx datagramR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_datagram()); + + menu(); + + string line = null; + do + { + try + { + Console.Out.Write("==> "); + Console.Out.Flush(); + line = Console.In.ReadLine(); + if(line == null) + { + break; + } + if(line.Equals("t")) + { + twoway.initiateCallback(twowayR); + } + else if(line.Equals("o")) + { + oneway.initiateCallback(onewayR); + } + else if(line.Equals("O")) + { + batchOneway.initiateCallback(onewayR); + } + else if(line.Equals("d")) + { + datagram.initiateCallback(datagramR); + } + else if(line.Equals("D")) + { + batchDatagram.initiateCallback(datagramR); + } + else if(line.Equals("f")) + { + communicator().flushBatchRequests(); + } + else if(line.Equals("s")) + { + twoway.shutdown(); + } + else if(line.Equals("x")) + { + // Nothing to do + } + else if(line.Equals("?")) + { + menu(); + } + else + { + Console.Out.WriteLine("unknown command `" + line + "'"); + menu(); + } + } + catch(System.Exception ex) + { + Console.Error.WriteLine(ex); + } + } + while(!line.Equals("x")); + + return 0; + } + public static void Main(string[] args) { - CallbackClient app = new CallbackClient(); + Client app = new Client(); int status = app.main(args, "config"); System.Environment.Exit(status); } diff --git a/cs/demo/Ice/callback/Makefile b/cs/demo/Ice/callback/Makefile index f9026806f54..223bde08f79 100644 --- a/cs/demo/Ice/callback/Makefile +++ b/cs/demo/Ice/callback/Makefile @@ -11,8 +11,8 @@ top_srcdir = ../../.. TARGETS = client.exe server.exe -C_SRCS = CallbackClient.cs CallbackReceiverI.cs Client.cs -S_SRCS = CallbackSenderI.cs CallbackServer.cs Server.cs +C_SRCS = CallbackReceiverI.cs Client.cs +S_SRCS = CallbackSenderI.cs Server.cs SLICE_SRCS = $(SDIR)/Callback.ice diff --git a/cs/demo/Ice/callback/README b/cs/demo/Ice/callback/README new file mode 100644 index 00000000000..47beab48e3e --- /dev/null +++ b/cs/demo/Ice/callback/README @@ -0,0 +1,11 @@ +A simple callback demo that illustrates how a client can pass a proxy +to a server, invoke an operation in the server, and the server call +back into an object provided by the client as part of that invocation. + +To run the demo, first start the server: + +$ server + +In a separate window, start the client: + +$ client diff --git a/cs/demo/Ice/callback/Server.cs b/cs/demo/Ice/callback/Server.cs index d72362bfb2c..a83b3d4bd04 100755 --- a/cs/demo/Ice/callback/Server.cs +++ b/cs/demo/Ice/callback/Server.cs @@ -7,11 +7,22 @@ // // ********************************************************************** -public class Server +using Demo; + +public class Server : Ice.Application { + public override int run(string[] args) + { + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Server"); + adapter.add(new CallbackSenderI(), Ice.Util.stringToIdentity("callback")); + adapter.activate(); + communicator().waitForShutdown(); + return 0; + } + public static void Main(string[] args) { - CallbackServer app = new CallbackServer(); + Server app = new Server(); int status = app.main(args, "config"); System.Environment.Exit(status); } diff --git a/cs/demo/Ice/hello/Client.cs b/cs/demo/Ice/hello/Client.cs index b524121341b..ac7456942b4 100755 --- a/cs/demo/Ice/hello/Client.cs +++ b/cs/demo/Ice/hello/Client.cs @@ -10,7 +10,7 @@ using System; using Demo; -public class Client +public class Client : Ice.Application { private static void menu() { @@ -28,9 +28,9 @@ public class Client "?: help\n"); } - private static int run(string[] args, Ice.Communicator communicator) + public override int run(string[] args) { - Ice.Properties properties = communicator.getProperties(); + Ice.Properties properties = communicator().getProperties(); string proxyProperty = "Hello.Proxy"; string proxy = properties.getProperty(proxyProperty); if(proxy.Length == 0) @@ -39,8 +39,8 @@ public class Client return 1; } - Ice.ObjectPrx basePrx = communicator.stringToProxy(proxy); - HelloPrx twoway = HelloPrxHelper.checkedCast(basePrx.ice_twoway().ice_timeout(-1).ice_secure(false)); + HelloPrx twoway = HelloPrxHelper.checkedCast( + communicator().stringToProxy(proxy).ice_twoway().ice_timeout(-1).ice_secure(false)); if(twoway == null) { Console.Error.WriteLine("invalid proxy"); @@ -89,7 +89,7 @@ public class Client } else if(line.Equals("f")) { - communicator.flushBatchRequests(); + communicator().flushBatchRequests(); } else if(line.Equals("T")) { @@ -142,38 +142,11 @@ public class Client return 0; } - + public static void Main(string[] args) { - int status = 0; - Ice.Communicator communicator = null; - - try - { - Ice.Properties properties = Ice.Util.createProperties(); - properties.load("config"); - communicator = Ice.Util.initializeWithProperties(ref args, properties); - status = run(args, communicator); - } - catch(System.Exception ex) - { - Console.Error.WriteLine(ex); - status = 1; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(System.Exception ex) - { - Console.Error.WriteLine(ex); - status = 1; - } - } - + Client app = new Client(); + int status = app.main(args, "config"); System.Environment.Exit(status); } } diff --git a/cs/demo/Ice/hello/README b/cs/demo/Ice/hello/README new file mode 100644 index 00000000000..63c9dba1e7d --- /dev/null +++ b/cs/demo/Ice/hello/README @@ -0,0 +1,11 @@ +This demo illustrates how to invoke ordinary (twoway) +operations, as well as how to make oneway, datagram, +secure, and batched invocations. + +To run the demo, first start the server: + +$ server + +In a separate window, start the client: + +$ client diff --git a/cs/demo/Ice/hello/Server.cs b/cs/demo/Ice/hello/Server.cs index 21bbc2674cd..2c9c449deae 100755 --- a/cs/demo/Ice/hello/Server.cs +++ b/cs/demo/Ice/hello/Server.cs @@ -7,49 +7,21 @@ // // ********************************************************************** -public class Server +public class Server : Ice.Application { - private static int run(string[] args, Ice.Communicator communicator) + public override int run(string[] args) { - Ice.ObjectAdapter adapter = communicator.createObjectAdapter("Hello"); - Ice.Object obj = new HelloI(); - adapter.add(obj, Ice.Util.stringToIdentity("hello")); + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Hello"); + adapter.add(new HelloI(), Ice.Util.stringToIdentity("hello")); adapter.activate(); - communicator.waitForShutdown(); + communicator().waitForShutdown(); return 0; } - + public static void Main(string[] args) { - int status = 0; - Ice.Communicator communicator = null; - - try - { - Ice.Properties properties = Ice.Util.createProperties(); - properties.load("config"); - communicator = Ice.Util.initializeWithProperties(ref args, properties); - status = run(args, communicator); - } - catch(System.Exception ex) - { - System.Console.Error.WriteLine(ex); - status = 1; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(System.Exception ex) - { - System.Console.Error.WriteLine(ex); - status = 1; - } - } - + Server app = new Server(); + int status = app.main(args, "config"); System.Environment.Exit(status); } } diff --git a/cs/demo/Ice/invoke/Client.cs b/cs/demo/Ice/invoke/Client.cs index e8d6e64514a..95542b0f217 100644 --- a/cs/demo/Ice/invoke/Client.cs +++ b/cs/demo/Ice/invoke/Client.cs @@ -10,7 +10,7 @@ using System; using Demo; -public class Client +public class Client : Ice.Application { private static void menu() { @@ -30,9 +30,10 @@ public class Client "?: help\n"); } - private static int run(string[] args, Ice.Communicator communicator) + public override int + run(string[] args) { - Ice.Properties properties = communicator.getProperties(); + Ice.Properties properties = communicator().getProperties(); string proxyProperty = "Printer.Proxy"; string proxy = properties.getProperty(proxyProperty); if(proxy.Length == 0) @@ -41,7 +42,7 @@ public class Client return 1; } - Ice.ObjectPrx obj = communicator.stringToProxy(proxy); + Ice.ObjectPrx obj = communicator().stringToProxy(proxy); menu(); @@ -65,7 +66,7 @@ public class Client // // Marshal the in parameter. // - Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator); + Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator()); outStream.writeString("The streaming API works!"); // @@ -83,7 +84,7 @@ public class Client // // Marshal the in parameter. // - Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator); + Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator()); string[] arr = { "The", "streaming", "API", "works!" }; Demo.StringSeqHelper.write(outStream, arr); @@ -102,7 +103,7 @@ public class Client // // Marshal the in parameter. // - Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator); + Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator()); StringDict dict = new StringDict(); dict["The"] = "streaming"; dict["API"] = "works!"; @@ -123,7 +124,7 @@ public class Client // // Marshal the in parameter. // - Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator); + Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator()); Demo.ColorHelper.write(outStream, Demo.Color.green); // @@ -141,7 +142,7 @@ public class Client // // Marshal the in parameter. // - Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator); + Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator()); Demo.Structure s = new Demo.Structure(); s.name = "red"; s.value = Demo.Color.red; @@ -162,7 +163,7 @@ public class Client // // Marshal the in parameter. // - Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator); + Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator()); Demo.Structure[] arr = new Demo.Structure[3]; arr[0] = new Demo.Structure(); arr[0].name = "red"; @@ -191,7 +192,7 @@ public class Client // // Marshal the in parameter. // - Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator); + Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator()); Demo.C c = new Demo.C(); c.s = new Demo.Structure(); c.s.name = "blue"; @@ -223,7 +224,7 @@ public class Client // // Unmarshal the results. // - Ice.InputStream inStream = Ice.Util.createInputStream(communicator, outParams); + Ice.InputStream inStream = Ice.Util.createInputStream(communicator(), outParams); Demo.CHelper ch = new Demo.CHelper(inStream); ch.read(); String str = inStream.readString(); @@ -244,7 +245,7 @@ public class Client continue; } - Ice.InputStream inStream = Ice.Util.createInputStream(communicator, outParams); + Ice.InputStream inStream = Ice.Util.createInputStream(communicator(), outParams); try { inStream.throwException(); @@ -289,35 +290,8 @@ public class Client public static void Main(string[] args) { - int status = 0; - Ice.Communicator communicator = null; - - try - { - Ice.Properties properties = Ice.Util.createProperties(); - properties.load("config"); - communicator = Ice.Util.initializeWithProperties(ref args, properties); - status = run(args, communicator); - } - catch(Ice.LocalException ex) - { - Console.Error.WriteLine(ex); - status = 1; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(Ice.LocalException ex) - { - Console.Error.WriteLine(ex); - status = 1; - } - } - - Environment.Exit(status); + Client app = new Client(); + int status = app.main(args, "config"); + System.Environment.Exit(status); } } diff --git a/cs/demo/Ice/invoke/README b/cs/demo/Ice/invoke/README new file mode 100644 index 00000000000..76ca767d80b --- /dev/null +++ b/cs/demo/Ice/invoke/README @@ -0,0 +1,9 @@ +This demo illustrates the use of the Ice streaming API. + +To run the demo, first start the server: + +$ server + +In a separate window, start the client: + +$ client diff --git a/cs/demo/Ice/invoke/Server.cs b/cs/demo/Ice/invoke/Server.cs index a711c6f0561..648e9c022e3 100644 --- a/cs/demo/Ice/invoke/Server.cs +++ b/cs/demo/Ice/invoke/Server.cs @@ -10,49 +10,22 @@ using Demo; using System; -public class Server +public class Server : Ice.Application { - private static int run(string[] args, Ice.Communicator communicator) + public override int + run(string[] args) { - Ice.ObjectAdapter adapter = communicator.createObjectAdapter("Printer"); - Ice.Object @object = new PrinterI(); - adapter.add(@object, Ice.Util.stringToIdentity("printer")); + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Printer"); + adapter.add(new PrinterI(), Ice.Util.stringToIdentity("printer")); adapter.activate(); - communicator.waitForShutdown(); + communicator().waitForShutdown(); return 0; } public static void Main(string[] args) { - int status = 0; - Ice.Communicator communicator = null; - - try - { - Ice.Properties properties = Ice.Util.createProperties(); - properties.load("config"); - communicator = Ice.Util.initializeWithProperties(ref args, properties); - status = run(args, communicator); - } - catch(Ice.LocalException ex) - { - Console.Error.WriteLine(ex); - status = 1; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(Ice.LocalException ex) - { - Console.Error.WriteLine(ex); - status = 1; - } - } - - Environment.Exit(status); + Server app = new Server(); + int status = app.main(args, "config"); + System.Environment.Exit(status); } } diff --git a/cs/demo/Ice/latency/Client.cs b/cs/demo/Ice/latency/Client.cs index 3442c8316f6..906b2973ba1 100755 --- a/cs/demo/Ice/latency/Client.cs +++ b/cs/demo/Ice/latency/Client.cs @@ -10,11 +10,12 @@ using System; using Demo; -public class Client +public class Client : Ice.Application { - private static int run(string[] args, Ice.Communicator communicator) + public override int + run(string[] args) { - Ice.Properties properties = communicator.getProperties(); + Ice.Properties properties = communicator().getProperties(); string refProperty = "Latency.Ping"; string @ref = properties.getProperty(refProperty); if(@ref.Length == 0) @@ -23,8 +24,7 @@ public class Client return 1; } - Ice.ObjectPrx @base = communicator.stringToProxy(@ref); - PingPrx ping = PingPrxHelper.checkedCast(@base); + PingPrx ping = PingPrxHelper.checkedCast(communicator().stringToProxy(@ref)); if(ping == null) { Console.Error.WriteLine("invalid proxy"); @@ -51,38 +51,11 @@ public class Client return 0; } - + public static void Main(string[] args) { - int status = 0; - Ice.Communicator communicator = null; - - try - { - Ice.Properties properties = Ice.Util.createProperties(); - properties.load("config"); - communicator = Ice.Util.initializeWithProperties(ref args, properties); - status = run(args, communicator); - } - catch(System.Exception ex) - { - Console.Error.WriteLine(ex); - status = 1; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(System.Exception ex) - { - Console.Error.WriteLine(ex); - status = 1; - } - } - + Client app = new Client(); + int status = app.main(args, "config"); System.Environment.Exit(status); } } diff --git a/cs/demo/Ice/latency/README b/cs/demo/Ice/latency/README new file mode 100644 index 00000000000..1c18a9e4e49 --- /dev/null +++ b/cs/demo/Ice/latency/README @@ -0,0 +1,10 @@ +A simple latency test that measures the basic call dispatch +delay of Ice. + +To run the demo, first start the server: + +$ server + +In a separate window, start the client: + +$ client diff --git a/cs/demo/Ice/latency/Server.cs b/cs/demo/Ice/latency/Server.cs index 72aabd94f22..04d6dbee22a 100755 --- a/cs/demo/Ice/latency/Server.cs +++ b/cs/demo/Ice/latency/Server.cs @@ -10,49 +10,22 @@ using System; using Demo; -public class Server +public class Server : Ice.Application { - private static int run(string[] args, Ice.Communicator communicator) + public override int + run(string[] args) { - Ice.ObjectAdapter adapter = communicator.createObjectAdapter("Latency"); - Ice.Object @object = new Ping(); - adapter.add(@object, Ice.Util.stringToIdentity("ping")); + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Latency"); + adapter.add(new Ping(), Ice.Util.stringToIdentity("ping")); adapter.activate(); - communicator.waitForShutdown(); + communicator().waitForShutdown(); return 0; } - + public static void Main(string[] args) { - int status = 0; - Ice.Communicator communicator = null; - - try - { - Ice.Properties properties = Ice.Util.createProperties(); - properties.load("config"); - communicator = Ice.Util.initializeWithProperties(ref args, properties); - status = run(args, communicator); - } - catch(System.Exception ex) - { - Console.Error.WriteLine(ex); - status = 1; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(System.Exception ex) - { - Console.Error.WriteLine(ex); - status = 1; - } - } - + Server app = new Server(); + int status = app.main(args, "config"); System.Environment.Exit(status); } } diff --git a/cs/demo/Ice/minimal/Client.cs b/cs/demo/Ice/minimal/Client.cs new file mode 100755 index 00000000000..73b3363c6fb --- /dev/null +++ b/cs/demo/Ice/minimal/Client.cs @@ -0,0 +1,118 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +using System; +using Demo; + +public class Client +{ + private static void menu() + { + Console.WriteLine( + "usage:\n" + + "h: send greeting\n" + + "x: exit\n" + + "?: help\n"); + } + + public static int run(string[] args, Ice.Communicator communicator) + { + Ice.Properties properties = communicator.getProperties(); + string proxyProperty = "Hello.Proxy"; + string proxy = properties.getProperty(proxyProperty); + if(proxy.Length == 0) + { + Console.Error.WriteLine("property `" + proxyProperty + "' not set"); + return 1; + } + + HelloPrx hello = HelloPrxHelper.checkedCast( + communicator.stringToProxy(proxy).ice_twoway().ice_timeout(-1).ice_secure(false)); + if(hello == null) + { + Console.Error.WriteLine("invalid proxy"); + return 1; + } + + menu(); + + string line = null; + do + { + try + { + Console.Out.Write("==> "); + Console.Out.Flush(); + line = Console.In.ReadLine(); + if(line == null) + { + break; + } + if(line.Equals("h")) + { + hello.sayHello(); + } + else if(line.Equals("x")) + { + // Nothing to do + } + else if(line.Equals("?")) + { + menu(); + } + else + { + Console.WriteLine("unknown command `" + line + "'"); + menu(); + } + } + catch(System.Exception ex) + { + Console.Error.WriteLine(ex); + } + } + while (!line.Equals("x")); + + return 0; + } + + public static void Main(string[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + try + { + Ice.Properties properties = Ice.Util.createProperties(); + properties.load("config"); + communicator = Ice.Util.initializeWithProperties(ref args, properties); + status = run(args, communicator); + } + catch(System.Exception ex) + { + Console.Error.WriteLine(ex); + status = 1; + } + + if(communicator != null) + { + try + { + communicator.destroy(); + } + catch(System.Exception ex) + { + Console.Error.WriteLine(ex); + status = 1; + } + } + + System.Environment.Exit(status); + } +} diff --git a/cs/demo/Ice/minimal/Hello.ice b/cs/demo/Ice/minimal/Hello.ice new file mode 100644 index 00000000000..1e35e0829fa --- /dev/null +++ b/cs/demo/Ice/minimal/Hello.ice @@ -0,0 +1,23 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef HELLO_ICE +#define HELLO_ICE + +module Demo +{ + +interface Hello +{ + nonmutating void sayHello(); +}; + +}; + +#endif diff --git a/cs/demo/Glacier2/callback/CallbackServer.cs b/cs/demo/Ice/minimal/HelloI.cs index 76214a3a022..6e65c0287c9 100644..100755 --- a/cs/demo/Glacier2/callback/CallbackServer.cs +++ b/cs/demo/Ice/minimal/HelloI.cs @@ -9,14 +9,10 @@ using Demo; -class CallbackServer : Ice.Application +public class HelloI : _HelloDisp { - public override int run(string[] args) + public override void sayHello(Ice.Current current) { - Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Server"); - adapter.add(new CallbackI(), Ice.Util.stringToIdentity("callback")); - adapter.activate(); - communicator().waitForShutdown(); - return 0; + System.Console.Out.WriteLine("Hello World!"); } } diff --git a/cs/demo/Ice/minimal/Makefile b/cs/demo/Ice/minimal/Makefile new file mode 100644 index 00000000000..d44240f2a70 --- /dev/null +++ b/cs/demo/Ice/minimal/Makefile @@ -0,0 +1,35 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../../.. + +TARGETS = client.exe server.exe + +C_SRCS = Client.cs +S_SRCS = HelloI.cs Server.cs + +SLICE_SRCS = $(SDIR)/Hello.ice + +SDIR = . + +GDIR = generated + +include $(top_srcdir)/config/Make.rules.cs + +MCSFLAGS := $(MCSFLAGS) -target:exe + +SLICE2CSFLAGS := $(SLICE2CSFLAGS) --ice -I. -I$(slicedir) + +client.exe: $(C_SRCS) $(GEN_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ -r:$(bindir)/icecs.dll $^ + +server.exe: $(S_SRCS) $(GEN_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ -r:$(bindir)/icecs.dll $^ + +include .depend diff --git a/cs/demo/Ice/minimal/README b/cs/demo/Ice/minimal/README new file mode 100644 index 00000000000..63c9dba1e7d --- /dev/null +++ b/cs/demo/Ice/minimal/README @@ -0,0 +1,11 @@ +This demo illustrates how to invoke ordinary (twoway) +operations, as well as how to make oneway, datagram, +secure, and batched invocations. + +To run the demo, first start the server: + +$ server + +In a separate window, start the client: + +$ client diff --git a/cs/demo/Ice/minimal/Server.cs b/cs/demo/Ice/minimal/Server.cs new file mode 100755 index 00000000000..318ead94e5a --- /dev/null +++ b/cs/demo/Ice/minimal/Server.cs @@ -0,0 +1,56 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +using System; + +public class Server +{ + public static int run(string[] args, Ice.Communicator communicator) + { + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("Hello"); + adapter.add(new HelloI(), Ice.Util.stringToIdentity("hello")); + adapter.activate(); + communicator.waitForShutdown(); + return 0; + } + + public static void Main(string[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + try + { + Ice.Properties properties = Ice.Util.createProperties(); + properties.load("config"); + communicator = Ice.Util.initializeWithProperties(ref args, properties); + status = run(args, communicator); + } + catch(System.Exception ex) + { + Console.Error.WriteLine(ex); + status = 1; + } + + if(communicator != null) + { + try + { + communicator.destroy(); + } + catch(System.Exception ex) + { + Console.Error.WriteLine(ex); + status = 1; + } + } + + System.Environment.Exit(status); + } +} diff --git a/cs/demo/Ice/minimal/config b/cs/demo/Ice/minimal/config new file mode 100644 index 00000000000..fa5e48fd529 --- /dev/null +++ b/cs/demo/Ice/minimal/config @@ -0,0 +1,50 @@ +# +# The client reads this property to create the reference to the +# "hello" object in the server. +# +Hello.Proxy=hello:tcp -p 10000:udp -p 10000 + +# +# The server creates one single object adapter with the name +# "helloadapater". The following line sets the endpoints for this +# adapter +# +Hello.Endpoints=tcp -p 10000:udp -p 10000 + +# +# Warn about connection exceptions +# +Ice.Warn.Connections=1 + +# +# We want a faster ACM for this demo. +# +Ice.ACM.Client=10 +Ice.ACM.Server=10 + +# +# Network Tracing +# +# 0 = no network tracing +# 1 = trace connection establishment and closure +# 2 = like 1, but more detailed +# 3 = like 2, but also trace data transfer +# +Ice.Trace.Network=0 + +# +# Protocol Tracing +# +# 0 = no protocol tracing +# 1 = trace protocol messages +# +Ice.Trace.Protocol=0 + +# +# Security Tracing +# +# 0 = no security tracing +# 1 = trace warning messages +# 2 = config file parsing warnings +# +#Ice.Trace.Security=2 diff --git a/cs/demo/Ice/nested/Client.cs b/cs/demo/Ice/nested/Client.cs index 6c45fbdc2d7..95c30deb987 100755 --- a/cs/demo/Ice/nested/Client.cs +++ b/cs/demo/Ice/nested/Client.cs @@ -7,11 +7,74 @@ // // ********************************************************************** -public class Client +using System; +using Demo; + +public class Client : Ice.Application { + public override int run(string[] args) + { + Ice.Properties properties = communicator().getProperties(); + string proxyProperty = "Nested.Client.NestedServer"; + string proxy = properties.getProperty(proxyProperty); + if(proxy.Length == 0) + { + Console.Error.WriteLine("property `" + proxyProperty + "' not set"); + return 1; + } + + NestedPrx nested = NestedPrxHelper.checkedCast(communicator().stringToProxy(proxy)); + if(nested == null) + { + Console.Error.WriteLine("invalid proxy"); + return 1; + } + + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Nested.Client"); + NestedPrx self = NestedPrxHelper.uncheckedCast(adapter.createProxy(Ice.Util.stringToIdentity("nestedClient"))); + adapter.add(new NestedI(self), Ice.Util.stringToIdentity("nestedClient")); + adapter.activate(); + + Console.Out.WriteLine("Note: The maximum nesting level is sz * 2, with sz being"); + Console.Out.WriteLine("the maximum number of threads in the server thread pool. If"); + Console.Out.WriteLine("you specify a value higher than that, the application will"); + Console.Out.WriteLine("block or timeout."); + Console.Out.WriteLine(); + + string s = null; + do + { + try + { + Console.Out.Write("enter nesting level or 'x' for exit: "); + Console.Out.Flush(); + s = Console.In.ReadLine(); + if(s == null) + { + break; + } + int level = System.Int32.Parse(s); + if(level > 0) + { + nested.nestedCall(level, self); + } + } + catch(System.FormatException) + { + } + catch(System.Exception ex) + { + Console.Error.WriteLine(ex); + } + } + while(!s.Equals("x")); + + return 0; + } + public static void Main(string[] args) { - NestedClient app = new NestedClient(); + Client app = new Client(); int status = app.main(args, "config"); System.Environment.Exit(status); } diff --git a/cs/demo/Ice/nested/Makefile b/cs/demo/Ice/nested/Makefile index 46750993392..5eabd8fe82f 100644 --- a/cs/demo/Ice/nested/Makefile +++ b/cs/demo/Ice/nested/Makefile @@ -11,8 +11,8 @@ top_srcdir = ../../.. TARGETS = client.exe server.exe -C_SRCS = Client.cs NestedClient.cs NestedI.cs -S_SRCS = Server.cs NestedServer.cs NestedI.cs +C_SRCS = Client.cs NestedI.cs +S_SRCS = Server.cs NestedI.cs SLICE_SRCS = $(SDIR)/Nested.ice diff --git a/cs/demo/Ice/nested/NestedClient.cs b/cs/demo/Ice/nested/NestedClient.cs deleted file mode 100755 index 32281b5d31c..00000000000 --- a/cs/demo/Ice/nested/NestedClient.cs +++ /dev/null @@ -1,75 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -using System; -using Demo; - -class NestedClient : Ice.Application -{ - public override int run(string[] args) - { - Ice.Properties properties = communicator().getProperties(); - string proxyProperty = "Nested.Client.NestedServer"; - string proxy = properties.getProperty(proxyProperty); - if(proxy.Length == 0) - { - Console.Error.WriteLine("property `" + proxyProperty + "' not set"); - return 1; - } - - Ice.ObjectPrx @base = communicator().stringToProxy(proxy); - NestedPrx nested = NestedPrxHelper.checkedCast(@base); - if(nested == null) - { - Console.Error.WriteLine("invalid proxy"); - return 1; - } - - Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Nested.Client"); - NestedPrx self = NestedPrxHelper.uncheckedCast(adapter.createProxy(Ice.Util.stringToIdentity("nestedClient"))); - adapter.add(new NestedI(self), Ice.Util.stringToIdentity("nestedClient")); - adapter.activate(); - - Console.Out.WriteLine("Note: The maximum nesting level is sz * 2, with sz being"); - Console.Out.WriteLine("the maximum number of threads in the server thread pool. If"); - Console.Out.WriteLine("you specify a value higher than that, the application will"); - Console.Out.WriteLine("block or timeout."); - Console.Out.WriteLine(); - - string s = null; - do - { - try - { - Console.Out.Write("enter nesting level or 'x' for exit: "); - Console.Out.Flush(); - s = Console.In.ReadLine(); - if(s == null) - { - break; - } - int level = System.Int32.Parse(s); - if(level > 0) - { - nested.nestedCall(level, self); - } - } - catch(System.FormatException) - { - } - catch(System.Exception ex) - { - Console.Error.WriteLine(ex); - } - } - while(!s.Equals("x")); - - return 0; - } -} diff --git a/cs/demo/Ice/nested/NestedServer.cs b/cs/demo/Ice/nested/NestedServer.cs deleted file mode 100755 index 03f0ba85a13..00000000000 --- a/cs/demo/Ice/nested/NestedServer.cs +++ /dev/null @@ -1,23 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -using Demo; - -class NestedServer : Ice.Application -{ - public override int run(string[] args) - { - Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Nested.Server"); - NestedPrx self = NestedPrxHelper.uncheckedCast(adapter.createProxy(Ice.Util.stringToIdentity("nestedServer"))); - adapter.add(new NestedI(self), Ice.Util.stringToIdentity("nestedServer")); - adapter.activate(); - communicator().waitForShutdown(); - return 0; - } -} diff --git a/cs/demo/Ice/nested/README b/cs/demo/Ice/nested/README new file mode 100644 index 00000000000..60e7c9b734a --- /dev/null +++ b/cs/demo/Ice/nested/README @@ -0,0 +1,10 @@ +A demo to illustrate how nested callbacks work, and how the size of +the thread pool affects the maximum nesting depth. + +To run the demo, first start the server: + +$ server + +In a separate window, start the client: + +$ client diff --git a/cs/demo/Ice/nested/Server.cs b/cs/demo/Ice/nested/Server.cs index cbd48ad0ec9..04a0a443a23 100755 --- a/cs/demo/Ice/nested/Server.cs +++ b/cs/demo/Ice/nested/Server.cs @@ -7,11 +7,23 @@ // // ********************************************************************** -public class Server +using Demo; + +public class Server : Ice.Application { + public override int run(string[] args) + { + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Nested.Server"); + NestedPrx self = NestedPrxHelper.uncheckedCast(adapter.createProxy(Ice.Util.stringToIdentity("nestedServer"))); + adapter.add(new NestedI(self), Ice.Util.stringToIdentity("nestedServer")); + adapter.activate(); + communicator().waitForShutdown(); + return 0; + } + public static void Main(string[] args) { - NestedServer app = new NestedServer(); + Server app = new Server(); int status = app.main(args, "config"); System.Environment.Exit(status); } diff --git a/cs/demo/Ice/session/Client.cs b/cs/demo/Ice/session/Client.cs index 9b0ae6b6902..ad89fe1c5dc 100755 --- a/cs/demo/Ice/session/Client.cs +++ b/cs/demo/Ice/session/Client.cs @@ -7,11 +7,216 @@ // // ********************************************************************** -public class Client +using System; +using System.Threading; +using System.Collections; +using Demo; + +public class Client : Ice.Application { + class SessionRefreshThread + { + public SessionRefreshThread(Ice.Logger logger, int timeout, SessionPrx session) + { + _logger = logger; + _session = session; + _timeout = timeout; + _terminated = false; + } + + public void run() + { + lock(this) + { + while(!_terminated) + { + System.Threading.Monitor.Wait(this, _timeout); + if(!_terminated) + { + try + { + _session.refresh(); + } + catch(Ice.Exception ex) + { + _logger.warning("SessionRefreshThread: " + ex); + _terminated = true; + } + } + } + } + } + + public void terminate() + { + lock(this) + { + _terminated = true; + System.Threading.Monitor.Pulse(this); + } + } + + private Ice.Logger _logger; + private SessionPrx _session; + private int _timeout; + private bool _terminated; + }; + + public override int run(string[] args) + { + string name; + do + { + Console.Out.Write("Please enter your name ==> "); + Console.Out.Flush(); + + name = Console.In.ReadLine(); + if(name == null) + { + return 1; + } + name = name.Trim(); + } + while(name.Length == 0); + + Ice.Properties properties = communicator().getProperties(); + string proxyProperty = "SessionFactory.Proxy"; + string proxy = properties.getProperty(proxyProperty); + if(proxy.Length == 0) + { + Console.Error.WriteLine("property `" + proxyProperty + "' not set"); + return 1; + } + + Ice.ObjectPrx basePrx = communicator().stringToProxy(proxy); + SessionFactoryPrx factory = SessionFactoryPrxHelper.checkedCast(basePrx); + if(factory == null) + { + Console.Error.WriteLine("invalid proxy"); + return 1; + } + + SessionPrx session = factory.create(name); + + SessionRefreshThread refresh = new SessionRefreshThread(communicator().getLogger(), 5000, session); + Thread refreshThread = new Thread(new ThreadStart(refresh.run)); + refreshThread.Start(); + + ArrayList hellos = new ArrayList(); + + menu(); + + try + { + bool destroy = true; + bool shutdown = false; + while(true) + { + Console.Out.Write("==> "); + Console.Out.Flush(); + string line = Console.In.ReadLine(); + if(line == null) + { + break; + } + if(line.Length > 0 && Char.IsDigit(line[0])) + { + int index = Int32.Parse(line); + if(index < hellos.Count) + { + HelloPrx hello = (HelloPrx)hellos[index]; + hello.sayHello(); + } + else + { + Console.Out.WriteLine("Index is too high. " + hellos.Count + + " hello objects exist so far.\n" + + "Use `c' to create a new hello object."); + } + } + else if(line.Equals("c")) + { + hellos.Add(session.createHello()); + Console.Out.WriteLine("Created hello object " + (hellos.Count - 1)); + } + else if(line.Equals("s")) + { + destroy = false; + shutdown = true; + break; + } + else if(line.Equals("x")) + { + break; + } + else if(line.Equals("t")) + { + destroy = false; + break; + } + else if(line.Equals("?")) + { + menu(); + } + else + { + Console.Out.WriteLine("Unknown command `" + line + "'."); + menu(); + } + } + + // + // The refresher thread must be terminated before destroy is + // called, otherwise it might get ObjectNotExistException. refresh + // is set to 0 so that if session.destroy() raises an exception + // the thread will not be re-terminated and re-joined. + // + refresh.terminate(); + refreshThread.Join(); + refresh = null; + + if(destroy) + { + session.destroy(); + } + if(shutdown) + { + factory.shutdown(); + } + } + catch(System.Exception) + { + // + // The refresher thread must be terminated in the event of a + // failure. + // + if(refresh != null) + { + refresh.terminate(); + refreshThread.Join(); + refresh = null; + } + throw; + } + + return 0; + } + + private static void menu() + { + Console.Out.WriteLine( + "usage:\n" + + "c: create a new per-client hello object\n" + + "0-9: send a greeting to a hello object\n" + + "s: shutdown the server and exit\n" + + "x: exit\n" + + "t: exit without destroying the session\n" + + "?: help\n"); + } + public static void Main(string[] args) { - SessionClient app = new SessionClient(); + Client app = new Client(); int status = app.main(args, "config"); System.Environment.Exit(status); } diff --git a/cs/demo/Ice/session/Makefile b/cs/demo/Ice/session/Makefile index 3dd64cfc163..e5d30122a50 100644 --- a/cs/demo/Ice/session/Makefile +++ b/cs/demo/Ice/session/Makefile @@ -11,8 +11,8 @@ top_srcdir = ../../.. TARGETS = client.exe server.exe -C_SRCS = Client.cs SessionClient.cs -S_SRCS = HelloI.cs ReapThread.cs Server.cs SessionFactoryI.cs SessionI.cs SessionServer.cs +C_SRCS = Client.cs +S_SRCS = HelloI.cs ReapThread.cs Server.cs SessionFactoryI.cs SessionI.cs SLICE_SRCS = $(SDIR)/Session.ice diff --git a/cs/demo/Ice/session/Server.cs b/cs/demo/Ice/session/Server.cs index a22812045bf..5d1d702bb17 100755 --- a/cs/demo/Ice/session/Server.cs +++ b/cs/demo/Ice/session/Server.cs @@ -7,11 +7,33 @@ // // ********************************************************************** -public class Server +using System; +using System.Threading; +using Demo; + +public class Server : Ice.Application { + public override int run(string[] args) + { + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("SessionFactory"); + + ReapThread reaper = new ReapThread(); + Thread reaperThread = new Thread(new ThreadStart(reaper.run)); + reaperThread.Start(); + + adapter.add(new SessionFactoryI(reaper), Ice.Util.stringToIdentity("SessionFactory")); + adapter.activate(); + communicator().waitForShutdown(); + + reaper.terminate(); + reaperThread.Join(); + + return 0; + } + public static void Main(string[] args) { - SessionServer app = new SessionServer(); + Server app = new Server(); int status = app.main(args, "config"); System.Environment.Exit(status); } diff --git a/cs/demo/Ice/session/SessionClient.cs b/cs/demo/Ice/session/SessionClient.cs deleted file mode 100755 index fbce383b44b..00000000000 --- a/cs/demo/Ice/session/SessionClient.cs +++ /dev/null @@ -1,216 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -using System; -using System.Threading; -using System.Collections; -using Demo; - -class SessionClient : Ice.Application -{ - class SessionRefreshThread - { - public SessionRefreshThread(Ice.Logger logger, int timeout, SessionPrx session) - { - _logger = logger; - _session = session; - _timeout = timeout; - _terminated = false; - } - - public void run() - { - lock(this) - { - while(!_terminated) - { - System.Threading.Monitor.Wait(this, _timeout); - if(!_terminated) - { - try - { - _session.refresh(); - } - catch(Ice.Exception ex) - { - _logger.warning("SessionRefreshThread: " + ex); - _terminated = true; - } - } - } - } - } - - public void terminate() - { - lock(this) - { - _terminated = true; - System.Threading.Monitor.Pulse(this); - } - } - - private Ice.Logger _logger; - private SessionPrx _session; - private int _timeout; - private bool _terminated; - }; - - public override int run(string[] args) - { - string name; - do - { - Console.Out.Write("Please enter your name ==> "); - Console.Out.Flush(); - - name = Console.In.ReadLine(); - if(name == null) - { - return 1; - } - name = name.Trim(); - } - while(name.Length == 0); - - Ice.Properties properties = communicator().getProperties(); - string proxyProperty = "SessionFactory.Proxy"; - string proxy = properties.getProperty(proxyProperty); - if(proxy.Length == 0) - { - Console.Error.WriteLine("property `" + proxyProperty + "' not set"); - return 1; - } - - Ice.ObjectPrx basePrx = communicator().stringToProxy(proxy); - SessionFactoryPrx factory = SessionFactoryPrxHelper.checkedCast(basePrx); - if(factory == null) - { - Console.Error.WriteLine("invalid proxy"); - return 1; - } - - SessionPrx session = factory.create(name); - - SessionRefreshThread refresh = new SessionRefreshThread(communicator().getLogger(), 5000, session); - Thread refreshThread = new Thread(new ThreadStart(refresh.run)); - refreshThread.Start(); - - ArrayList hellos = new ArrayList(); - - menu(); - - try - { - bool destroy = true; - bool shutdown = false; - while(true) - { - Console.Out.Write("==> "); - Console.Out.Flush(); - string line = Console.In.ReadLine(); - if(line == null) - { - break; - } - if(line.Length > 0 && Char.IsDigit(line[0])) - { - int index = Int32.Parse(line); - if(index < hellos.Count) - { - HelloPrx hello = (HelloPrx)hellos[index]; - hello.sayHello(); - } - else - { - Console.Out.WriteLine("Index is too high. " + hellos.Count + - " hello objects exist so far.\n" + - "Use `c' to create a new hello object."); - } - } - else if(line.Equals("c")) - { - hellos.Add(session.createHello()); - Console.Out.WriteLine("Created hello object " + (hellos.Count - 1)); - } - else if(line.Equals("s")) - { - destroy = false; - shutdown = true; - break; - } - else if(line.Equals("x")) - { - break; - } - else if(line.Equals("t")) - { - destroy = false; - break; - } - else if(line.Equals("?")) - { - menu(); - } - else - { - Console.Out.WriteLine("Unknown command `" + line + "'."); - menu(); - } - } - - // - // The refresher thread must be terminated before destroy is - // called, otherwise it might get ObjectNotExistException. refresh - // is set to 0 so that if session.destroy() raises an exception - // the thread will not be re-terminated and re-joined. - // - refresh.terminate(); - refreshThread.Join(); - refresh = null; - - if(destroy) - { - session.destroy(); - } - if(shutdown) - { - factory.shutdown(); - } - } - catch(System.Exception) - { - // - // The refresher thread must be terminated in the event of a - // failure. - // - if(refresh != null) - { - refresh.terminate(); - refreshThread.Join(); - refresh = null; - } - throw; - } - - return 0; - } - - private static void menu() - { - Console.Out.WriteLine( - "usage:\n" + - "c: create a new per-client hello object\n" + - "0-9: send a greeting to a hello object\n" + - "s: shutdown the server and exit\n" + - "x: exit\n" + - "t: exit without destroying the session\n" + - "?: help\n"); - } -} diff --git a/cs/demo/Ice/session/SessionServer.cs b/cs/demo/Ice/session/SessionServer.cs deleted file mode 100755 index 41b5e454c47..00000000000 --- a/cs/demo/Ice/session/SessionServer.cs +++ /dev/null @@ -1,34 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -using System; -using System.Threading; -using Demo; - -class SessionServer : Ice.Application -{ - public override int run(string[] args) - { - Ice.ObjectAdapter adapter = communicator().createObjectAdapter("SessionFactory"); - - ReapThread reaper = new ReapThread(); - Thread reaperThread = new Thread(new ThreadStart(reaper.run)); - reaperThread.Start(); - - adapter.add(new SessionFactoryI(reaper), Ice.Util.stringToIdentity("SessionFactory")); - adapter.activate(); - communicator().waitForShutdown(); - - reaper.terminate(); - reaperThread.Join(); - - return 0; - } -} - diff --git a/cs/demo/Ice/throughput/Client.cs b/cs/demo/Ice/throughput/Client.cs index db0e76db14c..8db4ca4f635 100755 --- a/cs/demo/Ice/throughput/Client.cs +++ b/cs/demo/Ice/throughput/Client.cs @@ -10,7 +10,7 @@ using System; using Demo; -public class Client +public class Client : Ice.Application { private static void menu() { @@ -34,9 +34,10 @@ public class Client + "?: help\n"); } - private static int run(string[] args, Ice.Communicator communicator) + public override int + run(string[] args) { - Ice.Properties properties = communicator.getProperties(); + Ice.Properties properties = communicator().getProperties(); string refProperty = "Throughput.Throughput"; string r = properties.getProperty(refProperty); if(r.Length == 0) @@ -45,7 +46,7 @@ public class Client return 1; } - Ice.ObjectPrx b = communicator.stringToProxy(r); + Ice.ObjectPrx b = communicator().stringToProxy(r); ThroughputPrx throughput = ThroughputPrxHelper.checkedCast(b); if(throughput == null) { @@ -386,38 +387,11 @@ public class Client return 0; } - + public static void Main(string[] args) { - int status = 0; - Ice.Communicator communicator = null; - - try - { - Ice.Properties properties = Ice.Util.createProperties(); - properties.load("config"); - communicator = Ice.Util.initializeWithProperties(ref args, properties); - status = run(args, communicator); - } - catch(System.Exception ex) - { - Console.Error.WriteLine(ex); - status = 1; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(System.Exception ex) - { - Console.Error.WriteLine(ex); - status = 1; - } - } - + Client app = new Client(); + int status = app.main(args, "config"); System.Environment.Exit(status); } } diff --git a/cs/demo/Ice/throughput/README b/cs/demo/Ice/throughput/README new file mode 100644 index 00000000000..c6dc9bd0ba9 --- /dev/null +++ b/cs/demo/Ice/throughput/README @@ -0,0 +1,11 @@ +A simple throughput demo that allows you to send sequences of various +types between client and server and to measure the maximum bandwidth +that can be achieved using serialized synchronous requests. + +To run the demo, first start the server: + +$ server + +In a separate window, start the client: + +$ client diff --git a/cs/demo/Ice/throughput/Server.cs b/cs/demo/Ice/throughput/Server.cs index 83d6e723ee1..6d3c2558bba 100755 --- a/cs/demo/Ice/throughput/Server.cs +++ b/cs/demo/Ice/throughput/Server.cs @@ -7,49 +7,22 @@ // // ********************************************************************** -public class Server +public class Server : Ice.Application { - private static int run(string[] args, Ice.Communicator communicator) + public override int + run(string[] args) { - Ice.ObjectAdapter adapter = communicator.createObjectAdapter("Throughput"); - Ice.Object obj = new ThroughputI(); - adapter.add(obj, Ice.Util.stringToIdentity("throughput")); + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Throughput"); + adapter.add(new ThroughputI(), Ice.Util.stringToIdentity("throughput")); adapter.activate(); - communicator.waitForShutdown(); + communicator().waitForShutdown(); return 0; } - + public static void Main(string[] args) { - int status = 0; - Ice.Communicator communicator = null; - - try - { - Ice.Properties properties = Ice.Util.createProperties(); - properties.load("config"); - communicator = Ice.Util.initializeWithProperties(ref args, properties); - status = run(args, communicator); - } - catch(System.Exception ex) - { - System.Console.Error.WriteLine(ex); - status = 1; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(System.Exception ex) - { - System.Console.Error.WriteLine(ex); - status = 1; - } - } - + Server app = new Server(); + int status = app.main(args, "config"); System.Environment.Exit(status); } } diff --git a/cs/demo/Ice/value/README b/cs/demo/Ice/value/README new file mode 100644 index 00000000000..99557d6811a --- /dev/null +++ b/cs/demo/Ice/value/README @@ -0,0 +1,10 @@ +This demo shows how to use classes, class factories, and the +difference between local and remote invocations of class operations. + +To run the demo, first start the server: + +$ server + +In a separate window, start the client: + +$ client diff --git a/cs/demo/IcePack/hello/Client.cs b/cs/demo/IcePack/hello/Client.cs index 28d8e6724d2..d52202b8902 100644 --- a/cs/demo/IcePack/hello/Client.cs +++ b/cs/demo/IcePack/hello/Client.cs @@ -10,7 +10,7 @@ using System; using Demo; -public class Client +public class Client : Ice.Application { private static void menu() { @@ -26,9 +26,9 @@ public class Client "?: help\n"); } - private static int run(string[] args, Ice.Communicator communicator) + public override int run(string[] args) { - IcePack.QueryPrx query = IcePack.QueryPrxHelper.checkedCast(communicator.stringToProxy("IcePack/Query")); + IcePack.QueryPrx query = IcePack.QueryPrxHelper.checkedCast(communicator().stringToProxy("IcePack/Query")); // // Get an object implementing the HelloFactory interface. @@ -156,35 +156,8 @@ public class Client public static void Main(string[] args) { - int status = 0; - Ice.Communicator communicator = null; - - try - { - Ice.Properties properties = Ice.Util.createProperties(); - properties.load("config"); - communicator = Ice.Util.initializeWithProperties(ref args, properties); - status = run(args, communicator); - } - catch(Exception ex) - { - Console.Error.WriteLine(ex); - status = 1; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(Ice.LocalException ex) - { - Console.Error.WriteLine(ex); - status = 1; - } - } - - Environment.Exit(status); + Client app = new Client(); + int status = app.main(args, "config"); + System.Environment.Exit(status); } } diff --git a/cs/demo/IcePack/hello/Server.cs b/cs/demo/IcePack/hello/Server.cs index 4e21e8e5991..2a57d78df38 100644 --- a/cs/demo/IcePack/hello/Server.cs +++ b/cs/demo/IcePack/hello/Server.cs @@ -17,8 +17,7 @@ public class Server : Ice.Application String id = communicator().getProperties().getProperty("Identity"); - Ice.Object @object = new HelloFactoryI(); - adapter.add(@object, Ice.Util.stringToIdentity(id)); + adapter.add(new HelloFactoryI(), Ice.Util.stringToIdentity(id)); adapter.activate(); communicator().waitForShutdown(); diff --git a/cs/demo/IcePack/simple/Client.cs b/cs/demo/IcePack/simple/Client.cs index da5172a07f4..ac5f962ab3b 100644 --- a/cs/demo/IcePack/simple/Client.cs +++ b/cs/demo/IcePack/simple/Client.cs @@ -10,9 +10,9 @@ using System; using Demo; -public class Client +public class Client : Ice.Application { - private static void menu() + private void menu() { Console.WriteLine( "usage:\n" + @@ -28,9 +28,9 @@ public class Client "?: help\n"); } - private static int run(string[] args, Ice.Communicator communicator) + public override int run(string[] args) { - IcePack.QueryPrx query = IcePack.QueryPrxHelper.checkedCast(communicator.stringToProxy("IcePack/Query")); + IcePack.QueryPrx query = IcePack.QueryPrxHelper.checkedCast(communicator().stringToProxy("IcePack/Query")); Ice.ObjectPrx @base = null; try @@ -89,7 +89,7 @@ public class Client } else if(line.Equals("f")) { - communicator.flushBatchRequests(); + communicator().flushBatchRequests(); } else if(line.Equals("T")) { @@ -145,35 +145,8 @@ public class Client public static void Main(string[] args) { - int status = 0; - Ice.Communicator communicator = null; - - try - { - Ice.Properties properties = Ice.Util.createProperties(); - properties.load("config"); - communicator = Ice.Util.initializeWithProperties(ref args, properties); - status = run(args, communicator); - } - catch(Ice.LocalException ex) - { - Console.WriteLine(ex); - status = 1; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(Ice.LocalException ex) - { - Console.WriteLine(ex); - status = 1; - } - } - - Environment.Exit(status); + Client app = new Client(); + int status = app.main(args, "config"); + System.Environment.Exit(status); } } diff --git a/cs/demo/IcePack/simple/Server.cs b/cs/demo/IcePack/simple/Server.cs index 3a19a911340..dc134210344 100644 --- a/cs/demo/IcePack/simple/Server.cs +++ b/cs/demo/IcePack/simple/Server.cs @@ -14,8 +14,7 @@ public class Server : Ice.Application Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Hello"); string id = communicator().getProperties().getProperty("Identity"); - Ice.Object @object = new HelloI(); - adapter.add(@object, Ice.Util.stringToIdentity(id)); + adapter.add(new HelloI(), Ice.Util.stringToIdentity(id)); adapter.activate(); communicator().waitForShutdown(); return 0; @@ -24,6 +23,7 @@ public class Server : Ice.Application static public void Main(string[] args) { Server app = new Server(); - app.main(args); + int status = app.main(args); + System.Environment.Exit(status); } } diff --git a/java/demo/Freeze/bench/README b/java/demo/Freeze/bench/README new file mode 100644 index 00000000000..b22bb16473f --- /dev/null +++ b/java/demo/Freeze/bench/README @@ -0,0 +1,6 @@ +This demo is a simple benchmark to measure the performance of Freeze +for various data types. + +To run the demo, start the client: + +$ java Client diff --git a/java/demo/Glacier2/callback/CallbackClient.java b/java/demo/Glacier2/callback/CallbackClient.java deleted file mode 100644 index 98b73d6b99e..00000000000 --- a/java/demo/Glacier2/callback/CallbackClient.java +++ /dev/null @@ -1,235 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -import Demo.*; - -class CallbackClient extends Ice.Application -{ - private static void - menu() - { - System.out.println( - "usage:\n" + - "t: send callback as twoway\n" + - "o: send callback as oneway\n" + - "O: send callback as batch oneway\n" + - "f: flush all batch requests\n" + - "v: set/reset override context field\n" + - "F: set/reset fake category\n" + - "s: shutdown server\n" + - "x: exit\n" + - "?: help\n"); - } - - public int - run(String[] args) - { - Ice.RouterPrx defaultRouter = communicator().getDefaultRouter(); - if(defaultRouter == null) - { - System.err.println("no default router set"); - return 1; - } - - Glacier2.RouterPrx router = Glacier2.RouterPrxHelper.checkedCast(defaultRouter); - if(router == null) - { - System.err.println("configured router is not a Glacier2 router"); - return 1; - } - - java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); - while(true) - { - System.out.println("This demo accepts any user-id / password combination."); - - try - { - String id; - System.out.print("user id: "); - System.out.flush(); - id = in.readLine(); - - String pw; - System.out.print("password: "); - System.out.flush(); - pw = in.readLine(); - - try - { - router.createSession(id, pw); - break; - } - catch(Glacier2.PermissionDeniedException ex) - { - System.out.println("permission denied:\n" + ex.reason); - } - catch(Glacier2.CannotCreateSessionException ex) - { - System.out.println("cannot create session:\n" + ex.reason); - } - } - catch(java.io.IOException ex) - { - ex.printStackTrace(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } - } - - String category = router.getServerProxy().ice_getIdentity().category; - Ice.Identity callbackReceiverIdent = new Ice.Identity(); - callbackReceiverIdent.name = "callbackReceiver"; - callbackReceiverIdent.category = category; - Ice.Identity callbackReceiverFakeIdent = new Ice.Identity(); - callbackReceiverFakeIdent.name = "callbackReceiver"; - callbackReceiverFakeIdent.category = "fake"; - - Ice.Properties properties = communicator().getProperties(); - final String proxyProperty = "Callback.Proxy"; - String proxy = properties.getProperty(proxyProperty); - if(proxy.length() == 0) - { - System.err.println("property `" + proxyProperty + "' not set"); - return 1; - } - - Ice.ObjectPrx base = communicator().stringToProxy(proxy); - CallbackPrx twoway = CallbackPrxHelper.checkedCast(base); - CallbackPrx oneway = CallbackPrxHelper.uncheckedCast(twoway.ice_oneway()); - CallbackPrx batchOneway = CallbackPrxHelper.uncheckedCast(twoway.ice_batchOneway()); - - Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Client"); - adapter.add(new CallbackReceiverI(), callbackReceiverIdent); - adapter.add(new CallbackReceiverI(), callbackReceiverFakeIdent); - adapter.activate(); - - CallbackReceiverPrx twowayR = CallbackReceiverPrxHelper.uncheckedCast( - adapter.createProxy(callbackReceiverIdent)); - CallbackReceiverPrx onewayR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_oneway()); - - menu(); - - String line = null; - String override = null; - boolean fake = false; - do - { - try - { - System.out.print("==> "); - System.out.flush(); - line = in.readLine(); - if(line == null) - { - break; - } - if(line.equals("t")) - { - java.util.Map context = new java.util.HashMap(); - context.put("_fwd", "t"); - if(override != null) - { - context.put("_ovrd", override); - } - twoway.initiateCallback(twowayR, context); - } - else if(line.equals("o")) - { - java.util.Map context = new java.util.HashMap(); - context.put("_fwd", "o"); - if(override != null) - { - context.put("_ovrd", override); - } - oneway.initiateCallback(onewayR, context); - } - else if(line.equals("O")) - { - java.util.Map context = new java.util.HashMap(); - context.put("_fwd", "O"); - if(override != null) - { - context.put("_ovrd", override); - } - batchOneway.initiateCallback(onewayR, context); - } - else if(line.equals("f")) - { - communicator().flushBatchRequests(); - } - else if(line.equals("v")) - { - if(override == null) - { - override = "some_value"; - System.out.println("override context field is now `" + override + "'"); - } - else - { - override = null; - System.out.println("override context field is empty"); - } - } - else if(line.equals("F")) - { - fake = !fake; - - if(fake) - { - twowayR = CallbackReceiverPrxHelper.uncheckedCast( - twowayR.ice_newIdentity(callbackReceiverFakeIdent)); - onewayR = CallbackReceiverPrxHelper.uncheckedCast( - onewayR.ice_newIdentity(callbackReceiverFakeIdent)); - } - else - { - twowayR = CallbackReceiverPrxHelper.uncheckedCast( - twowayR.ice_newIdentity(callbackReceiverIdent)); - onewayR = CallbackReceiverPrxHelper.uncheckedCast( - onewayR.ice_newIdentity(callbackReceiverIdent)); - } - - System.out.println("callback receiver identity: " + - Ice.Util.identityToString(twowayR.ice_getIdentity())); - } - else if(line.equals("s")) - { - twoway.shutdown(); - } - else if(line.equals("x")) - { - // Nothing to do - } - else if(line.equals("?")) - { - menu(); - } - else - { - System.out.println("unknown command `" + line + "'"); - menu(); - } - } - catch(java.io.IOException ex) - { - ex.printStackTrace(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } - } - while(!line.equals("x")); - - return 0; - } -} diff --git a/java/demo/Glacier2/callback/Client.java b/java/demo/Glacier2/callback/Client.java index 060717e17e8..27dc66792fd 100644 --- a/java/demo/Glacier2/callback/Client.java +++ b/java/demo/Glacier2/callback/Client.java @@ -7,12 +7,236 @@ // // ********************************************************************** -public class Client +import Demo.*; + +public class Client extends Ice.Application { + private static void + menu() + { + System.out.println( + "usage:\n" + + "t: send callback as twoway\n" + + "o: send callback as oneway\n" + + "O: send callback as batch oneway\n" + + "f: flush all batch requests\n" + + "v: set/reset override context field\n" + + "F: set/reset fake category\n" + + "s: shutdown server\n" + + "x: exit\n" + + "?: help\n"); + } + + public int + run(String[] args) + { + Ice.RouterPrx defaultRouter = communicator().getDefaultRouter(); + if(defaultRouter == null) + { + System.err.println("no default router set"); + return 1; + } + + Glacier2.RouterPrx router = Glacier2.RouterPrxHelper.checkedCast(defaultRouter); + if(router == null) + { + System.err.println("configured router is not a Glacier2 router"); + return 1; + } + + java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); + while(true) + { + System.out.println("This demo accepts any user-id / password combination."); + + try + { + String id; + System.out.print("user id: "); + System.out.flush(); + id = in.readLine(); + + String pw; + System.out.print("password: "); + System.out.flush(); + pw = in.readLine(); + + try + { + router.createSession(id, pw); + break; + } + catch(Glacier2.PermissionDeniedException ex) + { + System.out.println("permission denied:\n" + ex.reason); + } + catch(Glacier2.CannotCreateSessionException ex) + { + System.out.println("cannot create session:\n" + ex.reason); + } + } + catch(java.io.IOException ex) + { + ex.printStackTrace(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + + String category = router.getServerProxy().ice_getIdentity().category; + Ice.Identity callbackReceiverIdent = new Ice.Identity(); + callbackReceiverIdent.name = "callbackReceiver"; + callbackReceiverIdent.category = category; + Ice.Identity callbackReceiverFakeIdent = new Ice.Identity(); + callbackReceiverFakeIdent.name = "callbackReceiver"; + callbackReceiverFakeIdent.category = "fake"; + + Ice.Properties properties = communicator().getProperties(); + final String proxyProperty = "Callback.Proxy"; + String proxy = properties.getProperty(proxyProperty); + if(proxy.length() == 0) + { + System.err.println("property `" + proxyProperty + "' not set"); + return 1; + } + + Ice.ObjectPrx base = communicator().stringToProxy(proxy); + CallbackPrx twoway = CallbackPrxHelper.checkedCast(base); + CallbackPrx oneway = CallbackPrxHelper.uncheckedCast(twoway.ice_oneway()); + CallbackPrx batchOneway = CallbackPrxHelper.uncheckedCast(twoway.ice_batchOneway()); + + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Client"); + adapter.add(new CallbackReceiverI(), callbackReceiverIdent); + adapter.add(new CallbackReceiverI(), callbackReceiverFakeIdent); + adapter.activate(); + + CallbackReceiverPrx twowayR = CallbackReceiverPrxHelper.uncheckedCast( + adapter.createProxy(callbackReceiverIdent)); + CallbackReceiverPrx onewayR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_oneway()); + + menu(); + + String line = null; + String override = null; + boolean fake = false; + do + { + try + { + System.out.print("==> "); + System.out.flush(); + line = in.readLine(); + if(line == null) + { + break; + } + if(line.equals("t")) + { + java.util.Map context = new java.util.HashMap(); + context.put("_fwd", "t"); + if(override != null) + { + context.put("_ovrd", override); + } + twoway.initiateCallback(twowayR, context); + } + else if(line.equals("o")) + { + java.util.Map context = new java.util.HashMap(); + context.put("_fwd", "o"); + if(override != null) + { + context.put("_ovrd", override); + } + oneway.initiateCallback(onewayR, context); + } + else if(line.equals("O")) + { + java.util.Map context = new java.util.HashMap(); + context.put("_fwd", "O"); + if(override != null) + { + context.put("_ovrd", override); + } + batchOneway.initiateCallback(onewayR, context); + } + else if(line.equals("f")) + { + communicator().flushBatchRequests(); + } + else if(line.equals("v")) + { + if(override == null) + { + override = "some_value"; + System.out.println("override context field is now `" + override + "'"); + } + else + { + override = null; + System.out.println("override context field is empty"); + } + } + else if(line.equals("F")) + { + fake = !fake; + + if(fake) + { + twowayR = CallbackReceiverPrxHelper.uncheckedCast( + twowayR.ice_newIdentity(callbackReceiverFakeIdent)); + onewayR = CallbackReceiverPrxHelper.uncheckedCast( + onewayR.ice_newIdentity(callbackReceiverFakeIdent)); + } + else + { + twowayR = CallbackReceiverPrxHelper.uncheckedCast( + twowayR.ice_newIdentity(callbackReceiverIdent)); + onewayR = CallbackReceiverPrxHelper.uncheckedCast( + onewayR.ice_newIdentity(callbackReceiverIdent)); + } + + System.out.println("callback receiver identity: " + + Ice.Util.identityToString(twowayR.ice_getIdentity())); + } + else if(line.equals("s")) + { + twoway.shutdown(); + } + else if(line.equals("x")) + { + // Nothing to do + } + else if(line.equals("?")) + { + menu(); + } + else + { + System.out.println("unknown command `" + line + "'"); + menu(); + } + } + catch(java.io.IOException ex) + { + ex.printStackTrace(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + while(!line.equals("x")); + + return 0; + } + public static void main(String[] args) { - CallbackClient app = new CallbackClient(); + Client app = new Client(); int status = app.main("Client", args, "config"); System.exit(status); } diff --git a/java/demo/Glacier2/callback/Server.java b/java/demo/Glacier2/callback/Server.java index 56f04bf8085..fa8a9060ed2 100644 --- a/java/demo/Glacier2/callback/Server.java +++ b/java/demo/Glacier2/callback/Server.java @@ -7,12 +7,24 @@ // // ********************************************************************** -public class Server +import Demo.*; + +public class Server extends Ice.Application { + public int + run(String[] args) + { + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Server"); + adapter.add(new CallbackI(), Ice.Util.stringToIdentity("callback")); + adapter.activate(); + communicator().waitForShutdown(); + return 0; + } + public static void main(String[] args) { - CallbackServer app = new CallbackServer(); + Server app = new Server(); int status = app.main("Server", args, "config.server"); System.exit(status); } diff --git a/java/demo/Ice/README b/java/demo/Ice/README index e9c6ea12b20..90165ee7ca2 100644 --- a/java/demo/Ice/README +++ b/java/demo/Ice/README @@ -1,5 +1,9 @@ Demos in this directory: +- minimal + + This demo illustrates a minimal Ice application. + - bidir This demo shows how to use bi-directional connections for diff --git a/java/demo/Ice/bidir/CallbackClient.java b/java/demo/Ice/bidir/CallbackClient.java deleted file mode 100755 index d25cfa55fbd..00000000000 --- a/java/demo/Ice/bidir/CallbackClient.java +++ /dev/null @@ -1,46 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -import Demo.*; - -class CallbackClient extends Ice.Application -{ - public int - run(String[] args) - { - Ice.Properties properties = communicator().getProperties(); - final String proxyProperty = "Callback.Client.CallbackServer"; - String proxy = properties.getProperty(proxyProperty); - if(proxy.length() == 0) - { - System.err.println("property `" + proxyProperty + "' not set"); - return 1; - } - - Ice.ObjectPrx base = communicator().stringToProxy(proxy); - CallbackSenderPrx server = CallbackSenderPrxHelper.checkedCast(base); - if(server == null) - { - System.err.println("invalid proxy"); - return 1; - } - - Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Client"); - Ice.Identity ident = new Ice.Identity(); - ident.name = Ice.Util.generateUUID(); - ident.category = ""; - adapter.add(new CallbackReceiverI(), ident); - adapter.activate(); - server.ice_connection().setAdapter(adapter); - server.addClient(ident); - communicator().waitForShutdown(); - - return 0; - } -} diff --git a/java/demo/Ice/bidir/CallbackReceiverI.java b/java/demo/Ice/bidir/CallbackReceiverI.java index bbc4a4b137d..5fe3bbc78f0 100755 --- a/java/demo/Ice/bidir/CallbackReceiverI.java +++ b/java/demo/Ice/bidir/CallbackReceiverI.java @@ -6,18 +6,18 @@ // ICE_LICENSE file included in this distribution. // // ********************************************************************** -
-import Demo.*;
-
-class CallbackReceiverI extends _CallbackReceiverDisp
-{
- CallbackReceiverI()
- {
- }
-
- public void
- callback(int num, Ice.Current current)
- {
- System.out.println("received callback #" + num);
- }
-}
+ +import Demo.*; + +class CallbackReceiverI extends _CallbackReceiverDisp +{ + CallbackReceiverI() + { + } + + public void + callback(int num, Ice.Current current) + { + System.out.println("received callback #" + num); + } +} diff --git a/java/demo/Ice/bidir/CallbackSenderI.java b/java/demo/Ice/bidir/CallbackSenderI.java index ddc861f9ecb..78457d9246c 100755 --- a/java/demo/Ice/bidir/CallbackSenderI.java +++ b/java/demo/Ice/bidir/CallbackSenderI.java @@ -11,13 +11,6 @@ import Demo.*; class CallbackSenderI extends _CallbackSenderDisp implements java.lang.Runnable { - CallbackSenderI() - { - _destroy = false; - _num = 0; - _clients = new java.util.Vector(); - } - synchronized public void destroy() { @@ -73,7 +66,7 @@ class CallbackSenderI extends _CallbackSenderDisp implements java.lang.Runnable } } - private boolean _destroy; - private int _num; - private java.util.Vector _clients; + private boolean _destroy = false; + private int _num = 0; + private java.util.Vector _clients = new java.util.Vector(); } diff --git a/java/demo/Ice/bidir/CallbackServer.java b/java/demo/Ice/bidir/CallbackServer.java deleted file mode 100755 index 5aaee148385..00000000000 --- a/java/demo/Ice/bidir/CallbackServer.java +++ /dev/null @@ -1,43 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** -
-import Demo.*;
-
-class CallbackServer extends Ice.Application
-{
- public int
- run(String[] args)
- {
- Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Server");
- CallbackSenderI sender = new CallbackSenderI();
- adapter.add(sender, Ice.Util.stringToIdentity("sender"));
- adapter.activate();
-
- Thread t = new Thread(sender);
- t.start();
-
- try
- {
- communicator().waitForShutdown();
- }
- finally
- {
- sender.destroy();
- try
- {
- t.join();
- }
- catch(java.lang.InterruptedException ex)
- {
- }
- }
-
- return 0;
- }
-}
diff --git a/java/demo/Ice/bidir/Client.java b/java/demo/Ice/bidir/Client.java index 060717e17e8..c54c24eba18 100755 --- a/java/demo/Ice/bidir/Client.java +++ b/java/demo/Ice/bidir/Client.java @@ -7,12 +7,46 @@ // // ********************************************************************** -public class Client +import Demo.*; + +public class Client extends Ice.Application { + public int + run(String[] args) + { + Ice.Properties properties = communicator().getProperties(); + final String proxyProperty = "Callback.Client.CallbackServer"; + String proxy = properties.getProperty(proxyProperty); + if(proxy.length() == 0) + { + System.err.println("property `" + proxyProperty + "' not set"); + return 1; + } + + CallbackSenderPrx server = CallbackSenderPrxHelper.checkedCast(communicator().stringToProxy(proxy)); + if(server == null) + { + System.err.println("invalid proxy"); + return 1; + } + + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Client"); + Ice.Identity ident = new Ice.Identity(); + ident.name = Ice.Util.generateUUID(); + ident.category = ""; + adapter.add(new CallbackReceiverI(), ident); + adapter.activate(); + server.ice_connection().setAdapter(adapter); + server.addClient(ident); + communicator().waitForShutdown(); + + return 0; + } + public static void main(String[] args) { - CallbackClient app = new CallbackClient(); + Client app = new Client(); int status = app.main("Client", args, "config"); System.exit(status); } diff --git a/java/demo/Ice/bidir/README b/java/demo/Ice/bidir/README new file mode 100644 index 00000000000..def66e6f7c0 --- /dev/null +++ b/java/demo/Ice/bidir/README @@ -0,0 +1,12 @@ +This demo shows how to use bi-directional connections for +callbacks. This is typically used if the server cannot open a +connection to the client to send callbacks, for example, because +firewalls block incoming connections to the client. + +To run the demo, first start the server: + +$ java Server + +In a separate window, start the client: + +$ java Client diff --git a/java/demo/Ice/bidir/Server.java b/java/demo/Ice/bidir/Server.java index aff0e12818c..0971f0eae01 100755 --- a/java/demo/Ice/bidir/Server.java +++ b/java/demo/Ice/bidir/Server.java @@ -7,12 +7,44 @@ // // ********************************************************************** -public class Server +import Demo.*; + +public class Server extends Ice.Application { + public int + run(String[] args) + { + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Server"); + CallbackSenderI sender = new CallbackSenderI(); + adapter.add(sender, Ice.Util.stringToIdentity("sender")); + adapter.activate(); + + Thread t = new Thread(sender); + t.start(); + + try + { + communicator().waitForShutdown(); + } + finally + { + sender.destroy(); + try + { + t.join(); + } + catch(java.lang.InterruptedException ex) + { + } + } + + return 0; + } + public static void main(String[] args) { - CallbackServer app = new CallbackServer(); + Server app = new Server(); int status = app.main("Server", args, "config"); System.exit(status); } diff --git a/java/demo/Ice/build.xml b/java/demo/Ice/build.xml index 58576e43d28..780b11a8ea4 100644 --- a/java/demo/Ice/build.xml +++ b/java/demo/Ice/build.xml @@ -17,6 +17,7 @@ <ant dir="hello"/> <ant dir="invoke"/> <ant dir="latency"/> + <ant dir="minimal"/> <ant dir="nested"/> <ant dir="throughput"/> <ant dir="value"/> @@ -29,6 +30,7 @@ <ant dir="hello" target="clean"/> <ant dir="invoke" target="clean"/> <ant dir="latency" target="clean"/> + <ant dir="minimal" target="clean"/> <ant dir="nested" target="clean"/> <ant dir="throughput" target="clean"/> <ant dir="value" target="clean"/> diff --git a/java/demo/Ice/callback/CallbackClient.java b/java/demo/Ice/callback/CallbackClient.java deleted file mode 100644 index d962a32d9fe..00000000000 --- a/java/demo/Ice/callback/CallbackClient.java +++ /dev/null @@ -1,178 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -import Demo.*; - -class CallbackClient extends Ice.Application -{ - private static void - menu() - { - System.out.println( - "usage:\n" + - "t: send callback as twoway\n" + - "o: send callback as oneway\n" + - "O: send callback as batch oneway\n" + - "d: send callback as datagram\n" + - "D: send callback as batch datagram\n" + - "f: flush all batch requests\n" + - "S: switch secure mode on/off\n" + - "s: shutdown server\n" + - "x: exit\n" + - "?: help\n"); - } - - public int - run(String[] args) - { - Ice.Properties properties = communicator().getProperties(); - final String proxyProperty = "Callback.Client.CallbackServer"; - String proxy = properties.getProperty(proxyProperty); - if(proxy.length() == 0) - { - System.err.println("property `" + proxyProperty + "' not set"); - return 1; - } - - Ice.ObjectPrx base = communicator().stringToProxy(proxy); - CallbackSenderPrx twoway = - CallbackSenderPrxHelper.checkedCast(base.ice_twoway().ice_timeout(-1).ice_secure(false)); - if(twoway == null) - { - System.err.println("invalid proxy"); - return 1; - } - CallbackSenderPrx oneway = CallbackSenderPrxHelper.uncheckedCast(twoway.ice_oneway()); - CallbackSenderPrx batchOneway = CallbackSenderPrxHelper.uncheckedCast(twoway.ice_batchOneway()); - CallbackSenderPrx datagram = CallbackSenderPrxHelper.uncheckedCast(twoway.ice_datagram()); - CallbackSenderPrx batchDatagram = CallbackSenderPrxHelper.uncheckedCast(twoway.ice_batchDatagram()); - - Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Client"); - adapter.add(new CallbackReceiverI(), Ice.Util.stringToIdentity("callbackReceiver")); - adapter.activate(); - - CallbackReceiverPrx twowayR = - CallbackReceiverPrxHelper.uncheckedCast(adapter.createProxy( - Ice.Util.stringToIdentity("callbackReceiver"))); - CallbackReceiverPrx onewayR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_oneway()); - CallbackReceiverPrx datagramR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_datagram()); - - boolean secure = false; - String secureStr = ""; - - menu(); - - java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); - - String line = null; - do - { - try - { - System.out.print("==> "); - System.out.flush(); - line = in.readLine(); - if(line == null) - { - break; - } - if(line.equals("t")) - { - twoway.initiateCallback(twowayR); - } - else if(line.equals("o")) - { - oneway.initiateCallback(onewayR); - } - else if(line.equals("O")) - { - batchOneway.initiateCallback(onewayR); - } - else if(line.equals("d")) - { - if(secure) - { - System.out.println("secure datagrams are not supported"); - } - else - { - datagram.initiateCallback(datagramR); - } - } - else if(line.equals("D")) - { - if(secure) - { - System.out.println("secure datagrams are not supported"); - } - else - { - batchDatagram.initiateCallback(datagramR); - } - } - else if(line.equals("S")) - { - secure = !secure; - secureStr = secure ? "s" : ""; - - twoway = CallbackSenderPrxHelper.uncheckedCast(twoway.ice_secure(secure)); - oneway = CallbackSenderPrxHelper.uncheckedCast(oneway.ice_secure(secure)); - batchOneway = CallbackSenderPrxHelper.uncheckedCast(batchOneway.ice_secure(secure)); - datagram = CallbackSenderPrxHelper.uncheckedCast(datagram.ice_secure(secure)); - batchDatagram = CallbackSenderPrxHelper.uncheckedCast(batchDatagram.ice_secure(secure)); - - twowayR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_secure(secure)); - onewayR = CallbackReceiverPrxHelper.uncheckedCast(onewayR.ice_secure(secure)); - datagramR = CallbackReceiverPrxHelper.uncheckedCast(datagramR.ice_secure(secure)); - - if(secure) - { - System.out.println("secure mode is now on"); - } - else - { - System.out.println("secure mode is now off"); - } - } - else if(line.equals("f")) - { - communicator().flushBatchRequests(); - } - else if(line.equals("s")) - { - twoway.shutdown(); - } - else if(line.equals("x")) - { - // Nothing to do - } - else if(line.equals("?")) - { - menu(); - } - else - { - System.out.println("unknown command `" + line + "'"); - menu(); - } - } - catch(java.io.IOException ex) - { - ex.printStackTrace(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } - } - while(!line.equals("x")); - - return 0; - } -} diff --git a/java/demo/Ice/callback/CallbackServer.java b/java/demo/Ice/callback/CallbackServer.java deleted file mode 100644 index 3a55c49d30e..00000000000 --- a/java/demo/Ice/callback/CallbackServer.java +++ /dev/null @@ -1,23 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -import Demo.*; - -class CallbackServer extends Ice.Application -{ - public int - run(String[] args) - { - Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Server"); - adapter.add(new CallbackSenderI(), Ice.Util.stringToIdentity("callback")); - adapter.activate(); - communicator().waitForShutdown(); - return 0; - } -} diff --git a/java/demo/Ice/callback/Client.java b/java/demo/Ice/callback/Client.java index 060717e17e8..e5c1620e6af 100644 --- a/java/demo/Ice/callback/Client.java +++ b/java/demo/Ice/callback/Client.java @@ -7,12 +7,178 @@ // // ********************************************************************** -public class Client +import Demo.*; + +public class Client extends Ice.Application { + private static void + menu() + { + System.out.println( + "usage:\n" + + "t: send callback as twoway\n" + + "o: send callback as oneway\n" + + "O: send callback as batch oneway\n" + + "d: send callback as datagram\n" + + "D: send callback as batch datagram\n" + + "f: flush all batch requests\n" + + "S: switch secure mode on/off\n" + + "s: shutdown server\n" + + "x: exit\n" + + "?: help\n"); + } + + public int + run(String[] args) + { + Ice.Properties properties = communicator().getProperties(); + final String proxyProperty = "Callback.Client.CallbackServer"; + String proxy = properties.getProperty(proxyProperty); + if(proxy.length() == 0) + { + System.err.println("property `" + proxyProperty + "' not set"); + return 1; + } + + CallbackSenderPrx twoway = CallbackSenderPrxHelper.checkedCast( + communicator().stringToProxy(proxy).ice_twoway().ice_timeout(-1).ice_secure(false)); + if(twoway == null) + { + System.err.println("invalid proxy"); + return 1; + } + CallbackSenderPrx oneway = CallbackSenderPrxHelper.uncheckedCast(twoway.ice_oneway()); + CallbackSenderPrx batchOneway = CallbackSenderPrxHelper.uncheckedCast(twoway.ice_batchOneway()); + CallbackSenderPrx datagram = CallbackSenderPrxHelper.uncheckedCast(twoway.ice_datagram()); + CallbackSenderPrx batchDatagram = CallbackSenderPrxHelper.uncheckedCast(twoway.ice_batchDatagram()); + + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Client"); + adapter.add(new CallbackReceiverI(), Ice.Util.stringToIdentity("callbackReceiver")); + adapter.activate(); + + CallbackReceiverPrx twowayR = + CallbackReceiverPrxHelper.uncheckedCast(adapter.createProxy( + Ice.Util.stringToIdentity("callbackReceiver"))); + CallbackReceiverPrx onewayR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_oneway()); + CallbackReceiverPrx datagramR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_datagram()); + + boolean secure = false; + String secureStr = ""; + + menu(); + + java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); + + String line = null; + do + { + try + { + System.out.print("==> "); + System.out.flush(); + line = in.readLine(); + if(line == null) + { + break; + } + if(line.equals("t")) + { + twoway.initiateCallback(twowayR); + } + else if(line.equals("o")) + { + oneway.initiateCallback(onewayR); + } + else if(line.equals("O")) + { + batchOneway.initiateCallback(onewayR); + } + else if(line.equals("d")) + { + if(secure) + { + System.out.println("secure datagrams are not supported"); + } + else + { + datagram.initiateCallback(datagramR); + } + } + else if(line.equals("D")) + { + if(secure) + { + System.out.println("secure datagrams are not supported"); + } + else + { + batchDatagram.initiateCallback(datagramR); + } + } + else if(line.equals("S")) + { + secure = !secure; + secureStr = secure ? "s" : ""; + + twoway = CallbackSenderPrxHelper.uncheckedCast(twoway.ice_secure(secure)); + oneway = CallbackSenderPrxHelper.uncheckedCast(oneway.ice_secure(secure)); + batchOneway = CallbackSenderPrxHelper.uncheckedCast(batchOneway.ice_secure(secure)); + datagram = CallbackSenderPrxHelper.uncheckedCast(datagram.ice_secure(secure)); + batchDatagram = CallbackSenderPrxHelper.uncheckedCast(batchDatagram.ice_secure(secure)); + + twowayR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_secure(secure)); + onewayR = CallbackReceiverPrxHelper.uncheckedCast(onewayR.ice_secure(secure)); + datagramR = CallbackReceiverPrxHelper.uncheckedCast(datagramR.ice_secure(secure)); + + if(secure) + { + System.out.println("secure mode is now on"); + } + else + { + System.out.println("secure mode is now off"); + } + } + else if(line.equals("f")) + { + communicator().flushBatchRequests(); + } + else if(line.equals("s")) + { + twoway.shutdown(); + } + else if(line.equals("x")) + { + // Nothing to do + } + else if(line.equals("?")) + { + menu(); + } + else + { + System.out.println("unknown command `" + line + "'"); + menu(); + } + } + catch(java.io.IOException ex) + { + ex.printStackTrace(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + while(!line.equals("x")); + + return 0; + } + public static void main(String[] args) { - CallbackClient app = new CallbackClient(); + Client app = new Client(); int status = app.main("Client", args, "config"); System.exit(status); } diff --git a/java/demo/Ice/callback/README b/java/demo/Ice/callback/README new file mode 100644 index 00000000000..3c327b8f60f --- /dev/null +++ b/java/demo/Ice/callback/README @@ -0,0 +1,11 @@ +A simple callback demo that illustrates how a client can pass a proxy +to a server, invoke an operation in the server, and the server call +back into an object provided by the client as part of that invocation. + +To run the demo, first start the server: + +$ java Server + +In a separate window, start the client: + +$ java Client diff --git a/java/demo/Ice/callback/Server.java b/java/demo/Ice/callback/Server.java index aff0e12818c..e62d1ec07e8 100644 --- a/java/demo/Ice/callback/Server.java +++ b/java/demo/Ice/callback/Server.java @@ -7,12 +7,24 @@ // // ********************************************************************** -public class Server +import Demo.*; + +public class Server extends Ice.Application { + public int + run(String[] args) + { + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Server"); + adapter.add(new CallbackSenderI(), Ice.Util.stringToIdentity("callback")); + adapter.activate(); + communicator().waitForShutdown(); + return 0; + } + public static void main(String[] args) { - CallbackServer app = new CallbackServer(); + Server app = new Server(); int status = app.main("Server", args, "config"); System.exit(status); } diff --git a/java/demo/Ice/hello/Client.java b/java/demo/Ice/hello/Client.java index ed4b39b89ca..ba39718b957 100644 --- a/java/demo/Ice/hello/Client.java +++ b/java/demo/Ice/hello/Client.java @@ -9,7 +9,7 @@ import Demo.*; -public class Client +public class Client extends Ice.Application { private static void menu() @@ -29,10 +29,10 @@ public class Client "?: help\n"); } - private static int - run(String[] args, Ice.Communicator communicator) + public int + run(String[] args) { - Ice.Properties properties = communicator.getProperties(); + Ice.Properties properties = communicator().getProperties(); final String proxyProperty = "Hello.Proxy"; String proxy = properties.getProperty(proxyProperty); if(proxy.length() == 0) @@ -41,8 +41,8 @@ public class Client return 1; } - Ice.ObjectPrx base = communicator.stringToProxy(proxy); - HelloPrx twoway = HelloPrxHelper.checkedCast(base.ice_twoway().ice_timeout(-1).ice_secure(false)); + HelloPrx twoway = HelloPrxHelper.checkedCast( + communicator().stringToProxy(proxy).ice_twoway().ice_timeout(-1).ice_secure(false)); if(twoway == null) { System.err.println("invalid proxy"); @@ -108,7 +108,7 @@ public class Client } else if(line.equals("f")) { - communicator.flushBatchRequests(); + communicator().flushBatchRequests(); } else if(line.equals("T")) { @@ -188,35 +188,8 @@ public class Client public static void main(String[] args) { - int status = 0; - Ice.Communicator communicator = null; - - try - { - Ice.Properties properties = Ice.Util.createProperties(); - properties.load("config"); - communicator = Ice.Util.initializeWithProperties(args, properties); - status = run(args, communicator); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - } - + Client app = new Client(); + int status = app.main("Client", args, "config"); System.exit(status); } } diff --git a/java/demo/Ice/hello/README b/java/demo/Ice/hello/README new file mode 100644 index 00000000000..4ccfddd8f3b --- /dev/null +++ b/java/demo/Ice/hello/README @@ -0,0 +1,11 @@ +This demo illustrates how to invoke ordinary (twoway) +operations, as well as how to make oneway, datagram, +secure, and batched invocations. + +To run the demo, first start the server: + +$ java Server + +In a separate window, start the client: + +$ java Client diff --git a/java/demo/Ice/hello/Server.java b/java/demo/Ice/hello/Server.java index 10bd5b1352a..b486c45d52e 100644 --- a/java/demo/Ice/hello/Server.java +++ b/java/demo/Ice/hello/Server.java @@ -9,51 +9,23 @@ import Demo.*; -public class Server +public class Server extends Ice.Application { - private static int - run(String[] args, Ice.Communicator communicator) + public int + run(String[] args) { - Ice.ObjectAdapter adapter = communicator.createObjectAdapter("Hello"); - Ice.Object object = new HelloI(); - adapter.add(object, Ice.Util.stringToIdentity("hello")); + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Hello"); + adapter.add(new HelloI(), Ice.Util.stringToIdentity("hello")); adapter.activate(); - communicator.waitForShutdown(); + communicator().waitForShutdown(); return 0; } public static void main(String[] args) { - int status = 0; - Ice.Communicator communicator = null; - - try - { - Ice.Properties properties = Ice.Util.createProperties(); - properties.load("config"); - communicator = Ice.Util.initializeWithProperties(args, properties); - status = run(args, communicator); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - } - + Server app = new Server(); + int status = app.main("Server", args, "config"); System.exit(status); } } diff --git a/java/demo/Ice/invoke/Client.java b/java/demo/Ice/invoke/Client.java index 223ef32195f..bc687bddb4c 100644 --- a/java/demo/Ice/invoke/Client.java +++ b/java/demo/Ice/invoke/Client.java @@ -9,7 +9,7 @@ import Demo.*; -public class Client +public class Client extends Ice.Application { private static void menu() @@ -30,10 +30,10 @@ public class Client "?: help\n"); } - private static int - run(String[] args, Ice.Communicator communicator) + public int + run(String[] args) { - Ice.Properties properties = communicator.getProperties(); + Ice.Properties properties = communicator().getProperties(); final String proxyProperty = "Printer.Proxy"; String proxy = properties.getProperty(proxyProperty); if(proxy.length() == 0) @@ -42,7 +42,7 @@ public class Client return 1; } - Ice.ObjectPrx obj = communicator.stringToProxy(proxy); + Ice.ObjectPrx obj = communicator().stringToProxy(proxy); menu(); @@ -65,7 +65,7 @@ public class Client // // Marshal the in parameter. // - Ice.OutputStream out = Ice.Util.createOutputStream(communicator); + Ice.OutputStream out = Ice.Util.createOutputStream(communicator()); out.writeString("The streaming API works!"); // @@ -83,7 +83,7 @@ public class Client // // Marshal the in parameter. // - Ice.OutputStream out = Ice.Util.createOutputStream(communicator); + Ice.OutputStream out = Ice.Util.createOutputStream(communicator()); final String[] arr = { "The", "streaming", "API", "works!" }; Demo.StringSeqHelper.write(out, arr); @@ -102,7 +102,7 @@ public class Client // // Marshal the in parameter. // - Ice.OutputStream out = Ice.Util.createOutputStream(communicator); + Ice.OutputStream out = Ice.Util.createOutputStream(communicator()); java.util.Map dict = new java.util.HashMap(); dict.put("The", "streaming"); dict.put("API", "works!"); @@ -123,7 +123,7 @@ public class Client // // Marshal the in parameter. // - Ice.OutputStream out = Ice.Util.createOutputStream(communicator); + Ice.OutputStream out = Ice.Util.createOutputStream(communicator()); Demo.Color.green.__write(out); // @@ -141,7 +141,7 @@ public class Client // // Marshal the in parameter. // - Ice.OutputStream out = Ice.Util.createOutputStream(communicator); + Ice.OutputStream out = Ice.Util.createOutputStream(communicator()); Demo.Structure s = new Demo.Structure(); s.name = "red"; s.value = Demo.Color.red; @@ -162,7 +162,7 @@ public class Client // // Marshal the in parameter. // - Ice.OutputStream out = Ice.Util.createOutputStream(communicator); + Ice.OutputStream out = Ice.Util.createOutputStream(communicator()); Demo.Structure[] arr = new Demo.Structure[3]; arr[0] = new Demo.Structure(); arr[0].name = "red"; @@ -190,7 +190,7 @@ public class Client // // Marshal the in parameter. // - Ice.OutputStream out = Ice.Util.createOutputStream(communicator); + Ice.OutputStream out = Ice.Util.createOutputStream(communicator()); Demo.C c = new Demo.C(); c.s = new Demo.Structure(); c.s.name = "blue"; @@ -223,7 +223,7 @@ public class Client // // Unmarshal the results. // - Ice.InputStream in = Ice.Util.createInputStream(communicator, outParams.value); + Ice.InputStream in = Ice.Util.createInputStream(communicator(), outParams.value); Demo.CHolder c = new Demo.CHolder(); Demo.CHelper.read(in, c); String str = in.readString(); @@ -244,7 +244,7 @@ public class Client continue; } - Ice.InputStream in = Ice.Util.createInputStream(communicator, outParams.value); + Ice.InputStream in = Ice.Util.createInputStream(communicator(), outParams.value); try { in.throwException(); @@ -294,35 +294,8 @@ public class Client public static void main(String[] args) { - int status = 0; - Ice.Communicator communicator = null; - - try - { - Ice.Properties properties = Ice.Util.createProperties(); - properties.load("config"); - communicator = Ice.Util.initializeWithProperties(args, properties); - status = run(args, communicator); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - } - + Client app = new Client(); + int status = app.main("Client", args, "config"); System.exit(status); } } diff --git a/java/demo/Ice/invoke/README b/java/demo/Ice/invoke/README new file mode 100644 index 00000000000..cd086ebeb42 --- /dev/null +++ b/java/demo/Ice/invoke/README @@ -0,0 +1,9 @@ +This demo illustrates the use of the Ice streaming API. + +To run the demo, first start the server: + +$ java Server + +In a separate window, start the client: + +$ java Client diff --git a/java/demo/Ice/invoke/Server.java b/java/demo/Ice/invoke/Server.java index f82de481416..9f97355ea30 100644 --- a/java/demo/Ice/invoke/Server.java +++ b/java/demo/Ice/invoke/Server.java @@ -9,51 +9,23 @@ import Demo.*; -public class Server +public class Server extends Ice.Application { - private static int - run(String[] args, Ice.Communicator communicator) + public int + run(String[] args) { - Ice.ObjectAdapter adapter = communicator.createObjectAdapter("Printer"); - Ice.Object object = new PrinterI(); - adapter.add(object, Ice.Util.stringToIdentity("printer")); + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Printer"); + adapter.add(new PrinterI(), Ice.Util.stringToIdentity("printer")); adapter.activate(); - communicator.waitForShutdown(); + communicator().waitForShutdown(); return 0; } public static void main(String[] args) { - int status = 0; - Ice.Communicator communicator = null; - - try - { - Ice.Properties properties = Ice.Util.createProperties(); - properties.load("config"); - communicator = Ice.Util.initializeWithProperties(args, properties); - status = run(args, communicator); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - } - + Server app = new Server(); + int status = app.main("Server", args, "config"); System.exit(status); } } diff --git a/java/demo/Ice/latency/Client.java b/java/demo/Ice/latency/Client.java index b27d6eab317..f641c861fb0 100644 --- a/java/demo/Ice/latency/Client.java +++ b/java/demo/Ice/latency/Client.java @@ -9,12 +9,12 @@ import Demo.*; -public class Client +class Client extends Ice.Application { - private static int - run(String[] args, Ice.Communicator communicator) + public int + run(String[] args) { - Ice.Properties properties = communicator.getProperties(); + Ice.Properties properties = communicator().getProperties(); final String refProperty = "Latency.Ping"; String ref = properties.getProperty(refProperty); if(ref.length() == 0) @@ -23,8 +23,7 @@ public class Client return 1; } - Ice.ObjectPrx base = communicator.stringToProxy(ref); - PingPrx ping = PingPrxHelper.checkedCast(base); + PingPrx ping = PingPrxHelper.checkedCast(communicator().stringToProxy(ref)); if(ping == null) { System.err.println("invalid proxy"); @@ -55,35 +54,8 @@ public class Client public static void main(String[] args) { - int status = 0; - Ice.Communicator communicator = null; - - try - { - Ice.Properties properties = Ice.Util.createProperties(); - properties.load("config"); - communicator = Ice.Util.initializeWithProperties(args, properties); - status = run(args, communicator); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - } - + Client app = new Client(); + int status = app.main("Client", args, "config"); System.exit(status); } } diff --git a/java/demo/Ice/latency/README b/java/demo/Ice/latency/README new file mode 100644 index 00000000000..887b526f6f9 --- /dev/null +++ b/java/demo/Ice/latency/README @@ -0,0 +1,10 @@ +A simple latency test that measures the basic call dispatch +delay of Ice. + +To run the demo, first start the server: + +$ java Server + +In a separate window, start the client: + +$ java Client diff --git a/java/demo/Ice/latency/Server.java b/java/demo/Ice/latency/Server.java index 5f94a75e15c..2791908994c 100644 --- a/java/demo/Ice/latency/Server.java +++ b/java/demo/Ice/latency/Server.java @@ -9,51 +9,23 @@ import Demo.*; -public class Server +public class Server extends Ice.Application { - private static int - run(String[] args, Ice.Communicator communicator) + public int + run(String[] args) { - Ice.ObjectAdapter adapter = communicator.createObjectAdapter("Latency"); - Ice.Object object = new Ping(); - adapter.add(object, Ice.Util.stringToIdentity("ping")); + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Latency"); + adapter.add(new Ping(), Ice.Util.stringToIdentity("ping")); adapter.activate(); - communicator.waitForShutdown(); + communicator().waitForShutdown(); return 0; } public static void main(String[] args) { - int status = 0; - Ice.Communicator communicator = null; - - try - { - Ice.Properties properties = Ice.Util.createProperties(); - properties.load("config"); - communicator = Ice.Util.initializeWithProperties(args, properties); - status = run(args, communicator); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - } - + Server app = new Server(); + int status = app.main("Server", args, "config"); System.exit(status); } } diff --git a/java/demo/Ice/minimal/Client.java b/java/demo/Ice/minimal/Client.java new file mode 100755 index 00000000000..766b8a7b659 --- /dev/null +++ b/java/demo/Ice/minimal/Client.java @@ -0,0 +1,125 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +import Demo.*; + +public class Client +{ + private static void + menu() + { + System.out.println( + "usage:\n" + + "h: send greeting\n" + + "x: exit\n" + + "?: help\n"); + } + + private static int + run(String[] args, Ice.Communicator communicator) + { + Ice.Properties properties = communicator.getProperties(); + final String proxyProperty = "Hello.Proxy"; + String proxy = properties.getProperty(proxyProperty); + if(proxy.length() == 0) + { + System.err.println("property `" + proxyProperty + "' not set"); + return 1; + } + + HelloPrx hello = HelloPrxHelper.checkedCast(communicator.stringToProxy(proxy)); + if(hello == null) + { + System.err.println("invalid proxy"); + return 1; + } + + menu(); + + java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); + + String line = null; + do + { + try + { + System.out.print("==> "); + System.out.flush(); + line = in.readLine(); + if(line == null) + { + break; + } + if(line.equals("h")) + { + hello.sayHello(); + } + else if(line.equals("x")) + { + // Nothing to do + } + else if(line.equals("?")) + { + menu(); + } + else + { + System.out.println("unknown command `" + line + "'"); + menu(); + } + } + catch(java.io.IOException ex) + { + ex.printStackTrace(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + while(!line.equals("x")); + + return 0; + } + + public static void + main(String[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + try + { + Ice.Properties properties = Ice.Util.createProperties(); + properties.load("config"); + communicator = Ice.Util.initializeWithProperties(args, properties); + status = run(args, communicator); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + status = 1; + } + + if(communicator != null) + { + try + { + communicator.destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + status = 1; + } + } + + System.exit(status); + } +} diff --git a/java/demo/Ice/minimal/Hello.ice b/java/demo/Ice/minimal/Hello.ice new file mode 100644 index 00000000000..1e35e0829fa --- /dev/null +++ b/java/demo/Ice/minimal/Hello.ice @@ -0,0 +1,23 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef HELLO_ICE +#define HELLO_ICE + +module Demo +{ + +interface Hello +{ + nonmutating void sayHello(); +}; + +}; + +#endif diff --git a/java/demo/Glacier2/callback/CallbackServer.java b/java/demo/Ice/minimal/HelloI.java index 302f4770154..14737d3c46a 100644 --- a/java/demo/Glacier2/callback/CallbackServer.java +++ b/java/demo/Ice/minimal/HelloI.java @@ -9,15 +9,11 @@ import Demo.*; -class CallbackServer extends Ice.Application +public class HelloI extends _HelloDisp { - public int - run(String[] args) + public void + sayHello(Ice.Current current) { - Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Server"); - adapter.add(new CallbackI(), Ice.Util.stringToIdentity("callback")); - adapter.activate(); - communicator().waitForShutdown(); - return 0; + System.out.println("Hello World!"); } } diff --git a/java/demo/Ice/minimal/README b/java/demo/Ice/minimal/README new file mode 100644 index 00000000000..744c350c3b7 --- /dev/null +++ b/java/demo/Ice/minimal/README @@ -0,0 +1,9 @@ +This demo is a minimal Ice "hello world" application. + +To run the demo, first start the server: + +$ java Server + +In a separate window, start the client: + +$ java Client diff --git a/java/demo/Ice/minimal/Server.java b/java/demo/Ice/minimal/Server.java new file mode 100755 index 00000000000..ce13d72873d --- /dev/null +++ b/java/demo/Ice/minimal/Server.java @@ -0,0 +1,58 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +import Demo.*; + +public class Server +{ + public static int + run(String[] args, Ice.Communicator communicator) + { + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("Hello"); + adapter.add(new HelloI(), Ice.Util.stringToIdentity("hello")); + adapter.activate(); + communicator.waitForShutdown(); + return 0; + } + + public static void + main(String[] args) + { + int status = 0; + Ice.Communicator communicator = null; + + try + { + Ice.Properties properties = Ice.Util.createProperties(); + properties.load("config"); + communicator = Ice.Util.initializeWithProperties(args, properties); + status = run(args, communicator); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + status = 1; + } + + if(communicator != null) + { + try + { + communicator.destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + status = 1; + } + } + + System.exit(status); + } +} diff --git a/java/demo/Ice/minimal/build.xml b/java/demo/Ice/minimal/build.xml new file mode 100644 index 00000000000..34729f32f5c --- /dev/null +++ b/java/demo/Ice/minimal/build.xml @@ -0,0 +1,59 @@ +<!-- + ********************************************************************** + + Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. + + This copy of Ice is licensed to you under the terms described in the + ICE_LICENSE file included in this distribution. + + ********************************************************************** + --> + +<!DOCTYPE project [ +<!ENTITY common SYSTEM "file:../../../config/common.xml"> +]> + +<project name="demo_Ice_minimal" default="all" basedir="."> + + <!-- set global properties for this build --> + <property name="top.dir" value="../../.."/> + + <!-- Include common definitions --> + &common; + + <property name="class.dir" value="classes"/> + <property name="generated.dir" value="generated"/> + + <target name="init" depends="config-init"> + <!-- Create the time stamp --> + <tstamp/> + </target> + + <target name="generate" depends="init"> + <!-- Create the output directory for generated code --> + <mkdir dir="${generated.dir}"/> + <slice2java outputdir="${generated.dir}"> + <fileset dir="." includes="Hello.ice"/> + </slice2java> + </target> + + <target name="compile" depends="generate"> + <mkdir dir="${class.dir}"/> + <javac srcdir="${generated.dir}" destdir="${class.dir}" + source="1.4" debug="${debug}"> + <classpath refid="ice.classpath"/> + </javac> + <javac srcdir="." destdir="${class.dir}" source="1.4" + excludes="generated/**" debug="${debug}"> + <classpath refid="ice.classpath"/> + </javac> + </target> + + <target name="all" depends="compile"/> + + <target name="clean"> + <delete dir="${generated.dir}"/> + <delete dir="${class.dir}"/> + </target> + +</project> diff --git a/java/demo/Ice/minimal/config b/java/demo/Ice/minimal/config new file mode 100644 index 00000000000..449556359f1 --- /dev/null +++ b/java/demo/Ice/minimal/config @@ -0,0 +1,63 @@ +# +# The client reads this property to create the reference to the +# "hello" object in the server. +# +Hello.Proxy=hello:tcp -p 10000:udp -p 10000:ssl -p 10001 + +# +# The server creates one single object adapter with the name +# "helloadapater". The following line sets the endpoints for this +# adapter +# +Hello.Endpoints=tcp -p 10000:udp -p 10000:ssl -p 10001 + +# +# Warn about connection exceptions +# +Ice.Warn.Connections=2 + +# +# We want a faster ACM for this demo. +# +Ice.ACM.Client=10 +Ice.ACM.Server=10 + +# +# Network Tracing +# +# 0 = no network tracing +# 1 = trace connection establishment and closure +# 2 = like 1, but more detailed +# 3 = like 2, but also trace data transfer +# +Ice.Trace.Network=3 + +# +# Protocol Tracing +# +# 0 = no protocol tracing +# 1 = trace protocol messages +# +Ice.Trace.Protocol=3 + +# +# Security Tracing +# +# 0 = no security tracing +# 1 = trace warning messages +# 2 = config file parsing warnings +# +IceSSL.Trace.Security=0 + +# +# SSL Configuration +# +Ice.Plugin.IceSSL=IceSSL.PluginFactory +Ice.ThreadPerConnection=1 +IceSSL.Client.Keystore=../../../certs/client.jks +IceSSL.Client.Password=password +IceSSL.Client.Certs=../../../certs/certs.jks +IceSSL.Server.Keystore=../../../certs/server.jks +IceSSL.Server.Password=password +IceSSL.Server.ClientAuth=1 +IceSSL.Server.Certs=../../../certs/certs.jks diff --git a/java/demo/Ice/nested/Client.java b/java/demo/Ice/nested/Client.java index fda6f12f70a..2f4499bb0d4 100644 --- a/java/demo/Ice/nested/Client.java +++ b/java/demo/Ice/nested/Client.java @@ -7,12 +7,81 @@ // // ********************************************************************** -public class Client +import Demo.*; + +public class Client extends Ice.Application { + public int + run(String[] args) + { + Ice.Properties properties = communicator().getProperties(); + final String proxyProperty = "Nested.Client.NestedServer"; + String proxy = properties.getProperty(proxyProperty); + if(proxy.length() == 0) + { + System.err.println("property `" + proxyProperty + "' not set"); + return 1; + } + + NestedPrx nested = NestedPrxHelper.checkedCast(communicator().stringToProxy(proxy)); + if(nested == null) + { + System.err.println("invalid proxy"); + return 1; + } + + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Nested.Client"); + NestedPrx self = NestedPrxHelper.uncheckedCast(adapter.createProxy(Ice.Util.stringToIdentity("nestedClient"))); + adapter.add(new NestedI(self), Ice.Util.stringToIdentity("nestedClient")); + adapter.activate(); + + System.out.println("Note: The maximum nesting level is sz * 2, with sz being"); + System.out.println("the maximum number of threads in the server thread pool. If"); + System.out.println("you specify a value higher than that, the application will"); + System.out.println("block or timeout."); + System.out.println(); + + java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); + + String s = null; + do + { + try + { + System.out.print("enter nesting level or 'x' for exit: "); + System.out.flush(); + s = in.readLine(); + if(s == null) + { + break; + } + int level = Integer.parseInt(s); + if(level > 0) + { + nested.nestedCall(level, self); + } + } + catch(NumberFormatException ex) + { + } + catch(java.io.IOException ex) + { + ex.printStackTrace(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + while(!s.equals("x")); + + return 0; + } + public static void main(String[] args) { - NestedClient app = new NestedClient(); + Client app = new Client(); int status = app.main("Client", args, "config"); System.exit(status); } diff --git a/java/demo/Ice/nested/NestedClient.java b/java/demo/Ice/nested/NestedClient.java index b589e62d32a..f949cafd4d0 100644 --- a/java/demo/Ice/nested/NestedClient.java +++ b/java/demo/Ice/nested/NestedClient.java @@ -23,8 +23,7 @@ class NestedClient extends Ice.Application return 1; } - Ice.ObjectPrx base = communicator().stringToProxy(proxy); - NestedPrx nested = NestedPrxHelper.checkedCast(base); + NestedPrx nested = NestedPrxHelper.checkedCast(communicator().stringToProxy(proxy)); if(nested == null) { System.err.println("invalid proxy"); diff --git a/java/demo/Ice/nested/README b/java/demo/Ice/nested/README new file mode 100644 index 00000000000..49811a4dd4e --- /dev/null +++ b/java/demo/Ice/nested/README @@ -0,0 +1,10 @@ +A demo to illustrate how nested callbacks work, and how the size of +the thread pool affects the maximum nesting depth. + +To run the demo, first start the server: + +$ java Server + +In a separate window, start the client: + +$ java Client diff --git a/java/demo/Ice/nested/Server.java b/java/demo/Ice/nested/Server.java index b22c1cece1a..b38ea7041e4 100644 --- a/java/demo/Ice/nested/Server.java +++ b/java/demo/Ice/nested/Server.java @@ -7,12 +7,25 @@ // // ********************************************************************** -public class Server +import Demo.*; + +public class Server extends Ice.Application { + public int + run(String[] args) + { + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Nested.Server"); + NestedPrx self = NestedPrxHelper.uncheckedCast(adapter.createProxy(Ice.Util.stringToIdentity("nestedServer"))); + adapter.add(new NestedI(self), Ice.Util.stringToIdentity("nestedServer")); + adapter.activate(); + communicator().waitForShutdown(); + return 0; + } + public static void main(String[] args) { - NestedServer app = new NestedServer(); + Server app = new Server(); int status = app.main("Server", args, "config"); System.exit(status); } diff --git a/java/demo/Ice/session/Client.java b/java/demo/Ice/session/Client.java index 44e8da1b2df..4a2c9cbc35f 100644 --- a/java/demo/Ice/session/Client.java +++ b/java/demo/Ice/session/Client.java @@ -9,12 +9,238 @@ import Demo.*; -public class Client +public class Client extends Ice.Application { + static private class SessionRefreshThread extends Thread + { + SessionRefreshThread(Ice.Logger logger, long timeout, SessionPrx session) + { + _logger = logger; + _session = session; + _timeout = timeout; + } + + synchronized public void + run() + { + while(!_terminated) + { + try + { + wait(_timeout); + } + catch(InterruptedException e) + { + } + if(!_terminated) + { + try + { + _session.refresh(); + } + catch(Ice.LocalException ex) + { + _logger.warning("SessionRefreshThread: " + ex); + _terminated = true; + } + } + } + } + + synchronized private void + terminate() + { + _terminated = true; + notify(); + } + + final private Ice.Logger _logger; + final private SessionPrx _session; + final private long _timeout; + private boolean _terminated = false; + } + + private static void + menu() + { + System.out.println( + "usage:\n" + + "c: create a new per-client hello object\n" + + "0-9: send a greeting to a hello object\n" + + "s: shutdown the server and exit\n" + + "x: exit\n" + + "t: exit without destroying the session\n" + + "?: help\n"); + } + + public int + run(String[] args) + { + java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); + String name; + try + { + do + { + System.out.print("Please enter your name ==> "); + System.out.flush(); + name = in.readLine().trim(); + } + while(name.length() == 0); + } + catch(java.io.IOException ex) + { + ex.printStackTrace(); + return 0; + } + + Ice.Properties properties = communicator().getProperties(); + final String proxyProperty = "SessionFactory.Proxy"; + String proxy = properties.getProperty(proxyProperty); + if(proxy.length() == 0) + { + System.err.println("property `" + proxyProperty + "' not set"); + return 1; + } + + Ice.ObjectPrx base = communicator().stringToProxy(proxy); + SessionFactoryPrx factory = SessionFactoryPrxHelper.checkedCast(base); + if(factory == null) + { + System.err.println("invalid proxy"); + return 1; + } + + SessionPrx session = factory.create(name); + SessionRefreshThread refresh = new SessionRefreshThread(communicator().getLogger(), 5000, session); + refresh.start(); + + java.util.ArrayList hellos = new java.util.ArrayList(); + + menu(); + + + try + { + boolean destroy = true; + boolean shutdown = false; + while(true) + { + System.out.print("==> "); + System.out.flush(); + String line = in.readLine(); + if(line == null) + { + break; + } + if(line.length() > 0 && Character.isDigit(line.charAt(0))) + { + int index; + try + { + index = Integer.parseInt(line); + } + catch(NumberFormatException e) + { + menu(); + continue; + } + if(index < hellos.size()) + { + HelloPrx hello = (HelloPrx)hellos.get(index); + hello.sayHello(); + } + else + { + System.out.println("index is too high. " + hellos.size() + " exist so far. " + + "Use 'c' to create a new hello object."); + } + } + else if(line.equals("c")) + { + hellos.add(session.createHello()); + System.out.println("created hello object " + (hellos.size()-1)); + } + else if(line.equals("s")) + { + destroy = false; + shutdown = true; + break; + } + else if(line.equals("x")) + { + break; + } + else if(line.equals("t")) + { + destroy = false; + break; + } + else if(line.equals("?")) + { + menu(); + } + else + { + System.out.println("unknown command `" + line + "'"); + menu(); + } + } + // + // The refresher thread must be terminated before destroy is + // called, otherwise it might get ObjectNotExistException. refresh + // is set to 0 so that if session->destroy() raises an exception + // the thread will not be re-terminated and re-joined. + // + refresh.terminate(); + try + { + refresh.join(); + } + catch(InterruptedException e) + { + } + refresh = null; + + if(destroy) + { + session.destroy(); + } + if(shutdown) + { + factory.shutdown(); + } + } + catch(java.io.IOException ex) + { + ex.printStackTrace(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + finally + { + if(refresh != null) + { + refresh.terminate(); + try + { + refresh.join(); + } + catch(InterruptedException e) + { + } + } + } + + return 0; + } + public static void main(String[] args) { - SessionClient app = new SessionClient(); + Client app = new Client(); int status = app.main("Client", args, "config"); System.exit(status); } diff --git a/java/demo/Ice/session/Server.java b/java/demo/Ice/session/Server.java index dadc0a8915a..6bcbc329aa9 100644 --- a/java/demo/Ice/session/Server.java +++ b/java/demo/Ice/session/Server.java @@ -9,12 +9,35 @@ import Demo.*; -public class Server +public class Server extends Ice.Application { + public int + run(String[] args) + { + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("SessionFactory"); + ReapThread reaper = new ReapThread(); + reaper.start(); + + adapter.add(new SessionFactoryI(reaper), Ice.Util.stringToIdentity("SessionFactory")); + adapter.activate(); + communicator().waitForShutdown(); + + reaper.terminate(); + try + { + reaper.join(); + } + catch(InterruptedException e) + { + } + + return 0; + } + public static void main(String[] args) { - SessionServer app = new SessionServer(); + Server app = new Server(); int status = app.main("Server", args, "config"); System.exit(status); } diff --git a/java/demo/Ice/session/SessionClient.java b/java/demo/Ice/session/SessionClient.java deleted file mode 100644 index 848d33f17b9..00000000000 --- a/java/demo/Ice/session/SessionClient.java +++ /dev/null @@ -1,239 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -import Demo.*; - -class SessionClient extends Ice.Application -{ - static private class SessionRefreshThread extends Thread - { - SessionRefreshThread(Ice.Logger logger, long timeout, SessionPrx session) - { - _logger = logger; - _session = session; - _timeout = timeout; - } - - synchronized public void - run() - { - while(!_terminated) - { - try - { - wait(_timeout); - } - catch(InterruptedException e) - { - } - if(!_terminated) - { - try - { - _session.refresh(); - } - catch(Ice.LocalException ex) - { - _logger.warning("SessionRefreshThread: " + ex); - _terminated = true; - } - } - } - } - - synchronized private void - terminate() - { - _terminated = true; - notify(); - } - - final private Ice.Logger _logger; - final private SessionPrx _session; - final private long _timeout; - private boolean _terminated = false; - } - - private static void - menu() - { - System.out.println( - "usage:\n" + - "c: create a new per-client hello object\n" + - "0-9: send a greeting to a hello object\n" + - "s: shutdown the server and exit\n" + - "x: exit\n" + - "t: exit without destroying the session\n" + - "?: help\n"); - } - - public int - run(String[] args) - { - java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); - String name; - try - { - do - { - System.out.print("Please enter your name ==> "); - System.out.flush(); - name = in.readLine().trim(); - } - while(name.length() == 0); - } - catch(java.io.IOException ex) - { - ex.printStackTrace(); - return 0; - } - - Ice.Properties properties = communicator().getProperties(); - final String proxyProperty = "SessionFactory.Proxy"; - String proxy = properties.getProperty(proxyProperty); - if(proxy.length() == 0) - { - System.err.println("property `" + proxyProperty + "' not set"); - return 1; - } - - Ice.ObjectPrx base = communicator().stringToProxy(proxy); - SessionFactoryPrx factory = SessionFactoryPrxHelper.checkedCast(base); - if(factory == null) - { - System.err.println("invalid proxy"); - return 1; - } - - SessionPrx session = factory.create(name); - SessionRefreshThread refresh = new SessionRefreshThread(communicator().getLogger(), 5000, session); - refresh.start(); - - java.util.ArrayList hellos = new java.util.ArrayList(); - - menu(); - - - try - { - boolean destroy = true; - boolean shutdown = false; - while(true) - { - System.out.print("==> "); - System.out.flush(); - String line = in.readLine(); - if(line == null) - { - break; - } - if(line.length() > 0 && Character.isDigit(line.charAt(0))) - { - int index; - try - { - index = Integer.parseInt(line); - } - catch(NumberFormatException e) - { - menu(); - continue; - } - if(index < hellos.size()) - { - HelloPrx hello = (HelloPrx)hellos.get(index); - hello.sayHello(); - } - else - { - System.out.println("index is too high. " + hellos.size() + " exist so far. " + - "Use 'c' to create a new hello object."); - } - } - else if(line.equals("c")) - { - hellos.add(session.createHello()); - System.out.println("created hello object " + (hellos.size()-1)); - } - else if(line.equals("s")) - { - destroy = false; - shutdown = true; - break; - } - else if(line.equals("x")) - { - break; - } - else if(line.equals("t")) - { - destroy = false; - break; - } - else if(line.equals("?")) - { - menu(); - } - else - { - System.out.println("unknown command `" + line + "'"); - menu(); - } - } - // - // The refresher thread must be terminated before destroy is - // called, otherwise it might get ObjectNotExistException. refresh - // is set to 0 so that if session->destroy() raises an exception - // the thread will not be re-terminated and re-joined. - // - refresh.terminate(); - try - { - refresh.join(); - } - catch(InterruptedException e) - { - } - refresh = null; - - if(destroy) - { - session.destroy(); - } - if(shutdown) - { - factory.shutdown(); - } - } - catch(java.io.IOException ex) - { - ex.printStackTrace(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } - finally - { - if(refresh != null) - { - refresh.terminate(); - try - { - refresh.join(); - } - catch(InterruptedException e) - { - } - } - } - - return 0; - } -} diff --git a/java/demo/Ice/session/SessionServer.java b/java/demo/Ice/session/SessionServer.java deleted file mode 100644 index 757fd8a2ead..00000000000 --- a/java/demo/Ice/session/SessionServer.java +++ /dev/null @@ -1,36 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -import Demo.*; - -class SessionServer extends Ice.Application -{ - public int - run(String[] args) - { - Ice.ObjectAdapter adapter = communicator().createObjectAdapter("SessionFactory"); - ReapThread reaper = new ReapThread(); - reaper.start(); - - adapter.add(new SessionFactoryI(reaper), Ice.Util.stringToIdentity("SessionFactory")); - adapter.activate(); - communicator().waitForShutdown(); - - reaper.terminate(); - try - { - reaper.join(); - } - catch(InterruptedException e) - { - } - - return 0; - } -} diff --git a/java/demo/Ice/throughput/Client.java b/java/demo/Ice/throughput/Client.java index 3a6eac769a9..4dc7af06ebe 100644 --- a/java/demo/Ice/throughput/Client.java +++ b/java/demo/Ice/throughput/Client.java @@ -9,7 +9,7 @@ import Demo.*; -public class Client +public class Client extends Ice.Application { private static void menu() @@ -35,10 +35,10 @@ public class Client "?: help\n"); } - private static int - run(String[] args, Ice.Communicator communicator) + public int + run(String[] args) { - Ice.Properties properties = communicator.getProperties(); + Ice.Properties properties = communicator().getProperties(); final String refProperty = "Throughput.Throughput"; String ref = properties.getProperty(refProperty); if(ref.length() == 0) @@ -47,7 +47,7 @@ public class Client return 1; } - Ice.ObjectPrx base = communicator.stringToProxy(ref); + Ice.ObjectPrx base = communicator().stringToProxy(ref); ThroughputPrx throughput = ThroughputPrxHelper.checkedCast(base); if(throughput == null) { @@ -408,35 +408,8 @@ public class Client public static void main(String[] args) { - int status = 0; - Ice.Communicator communicator = null; - - try - { - Ice.Properties properties = Ice.Util.createProperties(); - properties.load("config"); - communicator = Ice.Util.initializeWithProperties(args, properties); - status = run(args, communicator); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - } - + Client app = new Client(); + int status = app.main("Client", args, "config"); System.exit(status); } } diff --git a/java/demo/Ice/throughput/README b/java/demo/Ice/throughput/README new file mode 100644 index 00000000000..5dc47deceaa --- /dev/null +++ b/java/demo/Ice/throughput/README @@ -0,0 +1,11 @@ +A simple throughput demo that allows you to send sequences of various +types between client and server and to measure the maximum bandwidth +that can be achieved using serialized synchronous requests. + +To run the demo, first start the server: + +$ java Server + +In a separate window, start the client: + +$ java Client diff --git a/java/demo/Ice/throughput/Server.java b/java/demo/Ice/throughput/Server.java index 192ddd41384..924d2e5464e 100644 --- a/java/demo/Ice/throughput/Server.java +++ b/java/demo/Ice/throughput/Server.java @@ -7,51 +7,25 @@ // // ********************************************************************** -public class Server +import Demo.*; + +public class Server extends Ice.Application { - private static int - run(String[] args, Ice.Communicator communicator) + public int + run(String[] args) { - Ice.ObjectAdapter adapter = communicator.createObjectAdapter("Throughput"); - Ice.Object object = new ThroughputI(); - adapter.add(object, Ice.Util.stringToIdentity("throughput")); + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Throughput"); + adapter.add(new ThroughputI(), Ice.Util.stringToIdentity("throughput")); adapter.activate(); - communicator.waitForShutdown(); + communicator().waitForShutdown(); return 0; } public static void main(String[] args) { - int status = 0; - Ice.Communicator communicator = null; - - try - { - Ice.Properties properties = Ice.Util.createProperties(); - properties.load("config"); - communicator = Ice.Util.initializeWithProperties(args, properties); - status = run(args, communicator); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - } - + Server app = new Server(); + int status = app.main("Server", args, "config"); System.exit(status); } } diff --git a/java/demo/Ice/value/InitialI.java b/java/demo/Ice/value/InitialI.java index bdcedc5ba8e..7b6a16381aa 100644 --- a/java/demo/Ice/value/InitialI.java +++ b/java/demo/Ice/value/InitialI.java @@ -13,14 +13,11 @@ class InitialI extends Initial { InitialI(Ice.ObjectAdapter adapter) { - _simple = new Simple(); _simple.message = "a message 4 u"; - _printer = new PrinterI(); _printer.message = "Ice rulez!"; _printerProxy = PrinterPrxHelper.uncheckedCast(adapter.addWithUUID(_printer)); - _derivedPrinter = new DerivedPrinterI(); _derivedPrinter.message = _printer.message; _derivedPrinter.derivedMessage = "a derived message 4 u"; adapter.addWithUUID(_derivedPrinter); @@ -54,8 +51,8 @@ class InitialI extends Initial throw ex; } - private Simple _simple; - private Printer _printer; + private Simple _simple = new Simple(); + private Printer _printer = new PrinterI(); private PrinterPrx _printerProxy; - private DerivedPrinter _derivedPrinter; + private DerivedPrinter _derivedPrinter = new DerivedPrinterI(); } diff --git a/java/demo/Ice/value/README b/java/demo/Ice/value/README new file mode 100644 index 00000000000..a813e70775b --- /dev/null +++ b/java/demo/Ice/value/README @@ -0,0 +1,10 @@ +This demo shows how to use classes, class factories, and the +difference between local and remote invocations of class operations. + +To run the demo, first start the server: + +$ java Server + +In a separate window, start the client: + +$ java Client diff --git a/java/demo/IceBox/hello/Client.java b/java/demo/IceBox/hello/Client.java index 851826753ed..c89be59d095 100644 --- a/java/demo/IceBox/hello/Client.java +++ b/java/demo/IceBox/hello/Client.java @@ -9,9 +9,9 @@ import Demo.*; -public class Client +public class Client extends Ice.Application { - private static void + private void menu() { System.out.println( @@ -27,10 +27,10 @@ public class Client "?: help\n"); } - private static int - run(String[] args, Ice.Communicator communicator) + public int + run(String[] args) { - Ice.Properties properties = communicator.getProperties(); + Ice.Properties properties = communicator().getProperties(); final String refProperty = "Hello.Hello"; String ref = properties.getProperty(refProperty); if(ref.length() == 0) @@ -39,8 +39,8 @@ public class Client return 1; } - Ice.ObjectPrx base = communicator.stringToProxy(ref); - HelloPrx twoway = HelloPrxHelper.checkedCast(base.ice_twoway().ice_timeout(-1).ice_secure(false)); + HelloPrx twoway = HelloPrxHelper.checkedCast( + communicator().stringToProxy(ref).ice_twoway().ice_timeout(-1).ice_secure(false)); if(twoway == null) { System.err.println("invalid object reference"); @@ -91,7 +91,7 @@ public class Client } else if(line.equals("f")) { - communicator.flushBatchRequests(); + communicator().flushBatchRequests(); } else if(line.equals("T")) { @@ -148,35 +148,8 @@ public class Client public static void main(String[] args) { - int status = 0; - Ice.Communicator communicator = null; - - try - { - Ice.Properties properties = Ice.Util.createProperties(); - properties.load("config"); - communicator = Ice.Util.initializeWithProperties(args, properties); - status = run(args, communicator); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - } - - System.exit(status); + Client app = new Client(); + int status = app.main("Client", args, "config"); + System.exit(status); } } diff --git a/java/demo/IceBox/hello/HelloServiceI.java b/java/demo/IceBox/hello/HelloServiceI.java index 89659160aeb..e417648ba2e 100644 --- a/java/demo/IceBox/hello/HelloServiceI.java +++ b/java/demo/IceBox/hello/HelloServiceI.java @@ -13,8 +13,7 @@ public class HelloServiceI extends Ice.LocalObjectImpl implements IceBox.Service start(String name, Ice.Communicator communicator, String[] args) { _adapter = communicator.createObjectAdapter(name); - Ice.Object object = new HelloI(); - _adapter.add(object, Ice.Util.stringToIdentity("hello")); + _adapter.add(new HelloI(), Ice.Util.stringToIdentity("hello")); _adapter.activate(); } diff --git a/java/demo/IcePack/hello/Client.java b/java/demo/IcePack/hello/Client.java index f2e73d43ff0..3f308bf8868 100644 --- a/java/demo/IcePack/hello/Client.java +++ b/java/demo/IcePack/hello/Client.java @@ -9,193 +9,182 @@ import Demo.*; -public class Client +public class Client extends Ice.Application { - private static void + private void menu() { - System.out.println( - "usage:\n" + - "c: create a hello object\n" + - "d: destroy the current hello object\n" + - "s: set the current hello object\n" + - "r: set the current hello object to a random hello object\n" + - "S: show the name of the current hello object\n" + - "t: send greeting\n" + - "x: exit\n" + - "?: help\n"); + System.out.println( + "usage:\n" + + "c: create a hello object\n" + + "d: destroy the current hello object\n" + + "s: set the current hello object\n" + + "r: set the current hello object to a random hello object\n" + + "S: show the name of the current hello object\n" + + "t: send greeting\n" + + "x: exit\n" + + "?: help\n"); } - private static int - run(String[] args, Ice.Communicator communicator) - throws Ice.UserException + public int + run(String[] args) { - Ice.Properties properties = communicator.getProperties(); + try + { + IcePack.QueryPrx query = IcePack.QueryPrxHelper.checkedCast(communicator().stringToProxy("IcePack/Query")); + // + // Get an object implementing the HelloFactory interface. + // + HelloFactoryPrx factory = HelloFactoryPrxHelper.checkedCast(query.findObjectByType("::Demo::HelloFactory")); - IcePack.QueryPrx query = IcePack.QueryPrxHelper.checkedCast(communicator.stringToProxy("IcePack/Query")); + // + // By default we create a Hello object named 'Foo'. + // + HelloPrx hello; + try + { + hello = factory.find("Foo"); + } + catch(NameNotExistException ex) + { + hello = factory.create("Foo"); + } - // - // Get an object implementing the HelloFactory interface. - // - HelloFactoryPrx factory = HelloFactoryPrxHelper.checkedCast(query.findObjectByType("::Demo::HelloFactory")); + menu(); - // - // By default we create a Hello object named 'Foo'. - // - HelloPrx hello; - try - { - hello = factory.find("Foo"); - } - catch(NameNotExistException ex) - { - hello = factory.create("Foo"); - } + java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); - menu(); + String line = null; + do + { + try + { + System.out.print("==> "); + System.out.flush(); + line = in.readLine(); + if(line == null) + { + break; + } + if(line.equals("t")) + { + hello.sayHello(); + } + else if(line.equals("c")) + { + System.out.print("name: "); + System.out.flush(); + String name = in.readLine(); + if(name != null && name.length() > 0) + { + try + { + hello = factory.find(name); + System.out.println("Hello object named '" + name + "' already exists"); + } + catch(NameNotExistException ex) + { + try + { + factory = HelloFactoryPrxHelper.checkedCast( + query.findObjectByType("::Demo::HelloFactory")); + hello = factory.create(name); + } + catch(IcePack.ObjectNotExistException e) + { + } + } + } + } + else if(line.equals("d")) + { + if(Ice.Util.identityToString(hello.ice_getIdentity()).equals("Foo")) + { + System.out.println("Can't delete the default Hello object named 'Foo'"); + } + else + { + hello.destroy(); - java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); - - String line = null; - do - { - try - { - System.out.print("==> "); - System.out.flush(); - line = in.readLine(); - if(line == null) - { - break; - } - if(line.equals("t")) - { - hello.sayHello(); - } - else if(line.equals("c")) - { - System.out.print("name: "); - System.out.flush(); - String name = in.readLine(); - if(name != null && name.length() > 0) - { - try - { - hello = factory.find(name); - System.out.println("Hello object named '" + name + "' already exists"); - } - catch(NameNotExistException ex) - { - factory = HelloFactoryPrxHelper.checkedCast(query.findObjectByType("::Demo::HelloFactory")); - hello = factory.create(name); - } - } - } - else if(line.equals("d")) - { - if(Ice.Util.identityToString(hello.ice_getIdentity()).equals("Foo")) - { - System.out.println("Can't delete the default Hello object named 'Foo'"); - } - else - { - hello.destroy(); - - try - { - hello = factory.find("Foo"); - } - catch(NameNotExistException ex) - { - hello = factory.create("Foo"); - } - } - } - else if(line.equals("s")) - { - System.out.print("name: "); - System.out.flush(); - String name = in.readLine(); - if(name != null && name.length() > 0) - { - try - { - hello = HelloPrxHelper.checkedCast(factory.find(name)); - } - catch(NameNotExistException ex) - { - System.out.println("This name doesn't exist"); - } - } - } - else if(line.equals("r")) - { - hello = HelloPrxHelper.checkedCast(query.findObjectByType("::Demo::Hello")); - } - else if(line.equals("S")) - { - System.out.println(Ice.Util.identityToString(hello.ice_getIdentity())); - } - else if(line.equals("x")) - { - // Nothing to do - } - else if(line.equals("?")) - { - menu(); - } - else - { - System.out.println("unknown command `" + line + "'"); - menu(); - } - } - catch(java.io.IOException ex) - { - ex.printStackTrace(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } - } - while(!line.equals("x")); - - return 0; + try + { + hello = factory.find("Foo"); + } + catch(NameNotExistException ex) + { + hello = factory.create("Foo"); + } + } + } + else if(line.equals("s")) + { + System.out.print("name: "); + System.out.flush(); + String name = in.readLine(); + if(name != null && name.length() > 0) + { + try + { + hello = HelloPrxHelper.checkedCast(factory.find(name)); + } + catch(NameNotExistException ex) + { + System.out.println("This name doesn't exist"); + } + } + } + else if(line.equals("r")) + { + hello = HelloPrxHelper.checkedCast(query.findObjectByType("::Demo::Hello")); + } + else if(line.equals("S")) + { + System.out.println(Ice.Util.identityToString(hello.ice_getIdentity())); + } + else if(line.equals("x")) + { + // Nothing to do + } + else if(line.equals("?")) + { + menu(); + } + else + { + System.out.println("unknown command `" + line + "'"); + menu(); + } + } + catch(java.io.IOException ex) + { + ex.printStackTrace(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + while(!line.equals("x")); + } + catch(NameExistsException e) + { + e.printStackTrace(); + return 1; + } + catch(IcePack.ObjectNotExistException e) + { + e.printStackTrace(); + return 1; + } + + return 0; } public static void main(String[] args) { - int status = 0; - Ice.Communicator communicator = null; - - try - { - Ice.Properties properties = Ice.Util.createProperties(); - properties.load("config"); - communicator = Ice.Util.initializeWithProperties(args, properties); - status = run(args, communicator); - } - catch(Exception ex) - { - ex.printStackTrace(); - status = 1; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - } - - System.exit(status); + Client app = new Client(); + int status = app.main("Client", args, "config"); + System.exit(status); } } diff --git a/java/demo/IcePack/hello/Server.java b/java/demo/IcePack/hello/Server.java index b93391d9125..1ab34cda561 100644 --- a/java/demo/IcePack/hello/Server.java +++ b/java/demo/IcePack/hello/Server.java @@ -13,13 +13,9 @@ public class Server extends Ice.Application run(String[] args) { Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Hello"); - String id = communicator().getProperties().getProperty("Identity"); - - Ice.Object object = new HelloFactoryI(); - adapter.add(object, Ice.Util.stringToIdentity(id)); + adapter.add(new HelloFactoryI(), Ice.Util.stringToIdentity(id)); adapter.activate(); - communicator().waitForShutdown(); return 0; } diff --git a/java/demo/IcePack/simple/Client.java b/java/demo/IcePack/simple/Client.java index af3c0b605e7..5aa55e78994 100644 --- a/java/demo/IcePack/simple/Client.java +++ b/java/demo/IcePack/simple/Client.java @@ -9,9 +9,9 @@ import Demo.*; -public class Client +public class Client extends Ice.Application { - private static void + private void menu() { System.out.println( @@ -28,12 +28,12 @@ public class Client "?: help\n"); } - private static int - run(String[] args, Ice.Communicator communicator) + public int + run(String[] args) { - Ice.Properties properties = communicator.getProperties(); + Ice.Properties properties = communicator().getProperties(); - IcePack.QueryPrx query = IcePack.QueryPrxHelper.checkedCast(communicator.stringToProxy("IcePack/Query")); + IcePack.QueryPrx query = IcePack.QueryPrxHelper.checkedCast(communicator().stringToProxy("IcePack/Query")); Ice.ObjectPrx base = null; try @@ -94,7 +94,7 @@ public class Client } else if(line.equals("f")) { - communicator.flushBatchRequests(); + communicator().flushBatchRequests(); } else if(line.equals("T")) { @@ -155,35 +155,8 @@ public class Client public static void main(String[] args) { - int status = 0; - Ice.Communicator communicator = null; - - try - { - Ice.Properties properties = Ice.Util.createProperties(); - properties.load("config"); - communicator = Ice.Util.initializeWithProperties(args, properties); - status = run(args, communicator); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - - if(communicator != null) - { - try - { - communicator.destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - status = 1; - } - } - - System.exit(status); + Client app = new Client(); + int status = app.main("Client", args, "config"); + System.exit(status); } } diff --git a/java/demo/IcePack/simple/Server.java b/java/demo/IcePack/simple/Server.java index d3c74cfc09b..6de00c95dcd 100644 --- a/java/demo/IcePack/simple/Server.java +++ b/java/demo/IcePack/simple/Server.java @@ -15,8 +15,7 @@ public class Server extends Ice.Application Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Hello"); String id = communicator().getProperties().getProperty("Identity"); - Ice.Object object = new HelloI(); - adapter.add(object, Ice.Util.stringToIdentity(id)); + adapter.add(new HelloI(), Ice.Util.stringToIdentity(id)); adapter.activate(); communicator().waitForShutdown(); return 0; @@ -26,6 +25,7 @@ public class Server extends Ice.Application main(String[] args) { Server app = new Server(); - app.main("demo.IcePack.hello.Server", args); + int status = app.main("demo.IcePack.hello.Server", args); + System.exit(status); } } |