thrift 远程服务调用 简单示例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了thrift 远程服务调用 简单示例相关的知识,希望对你有一定的参考价值。
/* * @(#) HelloServiceClient.java 2015年7月22日 * */ package com.le.mms.thrift.client; import org.apache.thrift.TException; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.transport.TSocket; import org.apache.thrift.transport.TTransport; import org.apache.thrift.transport.TTransportException; import com.HelloService; public class HelloServiceClient { public static void main(String[] args) { try { // 设置调用的服务地址-端口 TTransport transport = new TSocket("localhost", 9090); // 使用二进制协议 TProtocol protocol = new TBinaryProtocol(transport); // 使用的接口 HelloService.Client client = new HelloService.Client(protocol); // 打开socket transport.open(); boolean b = client.sayBoolean(true); String s = client.sayString("Hello world"); int i = client.sayInt(20141111); client.sayVoid(); System.out.println(b); System.out.println(s); System.out.println(i); transport.close(); } catch (TTransportException e) { e.printStackTrace(); } catch (TException te) { te.printStackTrace(); } } }
HelloServiceServer
package com.le.mms.thrift.server; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TBinaryProtocol.Factory; import org.apache.thrift.server.TServer; import org.apache.thrift.server.TSimpleServer; import org.apache.thrift.transport.TServerSocket; import org.apache.thrift.transport.TTransportException; import com.HelloService; import com.HelloService.Processor; import com.le.mms.thrift.HelloServiceImpl; public class HelloServiceServer { public static void main(String[] args) { try { // 设置服务器端口 TServerSocket serverTransport = new TServerSocket(9090); // 设置二进制协议工厂 Factory protocolFactory = new TBinaryProtocol.Factory(); // 处理器关联业务实现 Processor<HelloService.Iface> processor = new HelloService.Processor<HelloService.Iface>(new HelloServiceImpl()); // 1. 使用单线程标准阻塞I/O模型 TServer.Args simpleArgs = new TServer.Args(serverTransport); simpleArgs.processor(processor); simpleArgs.protocolFactory(protocolFactory); TServer server = new TSimpleServer(simpleArgs); // 2. 使用线程池服务模型 // TThreadPoolServer.Args poolArgs = new TThreadPoolServer.Args(serverTransport); // poolArgs.processor(processor); // poolArgs.protocolFactory(protocolFactory); // TServer poolServer = new TThreadPoolServer(poolArgs); // poolServer.serve(); System.out.println("开启thrift服务器,监听端口:9090"); server.serve(); } catch (TTransportException e) { e.printStackTrace(); } } }
HelloServiceImpl
/* * @(#) HelloServiceImpl.java 2015年7月22日 * */ package com.le.mms.thrift; import org.apache.thrift.TException; import com.HelloService.Iface; /** * * @author hzzhouchong * @version 2015年7月22日 */ public class HelloServiceImpl implements Iface { @Override public int sayInt(int param) throws TException { System.out.println("say int"); return 11111; } @Override public String sayString(String param) throws TException { System.out.println("say param"); return "hello thrift的点点滴滴的" + param; } @Override public boolean sayBoolean(boolean param) throws TException { System.out.println("say boolean"); return false; } @Override public void sayVoid() throws TException { System.out.println("say void"); } }
HelloService thrift 自动生成
/** * Autogenerated by Thrift Compiler (0.9.0) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated */ package com; import org.apache.thrift.scheme.IScheme; import org.apache.thrift.scheme.SchemeFactory; import org.apache.thrift.scheme.StandardScheme; import org.apache.thrift.scheme.TupleScheme; import org.apache.thrift.protocol.TTupleProtocol; import org.apache.thrift.protocol.TProtocolException; import org.apache.thrift.EncodingUtils; import org.apache.thrift.TException; import java.util.List; import java.util.ArrayList; import java.util.Map; import java.util.HashMap; import java.util.EnumMap; import java.util.Set; import java.util.HashSet; import java.util.EnumSet; import java.util.Collections; import java.util.BitSet; import java.nio.ByteBuffer; import java.util.Arrays; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class HelloService { public interface Iface { public int sayInt(int param) throws org.apache.thrift.TException; public String sayString(String param) throws org.apache.thrift.TException; public boolean sayBoolean(boolean param) throws org.apache.thrift.TException; public void sayVoid() throws org.apache.thrift.TException; } public interface AsyncIface { public void sayInt(int param, org.apache.thrift.async.AsyncMethodCallback<AsyncClient.sayInt_call> resultHandler) throws org.apache.thrift.TException; public void sayString(String param, org.apache.thrift.async.AsyncMethodCallback<AsyncClient.sayString_call> resultHandler) throws org.apache.thrift.TException; public void sayBoolean(boolean param, org.apache.thrift.async.AsyncMethodCallback<AsyncClient.sayBoolean_call> resultHandler) throws org.apache.thrift.TException; public void sayVoid(org.apache.thrift.async.AsyncMethodCallback<AsyncClient.sayVoid_call> resultHandler) throws org.apache.thrift.TException; } public static class Client extends org.apache.thrift.TServiceClient implements Iface { public static class Factory implements org.apache.thrift.TServiceClientFactory<Client> { public Factory() {} public Client getClient(org.apache.thrift.protocol.TProtocol prot) { return new Client(prot); } public Client getClient(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) { return new Client(iprot, oprot); } } public Client(org.apache.thrift.protocol.TProtocol prot) { super(prot, prot); } public Client(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) { super(iprot, oprot); } public int sayInt(int param) throws org.apache.thrift.TException { send_sayInt(param); return recv_sayInt(); } public void send_sayInt(int param) throws org.apache.thrift.TException { sayInt_args args = new sayInt_args(); args.setParam(param); sendBase("sayInt", args); } public int recv_sayInt() throws org.apache.thrift.TException { sayInt_result result = new sayInt_result(); receiveBase(result, "sayInt"); if (result.isSetSuccess()) { return result.success; } throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "sayInt failed: unknown result"); } public String sayString(String param) throws org.apache.thrift.TException { send_sayString(param); return recv_sayString(); } public void send_sayString(String param) throws org.apache.thrift.TException { sayString_args args = new sayString_args(); args.setParam(param); sendBase("sayString", args); } public String recv_sayString() throws org.apache.thrift.TException { sayString_result result = new sayString_result(); receiveBase(result, "sayString"); if (result.isSetSuccess()) { return result.success; } throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "sayString failed: unknown result"); } public boolean sayBoolean(boolean param) throws org.apache.thrift.TException { send_sayBoolean(param); return recv_sayBoolean(); } public void send_sayBoolean(boolean param) throws org.apache.thrift.TException { sayBoolean_args args = new sayBoolean_args(); args.setParam(param); sendBase("sayBoolean", args); } public boolean recv_sayBoolean() throws org.apache.thrift.TException { sayBoolean_result result = new sayBoolean_result(); receiveBase(result, "sayBoolean"); if (result.isSetSuccess()) { return result.success; } throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "sayBoolean failed: unknown result"); } public void sayVoid() throws org.apache.thrift.TException { send_sayVoid(); recv_sayVoid(); } public void send_sayVoid() throws org.apache.thrift.TException { sayVoid_args args = new sayVoid_args(); sendBase("sayVoid", args); } public void recv_sayVoid() throws org.apache.thrift.TException { sayVoid_result result = new sayVoid_result(); receiveBase(result, "sayVoid"); return; } } public static class AsyncClient extends org.apache.thrift.async.TAsyncClient implements AsyncIface { public static class Factory implements org.apache.thrift.async.TAsyncClientFactory<AsyncClient> { private org.apache.thrift.async.TAsyncClientManager clientManager; private org.apache.thrift.protocol.TProtocolFactory protocolFactory; public Factory(org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.protocol.TProtocolFactory protocolFactory) { this.clientManager = clientManager; this.protocolFactory = protocolFactory; } public AsyncClient getAsyncClient(org.apache.thrift.transport.TNonblockingTransport transport) { return new AsyncClient(protocolFactory, clientManager, transport); } } public AsyncClient(org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.transport.TNonblockingTransport transport) { super(protocolFactory, clientManager, transport); } public void sayInt(int param, org.apache.thrift.async.AsyncMethodCallback<sayInt_call> resultHandler) throws org.apache.thrift.TException { checkReady(); sayInt_call method_call = new sayInt_call(param, resultHandler, this, ___protocolFactory, ___transport); this.___currentMethod = method_call; ___manager.call(method_call); } public static class sayInt_call extends org.apache.thrift.async.TAsyncMethodCall { private int param; public sayInt_call(int param, org.apache.thrift.async.AsyncMethodCallback<sayInt_call> resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { super(client, protocolFactory, transport, resultHandler, false); this.param = param; } public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("sayInt", org.apache.thrift.protocol.TMessageType.CALL, 0)); sayInt_args args = new sayInt_args(); args.setParam(param); args.write(prot); prot.writeMessageEnd(); } public int getResult() throws org.apache.thrift.TException { if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { throw new IllegalStateException("Method call not finished!"); } org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); return (new Client(prot)).recv_sayInt(); } } public void sayString(String param, org.apache.thrift.async.AsyncMethodCallback<sayString_call> resultHandler) throws org.apache.thrift.TException { checkReady(); sayString_call method_call = new sayString_call(param, resultHandler, this, ___protocolFactory, ___transport); this.___currentMethod = method_call; ___manager.call(method_call); } public static class sayString_call extends org.apache.thrift.async.TAsyncMethodCall { private String param; public sayString_call(String param, org.apache.thrift.async.AsyncMethodCallback<sayString_call> resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { super(client, protocolFactory, transport, resultHandler, false); this.param = param; } public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("sayString", org.apache.thrift.protocol.TMessageType.CALL, 0)); sayString_args args = new sayString_args(); args.setParam(param); args.write(prot); prot.writeMessageEnd(); } public String getResult() throws org.apache.thrift.TException { if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { throw new IllegalStateException("Method call not finished!"); } org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); return (new Client(prot)).recv_sayString(); } } public void sayBoolean(boolean param, org.apache.thrift.async.AsyncMethodCallback<sayBoolean_call> resultHandler) throws org.apache.thrift.TException { checkReady(); sayBoolean_call method_call = new sayBoolean_call(param, resultHandler, this, ___protocolFactory, ___transport); this.___currentMethod = method_call; ___manager.call(method_call); } public static class sayBoolean_call extends org.apache.thrift.async.TAsyncMethodCall { private boolean param; public sayBoolean_call(boolean param, org.apache.thrift.async.AsyncMethodCallback<sayBoolean_call> resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { super(client, protocolFactory, transport, resultHandler, false); this.param = param; } public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("sayBoolean", org.apache.thrift.protocol.TMessageType.CALL, 0)); sayBoolean_args args = new sayBoolean_args(); args.setParam(param); args.write(prot); prot.writeMessageEnd(); } public boolean getResult() throws org.apache.thrift.TException { if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { throw new IllegalStateException("Method call not finished!"); } org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); return (new Client(prot)).recv_sayBoolean(); } } public void sayVoid(org.apache.thrift.async.AsyncMethodCallback<sayVoid_call> resultHandler) throws org.apache.thrift.TException { checkReady(); sayVoid_call method_call = new sayVoid_call(resultHandler, this, ___protocolFactory, ___transport); this.___currentMethod = method_call; ___manager.call(method_call); } public static class sayVoid_call extends org.apache.thrift.async.TAsyncMethodCall { public sayVoid_call(org.apache.thrift.async.AsyncMethodCallback<sayVoid_call> resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { super(client, protocolFactory, transport, resultHandler, false); } public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("sayVoid", org.apache.thrift.protocol.TMessageType.CALL, 0)); sayVoid_args args = new sayVoid_args(); args.write(prot); prot.writeMessageEnd(); } public void getResult() throws org.apache.thrift.TException { if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { throw new IllegalStateException("Method call not finished!"); } org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); (new Client(prot)).recv_sayVoid(); } } } public static class Processor<I extends Iface> extends org.apache.thrift.TBaseProcessor<I> implements org.apache.thrift.TProcessor { private static final Logger LOGGER = LoggerFactory.getLogger(Processor.class.getName()); public Processor(I iface) { super(iface, getProcessMap(new HashMap<String, org.apache.thrift.ProcessFunction<I, ? extends org.apache.thrift.TBase>>())); } protected Processor(I iface, Map<String, org.apache.thrift.ProcessFunction<I, ? extends org.apache.thrift.TBase>> processMap) { super(iface, getProcessMap(processMap)); } private static <I extends Iface> Map<String, org.apache.thrift.ProcessFunction<I, ? extends org.apache.thrift.TBase>> getProcessMap(Map<String, org.apache.thrift.ProcessFunction<I, ? extends org.apache.thrift.TBase>> processMap) { processMap.put("sayInt", new sayInt()); processMap.put("sayString", new sayString()); processMap.put("sayBoolean", new sayBoolean()); processMap.put("sayVoid", new sayVoid()); return processMap; } public static class sayInt<I extends Iface> extends org.apache.thrift.ProcessFunction<I, sayInt_args> { public sayInt() { super("sayInt"); } public sayInt_args getEmptyArgsInstance() { return new sayInt_args(); } protected boolean isOneway() { return false; } public sayInt_result getResult(I iface, sayInt_args args) throws org.apache.thrift.TException { sayInt_result result = new sayInt_result(); result.success = iface.sayInt(args.param); result.setSuccessIsSet(true); return result; } } public static class sayString<I extends Iface> extends org.apache.thrift.ProcessFunction<I, sayString_args> { public sayString() { super("sayString"); } public sayString_args getEmptyArgsInstance() { return new sayString_args(); } protected boolean isOneway() { return false; } public sayString_result getResult(I iface, sayString_args args) throws org.apache.thrift.TException { sayString_result result = new sayString_result(); result.success = iface.sayString(args.param); return result; } } public static class sayBoolean<I extends Iface> extends org.apache.thrift.ProcessFunction<I, sayBoolean_args> { public sayBoolean() { super("sayBoolean"); } public sayBoolean_args getEmptyArgsInstance() { return new sayBoolean_args(); } protected boolean isOneway() { return false; } public sayBoolean_result getResult(I iface, sayBoolean_args args) throws org.apache.thrift.TException { sayBoolean_result result = new sayBoolean_result(); result.success = iface.sayBoolean(args.param); result.setSuccessIsSet(true); return result; } } public static class sayVoid<I extends Iface> extends org.apache.thrift.ProcessFunction<I, sayVoid_args> { public sayVoid() { super("sayVoid"); } public sayVoid_args getEmptyArgsInstance() { return new sayVoid_args(); } protected boolean isOneway() { return false; } public sayVoid_result getResult(I iface, sayVoid_args args) throws org.apache.thrift.TException { sayVoid_result result = new sayVoid_result(); iface.sayVoid(); return result; } } } public static class sayInt_args implements org.apache.thrift.TBase<sayInt_args, sayInt_args._Fields>, java.io.Serializable, Cloneable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("sayInt_args"); private static final org.apache.thrift.protocol.TField PARAM_FIELD_DESC = new org.apache.thrift.protocol.TField("param", org.apache.thrift.protocol.TType.I32, (short)1); private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>(); static { schemes.put(StandardScheme.class, new sayInt_argsStandardSchemeFactory()); schemes.put(TupleScheme.class, new sayInt_argsTupleSchemeFactory()); } public int param; // required /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ public enum _Fields implements org.apache.thrift.TFieldIdEnum { PARAM((short)1, "param"); private static final Map<String, _Fields> byName = new HashMap<String, _Fields>(); static { for (_Fields field : EnumSet.allOf(_Fields.class)) { byName.put(field.getFieldName(), field); } } /** * Find the _Fields constant that matches fieldId, or null if its not found. */ public static _Fields findByThriftId(int fieldId) { switch(fieldId) { case 1: // PARAM return PARAM; default: return null; } } /** * Find the _Fields constant that matches fieldId, throwing an exception * if it is not found. */ public static _Fields findByThriftIdOrThrow(int fieldId) { _Fields fields = findByThriftId(fieldId); if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn‘t exist!"); return fields; } /** * Find the _Fields constant that matches name, or null if its not found. */ public static _Fields findByName(String name) { return byName.get(name); } private final short _thriftId; private final String _fieldName; _Fields(short thriftId, String fieldName) { _thriftId = thriftId; _fieldName = fieldName; } public short getThriftFieldId() { return _thriftId; } public String getFieldName() { return _fieldName; } } // isset id assignments private static final int __PARAM_ISSET_ID = 0; private byte __isset_bitfield = 0; public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; static { Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); tmpMap.put(_Fields.PARAM, new org.apache.thrift.meta_data.FieldMetaData("param", org.apache.thrift.TFieldRequirementType.DEFAULT, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))); metaDataMap = Collections.unmodifiableMap(tmpMap); org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(sayInt_args.class, metaDataMap); } public sayInt_args() { } public sayInt_args( int param) { this(); this.param = param; setParamIsSet(true); } /** * Performs a deep copy on <i>other</i>. */ public sayInt_args(sayInt_args other) { __isset_bitfield = other.__isset_bitfield; this.param = other.param; } public sayInt_args deepCopy() { return new sayInt_args(this); } @Override public void clear() { setParamIsSet(false); this.param = 0; } public int getParam() { return this.param; } public sayInt_args setParam(int param) { this.param = param; setParamIsSet(true); return this; } public void unsetParam() { __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __PARAM_ISSET_ID); } /** Returns true if field param is set (has been assigned a value) and false otherwise */ public boolean isSetParam() { return EncodingUtils.testBit(__isset_bitfield, __PARAM_ISSET_ID); } public void setParamIsSet(boolean value) { __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __PARAM_ISSET_ID, value); } public void setFieldValue(_Fields field, Object value) { switch (field) { case PARAM: if (value == null) { unsetParam(); } else { setParam((Integer)value); } break; } } public Object getFieldValue(_Fields field) { switch (field) { case PARAM: return Integer.valueOf(getParam()); } throw new IllegalStateException(); } /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ public boolean isSet(_Fields field) { if (field == null) { throw new IllegalArgumentException(); } switch (field) { case PARAM: return isSetParam(); } throw new IllegalStateException(); } @Override public boolean equals(Object that) { if (that == null) return false; if (that instanceof sayInt_args) return this.equals((sayInt_args)that); return false; } public boolean equals(sayInt_args that) { if (that == null) return false; boolean this_present_param = true; boolean that_present_param = true; if (this_present_param || that_present_param) { if (!(this_present_param && that_present_param)) return false; if (this.param != that.param) return false; } return true; } @Override public int hashCode() { return 0; } public int compareTo(sayInt_args other) { if (!getClass().equals(other.getClass())) { return getClass().getName().compareTo(other.getClass().getName()); } int lastComparison = 0; sayInt_args typedOther = (sayInt_args)other; lastComparison = Boolean.valueOf(isSetParam()).compareTo(typedOther.isSetParam()); if (lastComparison != 0) { return lastComparison; } if (isSetParam()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.param, typedOther.param); if (lastComparison != 0) { return lastComparison; } } return 0; } public _Fields fieldForId(int fieldId) { return _Fields.findByThriftId(fieldId); } public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { schemes.get(iprot.getScheme()).getScheme().read(iprot, this); } public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { schemes.get(oprot.getScheme()).getScheme().write(oprot, this); } @Override public String toString() { StringBuilder sb = new StringBuilder("sayInt_args("); boolean first = true; sb.append("param:"); sb.append(this.param); first = false; sb.append(")"); return sb.toString(); } public void validate() throws org.apache.thrift.TException { // check for required fields // check for sub-struct validity } private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { try { write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TiostreamTransport(out))); } catch (org.apache.thrift.TException te) { throw new java.io.IOException(te); } } private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { try { // it doesn‘t seem like you should have to do this, but java serialization is wacky, and doesn‘t call the default constructor. __isset_bitfield = 0; read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); } catch (org.apache.thrift.TException te) { throw new java.io.IOException(te); } } private static class sayInt_argsStandardSchemeFactory implements SchemeFactory { public sayInt_argsStandardScheme getScheme() { return new sayInt_argsStandardScheme(); } } private static class sayInt_argsStandardScheme extends StandardScheme<sayInt_args> { public void read(org.apache.thrift.protocol.TProtocol iprot, sayInt_args struct) throws org.apache.thrift.TException { org.apache.thrift.protocol.TField schemeField; iprot.readStructBegin(); while (true) { schemeField = iprot.readFieldBegin(); if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { break; } switch (schemeField.id) { case 1: // PARAM if (schemeField.type == org.apache.thrift.protocol.TType.I32) { struct.param = iprot.readI32(); struct.setParamIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; default: org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } iprot.readFieldEnd(); } iprot.readStructEnd(); // check for required fields of primitive type, which can‘t be checked in the validate method struct.validate(); } public void write(org.apache.thrift.protocol.TProtocol oprot, sayInt_args struct) throws org.apache.thrift.TException { struct.validate(); oprot.writeStructBegin(STRUCT_DESC); oprot.writeFieldBegin(PARAM_FIELD_DESC); oprot.writeI32(struct.param); oprot.writeFieldEnd(); oprot.writeFieldStop(); oprot.writeStructEnd(); } } private static class sayInt_argsTupleSchemeFactory implements SchemeFactory { public sayInt_argsTupleScheme getScheme() { return new sayInt_argsTupleScheme(); } } private static class sayInt_argsTupleScheme extends TupleScheme<sayInt_args> { @Override public void write(org.apache.thrift.protocol.TProtocol prot, sayInt_args struct) throws org.apache.thrift.TException { TTupleProtocol oprot = (TTupleProtocol) prot; BitSet optionals = new BitSet(); if (struct.isSetParam()) { optionals.set(0); } oprot.writeBitSet(optionals, 1); if (struct.isSetParam()) { oprot.writeI32(struct.param); } } @Override public void read(org.apache.thrift.protocol.TProtocol prot, sayInt_args struct) throws org.apache.thrift.TException { TTupleProtocol iprot = (TTupleProtocol) prot; BitSet incoming = iprot.readBitSet(1); if (incoming.get(0)) { struct.param = iprot.readI32(); struct.setParamIsSet(true); } } } } public static class sayInt_result implements org.apache.thrift.TBase<sayInt_result, sayInt_result._Fields>, java.io.Serializable, Cloneable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("sayInt_result"); private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.I32, (short)0); private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>(); static { schemes.put(StandardScheme.class, new sayInt_resultStandardSchemeFactory()); schemes.put(TupleScheme.class, new sayInt_resultTupleSchemeFactory()); } public int success; // required /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ public enum _Fields implements org.apache.thrift.TFieldIdEnum { SUCCESS((short)0, "success"); private static final Map<String, _Fields> byName = new HashMap<String, _Fields>(); static { for (_Fields field : EnumSet.allOf(_Fields.class)) { byName.put(field.getFieldName(), field); } } /** * Find the _Fields constant that matches fieldId, or null if its not found. */ public static _Fields findByThriftId(int fieldId) { switch(fieldId) { case 0: // SUCCESS return SUCCESS; default: return null; } } /** * Find the _Fields constant that matches fieldId, throwing an exception * if it is not found. */ public static _Fields findByThriftIdOrThrow(int fieldId) { _Fields fields = findByThriftId(fieldId); if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn‘t exist!"); return fields; } /** * Find the _Fields constant that matches name, or null if its not found. */ public static _Fields findByName(String name) { return byName.get(name); } private final short _thriftId; private final String _fieldName; _Fields(short thriftId, String fieldName) { _thriftId = thriftId; _fieldName = fieldName; } public short getThriftFieldId() { return _thriftId; } public String getFieldName() { return _fieldName; } } // isset id assignments private static final int __SUCCESS_ISSET_ID = 0; private byte __isset_bitfield = 0; public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; static { Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))); metaDataMap = Collections.unmodifiableMap(tmpMap); org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(sayInt_result.class, metaDataMap); } public sayInt_result() { } public sayInt_result( int success) { this(); this.success = success; setSuccessIsSet(true); } /** * Performs a deep copy on <i>other</i>. */ public sayInt_result(sayInt_result other) { __isset_bitfield = other.__isset_bitfield; this.success = other.success; } public sayInt_result deepCopy() { return new sayInt_result(this); } @Override public void clear() { setSuccessIsSet(false); this.success = 0; } public int getSuccess() { return this.success; } public sayInt_result setSuccess(int success) { this.success = success; setSuccessIsSet(true); return this; } public void unsetSuccess() { __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __SUCCESS_ISSET_ID); } /** Returns true if field success is set (has been assigned a value) and false otherwise */ public boolean isSetSuccess() { return EncodingUtils.testBit(__isset_bitfield, __SUCCESS_ISSET_ID); } public void setSuccessIsSet(boolean value) { __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __SUCCESS_ISSET_ID, value); } public void setFieldValue(_Fields field, Object value) { switch (field) { case SUCCESS: if (value == null) { unsetSuccess(); } else { setSuccess((Integer)value); } break; } } public Object getFieldValue(_Fields field) { switch (field) { case SUCCESS: return Integer.valueOf(getSuccess()); } throw new IllegalStateException(); } /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ public boolean isSet(_Fields field) { if (field == null) { throw new IllegalArgumentException(); } switch (field) { case SUCCESS: return isSetSuccess(); } throw new IllegalStateException(); } @Override public boolean equals(Object that) { if (that == null) return false; if (that instanceof sayInt_result) return this.equals((sayInt_result)that); return false; } public boolean equals(sayInt_result that) { if (that == null) return false; boolean this_present_success = true; boolean that_present_success = true; if (this_present_success || that_present_success) { if (!(this_present_success && that_present_success)) return false; if (this.success != that.success) return false; } return true; } @Override public int hashCode() { return 0; } public int compareTo(sayInt_result other) { if (!getClass().equals(other.getClass())) { return getClass().getName().compareTo(other.getClass().getName()); } int lastComparison = 0; sayInt_result typedOther = (sayInt_result)other; lastComparison = Boolean.valueOf(isSetSuccess()).compareTo(typedOther.isSetSuccess()); if (lastComparison != 0) { return lastComparison; } if (isSetSuccess()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, typedOther.success); if (lastComparison != 0) { return lastComparison; } } return 0; } public _Fields fieldForId(int fieldId) { return _Fields.findByThriftId(fieldId); } public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { schemes.get(iprot.getScheme()).getScheme().read(iprot, this); } public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { schemes.get(oprot.getScheme()).getScheme().write(oprot, this); } @Override public String toString() { StringBuilder sb = new StringBuilder("sayInt_result("); boolean first = true; sb.append("success:"); sb.append(this.success); first = false; sb.append(")"); return sb.toString(); } public void validate() throws org.apache.thrift.TException { // check for required fields // check for sub-struct validity } private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { try { write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); } catch (org.apache.thrift.TException te) { throw new java.io.IOException(te); } } private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { try { // it doesn‘t seem like you should have to do this, but java serialization is wacky, and doesn‘t call the default constructor. __isset_bitfield = 0; read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); } catch (org.apache.thrift.TException te) { throw new java.io.IOException(te); } } private static class sayInt_resultStandardSchemeFactory implements SchemeFactory { public sayInt_resultStandardScheme getScheme() { return new sayInt_resultStandardScheme(); } } private static class sayInt_resultStandardScheme extends StandardScheme<sayInt_result> { public void read(org.apache.thrift.protocol.TProtocol iprot, sayInt_result struct) throws org.apache.thrift.TException { org.apache.thrift.protocol.TField schemeField; iprot.readStructBegin(); while (true) { schemeField = iprot.readFieldBegin(); if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { break; } switch (schemeField.id) { case 0: // SUCCESS if (schemeField.type == org.apache.thrift.protocol.TType.I32) { struct.success = iprot.readI32(); struct.setSuccessIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; default: org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } iprot.readFieldEnd(); } iprot.readStructEnd(); // check for required fields of primitive type, which can‘t be checked in the validate method struct.validate(); } public void write(org.apache.thrift.protocol.TProtocol oprot, sayInt_result struct) throws org.apache.thrift.TException { struct.validate(); oprot.writeStructBegin(STRUCT_DESC); if (struct.isSetSuccess()) { oprot.writeFieldBegin(SUCCESS_FIELD_DESC); oprot.writeI32(struct.success); oprot.writeFieldEnd(); } oprot.writeFieldStop(); oprot.writeStructEnd(); } } private static class sayInt_resultTupleSchemeFactory implements SchemeFactory { public sayInt_resultTupleScheme getScheme() { return new sayInt_resultTupleScheme(); } } private static class sayInt_resultTupleScheme extends TupleScheme<sayInt_result> { @Override public void write(org.apache.thrift.protocol.TProtocol prot, sayInt_result struct) throws org.apache.thrift.TException { TTupleProtocol oprot = (TTupleProtocol) prot; BitSet optionals = new BitSet(); if (struct.isSetSuccess()) { optionals.set(0); } oprot.writeBitSet(optionals, 1); if (struct.isSetSuccess()) { oprot.writeI32(struct.success); } } @Override public void read(org.apache.thrift.protocol.TProtocol prot, sayInt_result struct) throws org.apache.thrift.TException { TTupleProtocol iprot = (TTupleProtocol) prot; BitSet incoming = iprot.readBitSet(1); if (incoming.get(0)) { struct.success = iprot.readI32(); struct.setSuccessIsSet(true); } } } } public static class sayString_args implements org.apache.thrift.TBase<sayString_args, sayString_args._Fields>, java.io.Serializable, Cloneable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("sayString_args"); private static final org.apache.thrift.protocol.TField PARAM_FIELD_DESC = new org.apache.thrift.protocol.TField("param", org.apache.thrift.protocol.TType.STRING, (short)1); private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>(); static { schemes.put(StandardScheme.class, new sayString_argsStandardSchemeFactory()); schemes.put(TupleScheme.class, new sayString_argsTupleSchemeFactory()); } public String param; // required /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ public enum _Fields implements org.apache.thrift.TFieldIdEnum { PARAM((short)1, "param"); private static final Map<String, _Fields> byName = new HashMap<String, _Fields>(); static { for (_Fields field : EnumSet.allOf(_Fields.class)) { byName.put(field.getFieldName(), field); } } /** * Find the _Fields constant that matches fieldId, or null if its not found. */ public static _Fields findByThriftId(int fieldId) { switch(fieldId) { case 1: // PARAM return PARAM; default: return null; } } /** * Find the _Fields constant that matches fieldId, throwing an exception * if it is not found. */ public static _Fields findByThriftIdOrThrow(int fieldId) { _Fields fields = findByThriftId(fieldId); if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn‘t exist!"); return fields; } /** * Find the _Fields constant that matches name, or null if its not found. */ public static _Fields findByName(String name) { return byName.get(name); } private final short _thriftId; private final String _fieldName; _Fields(short thriftId, String fieldName) { _thriftId = thriftId; _fieldName = fieldName; } public short getThriftFieldId() { return _thriftId; } public String getFieldName() { return _fieldName; } } // isset id assignments public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; static { Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); tmpMap.put(_Fields.PARAM, new org.apache.thrift.meta_data.FieldMetaData("param", org.apache.thrift.TFieldRequirementType.DEFAULT, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); metaDataMap = Collections.unmodifiableMap(tmpMap); org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(sayString_args.class, metaDataMap); } public sayString_args() { } public sayString_args( String param) { this(); this.param = param; } /** * Performs a deep copy on <i>other</i>. */ public sayString_args(sayString_args other) { if (other.isSetParam()) { this.param = other.param; } } public sayString_args deepCopy() { return new sayString_args(this); } @Override public void clear() { this.param = null; } public String getParam() { return this.param; } public sayString_args setParam(String param) { this.param = param; return this; } public void unsetParam() { this.param = null; } /** Returns true if field param is set (has been assigned a value) and false otherwise */ public boolean isSetParam() { return this.param != null; } public void setParamIsSet(boolean value) { if (!value) { this.param = null; } } public void setFieldValue(_Fields field, Object value) { switch (field) { case PARAM: if (value == null) { unsetParam(); } else { setParam((String)value); } break; } } public Object getFieldValue(_Fields field) { switch (field) { case PARAM: return getParam(); } throw new IllegalStateException(); } /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ public boolean isSet(_Fields field) { if (field == null) { throw new IllegalArgumentException(); } switch (field) { case PARAM: return isSetParam(); } throw new IllegalStateException(); } @Override public boolean equals(Object that) { if (that == null) return false; if (that instanceof sayString_args) return this.equals((sayString_args)that); return false; } public boolean equals(sayString_args that) { if (that == null) return false; boolean this_present_param = true && this.isSetParam(); boolean that_present_param = true && that.isSetParam(); if (this_present_param || that_present_param) { if (!(this_present_param && that_present_param)) return false; if (!this.param.equals(that.param)) return false; } return true; } @Override public int hashCode() { return 0; } public int compareTo(sayString_args other) { if (!getClass().equals(other.getClass())) { return getClass().getName().compareTo(other.getClass().getName()); } int lastComparison = 0; sayString_args typedOther = (sayString_args)other; lastComparison = Boolean.valueOf(isSetParam()).compareTo(typedOther.isSetParam()); if (lastComparison != 0) { return lastComparison; } if (isSetParam()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.param, typedOther.param); if (lastComparison != 0) { return lastComparison; } } return 0; } public _Fields fieldForId(int fieldId) { return _Fields.findByThriftId(fieldId); } public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { schemes.get(iprot.getScheme()).getScheme().read(iprot, this); } public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { schemes.get(oprot.getScheme()).getScheme().write(oprot, this); } @Override public String toString() { StringBuilder sb = new StringBuilder("sayString_args("); boolean first = true; sb.append("param:"); if (this.param == null) { sb.append("null"); } else { sb.append(this.param); } first = false; sb.append(")"); return sb.toString(); } public void validate() throws org.apache.thrift.TException { // check for required fields // check for sub-struct validity } private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { try { write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); } catch (org.apache.thrift.TException te) { throw new java.io.IOException(te); } } private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { try { read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); } catch (org.apache.thrift.TException te) { throw new java.io.IOException(te); } } private static class sayString_argsStandardSchemeFactory implements SchemeFactory { public sayString_argsStandardScheme getScheme() { return new sayString_argsStandardScheme(); } } private static class sayString_argsStandardScheme extends StandardScheme<sayString_args> { public void read(org.apache.thrift.protocol.TProtocol iprot, sayString_args struct) throws org.apache.thrift.TException { org.apache.thrift.protocol.TField schemeField; iprot.readStructBegin(); while (true) { schemeField = iprot.readFieldBegin(); if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { break; } switch (schemeField.id) { case 1: // PARAM if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { struct.param = iprot.readString(); struct.setParamIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; default: org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } iprot.readFieldEnd(); } iprot.readStructEnd(); // check for required fields of primitive type, which can‘t be checked in the validate method struct.validate(); } public void write(org.apache.thrift.protocol.TProtocol oprot, sayString_args struct) throws org.apache.thrift.TException { struct.validate(); oprot.writeStructBegin(STRUCT_DESC); if (struct.param != null) { oprot.writeFieldBegin(PARAM_FIELD_DESC); oprot.writeString(struct.param); oprot.writeFieldEnd(); } oprot.writeFieldStop(); oprot.writeStructEnd(); } } private static class sayString_argsTupleSchemeFactory implements SchemeFactory { public sayString_argsTupleScheme getScheme() { return new sayString_argsTupleScheme(); } } private static class sayString_argsTupleScheme extends TupleScheme<sayString_args> { @Override public void write(org.apache.thrift.protocol.TProtocol prot, sayString_args struct) throws org.apache.thrift.TException { TTupleProtocol oprot = (TTupleProtocol) prot; BitSet optionals = new BitSet(); if (struct.isSetParam()) { optionals.set(0); } oprot.writeBitSet(optionals, 1); if (struct.isSetParam()) { oprot.writeString(struct.param); } } @Override public void read(org.apache.thrift.protocol.TProtocol prot, sayString_args struct) throws org.apache.thrift.TException { TTupleProtocol iprot = (TTupleProtocol) prot; BitSet incoming = iprot.readBitSet(1); if (incoming.get(0)) { struct.param = iprot.readString(); struct.setParamIsSet(true); } } } } public static class sayString_result implements org.apache.thrift.TBase<sayString_result, sayString_result._Fields>, java.io.Serializable, Cloneable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("sayString_result"); private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.STRING, (short)0); private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>(); static { schemes.put(StandardScheme.class, new sayString_resultStandardSchemeFactory()); schemes.put(TupleScheme.class, new sayString_resultTupleSchemeFactory()); } public String success; // required /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ public enum _Fields implements org.apache.thrift.TFieldIdEnum { SUCCESS((short)0, "success"); private static final Map<String, _Fields> byName = new HashMap<String, _Fields>(); static { for (_Fields field : EnumSet.allOf(_Fields.class)) { byName.put(field.getFieldName(), field); } } /** * Find the _Fields constant that matches fieldId, or null if its not found. */ public static _Fields findByThriftId(int fieldId) { switch(fieldId) { case 0: // SUCCESS return SUCCESS; default: return null; } } /** * Find the _Fields constant that matches fieldId, throwing an exception * if it is not found. */ public static _Fields findByThriftIdOrThrow(int fieldId) { _Fields fields = findByThriftId(fieldId); if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn‘t exist!"); return fields; } /** * Find the _Fields constant that matches name, or null if its not found. */ public static _Fields findByName(String name) { return byName.get(name); } private final short _thriftId; private final String _fieldName; _Fields(short thriftId, String fieldName) { _thriftId = thriftId; _fieldName = fieldName; } public short getThriftFieldId() { return _thriftId; } public String getFieldName() { return _fieldName; } } // isset id assignments public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; static { Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); metaDataMap = Collections.unmodifiableMap(tmpMap); org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(sayString_result.class, metaDataMap); } public sayString_result() { } public sayString_result( String success) { this(); this.success = success; } /** * Performs a deep copy on <i>other</i>. */ public sayString_result(sayString_result other) { if (other.isSetSuccess()) { this.success = other.success; } } public sayString_result deepCopy() { return new sayString_result(this); } @Override public void clear() { this.success = null; } public String getSuccess() { return this.success; } public sayString_result setSuccess(String success) { this.success = success; return this; } public void unsetSuccess() { this.success = null; } /** Returns true if field success is set (has been assigned a value) and false otherwise */ public boolean isSetSuccess() { return this.success != null; } public void setSuccessIsSet(boolean value) { if (!value) { this.success = null; } } public void setFieldValue(_Fields field, Object value) { switch (field) { case SUCCESS: if (value == null) { unsetSuccess(); } else { setSuccess((String)value); } break; } } public Object getFieldValue(_Fields field) { switch (field) { case SUCCESS: return getSuccess(); } throw new IllegalStateException(); } /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ public boolean isSet(_Fields field) { if (field == null) { throw new IllegalArgumentException(); } switch (field) { case SUCCESS: return isSetSuccess(); } throw new IllegalStateException(); } @Override public boolean equals(Object that) { if (that == null) return false; if (that instanceof sayString_result) return this.equals((sayString_result)that); return false; } public boolean equals(sayString_result that) { if (that == null) return false; boolean this_present_success = true && this.isSetSuccess(); boolean that_present_success = true && that.isSetSuccess(); if (this_present_success || that_present_success) { if (!(this_present_success && that_present_success)) return false; if (!this.success.equals(that.success)) return false; } return true; } @Override public int hashCode() { return 0; } public int compareTo(sayString_result other) { if (!getClass().equals(other.getClass())) { return getClass().getName().compareTo(other.getClass().getName()); } int lastComparison = 0; sayString_result typedOther = (sayString_result)other; lastComparison = Boolean.valueOf(isSetSuccess()).compareTo(typedOther.isSetSuccess()); if (lastComparison != 0) { return lastComparison; } if (isSetSuccess()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, typedOther.success); if (lastComparison != 0) { return lastComparison; } } return 0; } public _Fields fieldForId(int fieldId) { return _Fields.findByThriftId(fieldId); } public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { schemes.get(iprot.getScheme()).getScheme().read(iprot, this); } public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { schemes.get(oprot.getScheme()).getScheme().write(oprot, this); } @Override public String toString() { StringBuilder sb = new StringBuilder("sayString_result("); boolean first = true; sb.append("success:"); if (this.success == null) { sb.append("null"); } else { sb.append(this.success); } first = false; sb.append(")"); return sb.toString(); } public void validate() throws org.apache.thrift.TException { // check for required fields // check for sub-struct validity } private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { try { write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); } catch (org.apache.thrift.TException te) { throw new java.io.IOException(te); } } private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { try { read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); } catch (org.apache.thrift.TException te) { throw new java.io.IOException(te); } } private static class sayString_resultStandardSchemeFactory implements SchemeFactory { public sayString_resultStandardScheme getScheme() { return new sayString_resultStandardScheme(); } } private static class sayString_resultStandardScheme extends StandardScheme<sayString_result> { public void read(org.apache.thrift.protocol.TProtocol iprot, sayString_result struct) throws org.apache.thrift.TException { org.apache.thrift.protocol.TField schemeField; iprot.readStructBegin(); while (true) { schemeField = iprot.readFieldBegin(); if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { break; } switch (schemeField.id) { case 0: // SUCCESS if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { struct.success = iprot.readString(); struct.setSuccessIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; default: org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);以上是关于thrift 远程服务调用 简单示例的主要内容,如果未能解决你的问题,请参考以下文章