diff options
author | Matthew Newhook <matthew@zeroc.com> | 2005-09-13 02:25:11 +0000 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2005-09-13 02:25:11 +0000 |
commit | 13c1478b4bf220e3c08055f7af39281e2f5d8875 (patch) | |
tree | 2d80b77591f870688270b6637678eddb3e1c6196 /java/demo/Ice | |
parent | updates. (diff) | |
download | ice-13c1478b4bf220e3c08055f7af39281e2f5d8875.tar.bz2 ice-13c1478b4bf220e3c08055f7af39281e2f5d8875.tar.xz ice-13c1478b4bf220e3c08055f7af39281e2f5d8875.zip |
http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=335
Diffstat (limited to 'java/demo/Ice')
42 files changed, 1117 insertions, 891 deletions
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/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/Ice/callback/CallbackServer.java b/java/demo/Ice/minimal/HelloI.java index 3a55c49d30e..14737d3c46a 100644 --- a/java/demo/Ice/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 CallbackSenderI(), 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 |