blob: 5dc70ed5d0aaf79fe0761773638df203ca3b1780 [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
Mark Sleecb39f082007-04-10 02:30:30 +000020// Generated code
21import tutorial.*;
22import shared.*;
23
Bryan Duxburyafa80ea2009-01-15 23:47:51 +000024import org.apache.thrift.TException;
25import org.apache.thrift.transport.TTransport;
26import org.apache.thrift.transport.TSocket;
27import org.apache.thrift.transport.TTransportException;
28import org.apache.thrift.protocol.TBinaryProtocol;
29import org.apache.thrift.protocol.TProtocol;
Mark Sleecb39f082007-04-10 02:30:30 +000030
31import java.util.AbstractMap;
32import java.util.HashMap;
33import java.util.HashSet;
34import java.util.ArrayList;
35
36public class JavaClient {
37 public static void main(String [] args) {
38 try {
David Reiss0c90f6f2008-02-06 22:18:40 +000039
40 TTransport transport = new TSocket("localhost", 9090);
Mark Sleecb39f082007-04-10 02:30:30 +000041 TProtocol protocol = new TBinaryProtocol(transport);
42 Calculator.Client client = new Calculator.Client(protocol);
43
44 transport.open();
45
46 client.ping();
47 System.out.println("ping()");
48
49 int sum = client.add(1,1);
50 System.out.println("1+1=" + sum);
51
52 Work work = new Work();
53
54 work.op = Operation.DIVIDE;
55 work.num1 = 1;
56 work.num2 = 0;
57 try {
58 int quotient = client.calculate(1, work);
59 System.out.println("Whoa we can divide by 0");
60 } catch (InvalidOperation io) {
61 System.out.println("Invalid operation: " + io.why);
62 }
63
64 work.op = Operation.SUBTRACT;
65 work.num1 = 15;
66 work.num2 = 10;
67 try {
68 int diff = client.calculate(1, work);
69 System.out.println("15-10=" + diff);
70 } catch (InvalidOperation io) {
71 System.out.println("Invalid operation: " + io.why);
72 }
David Reiss0c90f6f2008-02-06 22:18:40 +000073
Mark Sleecb39f082007-04-10 02:30:30 +000074 SharedStruct log = client.getStruct(1);
75 System.out.println("Check log: " + log.value);
76
77 transport.close();
David Reiss0c90f6f2008-02-06 22:18:40 +000078
Mark Sleecb39f082007-04-10 02:30:30 +000079 } catch (TException x) {
80 x.printStackTrace();
81 }
82
83 }
84
85}