ICE 3.4.2
[php5-ice-freebsdport.git] / java / demo / Ice / async / Client.java
blobfb12d18c85e2f02abd97d2f2b637c4e1444c7e1b
1 // **********************************************************************
2 //
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
4 //
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
7 //
8 // **********************************************************************
10 import Demo.*;
12 public class Client extends Ice.Application
14 class ShutdownHook extends Thread
16 public void
17 run()
19 try
21 communicator().destroy();
23 catch(Ice.LocalException ex)
25 ex.printStackTrace();
30 public class Callback_Hello_sayHelloI extends Callback_Hello_sayHello
32 @Override
33 public void response()
37 @Override
38 public void exception(Ice.LocalException ex)
40 System.err.println("sayHello AMI call failed:");
41 ex.printStackTrace();
44 @Override
45 public void exception(Ice.UserException ex)
47 if(ex instanceof Demo.RequestCanceledException)
49 System.out.println("Demo.RequestCanceledException");
51 else
53 ex.printStackTrace();
58 private static void
59 menu()
61 System.out.println(
62 "usage:\n" +
63 "i: send immediate greeting\n" +
64 "d: send delayed greeting\n" +
65 "s: shutdown the server\n" +
66 "x: exit\n" +
67 "?: help\n");
70 public int
71 run(String[] args)
73 if(args.length > 0)
75 System.err.println(appName() + ": too many arguments");
76 return 1;
80 // Since this is an interactive demo we want to clear the
81 // Application installed interrupt callback and install our
82 // own shutdown hook.
84 setInterruptHook(new ShutdownHook());
86 HelloPrx hello = HelloPrxHelper.checkedCast(communicator().propertyToProxy("Hello.Proxy"));
87 if(hello == null)
89 System.err.println("invalid proxy");
90 return 1;
93 menu();
95 java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
97 String line = null;
102 System.out.print("==> ");
103 System.out.flush();
104 line = in.readLine();
105 if(line == null)
107 break;
109 if(line.equals("i"))
111 hello.sayHello(0);
113 else if(line.equals("d"))
115 hello.begin_sayHello(5000, new Callback_Hello_sayHelloI());
117 else if(line.equals("s"))
119 hello.shutdown();
121 else if(line.equals("x"))
123 // Nothing to do
125 else
127 System.out.println("unknown command `" + line + "'");
128 menu();
131 catch(java.io.IOException ex)
133 ex.printStackTrace();
135 catch(Ice.UserException ex)
137 ex.printStackTrace();
139 catch(Ice.LocalException ex)
141 ex.printStackTrace();
144 while(!line.equals("x"));
146 return 0;
149 public static void
150 main(String[] args)
152 Client app = new Client();
153 int status = app.main("Client", args, "config.client");
154 System.exit(status);