blob: eaeafc9a922506c0d7de5176a84cd24361ba2a11 [file] [log] [blame]
Mark Sleecb39f082007-04-10 02:30:30 +00001// Generated code
2import tutorial.*;
3import shared.*;
4
Bryan Duxburyafa80ea2009-01-15 23:47:51 +00005import org.apache.thrift.TException;
6import org.apache.thrift.transport.TTransport;
7import org.apache.thrift.transport.TSocket;
8import org.apache.thrift.transport.TTransportException;
9import org.apache.thrift.protocol.TBinaryProtocol;
10import org.apache.thrift.protocol.TProtocol;
Mark Sleecb39f082007-04-10 02:30:30 +000011
12import java.util.AbstractMap;
13import java.util.HashMap;
14import java.util.HashSet;
15import java.util.ArrayList;
16
17public class JavaClient {
18 public static void main(String [] args) {
19 try {
David Reiss0c90f6f2008-02-06 22:18:40 +000020
21 TTransport transport = new TSocket("localhost", 9090);
Mark Sleecb39f082007-04-10 02:30:30 +000022 TProtocol protocol = new TBinaryProtocol(transport);
23 Calculator.Client client = new Calculator.Client(protocol);
24
25 transport.open();
26
27 client.ping();
28 System.out.println("ping()");
29
30 int sum = client.add(1,1);
31 System.out.println("1+1=" + sum);
32
33 Work work = new Work();
34
35 work.op = Operation.DIVIDE;
36 work.num1 = 1;
37 work.num2 = 0;
38 try {
39 int quotient = client.calculate(1, work);
40 System.out.println("Whoa we can divide by 0");
41 } catch (InvalidOperation io) {
42 System.out.println("Invalid operation: " + io.why);
43 }
44
45 work.op = Operation.SUBTRACT;
46 work.num1 = 15;
47 work.num2 = 10;
48 try {
49 int diff = client.calculate(1, work);
50 System.out.println("15-10=" + diff);
51 } catch (InvalidOperation io) {
52 System.out.println("Invalid operation: " + io.why);
53 }
David Reiss0c90f6f2008-02-06 22:18:40 +000054
Mark Sleecb39f082007-04-10 02:30:30 +000055 SharedStruct log = client.getStruct(1);
56 System.out.println("Check log: " + log.value);
57
58 transport.close();
David Reiss0c90f6f2008-02-06 22:18:40 +000059
Mark Sleecb39f082007-04-10 02:30:30 +000060 } catch (TException x) {
61 x.printStackTrace();
62 }
63
64 }
65
66}