summaryrefslogtreecommitdiff
path: root/java/demo/Ice/callback/Client.java
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2005-09-13 02:25:11 +0000
committerMatthew Newhook <matthew@zeroc.com>2005-09-13 02:25:11 +0000
commit13c1478b4bf220e3c08055f7af39281e2f5d8875 (patch)
tree2d80b77591f870688270b6637678eddb3e1c6196 /java/demo/Ice/callback/Client.java
parentupdates. (diff)
downloadice-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/callback/Client.java')
-rw-r--r--java/demo/Ice/callback/Client.java170
1 files changed, 168 insertions, 2 deletions
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);
}