Mark Slee | cb39f08 | 2007-04-10 02:30:30 +0000 | [diff] [blame] | 1 | // Generated code |
| 2 | import tutorial.*; |
| 3 | import shared.*; |
| 4 | |
| 5 | import com.facebook.thrift.TException; |
| 6 | import com.facebook.thrift.transport.TTransport; |
| 7 | import com.facebook.thrift.transport.TSocket; |
| 8 | import com.facebook.thrift.transport.TTransportException; |
| 9 | import com.facebook.thrift.protocol.TBinaryProtocol; |
| 10 | import com.facebook.thrift.protocol.TProtocol; |
| 11 | |
| 12 | import java.util.AbstractMap; |
| 13 | import java.util.HashMap; |
| 14 | import java.util.HashSet; |
| 15 | import java.util.ArrayList; |
| 16 | |
| 17 | public class JavaClient { |
| 18 | public static void main(String [] args) { |
| 19 | try { |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 20 | |
| 21 | TTransport transport = new TSocket("localhost", 9090); |
Mark Slee | cb39f08 | 2007-04-10 02:30:30 +0000 | [diff] [blame] | 22 | 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 Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 54 | |
Mark Slee | cb39f08 | 2007-04-10 02:30:30 +0000 | [diff] [blame] | 55 | SharedStruct log = client.getStruct(1); |
| 56 | System.out.println("Check log: " + log.value); |
| 57 | |
| 58 | transport.close(); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 59 | |
Mark Slee | cb39f08 | 2007-04-10 02:30:30 +0000 | [diff] [blame] | 60 | } catch (TException x) { |
| 61 | x.printStackTrace(); |
| 62 | } |
| 63 | |
| 64 | } |
| 65 | |
| 66 | } |