diff options
Diffstat (limited to 'cs')
54 files changed, 1243 insertions, 1222 deletions
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); } } |