ICE 3.4.2
[php5-ice-freebsdport.git] / java / demo / IceBox / hello / Client.java
blobad79802842a3b97ff43e344c63fc47037be0fe50
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 private void
31 menu()
33 System.out.println(
34 "usage:\n" +
35 "t: send greeting as twoway\n" +
36 "o: send greeting as oneway\n" +
37 "O: send greeting as batch oneway\n" +
38 "d: send greeting as datagram\n" +
39 "D: send greeting as batch datagram\n" +
40 "f: flush all batch requests\n" +
41 "x: exit\n" +
42 "?: help\n");
45 public int
46 run(String[] args)
48 if(args.length > 0)
50 System.err.println(appName() + ": too many arguments");
51 return 1;
55 // Since this is an interactive demo we want to clear the
56 // Application installed interrupt callback and install our
57 // own shutdown hook.
59 setInterruptHook(new ShutdownHook());
61 HelloPrx twoway = HelloPrxHelper.checkedCast(
62 communicator().propertyToProxy("Hello.Proxy").ice_twoway().ice_timeout(-1).ice_secure(false));
63 if(twoway == null)
65 System.err.println("invalid object reference");
66 return 1;
68 HelloPrx oneway = HelloPrxHelper.uncheckedCast(twoway.ice_oneway());
69 HelloPrx batchOneway = HelloPrxHelper.uncheckedCast(twoway.ice_batchOneway());
70 HelloPrx datagram = HelloPrxHelper.uncheckedCast(twoway.ice_datagram());
71 HelloPrx batchDatagram = HelloPrxHelper.uncheckedCast(twoway.ice_batchDatagram());
73 menu();
75 java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
77 String line = null;
80 try
82 System.out.print("==> ");
83 System.out.flush();
84 line = in.readLine();
85 if(line == null)
87 break;
89 if(line.equals("t"))
91 twoway.sayHello();
93 else if(line.equals("o"))
95 oneway.sayHello();
97 else if(line.equals("O"))
99 batchOneway.sayHello();
101 else if(line.equals("d"))
103 datagram.sayHello();
105 else if(line.equals("D"))
107 batchDatagram.sayHello();
109 else if(line.equals("f"))
111 communicator().flushBatchRequests();
113 else if(line.equals("x"))
115 // Nothing to do
117 else if(line.equals("?"))
119 menu();
121 else
123 System.out.println("unknown command `" + line + "'");
124 menu();
127 catch(java.io.IOException ex)
129 ex.printStackTrace();
131 catch(Ice.LocalException ex)
133 ex.printStackTrace();
136 while(!line.equals("x"));
138 return 0;
141 public static void
142 main(String[] args)
144 Client app = new Client();
145 int status = app.main("Client", args, "config.client");
146 System.exit(status);