diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2014-07-18 11:42:16 -0230 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2014-07-18 11:42:16 -0230 |
commit | 031821623646abf0e0689bb68c4f8d40d43a80f6 (patch) | |
tree | 4797c00f22a3886000b4950114b32d07925c4a3c /java/demo/Ice/context/Client.java | |
parent | - Removed support for .NET CF 3.5, replaced with support for .NET (diff) | |
download | ice-031821623646abf0e0689bb68c4f8d40d43a80f6.tar.bz2 ice-031821623646abf0e0689bb68c4f8d40d43a80f6.tar.xz ice-031821623646abf0e0689bb68c4f8d40d43a80f6.zip |
ICE-5194 added demo for use of Ice request contexts
Diffstat (limited to 'java/demo/Ice/context/Client.java')
-rw-r--r-- | java/demo/Ice/context/Client.java | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/java/demo/Ice/context/Client.java b/java/demo/Ice/context/Client.java new file mode 100644 index 00000000000..3b808b05199 --- /dev/null +++ b/java/demo/Ice/context/Client.java @@ -0,0 +1,149 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2014 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 extends Ice.Application +{ + class ShutdownHook extends Thread + { + public void + run() + { + try + { + communicator().destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + } + + private static void + menu() + { + System.out.println( + "usage:\n" + + "1: call with no request context\n" + + "2: call with explicit request context\n" + + "3: call with per-proxy request context\n" + + "4: call with implicit request context\n" + + "s: shutdown server\n" + + "x: exit\n" + + "?: help\n"); + } + + public int + run(String[] args) + { + if(args.length > 0) + { + System.err.println(appName() + ": too many arguments"); + return 1; + } + + // + // Since this is an interactive demo we want to clear the + // Application installed interrupt callback and install our + // own shutdown hook. + // + setInterruptHook(new ShutdownHook()); + + ContextPrx proxy = ContextPrxHelper.checkedCast(communicator().propertyToProxy("Context.Proxy")); + if(proxy == 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("1")) + { + proxy.call(); + } + else if(line.equals("2")) + { + java.util.Map<String, String> ctx = new java.util.HashMap<String, String>(); + ctx.put("type", "Explicit"); + proxy.call(ctx); + } + else if(line.equals("3")) + { + java.util.Map<String, String> ctx = new java.util.HashMap<String, String>(); + ctx.put("type", "Per-Proxy"); + ContextPrx proxy2 = ContextPrxHelper.uncheckedCast(proxy.ice_context(ctx)); + proxy2.call(); + } + else if(line.equals("4")) + { + Ice.ImplicitContext ic = communicator().getImplicitContext(); + java.util.Map<String, String> ctx = new java.util.HashMap<String, String>(); + ctx.put("type", "Implicit"); + ic.setContext(ctx); + proxy.call(); + ic.setContext(new java.util.HashMap<String, String>()); + } + else if(line.equals("s")) + { + proxy.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) + { + Client app = new Client(); + int status = app.main("Client", args, "config.client"); + System.exit(status); + } +} + |