diff --git a/src/main/java/org/exercise/work/ex1/client/RpcClient.java b/src/main/java/org/exercise/work/ex1/client/RpcClient.java new file mode 100644 index 0000000000000000000000000000000000000000..b3ff80cad987edf804e3309a128b117f1d418e9b --- /dev/null +++ b/src/main/java/org/exercise/work/ex1/client/RpcClient.java @@ -0,0 +1,42 @@ +package org.exercise.work.ex1.client; + +import org.apache.thrift.TConfiguration; +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.exercise.work.ex1.model.Student; +import org.exercise.work.ex1.service.Exercise1; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class RpcClient { + private static final String SERVER_IP="127.0.0.1"; + private static final int SERVER_PORT=9888; + private static final int TIMEOUT=1551; + + public static void main(String[] args) { + TTransport transport = null; + try{ + transport = new TSocket(new TConfiguration(), SERVER_IP, SERVER_PORT, TIMEOUT); + TProtocol protocol = new TBinaryProtocol(transport); + Exercise1.Client client = new Exercise1.Client(protocol); + transport.open(); + + Student student = new Student(); + student.setStudentName("zj"); + Set students = new HashSet(); + students.add(student); + List result = client.practice(99,61,students); + System.out.println("!!!"+result); + }catch (TException e){ + e.printStackTrace(); + }finally { + transport.close(); + } + } +} diff --git a/src/main/java/org/exercise/work/ex1/model/Student.java b/src/main/java/org/exercise/work/ex1/model/Student.java new file mode 100644 index 0000000000000000000000000000000000000000..5e94aa190e13cfa8cace40cf9709d3ee084c42f0 --- /dev/null +++ b/src/main/java/org/exercise/work/ex1/model/Student.java @@ -0,0 +1,632 @@ +/** + * Autogenerated by Thrift Compiler (0.15.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package org.exercise.work.ex1.model; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.15.0)", date = "2021-11-15") +public class Student implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("Student"); + + private static final org.apache.thrift.protocol.TField STUDENT_NO_FIELD_DESC = new org.apache.thrift.protocol.TField("studentNo", org.apache.thrift.protocol.TType.I64, (short)1); + private static final org.apache.thrift.protocol.TField STUDENT_NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("studentName", org.apache.thrift.protocol.TType.STRING, (short)2); + private static final org.apache.thrift.protocol.TField BOOK_NO_LIST_FIELD_DESC = new org.apache.thrift.protocol.TField("bookNoList", org.apache.thrift.protocol.TType.LIST, (short)3); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new StudentStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new StudentTupleSchemeFactory(); + + public long studentNo; // required + public @org.apache.thrift.annotation.Nullable String studentName; // optional + public @org.apache.thrift.annotation.Nullable java.util.List bookNoList; // optional + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + STUDENT_NO((short)1, "studentNo"), + STUDENT_NAME((short)2, "studentName"), + BOOK_NO_LIST((short)3, "bookNoList"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // STUDENT_NO + return STUDENT_NO; + case 2: // STUDENT_NAME + return STUDENT_NAME; + case 3: // BOOK_NO_LIST + return BOOK_NO_LIST; + 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. + */ + @org.apache.thrift.annotation.Nullable + 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 __STUDENTNO_ISSET_ID = 0; + private byte __isset_bitfield = 0; + private static final _Fields optionals[] = {_Fields.STUDENT_NAME,_Fields.BOOK_NO_LIST}; + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.STUDENT_NO, new org.apache.thrift.meta_data.FieldMetaData("studentNo", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))); + tmpMap.put(_Fields.STUDENT_NAME, new org.apache.thrift.meta_data.FieldMetaData("studentName", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + tmpMap.put(_Fields.BOOK_NO_LIST, new org.apache.thrift.meta_data.FieldMetaData("bookNoList", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(Student.class, metaDataMap); + } + + public Student() { + } + + public Student( + long studentNo) + { + this(); + this.studentNo = studentNo; + setStudentNoIsSet(true); + } + + /** + * Performs a deep copy on other. + */ + public Student(Student other) { + __isset_bitfield = other.__isset_bitfield; + this.studentNo = other.studentNo; + if (other.isSetStudentName()) { + this.studentName = other.studentName; + } + if (other.isSetBookNoList()) { + java.util.List __this__bookNoList = new java.util.ArrayList(other.bookNoList); + this.bookNoList = __this__bookNoList; + } + } + + public Student deepCopy() { + return new Student(this); + } + + @Override + public void clear() { + setStudentNoIsSet(false); + this.studentNo = 0; + this.studentName = null; + this.bookNoList = null; + } + + public long getStudentNo() { + return this.studentNo; + } + + public Student setStudentNo(long studentNo) { + this.studentNo = studentNo; + setStudentNoIsSet(true); + return this; + } + + public void unsetStudentNo() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __STUDENTNO_ISSET_ID); + } + + /** Returns true if field studentNo is set (has been assigned a value) and false otherwise */ + public boolean isSetStudentNo() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __STUDENTNO_ISSET_ID); + } + + public void setStudentNoIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __STUDENTNO_ISSET_ID, value); + } + + @org.apache.thrift.annotation.Nullable + public String getStudentName() { + return this.studentName; + } + + public Student setStudentName(@org.apache.thrift.annotation.Nullable String studentName) { + this.studentName = studentName; + return this; + } + + public void unsetStudentName() { + this.studentName = null; + } + + /** Returns true if field studentName is set (has been assigned a value) and false otherwise */ + public boolean isSetStudentName() { + return this.studentName != null; + } + + public void setStudentNameIsSet(boolean value) { + if (!value) { + this.studentName = null; + } + } + + public int getBookNoListSize() { + return (this.bookNoList == null) ? 0 : this.bookNoList.size(); + } + + @org.apache.thrift.annotation.Nullable + public java.util.Iterator getBookNoListIterator() { + return (this.bookNoList == null) ? null : this.bookNoList.iterator(); + } + + public void addToBookNoList(int elem) { + if (this.bookNoList == null) { + this.bookNoList = new java.util.ArrayList(); + } + this.bookNoList.add(elem); + } + + @org.apache.thrift.annotation.Nullable + public java.util.List getBookNoList() { + return this.bookNoList; + } + + public Student setBookNoList(@org.apache.thrift.annotation.Nullable java.util.List bookNoList) { + this.bookNoList = bookNoList; + return this; + } + + public void unsetBookNoList() { + this.bookNoList = null; + } + + /** Returns true if field bookNoList is set (has been assigned a value) and false otherwise */ + public boolean isSetBookNoList() { + return this.bookNoList != null; + } + + public void setBookNoListIsSet(boolean value) { + if (!value) { + this.bookNoList = null; + } + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable Object value) { + switch (field) { + case STUDENT_NO: + if (value == null) { + unsetStudentNo(); + } else { + setStudentNo((Long)value); + } + break; + + case STUDENT_NAME: + if (value == null) { + unsetStudentName(); + } else { + setStudentName((String)value); + } + break; + + case BOOK_NO_LIST: + if (value == null) { + unsetBookNoList(); + } else { + setBookNoList((java.util.List)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public Object getFieldValue(_Fields field) { + switch (field) { + case STUDENT_NO: + return getStudentNo(); + + case STUDENT_NAME: + return getStudentName(); + + case BOOK_NO_LIST: + return getBookNoList(); + + } + 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 STUDENT_NO: + return isSetStudentNo(); + case STUDENT_NAME: + return isSetStudentName(); + case BOOK_NO_LIST: + return isSetBookNoList(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that instanceof Student) + return this.equals((Student)that); + return false; + } + + public boolean equals(Student that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_studentNo = true; + boolean that_present_studentNo = true; + if (this_present_studentNo || that_present_studentNo) { + if (!(this_present_studentNo && that_present_studentNo)) + return false; + if (this.studentNo != that.studentNo) + return false; + } + + boolean this_present_studentName = true && this.isSetStudentName(); + boolean that_present_studentName = true && that.isSetStudentName(); + if (this_present_studentName || that_present_studentName) { + if (!(this_present_studentName && that_present_studentName)) + return false; + if (!this.studentName.equals(that.studentName)) + return false; + } + + boolean this_present_bookNoList = true && this.isSetBookNoList(); + boolean that_present_bookNoList = true && that.isSetBookNoList(); + if (this_present_bookNoList || that_present_bookNoList) { + if (!(this_present_bookNoList && that_present_bookNoList)) + return false; + if (!this.bookNoList.equals(that.bookNoList)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + org.apache.thrift.TBaseHelper.hashCode(studentNo); + + hashCode = hashCode * 8191 + ((isSetStudentName()) ? 131071 : 524287); + if (isSetStudentName()) + hashCode = hashCode * 8191 + studentName.hashCode(); + + hashCode = hashCode * 8191 + ((isSetBookNoList()) ? 131071 : 524287); + if (isSetBookNoList()) + hashCode = hashCode * 8191 + bookNoList.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(Student other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.compare(isSetStudentNo(), other.isSetStudentNo()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetStudentNo()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.studentNo, other.studentNo); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.compare(isSetStudentName(), other.isSetStudentName()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetStudentName()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.studentName, other.studentName); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.compare(isSetBookNoList(), other.isSetBookNoList()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetBookNoList()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.bookNoList, other.bookNoList); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("Student("); + boolean first = true; + + sb.append("studentNo:"); + sb.append(this.studentNo); + first = false; + if (isSetStudentName()) { + if (!first) sb.append(", "); + sb.append("studentName:"); + if (this.studentName == null) { + sb.append("null"); + } else { + sb.append(this.studentName); + } + first = false; + } + if (isSetBookNoList()) { + if (!first) sb.append(", "); + sb.append("bookNoList:"); + if (this.bookNoList == null) { + sb.append("null"); + } else { + sb.append(this.bookNoList); + } + first = false; + } + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // alas, we cannot check 'studentNo' because it's a primitive and you chose the non-beans generator. + // 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 StudentStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public StudentStandardScheme getScheme() { + return new StudentStandardScheme(); + } + } + + private static class StudentStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, Student 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: // STUDENT_NO + if (schemeField.type == org.apache.thrift.protocol.TType.I64) { + struct.studentNo = iprot.readI64(); + struct.setStudentNoIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // STUDENT_NAME + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.studentName = iprot.readString(); + struct.setStudentNameIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 3: // BOOK_NO_LIST + if (schemeField.type == org.apache.thrift.protocol.TType.LIST) { + { + org.apache.thrift.protocol.TList _list0 = iprot.readListBegin(); + struct.bookNoList = new java.util.ArrayList(_list0.size); + int _elem1; + for (int _i2 = 0; _i2 < _list0.size; ++_i2) + { + _elem1 = iprot.readI32(); + struct.bookNoList.add(_elem1); + } + iprot.readListEnd(); + } + struct.setBookNoListIsSet(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 + if (!struct.isSetStudentNo()) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'studentNo' was not found in serialized data! Struct: " + toString()); + } + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, Student struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldBegin(STUDENT_NO_FIELD_DESC); + oprot.writeI64(struct.studentNo); + oprot.writeFieldEnd(); + if (struct.studentName != null) { + if (struct.isSetStudentName()) { + oprot.writeFieldBegin(STUDENT_NAME_FIELD_DESC); + oprot.writeString(struct.studentName); + oprot.writeFieldEnd(); + } + } + if (struct.bookNoList != null) { + if (struct.isSetBookNoList()) { + oprot.writeFieldBegin(BOOK_NO_LIST_FIELD_DESC); + { + oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.I32, struct.bookNoList.size())); + for (int _iter3 : struct.bookNoList) + { + oprot.writeI32(_iter3); + } + oprot.writeListEnd(); + } + oprot.writeFieldEnd(); + } + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class StudentTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public StudentTupleScheme getScheme() { + return new StudentTupleScheme(); + } + } + + private static class StudentTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, Student struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + oprot.writeI64(struct.studentNo); + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetStudentName()) { + optionals.set(0); + } + if (struct.isSetBookNoList()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetStudentName()) { + oprot.writeString(struct.studentName); + } + if (struct.isSetBookNoList()) { + { + oprot.writeI32(struct.bookNoList.size()); + for (int _iter4 : struct.bookNoList) + { + oprot.writeI32(_iter4); + } + } + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, Student struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + struct.studentNo = iprot.readI64(); + struct.setStudentNoIsSet(true); + java.util.BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.studentName = iprot.readString(); + struct.setStudentNameIsSet(true); + } + if (incoming.get(1)) { + { + org.apache.thrift.protocol.TList _list5 = iprot.readListBegin(org.apache.thrift.protocol.TType.I32); + struct.bookNoList = new java.util.ArrayList(_list5.size); + int _elem6; + for (int _i7 = 0; _i7 < _list5.size; ++_i7) + { + _elem6 = iprot.readI32(); + struct.bookNoList.add(_elem6); + } + } + struct.setBookNoListIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } +} + diff --git a/src/main/java/org/exercise/work/ex1/server/RpcServer.java b/src/main/java/org/exercise/work/ex1/server/RpcServer.java new file mode 100644 index 0000000000000000000000000000000000000000..7802be95eab274794fe2d9ee488e125b583ca42b --- /dev/null +++ b/src/main/java/org/exercise/work/ex1/server/RpcServer.java @@ -0,0 +1,38 @@ +package org.exercise.work.ex1.server; + +import org.apache.thrift.protocol.TBinaryProtocol; +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 org.exercise.work.ex1.service.Exercise1; +import org.exercise.work.ex1.service.impl.ExerciseService; + +import java.io.IOException; +import java.net.ServerSocket; + +public class RpcServer { + public static final int SERVER_PORT = 9888; + public static void main(String[] args) throws IOException, TTransportException { + //设置服务端口 + ServerSocket serverSocket = new ServerSocket(SERVER_PORT); + TServerSocket serverTransport = new TServerSocket(serverSocket); + +//设置接口实现类 + Exercise1.Processor processor = new Exercise1.Processor(new ExerciseService()); + +//设置传输协议 + TBinaryProtocol.Factory protocolFactory = new TBinaryProtocol.Factory(); + +//初始化服务器启动参数 + TSimpleServer.Args tArgs = new TSimpleServer.Args(serverTransport); + tArgs.processor(processor); + tArgs.protocolFactory(protocolFactory); + +//启动服务 + TServer tServer = new TSimpleServer(tArgs); + System.out.println("Server Started"); + tServer.serve(); + + } +} diff --git a/src/main/java/org/exercise/work/ex1/service/Exercise1.java b/src/main/java/org/exercise/work/ex1/service/Exercise1.java new file mode 100644 index 0000000000000000000000000000000000000000..1ceaef4fd337ed28caba732e2e0c466fa32d180b --- /dev/null +++ b/src/main/java/org/exercise/work/ex1/service/Exercise1.java @@ -0,0 +1,1279 @@ +/** + * Autogenerated by Thrift Compiler (0.15.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package org.exercise.work.ex1.service; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.15.0)", date = "2021-11-15") +public class Exercise1 { + + public interface Iface { + + public java.util.List practice(int code, double score, java.util.Set students) throws org.apache.thrift.TException; + + } + + public interface AsyncIface { + + public void practice(int code, double score, java.util.Set students, org.apache.thrift.async.AsyncMethodCallback> 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 { + 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 java.util.List practice(int code, double score, java.util.Set students) throws org.apache.thrift.TException + { + send_practice(code, score, students); + return recv_practice(); + } + + public void send_practice(int code, double score, java.util.Set students) throws org.apache.thrift.TException + { + practice_args args = new practice_args(); + args.setCode(code); + args.setScore(score); + args.setStudents(students); + sendBase("practice", args); + } + + public java.util.List recv_practice() throws org.apache.thrift.TException + { + practice_result result = new practice_result(); + receiveBase(result, "practice"); + if (result.isSetSuccess()) { + return result.success; + } + throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "practice failed: unknown result"); + } + + } + public static class AsyncClient extends org.apache.thrift.async.TAsyncClient implements AsyncIface { + public static class Factory implements org.apache.thrift.async.TAsyncClientFactory { + 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 practice(int code, double score, java.util.Set students, org.apache.thrift.async.AsyncMethodCallback> resultHandler) throws org.apache.thrift.TException { + checkReady(); + practice_call method_call = new practice_call(code, score, students, resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class practice_call extends org.apache.thrift.async.TAsyncMethodCall> { + private int code; + private double score; + private java.util.Set students; + public practice_call(int code, double score, java.util.Set students, org.apache.thrift.async.AsyncMethodCallback> 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.code = code; + this.score = score; + this.students = students; + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("practice", org.apache.thrift.protocol.TMessageType.CALL, 0)); + practice_args args = new practice_args(); + args.setCode(code); + args.setScore(score); + args.setStudents(students); + args.write(prot); + prot.writeMessageEnd(); + } + + public java.util.List getResult() throws org.apache.thrift.TException { + if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { + throw new java.lang.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_practice(); + } + } + + } + + public static class Processor extends org.apache.thrift.TBaseProcessor implements org.apache.thrift.TProcessor { + private static final org.slf4j.Logger _LOGGER = org.slf4j.LoggerFactory.getLogger(Processor.class.getName()); + public Processor(I iface) { + super(iface, getProcessMap(new java.util.HashMap>())); + } + + protected Processor(I iface, java.util.Map> processMap) { + super(iface, getProcessMap(processMap)); + } + + private static java.util.Map> getProcessMap(java.util.Map> processMap) { + processMap.put("practice", new practice()); + return processMap; + } + + public static class practice extends org.apache.thrift.ProcessFunction { + public practice() { + super("practice"); + } + + public practice_args getEmptyArgsInstance() { + return new practice_args(); + } + + protected boolean isOneway() { + return false; + } + + @Override + protected boolean rethrowUnhandledExceptions() { + return false; + } + + public practice_result getResult(I iface, practice_args args) throws org.apache.thrift.TException { + practice_result result = new practice_result(); + result.success = iface.practice(args.code, args.score, args.students); + return result; + } + } + + } + + public static class AsyncProcessor extends org.apache.thrift.TBaseAsyncProcessor { + private static final org.slf4j.Logger _LOGGER = org.slf4j.LoggerFactory.getLogger(AsyncProcessor.class.getName()); + public AsyncProcessor(I iface) { + super(iface, getProcessMap(new java.util.HashMap>())); + } + + protected AsyncProcessor(I iface, java.util.Map> processMap) { + super(iface, getProcessMap(processMap)); + } + + private static java.util.Map> getProcessMap(java.util.Map> processMap) { + processMap.put("practice", new practice()); + return processMap; + } + + public static class practice extends org.apache.thrift.AsyncProcessFunction> { + public practice() { + super("practice"); + } + + public practice_args getEmptyArgsInstance() { + return new practice_args(); + } + + public org.apache.thrift.async.AsyncMethodCallback> getResultHandler(final org.apache.thrift.server.AbstractNonblockingServer.AsyncFrameBuffer fb, final int seqid) { + final org.apache.thrift.AsyncProcessFunction fcall = this; + return new org.apache.thrift.async.AsyncMethodCallback>() { + public void onComplete(java.util.List o) { + practice_result result = new practice_result(); + result.success = o; + try { + fcall.sendResponse(fb, result, org.apache.thrift.protocol.TMessageType.REPLY,seqid); + } catch (org.apache.thrift.transport.TTransportException e) { + _LOGGER.error("TTransportException writing to internal frame buffer", e); + fb.close(); + } catch (java.lang.Exception e) { + _LOGGER.error("Exception writing to internal frame buffer", e); + onError(e); + } + } + public void onError(java.lang.Exception e) { + byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; + org.apache.thrift.TSerializable msg; + practice_result result = new practice_result(); + if (e instanceof org.apache.thrift.transport.TTransportException) { + _LOGGER.error("TTransportException inside handler", e); + fb.close(); + return; + } else if (e instanceof org.apache.thrift.TApplicationException) { + _LOGGER.error("TApplicationException inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = (org.apache.thrift.TApplicationException)e; + } else { + _LOGGER.error("Exception inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage()); + } + try { + fcall.sendResponse(fb,msg,msgType,seqid); + } catch (java.lang.Exception ex) { + _LOGGER.error("Exception writing to internal frame buffer", ex); + fb.close(); + } + } + }; + } + + protected boolean isOneway() { + return false; + } + + public void start(I iface, practice_args args, org.apache.thrift.async.AsyncMethodCallback> resultHandler) throws org.apache.thrift.TException { + iface.practice(args.code, args.score, args.students,resultHandler); + } + } + + } + + public static class practice_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("practice_args"); + + private static final org.apache.thrift.protocol.TField CODE_FIELD_DESC = new org.apache.thrift.protocol.TField("code", org.apache.thrift.protocol.TType.I32, (short)1); + private static final org.apache.thrift.protocol.TField SCORE_FIELD_DESC = new org.apache.thrift.protocol.TField("score", org.apache.thrift.protocol.TType.DOUBLE, (short)-1); + private static final org.apache.thrift.protocol.TField STUDENTS_FIELD_DESC = new org.apache.thrift.protocol.TField("students", org.apache.thrift.protocol.TType.SET, (short)-2); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new practice_argsStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new practice_argsTupleSchemeFactory(); + + public int code; // required + public double score; // required + public @org.apache.thrift.annotation.Nullable java.util.Set students; // 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 { + CODE((short)1, "code"), + SCORE((short)-1, "score"), + STUDENTS((short)-2, "students"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // CODE + return CODE; + case -1: // SCORE + return SCORE; + case -2: // STUDENTS + return STUDENTS; + 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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __CODE_ISSET_ID = 0; + private static final int __SCORE_ISSET_ID = 1; + private byte __isset_bitfield = 0; + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.CODE, new org.apache.thrift.meta_data.FieldMetaData("code", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))); + tmpMap.put(_Fields.SCORE, new org.apache.thrift.meta_data.FieldMetaData("score", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.DOUBLE))); + tmpMap.put(_Fields.STUDENTS, new org.apache.thrift.meta_data.FieldMetaData("students", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.SetMetaData(org.apache.thrift.protocol.TType.SET, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, org.exercise.work.ex1.model.Student.class)))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(practice_args.class, metaDataMap); + } + + public practice_args() { + } + + public practice_args( + int code, + double score, + java.util.Set students) + { + this(); + this.code = code; + setCodeIsSet(true); + this.score = score; + setScoreIsSet(true); + this.students = students; + } + + /** + * Performs a deep copy on other. + */ + public practice_args(practice_args other) { + __isset_bitfield = other.__isset_bitfield; + this.code = other.code; + this.score = other.score; + if (other.isSetStudents()) { + java.util.Set __this__students = new java.util.HashSet(other.students.size()); + for (org.exercise.work.ex1.model.Student other_element : other.students) { + __this__students.add(new org.exercise.work.ex1.model.Student(other_element)); + } + this.students = __this__students; + } + } + + public practice_args deepCopy() { + return new practice_args(this); + } + + @Override + public void clear() { + setCodeIsSet(false); + this.code = 0; + setScoreIsSet(false); + this.score = 0.0; + this.students = null; + } + + public int getCode() { + return this.code; + } + + public practice_args setCode(int code) { + this.code = code; + setCodeIsSet(true); + return this; + } + + public void unsetCode() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __CODE_ISSET_ID); + } + + /** Returns true if field code is set (has been assigned a value) and false otherwise */ + public boolean isSetCode() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __CODE_ISSET_ID); + } + + public void setCodeIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __CODE_ISSET_ID, value); + } + + public double getScore() { + return this.score; + } + + public practice_args setScore(double score) { + this.score = score; + setScoreIsSet(true); + return this; + } + + public void unsetScore() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __SCORE_ISSET_ID); + } + + /** Returns true if field score is set (has been assigned a value) and false otherwise */ + public boolean isSetScore() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __SCORE_ISSET_ID); + } + + public void setScoreIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __SCORE_ISSET_ID, value); + } + + public int getStudentsSize() { + return (this.students == null) ? 0 : this.students.size(); + } + + @org.apache.thrift.annotation.Nullable + public java.util.Iterator getStudentsIterator() { + return (this.students == null) ? null : this.students.iterator(); + } + + public void addToStudents(org.exercise.work.ex1.model.Student elem) { + if (this.students == null) { + this.students = new java.util.HashSet(); + } + this.students.add(elem); + } + + @org.apache.thrift.annotation.Nullable + public java.util.Set getStudents() { + return this.students; + } + + public practice_args setStudents(@org.apache.thrift.annotation.Nullable java.util.Set students) { + this.students = students; + return this; + } + + public void unsetStudents() { + this.students = null; + } + + /** Returns true if field students is set (has been assigned a value) and false otherwise */ + public boolean isSetStudents() { + return this.students != null; + } + + public void setStudentsIsSet(boolean value) { + if (!value) { + this.students = null; + } + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) { + switch (field) { + case CODE: + if (value == null) { + unsetCode(); + } else { + setCode((java.lang.Integer)value); + } + break; + + case SCORE: + if (value == null) { + unsetScore(); + } else { + setScore((java.lang.Double)value); + } + break; + + case STUDENTS: + if (value == null) { + unsetStudents(); + } else { + setStudents((java.util.Set)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case CODE: + return getCode(); + + case SCORE: + return getScore(); + + case STUDENTS: + return getStudents(); + + } + throw new java.lang.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 java.lang.IllegalArgumentException(); + } + + switch (field) { + case CODE: + return isSetCode(); + case SCORE: + return isSetScore(); + case STUDENTS: + return isSetStudents(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that instanceof practice_args) + return this.equals((practice_args)that); + return false; + } + + public boolean equals(practice_args that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_code = true; + boolean that_present_code = true; + if (this_present_code || that_present_code) { + if (!(this_present_code && that_present_code)) + return false; + if (this.code != that.code) + return false; + } + + boolean this_present_score = true; + boolean that_present_score = true; + if (this_present_score || that_present_score) { + if (!(this_present_score && that_present_score)) + return false; + if (this.score != that.score) + return false; + } + + boolean this_present_students = true && this.isSetStudents(); + boolean that_present_students = true && that.isSetStudents(); + if (this_present_students || that_present_students) { + if (!(this_present_students && that_present_students)) + return false; + if (!this.students.equals(that.students)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + code; + + hashCode = hashCode * 8191 + org.apache.thrift.TBaseHelper.hashCode(score); + + hashCode = hashCode * 8191 + ((isSetStudents()) ? 131071 : 524287); + if (isSetStudents()) + hashCode = hashCode * 8191 + students.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(practice_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.compare(isSetCode(), other.isSetCode()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetCode()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.code, other.code); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.compare(isSetScore(), other.isSetScore()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetScore()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.score, other.score); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.compare(isSetStudents(), other.isSetStudents()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetStudents()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.students, other.students); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("practice_args("); + boolean first = true; + + sb.append("code:"); + sb.append(this.code); + first = false; + if (!first) sb.append(", "); + sb.append("score:"); + sb.append(this.score); + first = false; + if (!first) sb.append(", "); + sb.append("students:"); + if (this.students == null) { + sb.append("null"); + } else { + sb.append(this.students); + } + 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, java.lang.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 practice_argsStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public practice_argsStandardScheme getScheme() { + return new practice_argsStandardScheme(); + } + } + + private static class practice_argsStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, practice_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: // CODE + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.code = iprot.readI32(); + struct.setCodeIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case -1: // SCORE + if (schemeField.type == org.apache.thrift.protocol.TType.DOUBLE) { + struct.score = iprot.readDouble(); + struct.setScoreIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case -2: // STUDENTS + if (schemeField.type == org.apache.thrift.protocol.TType.SET) { + { + org.apache.thrift.protocol.TSet _set0 = iprot.readSetBegin(); + struct.students = new java.util.HashSet(2*_set0.size); + @org.apache.thrift.annotation.Nullable org.exercise.work.ex1.model.Student _elem1; + for (int _i2 = 0; _i2 < _set0.size; ++_i2) + { + _elem1 = new org.exercise.work.ex1.model.Student(); + _elem1.read(iprot); + struct.students.add(_elem1); + } + iprot.readSetEnd(); + } + struct.setStudentsIsSet(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, practice_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.students != null) { + oprot.writeFieldBegin(STUDENTS_FIELD_DESC); + { + oprot.writeSetBegin(new org.apache.thrift.protocol.TSet(org.apache.thrift.protocol.TType.STRUCT, struct.students.size())); + for (org.exercise.work.ex1.model.Student _iter3 : struct.students) + { + _iter3.write(oprot); + } + oprot.writeSetEnd(); + } + oprot.writeFieldEnd(); + } + oprot.writeFieldBegin(SCORE_FIELD_DESC); + oprot.writeDouble(struct.score); + oprot.writeFieldEnd(); + oprot.writeFieldBegin(CODE_FIELD_DESC); + oprot.writeI32(struct.code); + oprot.writeFieldEnd(); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class practice_argsTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public practice_argsTupleScheme getScheme() { + return new practice_argsTupleScheme(); + } + } + + private static class practice_argsTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, practice_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetCode()) { + optionals.set(0); + } + if (struct.isSetScore()) { + optionals.set(1); + } + if (struct.isSetStudents()) { + optionals.set(2); + } + oprot.writeBitSet(optionals, 3); + if (struct.isSetCode()) { + oprot.writeI32(struct.code); + } + if (struct.isSetScore()) { + oprot.writeDouble(struct.score); + } + if (struct.isSetStudents()) { + { + oprot.writeI32(struct.students.size()); + for (org.exercise.work.ex1.model.Student _iter4 : struct.students) + { + _iter4.write(oprot); + } + } + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, practice_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(3); + if (incoming.get(0)) { + struct.code = iprot.readI32(); + struct.setCodeIsSet(true); + } + if (incoming.get(1)) { + struct.score = iprot.readDouble(); + struct.setScoreIsSet(true); + } + if (incoming.get(2)) { + { + org.apache.thrift.protocol.TSet _set5 = iprot.readSetBegin(org.apache.thrift.protocol.TType.STRUCT); + struct.students = new java.util.HashSet(2*_set5.size); + @org.apache.thrift.annotation.Nullable org.exercise.work.ex1.model.Student _elem6; + for (int _i7 = 0; _i7 < _set5.size; ++_i7) + { + _elem6 = new org.exercise.work.ex1.model.Student(); + _elem6.read(iprot); + struct.students.add(_elem6); + } + } + struct.setStudentsIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + + public static class practice_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("practice_result"); + + private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.LIST, (short)0); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new practice_resultStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new practice_resultTupleSchemeFactory(); + + public @org.apache.thrift.annotation.Nullable java.util.List 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 java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + 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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.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.ListMetaData(org.apache.thrift.protocol.TType.LIST, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(practice_result.class, metaDataMap); + } + + public practice_result() { + } + + public practice_result( + java.util.List success) + { + this(); + this.success = success; + } + + /** + * Performs a deep copy on other. + */ + public practice_result(practice_result other) { + if (other.isSetSuccess()) { + java.util.List __this__success = new java.util.ArrayList(other.success); + this.success = __this__success; + } + } + + public practice_result deepCopy() { + return new practice_result(this); + } + + @Override + public void clear() { + this.success = null; + } + + public int getSuccessSize() { + return (this.success == null) ? 0 : this.success.size(); + } + + @org.apache.thrift.annotation.Nullable + public java.util.Iterator getSuccessIterator() { + return (this.success == null) ? null : this.success.iterator(); + } + + public void addToSuccess(java.lang.String elem) { + if (this.success == null) { + this.success = new java.util.ArrayList(); + } + this.success.add(elem); + } + + @org.apache.thrift.annotation.Nullable + public java.util.List getSuccess() { + return this.success; + } + + public practice_result setSuccess(@org.apache.thrift.annotation.Nullable java.util.List 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, @org.apache.thrift.annotation.Nullable java.lang.Object value) { + switch (field) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((java.util.List)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case SUCCESS: + return getSuccess(); + + } + throw new java.lang.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 java.lang.IllegalArgumentException(); + } + + switch (field) { + case SUCCESS: + return isSetSuccess(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that instanceof practice_result) + return this.equals((practice_result)that); + return false; + } + + public boolean equals(practice_result that) { + if (that == null) + return false; + if (this == that) + return true; + + 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() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetSuccess()) ? 131071 : 524287); + if (isSetSuccess()) + hashCode = hashCode * 8191 + success.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(practice_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.compare(isSetSuccess(), other.isSetSuccess()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSuccess()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, other.success); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("practice_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, java.lang.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 practice_resultStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public practice_resultStandardScheme getScheme() { + return new practice_resultStandardScheme(); + } + } + + private static class practice_resultStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, practice_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.LIST) { + { + org.apache.thrift.protocol.TList _list8 = iprot.readListBegin(); + struct.success = new java.util.ArrayList(_list8.size); + @org.apache.thrift.annotation.Nullable java.lang.String _elem9; + for (int _i10 = 0; _i10 < _list8.size; ++_i10) + { + _elem9 = iprot.readString(); + struct.success.add(_elem9); + } + iprot.readListEnd(); + } + 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, practice_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.success != null) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + { + oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRING, struct.success.size())); + for (java.lang.String _iter11 : struct.success) + { + oprot.writeString(_iter11); + } + oprot.writeListEnd(); + } + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class practice_resultTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public practice_resultTupleScheme getScheme() { + return new practice_resultTupleScheme(); + } + } + + private static class practice_resultTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, practice_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetSuccess()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetSuccess()) { + { + oprot.writeI32(struct.success.size()); + for (java.lang.String _iter12 : struct.success) + { + oprot.writeString(_iter12); + } + } + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, practice_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + { + org.apache.thrift.protocol.TList _list13 = iprot.readListBegin(org.apache.thrift.protocol.TType.STRING); + struct.success = new java.util.ArrayList(_list13.size); + @org.apache.thrift.annotation.Nullable java.lang.String _elem14; + for (int _i15 = 0; _i15 < _list13.size; ++_i15) + { + _elem14 = iprot.readString(); + struct.success.add(_elem14); + } + } + struct.setSuccessIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + +} diff --git a/src/main/java/org/exercise/work/ex1/service/impl/ExerciseService.java b/src/main/java/org/exercise/work/ex1/service/impl/ExerciseService.java new file mode 100644 index 0000000000000000000000000000000000000000..6bb273f5194fe2efff8f38978207cb5cfb20bb8f --- /dev/null +++ b/src/main/java/org/exercise/work/ex1/service/impl/ExerciseService.java @@ -0,0 +1,24 @@ +package org.exercise.work.ex1.service.impl; + +import org.apache.thrift.TException; +import org.exercise.work.ex1.model.Student; +import org.exercise.work.ex1.service.Exercise1; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +public class ExerciseService implements Exercise1.Iface { + @Override + public List practice(int code, double score, Set students) throws TException { + List result = new ArrayList(); + if(students == null || students.size() == 0){ + return result; + } + for (Student student :students + ) { + result.add(student.getBookNoListSize()+"-"+code+":"+score); + } + return result; + } +} diff --git a/src/main/java/org/exercise/work/ex2/client/RpcClient.java b/src/main/java/org/exercise/work/ex2/client/RpcClient.java new file mode 100644 index 0000000000000000000000000000000000000000..4557c37f6e8a4b88fbe4c34be66ff2370734d0af --- /dev/null +++ b/src/main/java/org/exercise/work/ex2/client/RpcClient.java @@ -0,0 +1,41 @@ +package org.exercise.work.ex2.client; + +import org.apache.thrift.TConfiguration; +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.exercise.work.ex2.model.CustomNumber; +import org.exercise.work.ex2.service.Exercise2Service; + +import java.util.ArrayList; +import java.util.List; + +public class RpcClient { + private static final String SERVER_IP="127.0.0.1"; + private static final int SERVER_PORT=9527; + private static final int TIMEOUT=1551; + + public static void main(String[] args) { + TTransport transport = null; + try { + transport = new TSocket(new TConfiguration(), SERVER_IP, SERVER_PORT, TIMEOUT); + TProtocol protocol = new TBinaryProtocol(transport); + Exercise2Service.Client client = new Exercise2Service.Client(protocol); + transport.open(); + + List customNumbers = new ArrayList(); + CustomNumber custnum = new CustomNumber(); + custnum.setDesc("123"); + custnum.setNo(1); + customNumbers.add(custnum); + String result = client.fetchNo(customNumbers ); + System.out.println(result); + } catch (TException e) { + e.printStackTrace(); + } finally { + transport.close(); + } + } +} diff --git a/src/main/java/org/exercise/work/ex2/model/CustomNumber.java b/src/main/java/org/exercise/work/ex2/model/CustomNumber.java new file mode 100644 index 0000000000000000000000000000000000000000..7697e4a7d1736cf5b65d6c1faac9ded93d878acd --- /dev/null +++ b/src/main/java/org/exercise/work/ex2/model/CustomNumber.java @@ -0,0 +1,465 @@ +/** + * Autogenerated by Thrift Compiler (0.15.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package org.exercise.work.ex2.model; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.15.0)", date = "2021-11-15") +public class CustomNumber implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("CustomNumber"); + + private static final org.apache.thrift.protocol.TField NO_FIELD_DESC = new org.apache.thrift.protocol.TField("no", org.apache.thrift.protocol.TType.I32, (short)1); + private static final org.apache.thrift.protocol.TField DESC_FIELD_DESC = new org.apache.thrift.protocol.TField("desc", org.apache.thrift.protocol.TType.STRING, (short)2); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new CustomNumberStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new CustomNumberTupleSchemeFactory(); + + public int no; // required + public @org.apache.thrift.annotation.Nullable java.lang.String desc; // 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 { + NO((short)1, "no"), + DESC((short)2, "desc"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // NO + return NO; + case 2: // DESC + return DESC; + 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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __NO_ISSET_ID = 0; + private byte __isset_bitfield = 0; + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.NO, new org.apache.thrift.meta_data.FieldMetaData("no", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))); + tmpMap.put(_Fields.DESC, new org.apache.thrift.meta_data.FieldMetaData("desc", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(CustomNumber.class, metaDataMap); + } + + public CustomNumber() { + } + + public CustomNumber( + int no, + java.lang.String desc) + { + this(); + this.no = no; + setNoIsSet(true); + this.desc = desc; + } + + /** + * Performs a deep copy on other. + */ + public CustomNumber(CustomNumber other) { + __isset_bitfield = other.__isset_bitfield; + this.no = other.no; + if (other.isSetDesc()) { + this.desc = other.desc; + } + } + + public CustomNumber deepCopy() { + return new CustomNumber(this); + } + + @Override + public void clear() { + setNoIsSet(false); + this.no = 0; + this.desc = null; + } + + public int getNo() { + return this.no; + } + + public CustomNumber setNo(int no) { + this.no = no; + setNoIsSet(true); + return this; + } + + public void unsetNo() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __NO_ISSET_ID); + } + + /** Returns true if field no is set (has been assigned a value) and false otherwise */ + public boolean isSetNo() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __NO_ISSET_ID); + } + + public void setNoIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __NO_ISSET_ID, value); + } + + @org.apache.thrift.annotation.Nullable + public java.lang.String getDesc() { + return this.desc; + } + + public CustomNumber setDesc(@org.apache.thrift.annotation.Nullable java.lang.String desc) { + this.desc = desc; + return this; + } + + public void unsetDesc() { + this.desc = null; + } + + /** Returns true if field desc is set (has been assigned a value) and false otherwise */ + public boolean isSetDesc() { + return this.desc != null; + } + + public void setDescIsSet(boolean value) { + if (!value) { + this.desc = null; + } + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) { + switch (field) { + case NO: + if (value == null) { + unsetNo(); + } else { + setNo((java.lang.Integer)value); + } + break; + + case DESC: + if (value == null) { + unsetDesc(); + } else { + setDesc((java.lang.String)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case NO: + return getNo(); + + case DESC: + return getDesc(); + + } + throw new java.lang.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 java.lang.IllegalArgumentException(); + } + + switch (field) { + case NO: + return isSetNo(); + case DESC: + return isSetDesc(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that instanceof CustomNumber) + return this.equals((CustomNumber)that); + return false; + } + + public boolean equals(CustomNumber that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_no = true; + boolean that_present_no = true; + if (this_present_no || that_present_no) { + if (!(this_present_no && that_present_no)) + return false; + if (this.no != that.no) + return false; + } + + boolean this_present_desc = true && this.isSetDesc(); + boolean that_present_desc = true && that.isSetDesc(); + if (this_present_desc || that_present_desc) { + if (!(this_present_desc && that_present_desc)) + return false; + if (!this.desc.equals(that.desc)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + no; + + hashCode = hashCode * 8191 + ((isSetDesc()) ? 131071 : 524287); + if (isSetDesc()) + hashCode = hashCode * 8191 + desc.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(CustomNumber other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.compare(isSetNo(), other.isSetNo()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetNo()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.no, other.no); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.compare(isSetDesc(), other.isSetDesc()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetDesc()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.desc, other.desc); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("CustomNumber("); + boolean first = true; + + sb.append("no:"); + sb.append(this.no); + first = false; + if (!first) sb.append(", "); + sb.append("desc:"); + if (this.desc == null) { + sb.append("null"); + } else { + sb.append(this.desc); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // alas, we cannot check 'no' because it's a primitive and you chose the non-beans generator. + if (desc == null) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'desc' was not present! Struct: " + toString()); + } + // 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, java.lang.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 CustomNumberStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public CustomNumberStandardScheme getScheme() { + return new CustomNumberStandardScheme(); + } + } + + private static class CustomNumberStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, CustomNumber 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: // NO + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.no = iprot.readI32(); + struct.setNoIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // DESC + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.desc = iprot.readString(); + struct.setDescIsSet(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 + if (!struct.isSetNo()) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'no' was not found in serialized data! Struct: " + toString()); + } + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, CustomNumber struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldBegin(NO_FIELD_DESC); + oprot.writeI32(struct.no); + oprot.writeFieldEnd(); + if (struct.desc != null) { + oprot.writeFieldBegin(DESC_FIELD_DESC); + oprot.writeString(struct.desc); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class CustomNumberTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public CustomNumberTupleScheme getScheme() { + return new CustomNumberTupleScheme(); + } + } + + private static class CustomNumberTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, CustomNumber struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + oprot.writeI32(struct.no); + oprot.writeString(struct.desc); + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, CustomNumber struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + struct.no = iprot.readI32(); + struct.setNoIsSet(true); + struct.desc = iprot.readString(); + struct.setDescIsSet(true); + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } +} + diff --git a/src/main/java/org/exercise/work/ex2/service/Exercise2Service.java b/src/main/java/org/exercise/work/ex2/service/Exercise2Service.java new file mode 100644 index 0000000000000000000000000000000000000000..0e40b445ede5d34fea1a187da2b86351370a83b4 --- /dev/null +++ b/src/main/java/org/exercise/work/ex2/service/Exercise2Service.java @@ -0,0 +1,1027 @@ +/** + * Autogenerated by Thrift Compiler (0.15.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package org.exercise.work.ex2.service; + +import org.exercise.work.ex2.model.CustomNumber; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.15.0)", date = "2021-11-15") +public class Exercise2Service { + + public interface Iface { + + public java.lang.String fetchNo(java.util.List numbers) throws org.apache.thrift.TException; + + } + + public interface AsyncIface { + + public void fetchNo(java.util.List numbers, org.apache.thrift.async.AsyncMethodCallback 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 { + 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 java.lang.String fetchNo(java.util.List numbers) throws org.apache.thrift.TException + { + send_fetchNo(numbers); + return recv_fetchNo(); + } + + public void send_fetchNo(java.util.List numbers) throws org.apache.thrift.TException + { + fetchNo_args args = new fetchNo_args(); + args.setNumbers(numbers); + sendBase("fetchNo", args); + } + + public java.lang.String recv_fetchNo() throws org.apache.thrift.TException + { + fetchNo_result result = new fetchNo_result(); + receiveBase(result, "fetchNo"); + if (result.isSetSuccess()) { + return result.success; + } + throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "fetchNo failed: unknown result"); + } + + } + public static class AsyncClient extends org.apache.thrift.async.TAsyncClient implements AsyncIface { + public static class Factory implements org.apache.thrift.async.TAsyncClientFactory { + 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 fetchNo(java.util.List numbers, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + checkReady(); + fetchNo_call method_call = new fetchNo_call(numbers, resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class fetchNo_call extends org.apache.thrift.async.TAsyncMethodCall { + private java.util.List numbers; + public fetchNo_call(java.util.List numbers, org.apache.thrift.async.AsyncMethodCallback 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.numbers = numbers; + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("fetchNo", org.apache.thrift.protocol.TMessageType.CALL, 0)); + fetchNo_args args = new fetchNo_args(); + args.setNumbers(numbers); + args.write(prot); + prot.writeMessageEnd(); + } + + public java.lang.String getResult() throws org.apache.thrift.TException { + if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { + throw new java.lang.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_fetchNo(); + } + } + + } + + public static class Processor extends org.apache.thrift.TBaseProcessor implements org.apache.thrift.TProcessor { + private static final org.slf4j.Logger _LOGGER = org.slf4j.LoggerFactory.getLogger(Processor.class.getName()); + public Processor(I iface) { + super(iface, getProcessMap(new java.util.HashMap>())); + } + + protected Processor(I iface, java.util.Map> processMap) { + super(iface, getProcessMap(processMap)); + } + + private static java.util.Map> getProcessMap(java.util.Map> processMap) { + processMap.put("fetchNo", new fetchNo()); + return processMap; + } + + public static class fetchNo extends org.apache.thrift.ProcessFunction { + public fetchNo() { + super("fetchNo"); + } + + public fetchNo_args getEmptyArgsInstance() { + return new fetchNo_args(); + } + + protected boolean isOneway() { + return false; + } + + @Override + protected boolean rethrowUnhandledExceptions() { + return false; + } + + public fetchNo_result getResult(I iface, fetchNo_args args) throws org.apache.thrift.TException { + fetchNo_result result = new fetchNo_result(); + result.success = iface.fetchNo(args.numbers); + return result; + } + } + + } + + public static class AsyncProcessor extends org.apache.thrift.TBaseAsyncProcessor { + private static final org.slf4j.Logger _LOGGER = org.slf4j.LoggerFactory.getLogger(AsyncProcessor.class.getName()); + public AsyncProcessor(I iface) { + super(iface, getProcessMap(new java.util.HashMap>())); + } + + protected AsyncProcessor(I iface, java.util.Map> processMap) { + super(iface, getProcessMap(processMap)); + } + + private static java.util.Map> getProcessMap(java.util.Map> processMap) { + processMap.put("fetchNo", new fetchNo()); + return processMap; + } + + public static class fetchNo extends org.apache.thrift.AsyncProcessFunction { + public fetchNo() { + super("fetchNo"); + } + + public fetchNo_args getEmptyArgsInstance() { + return new fetchNo_args(); + } + + public org.apache.thrift.async.AsyncMethodCallback getResultHandler(final org.apache.thrift.server.AbstractNonblockingServer.AsyncFrameBuffer fb, final int seqid) { + final org.apache.thrift.AsyncProcessFunction fcall = this; + return new org.apache.thrift.async.AsyncMethodCallback() { + public void onComplete(java.lang.String o) { + fetchNo_result result = new fetchNo_result(); + result.success = o; + try { + fcall.sendResponse(fb, result, org.apache.thrift.protocol.TMessageType.REPLY,seqid); + } catch (org.apache.thrift.transport.TTransportException e) { + _LOGGER.error("TTransportException writing to internal frame buffer", e); + fb.close(); + } catch (java.lang.Exception e) { + _LOGGER.error("Exception writing to internal frame buffer", e); + onError(e); + } + } + public void onError(java.lang.Exception e) { + byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; + org.apache.thrift.TSerializable msg; + fetchNo_result result = new fetchNo_result(); + if (e instanceof org.apache.thrift.transport.TTransportException) { + _LOGGER.error("TTransportException inside handler", e); + fb.close(); + return; + } else if (e instanceof org.apache.thrift.TApplicationException) { + _LOGGER.error("TApplicationException inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = (org.apache.thrift.TApplicationException)e; + } else { + _LOGGER.error("Exception inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage()); + } + try { + fcall.sendResponse(fb,msg,msgType,seqid); + } catch (java.lang.Exception ex) { + _LOGGER.error("Exception writing to internal frame buffer", ex); + fb.close(); + } + } + }; + } + + protected boolean isOneway() { + return false; + } + + public void start(I iface, fetchNo_args args, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + iface.fetchNo(args.numbers,resultHandler); + } + } + + } + + public static class fetchNo_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("fetchNo_args"); + + private static final org.apache.thrift.protocol.TField NUMBERS_FIELD_DESC = new org.apache.thrift.protocol.TField("numbers", org.apache.thrift.protocol.TType.LIST, (short)1); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new fetchNo_argsStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new fetchNo_argsTupleSchemeFactory(); + + public @org.apache.thrift.annotation.Nullable java.util.List numbers; // 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 { + NUMBERS((short)1, "numbers"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // NUMBERS + return NUMBERS; + 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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.NUMBERS, new org.apache.thrift.meta_data.FieldMetaData("numbers", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, CustomNumber.class)))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(fetchNo_args.class, metaDataMap); + } + + public fetchNo_args() { + } + + public fetchNo_args( + java.util.List numbers) + { + this(); + this.numbers = numbers; + } + + /** + * Performs a deep copy on other. + */ + public fetchNo_args(fetchNo_args other) { + if (other.isSetNumbers()) { + java.util.List __this__numbers = new java.util.ArrayList(other.numbers.size()); + for (CustomNumber other_element : other.numbers) { + __this__numbers.add(new CustomNumber(other_element)); + } + this.numbers = __this__numbers; + } + } + + public fetchNo_args deepCopy() { + return new fetchNo_args(this); + } + + @Override + public void clear() { + this.numbers = null; + } + + public int getNumbersSize() { + return (this.numbers == null) ? 0 : this.numbers.size(); + } + + @org.apache.thrift.annotation.Nullable + public java.util.Iterator getNumbersIterator() { + return (this.numbers == null) ? null : this.numbers.iterator(); + } + + public void addToNumbers(CustomNumber elem) { + if (this.numbers == null) { + this.numbers = new java.util.ArrayList(); + } + this.numbers.add(elem); + } + + @org.apache.thrift.annotation.Nullable + public java.util.List getNumbers() { + return this.numbers; + } + + public fetchNo_args setNumbers(@org.apache.thrift.annotation.Nullable java.util.List numbers) { + this.numbers = numbers; + return this; + } + + public void unsetNumbers() { + this.numbers = null; + } + + /** Returns true if field numbers is set (has been assigned a value) and false otherwise */ + public boolean isSetNumbers() { + return this.numbers != null; + } + + public void setNumbersIsSet(boolean value) { + if (!value) { + this.numbers = null; + } + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) { + switch (field) { + case NUMBERS: + if (value == null) { + unsetNumbers(); + } else { + setNumbers((java.util.List)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case NUMBERS: + return getNumbers(); + + } + throw new java.lang.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 java.lang.IllegalArgumentException(); + } + + switch (field) { + case NUMBERS: + return isSetNumbers(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that instanceof fetchNo_args) + return this.equals((fetchNo_args)that); + return false; + } + + public boolean equals(fetchNo_args that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_numbers = true && this.isSetNumbers(); + boolean that_present_numbers = true && that.isSetNumbers(); + if (this_present_numbers || that_present_numbers) { + if (!(this_present_numbers && that_present_numbers)) + return false; + if (!this.numbers.equals(that.numbers)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetNumbers()) ? 131071 : 524287); + if (isSetNumbers()) + hashCode = hashCode * 8191 + numbers.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(fetchNo_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.compare(isSetNumbers(), other.isSetNumbers()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetNumbers()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.numbers, other.numbers); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("fetchNo_args("); + boolean first = true; + + sb.append("numbers:"); + if (this.numbers == null) { + sb.append("null"); + } else { + sb.append(this.numbers); + } + 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, java.lang.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 fetchNo_argsStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public fetchNo_argsStandardScheme getScheme() { + return new fetchNo_argsStandardScheme(); + } + } + + private static class fetchNo_argsStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, fetchNo_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: // NUMBERS + if (schemeField.type == org.apache.thrift.protocol.TType.LIST) { + { + org.apache.thrift.protocol.TList _list0 = iprot.readListBegin(); + struct.numbers = new java.util.ArrayList(_list0.size); + @org.apache.thrift.annotation.Nullable CustomNumber _elem1; + for (int _i2 = 0; _i2 < _list0.size; ++_i2) + { + _elem1 = new CustomNumber(); + _elem1.read(iprot); + struct.numbers.add(_elem1); + } + iprot.readListEnd(); + } + struct.setNumbersIsSet(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, fetchNo_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.numbers != null) { + oprot.writeFieldBegin(NUMBERS_FIELD_DESC); + { + oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, struct.numbers.size())); + for (CustomNumber _iter3 : struct.numbers) + { + _iter3.write(oprot); + } + oprot.writeListEnd(); + } + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class fetchNo_argsTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public fetchNo_argsTupleScheme getScheme() { + return new fetchNo_argsTupleScheme(); + } + } + + private static class fetchNo_argsTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, fetchNo_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetNumbers()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetNumbers()) { + { + oprot.writeI32(struct.numbers.size()); + for (CustomNumber _iter4 : struct.numbers) + { + _iter4.write(oprot); + } + } + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, fetchNo_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + { + org.apache.thrift.protocol.TList _list5 = iprot.readListBegin(org.apache.thrift.protocol.TType.STRUCT); + struct.numbers = new java.util.ArrayList(_list5.size); + @org.apache.thrift.annotation.Nullable CustomNumber _elem6; + for (int _i7 = 0; _i7 < _list5.size; ++_i7) + { + _elem6 = new CustomNumber(); + _elem6.read(iprot); + struct.numbers.add(_elem6); + } + } + struct.setNumbersIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + + public static class fetchNo_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("fetchNo_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 org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new fetchNo_resultStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new fetchNo_resultTupleSchemeFactory(); + + public @org.apache.thrift.annotation.Nullable java.lang.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 java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + 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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.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 = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(fetchNo_result.class, metaDataMap); + } + + public fetchNo_result() { + } + + public fetchNo_result( + java.lang.String success) + { + this(); + this.success = success; + } + + /** + * Performs a deep copy on other. + */ + public fetchNo_result(fetchNo_result other) { + if (other.isSetSuccess()) { + this.success = other.success; + } + } + + public fetchNo_result deepCopy() { + return new fetchNo_result(this); + } + + @Override + public void clear() { + this.success = null; + } + + @org.apache.thrift.annotation.Nullable + public java.lang.String getSuccess() { + return this.success; + } + + public fetchNo_result setSuccess(@org.apache.thrift.annotation.Nullable java.lang.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, @org.apache.thrift.annotation.Nullable java.lang.Object value) { + switch (field) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((java.lang.String)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case SUCCESS: + return getSuccess(); + + } + throw new java.lang.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 java.lang.IllegalArgumentException(); + } + + switch (field) { + case SUCCESS: + return isSetSuccess(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that instanceof fetchNo_result) + return this.equals((fetchNo_result)that); + return false; + } + + public boolean equals(fetchNo_result that) { + if (that == null) + return false; + if (this == that) + return true; + + 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() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetSuccess()) ? 131071 : 524287); + if (isSetSuccess()) + hashCode = hashCode * 8191 + success.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(fetchNo_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.compare(isSetSuccess(), other.isSetSuccess()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSuccess()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, other.success); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("fetchNo_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, java.lang.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 fetchNo_resultStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public fetchNo_resultStandardScheme getScheme() { + return new fetchNo_resultStandardScheme(); + } + } + + private static class fetchNo_resultStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, fetchNo_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); + } + 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, fetchNo_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.success != null) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + oprot.writeString(struct.success); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class fetchNo_resultTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public fetchNo_resultTupleScheme getScheme() { + return new fetchNo_resultTupleScheme(); + } + } + + private static class fetchNo_resultTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, fetchNo_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetSuccess()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetSuccess()) { + oprot.writeString(struct.success); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, fetchNo_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + struct.success = iprot.readString(); + struct.setSuccessIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + +} diff --git a/src/main/java/org/exercise/work/ex4/client/RpcClient.java b/src/main/java/org/exercise/work/ex4/client/RpcClient.java new file mode 100644 index 0000000000000000000000000000000000000000..a44a546e9e0a604d6441080af050e2a6bc1bbc64 --- /dev/null +++ b/src/main/java/org/exercise/work/ex4/client/RpcClient.java @@ -0,0 +1,41 @@ +package org.exercise.work.ex4.client; + +import org.apache.thrift.TConfiguration; +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.exercise.work.ex4.model.Student; +import org.exercise.work.ex4.service.Exercise1; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class RpcClient { + private static final String SERVER_IP="127.0.0.1"; + private static final int SERVER_PORT=9888; + private static final int TIMEOUT=1551; + + public static void main(String[] args) { + TTransport transport = null; + try{ + transport = new TSocket(new TConfiguration(), SERVER_IP, SERVER_PORT, TIMEOUT); + TProtocol protocol = new TBinaryProtocol(transport); + Exercise1.Client client = new Exercise1.Client(protocol); + transport.open(); + + Student student = new Student(); + student.setStudentName(""); + Set students = new HashSet(); + students.add(student); + List result = client.practice(99,61,students); + System.out.println("!!!"+result); + }catch (TException e){ + e.printStackTrace(); + }finally { + transport.close(); + } + } +} diff --git a/src/main/java/org/exercise/work/ex4/model/CreateGoodReq.java b/src/main/java/org/exercise/work/ex4/model/CreateGoodReq.java new file mode 100644 index 0000000000000000000000000000000000000000..a56293963fc451b8f3c147804c4461fb3a4c9320 --- /dev/null +++ b/src/main/java/org/exercise/work/ex4/model/CreateGoodReq.java @@ -0,0 +1,16 @@ +package org.exercise.work.ex4.model; + +import com.facebook.swift.codec.ThriftField; +import com.facebook.swift.codec.ThriftStruct; + +import java.util.List; + +@ThriftStruct +public class CreateGoodReq { + @ThriftField(1) + public String name; + @ThriftField(2) + public Long price; + @ThriftField(3) + public List categories; +} diff --git a/src/main/java/org/exercise/work/ex4/model/Student.java b/src/main/java/org/exercise/work/ex4/model/Student.java new file mode 100644 index 0000000000000000000000000000000000000000..28dc4b8b1542cc5ce832d8c5c56100b39c8a02b9 --- /dev/null +++ b/src/main/java/org/exercise/work/ex4/model/Student.java @@ -0,0 +1,632 @@ +/** + * Autogenerated by Thrift Compiler (0.15.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package org.exercise.work.ex4.model; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.15.0)", date = "2021-11-15") +public class Student implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("Student"); + + private static final org.apache.thrift.protocol.TField STUDENT_NO_FIELD_DESC = new org.apache.thrift.protocol.TField("studentNo", org.apache.thrift.protocol.TType.I64, (short)1); + private static final org.apache.thrift.protocol.TField STUDENT_NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("studentName", org.apache.thrift.protocol.TType.STRING, (short)2); + private static final org.apache.thrift.protocol.TField BOOK_NO_LIST_FIELD_DESC = new org.apache.thrift.protocol.TField("bookNoList", org.apache.thrift.protocol.TType.LIST, (short)3); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new StudentStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new StudentTupleSchemeFactory(); + + public long studentNo; // required + public @org.apache.thrift.annotation.Nullable String studentName; // optional + public @org.apache.thrift.annotation.Nullable java.util.List bookNoList; // optional + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + STUDENT_NO((short)1, "studentNo"), + STUDENT_NAME((short)2, "studentName"), + BOOK_NO_LIST((short)3, "bookNoList"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // STUDENT_NO + return STUDENT_NO; + case 2: // STUDENT_NAME + return STUDENT_NAME; + case 3: // BOOK_NO_LIST + return BOOK_NO_LIST; + 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. + */ + @org.apache.thrift.annotation.Nullable + 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 __STUDENTNO_ISSET_ID = 0; + private byte __isset_bitfield = 0; + private static final _Fields optionals[] = {_Fields.STUDENT_NAME, _Fields.BOOK_NO_LIST}; + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.STUDENT_NO, new org.apache.thrift.meta_data.FieldMetaData("studentNo", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))); + tmpMap.put(_Fields.STUDENT_NAME, new org.apache.thrift.meta_data.FieldMetaData("studentName", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + tmpMap.put(_Fields.BOOK_NO_LIST, new org.apache.thrift.meta_data.FieldMetaData("bookNoList", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(Student.class, metaDataMap); + } + + public Student() { + } + + public Student( + long studentNo) + { + this(); + this.studentNo = studentNo; + setStudentNoIsSet(true); + } + + /** + * Performs a deep copy on other. + */ + public Student(Student other) { + __isset_bitfield = other.__isset_bitfield; + this.studentNo = other.studentNo; + if (other.isSetStudentName()) { + this.studentName = other.studentName; + } + if (other.isSetBookNoList()) { + java.util.List __this__bookNoList = new java.util.ArrayList(other.bookNoList); + this.bookNoList = __this__bookNoList; + } + } + + public Student deepCopy() { + return new Student(this); + } + + @Override + public void clear() { + setStudentNoIsSet(false); + this.studentNo = 0; + this.studentName = null; + this.bookNoList = null; + } + + public long getStudentNo() { + return this.studentNo; + } + + public Student setStudentNo(long studentNo) { + this.studentNo = studentNo; + setStudentNoIsSet(true); + return this; + } + + public void unsetStudentNo() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __STUDENTNO_ISSET_ID); + } + + /** Returns true if field studentNo is set (has been assigned a value) and false otherwise */ + public boolean isSetStudentNo() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __STUDENTNO_ISSET_ID); + } + + public void setStudentNoIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __STUDENTNO_ISSET_ID, value); + } + + @org.apache.thrift.annotation.Nullable + public String getStudentName() { + return this.studentName; + } + + public Student setStudentName(@org.apache.thrift.annotation.Nullable String studentName) { + this.studentName = studentName; + return this; + } + + public void unsetStudentName() { + this.studentName = null; + } + + /** Returns true if field studentName is set (has been assigned a value) and false otherwise */ + public boolean isSetStudentName() { + return this.studentName != null; + } + + public void setStudentNameIsSet(boolean value) { + if (!value) { + this.studentName = null; + } + } + + public int getBookNoListSize() { + return (this.bookNoList == null) ? 0 : this.bookNoList.size(); + } + + @org.apache.thrift.annotation.Nullable + public java.util.Iterator getBookNoListIterator() { + return (this.bookNoList == null) ? null : this.bookNoList.iterator(); + } + + public void addToBookNoList(int elem) { + if (this.bookNoList == null) { + this.bookNoList = new java.util.ArrayList(); + } + this.bookNoList.add(elem); + } + + @org.apache.thrift.annotation.Nullable + public java.util.List getBookNoList() { + return this.bookNoList; + } + + public Student setBookNoList(@org.apache.thrift.annotation.Nullable java.util.List bookNoList) { + this.bookNoList = bookNoList; + return this; + } + + public void unsetBookNoList() { + this.bookNoList = null; + } + + /** Returns true if field bookNoList is set (has been assigned a value) and false otherwise */ + public boolean isSetBookNoList() { + return this.bookNoList != null; + } + + public void setBookNoListIsSet(boolean value) { + if (!value) { + this.bookNoList = null; + } + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable Object value) { + switch (field) { + case STUDENT_NO: + if (value == null) { + unsetStudentNo(); + } else { + setStudentNo((Long)value); + } + break; + + case STUDENT_NAME: + if (value == null) { + unsetStudentName(); + } else { + setStudentName((String)value); + } + break; + + case BOOK_NO_LIST: + if (value == null) { + unsetBookNoList(); + } else { + setBookNoList((java.util.List)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public Object getFieldValue(_Fields field) { + switch (field) { + case STUDENT_NO: + return getStudentNo(); + + case STUDENT_NAME: + return getStudentName(); + + case BOOK_NO_LIST: + return getBookNoList(); + + } + 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 STUDENT_NO: + return isSetStudentNo(); + case STUDENT_NAME: + return isSetStudentName(); + case BOOK_NO_LIST: + return isSetBookNoList(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that instanceof Student) + return this.equals((Student)that); + return false; + } + + public boolean equals(Student that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_studentNo = true; + boolean that_present_studentNo = true; + if (this_present_studentNo || that_present_studentNo) { + if (!(this_present_studentNo && that_present_studentNo)) + return false; + if (this.studentNo != that.studentNo) + return false; + } + + boolean this_present_studentName = true && this.isSetStudentName(); + boolean that_present_studentName = true && that.isSetStudentName(); + if (this_present_studentName || that_present_studentName) { + if (!(this_present_studentName && that_present_studentName)) + return false; + if (!this.studentName.equals(that.studentName)) + return false; + } + + boolean this_present_bookNoList = true && this.isSetBookNoList(); + boolean that_present_bookNoList = true && that.isSetBookNoList(); + if (this_present_bookNoList || that_present_bookNoList) { + if (!(this_present_bookNoList && that_present_bookNoList)) + return false; + if (!this.bookNoList.equals(that.bookNoList)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + org.apache.thrift.TBaseHelper.hashCode(studentNo); + + hashCode = hashCode * 8191 + ((isSetStudentName()) ? 131071 : 524287); + if (isSetStudentName()) + hashCode = hashCode * 8191 + studentName.hashCode(); + + hashCode = hashCode * 8191 + ((isSetBookNoList()) ? 131071 : 524287); + if (isSetBookNoList()) + hashCode = hashCode * 8191 + bookNoList.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(Student other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.compare(isSetStudentNo(), other.isSetStudentNo()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetStudentNo()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.studentNo, other.studentNo); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.compare(isSetStudentName(), other.isSetStudentName()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetStudentName()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.studentName, other.studentName); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.compare(isSetBookNoList(), other.isSetBookNoList()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetBookNoList()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.bookNoList, other.bookNoList); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("Student("); + boolean first = true; + + sb.append("studentNo:"); + sb.append(this.studentNo); + first = false; + if (isSetStudentName()) { + if (!first) sb.append(", "); + sb.append("studentName:"); + if (this.studentName == null) { + sb.append("null"); + } else { + sb.append(this.studentName); + } + first = false; + } + if (isSetBookNoList()) { + if (!first) sb.append(", "); + sb.append("bookNoList:"); + if (this.bookNoList == null) { + sb.append("null"); + } else { + sb.append(this.bookNoList); + } + first = false; + } + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // alas, we cannot check 'studentNo' because it's a primitive and you chose the non-beans generator. + // 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 StudentStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public StudentStandardScheme getScheme() { + return new StudentStandardScheme(); + } + } + + private static class StudentStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, Student 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: // STUDENT_NO + if (schemeField.type == org.apache.thrift.protocol.TType.I64) { + struct.studentNo = iprot.readI64(); + struct.setStudentNoIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // STUDENT_NAME + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.studentName = iprot.readString(); + struct.setStudentNameIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 3: // BOOK_NO_LIST + if (schemeField.type == org.apache.thrift.protocol.TType.LIST) { + { + org.apache.thrift.protocol.TList _list0 = iprot.readListBegin(); + struct.bookNoList = new java.util.ArrayList(_list0.size); + int _elem1; + for (int _i2 = 0; _i2 < _list0.size; ++_i2) + { + _elem1 = iprot.readI32(); + struct.bookNoList.add(_elem1); + } + iprot.readListEnd(); + } + struct.setBookNoListIsSet(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 + if (!struct.isSetStudentNo()) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'studentNo' was not found in serialized data! Struct: " + toString()); + } + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, Student struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldBegin(STUDENT_NO_FIELD_DESC); + oprot.writeI64(struct.studentNo); + oprot.writeFieldEnd(); + if (struct.studentName != null) { + if (struct.isSetStudentName()) { + oprot.writeFieldBegin(STUDENT_NAME_FIELD_DESC); + oprot.writeString(struct.studentName); + oprot.writeFieldEnd(); + } + } + if (struct.bookNoList != null) { + if (struct.isSetBookNoList()) { + oprot.writeFieldBegin(BOOK_NO_LIST_FIELD_DESC); + { + oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.I32, struct.bookNoList.size())); + for (int _iter3 : struct.bookNoList) + { + oprot.writeI32(_iter3); + } + oprot.writeListEnd(); + } + oprot.writeFieldEnd(); + } + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class StudentTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public StudentTupleScheme getScheme() { + return new StudentTupleScheme(); + } + } + + private static class StudentTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, Student struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + oprot.writeI64(struct.studentNo); + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetStudentName()) { + optionals.set(0); + } + if (struct.isSetBookNoList()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetStudentName()) { + oprot.writeString(struct.studentName); + } + if (struct.isSetBookNoList()) { + { + oprot.writeI32(struct.bookNoList.size()); + for (int _iter4 : struct.bookNoList) + { + oprot.writeI32(_iter4); + } + } + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, Student struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + struct.studentNo = iprot.readI64(); + struct.setStudentNoIsSet(true); + java.util.BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.studentName = iprot.readString(); + struct.setStudentNameIsSet(true); + } + if (incoming.get(1)) { + { + org.apache.thrift.protocol.TList _list5 = iprot.readListBegin(org.apache.thrift.protocol.TType.I32); + struct.bookNoList = new java.util.ArrayList(_list5.size); + int _elem6; + for (int _i7 = 0; _i7 < _list5.size; ++_i7) + { + _elem6 = iprot.readI32(); + struct.bookNoList.add(_elem6); + } + } + struct.setBookNoListIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } +} + diff --git a/src/main/java/org/exercise/work/ex4/server/RpcServer.java b/src/main/java/org/exercise/work/ex4/server/RpcServer.java new file mode 100644 index 0000000000000000000000000000000000000000..1708d370a82a85383e3f9c87cb80a3ff71287a33 --- /dev/null +++ b/src/main/java/org/exercise/work/ex4/server/RpcServer.java @@ -0,0 +1,38 @@ +package org.exercise.work.ex4.server; + +import org.apache.thrift.protocol.TBinaryProtocol; +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 org.exercise.work.ex4.service.Exercise1; +import org.exercise.work.ex4.service.impl.ExerciseService; + +import java.io.IOException; +import java.net.ServerSocket; + +public class RpcServer { + public static final int SERVER_PORT = 9888; + public static void main(String[] args) throws IOException, TTransportException { + //设置服务端口 + ServerSocket serverSocket = new ServerSocket(SERVER_PORT); + TServerSocket serverTransport = new TServerSocket(serverSocket); + +//设置接口实现类 + Exercise1.Processor processor = new Exercise1.Processor(new ExerciseService()); + +//设置传输协议 + TBinaryProtocol.Factory protocolFactory = new TBinaryProtocol.Factory(); + +//初始化服务器启动参数 + TSimpleServer.Args tArgs = new TSimpleServer.Args(serverTransport); + tArgs.processor(processor); + tArgs.protocolFactory(protocolFactory); + +//启动服务 + TServer tServer = new TSimpleServer(tArgs); + System.out.println("Server Started"); + tServer.serve(); + + } +} diff --git a/src/main/java/org/exercise/work/ex4/service/Exercise1.java b/src/main/java/org/exercise/work/ex4/service/Exercise1.java new file mode 100644 index 0000000000000000000000000000000000000000..769e3fc7ca2e9b38e304438d6e415b660117fadb --- /dev/null +++ b/src/main/java/org/exercise/work/ex4/service/Exercise1.java @@ -0,0 +1,1281 @@ +/** + * Autogenerated by Thrift Compiler (0.15.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package org.exercise.work.ex4.service; + +import org.exercise.work.ex4.model.Student; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.15.0)", date = "2021-11-15") +public class Exercise1 { + + public interface Iface { + + public java.util.List practice(int code, double score, java.util.Set students) throws org.apache.thrift.TException; + + } + + public interface AsyncIface { + + public void practice(int code, double score, java.util.Set students, org.apache.thrift.async.AsyncMethodCallback> 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 { + 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 java.util.List practice(int code, double score, java.util.Set students) throws org.apache.thrift.TException + { + send_practice(code, score, students); + return recv_practice(); + } + + public void send_practice(int code, double score, java.util.Set students) throws org.apache.thrift.TException + { + practice_args args = new practice_args(); + args.setCode(code); + args.setScore(score); + args.setStudents(students); + sendBase("practice", args); + } + + public java.util.List recv_practice() throws org.apache.thrift.TException + { + practice_result result = new practice_result(); + receiveBase(result, "practice"); + if (result.isSetSuccess()) { + return result.success; + } + throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "practice failed: unknown result"); + } + + } + public static class AsyncClient extends org.apache.thrift.async.TAsyncClient implements AsyncIface { + public static class Factory implements org.apache.thrift.async.TAsyncClientFactory { + 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 practice(int code, double score, java.util.Set students, org.apache.thrift.async.AsyncMethodCallback> resultHandler) throws org.apache.thrift.TException { + checkReady(); + practice_call method_call = new practice_call(code, score, students, resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class practice_call extends org.apache.thrift.async.TAsyncMethodCall> { + private int code; + private double score; + private java.util.Set students; + public practice_call(int code, double score, java.util.Set students, org.apache.thrift.async.AsyncMethodCallback> 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.code = code; + this.score = score; + this.students = students; + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("practice", org.apache.thrift.protocol.TMessageType.CALL, 0)); + practice_args args = new practice_args(); + args.setCode(code); + args.setScore(score); + args.setStudents(students); + args.write(prot); + prot.writeMessageEnd(); + } + + public java.util.List getResult() throws org.apache.thrift.TException { + if (getState() != 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_practice(); + } + } + + } + + public static class Processor extends org.apache.thrift.TBaseProcessor implements org.apache.thrift.TProcessor { + private static final org.slf4j.Logger _LOGGER = org.slf4j.LoggerFactory.getLogger(Processor.class.getName()); + public Processor(I iface) { + super(iface, getProcessMap(new java.util.HashMap>())); + } + + protected Processor(I iface, java.util.Map> processMap) { + super(iface, getProcessMap(processMap)); + } + + private static java.util.Map> getProcessMap(java.util.Map> processMap) { + processMap.put("practice", new practice()); + return processMap; + } + + public static class practice extends org.apache.thrift.ProcessFunction { + public practice() { + super("practice"); + } + + public practice_args getEmptyArgsInstance() { + return new practice_args(); + } + + protected boolean isOneway() { + return false; + } + + @Override + protected boolean rethrowUnhandledExceptions() { + return false; + } + + public practice_result getResult(I iface, practice_args args) throws org.apache.thrift.TException { + practice_result result = new practice_result(); + result.success = iface.practice(args.code, args.score, args.students); + return result; + } + } + + } + + public static class AsyncProcessor extends org.apache.thrift.TBaseAsyncProcessor { + private static final org.slf4j.Logger _LOGGER = org.slf4j.LoggerFactory.getLogger(AsyncProcessor.class.getName()); + public AsyncProcessor(I iface) { + super(iface, getProcessMap(new java.util.HashMap>())); + } + + protected AsyncProcessor(I iface, java.util.Map> processMap) { + super(iface, getProcessMap(processMap)); + } + + private static java.util.Map> getProcessMap(java.util.Map> processMap) { + processMap.put("practice", new practice()); + return processMap; + } + + public static class practice extends org.apache.thrift.AsyncProcessFunction> { + public practice() { + super("practice"); + } + + public practice_args getEmptyArgsInstance() { + return new practice_args(); + } + + public org.apache.thrift.async.AsyncMethodCallback> getResultHandler(final org.apache.thrift.server.AbstractNonblockingServer.AsyncFrameBuffer fb, final int seqid) { + final org.apache.thrift.AsyncProcessFunction fcall = this; + return new org.apache.thrift.async.AsyncMethodCallback>() { + public void onComplete(java.util.List o) { + practice_result result = new practice_result(); + result.success = o; + try { + fcall.sendResponse(fb, result, org.apache.thrift.protocol.TMessageType.REPLY,seqid); + } catch (org.apache.thrift.transport.TTransportException e) { + _LOGGER.error("TTransportException writing to internal frame buffer", e); + fb.close(); + } catch (Exception e) { + _LOGGER.error("Exception writing to internal frame buffer", e); + onError(e); + } + } + public void onError(Exception e) { + byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; + org.apache.thrift.TSerializable msg; + practice_result result = new practice_result(); + if (e instanceof org.apache.thrift.transport.TTransportException) { + _LOGGER.error("TTransportException inside handler", e); + fb.close(); + return; + } else if (e instanceof org.apache.thrift.TApplicationException) { + _LOGGER.error("TApplicationException inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = (org.apache.thrift.TApplicationException)e; + } else { + _LOGGER.error("Exception inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage()); + } + try { + fcall.sendResponse(fb,msg,msgType,seqid); + } catch (Exception ex) { + _LOGGER.error("Exception writing to internal frame buffer", ex); + fb.close(); + } + } + }; + } + + protected boolean isOneway() { + return false; + } + + public void start(I iface, practice_args args, org.apache.thrift.async.AsyncMethodCallback> resultHandler) throws org.apache.thrift.TException { + iface.practice(args.code, args.score, args.students,resultHandler); + } + } + + } + + public static class practice_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("practice_args"); + + private static final org.apache.thrift.protocol.TField CODE_FIELD_DESC = new org.apache.thrift.protocol.TField("code", org.apache.thrift.protocol.TType.I32, (short)1); + private static final org.apache.thrift.protocol.TField SCORE_FIELD_DESC = new org.apache.thrift.protocol.TField("score", org.apache.thrift.protocol.TType.DOUBLE, (short)-1); + private static final org.apache.thrift.protocol.TField STUDENTS_FIELD_DESC = new org.apache.thrift.protocol.TField("students", org.apache.thrift.protocol.TType.SET, (short)-2); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new practice_argsStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new practice_argsTupleSchemeFactory(); + + public int code; // required + public double score; // required + public @org.apache.thrift.annotation.Nullable java.util.Set students; // 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 { + CODE((short)1, "code"), + SCORE((short)-1, "score"), + STUDENTS((short)-2, "students"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // CODE + return CODE; + case -1: // SCORE + return SCORE; + case -2: // STUDENTS + return STUDENTS; + 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. + */ + @org.apache.thrift.annotation.Nullable + 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 __CODE_ISSET_ID = 0; + private static final int __SCORE_ISSET_ID = 1; + private byte __isset_bitfield = 0; + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.CODE, new org.apache.thrift.meta_data.FieldMetaData("code", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))); + tmpMap.put(_Fields.SCORE, new org.apache.thrift.meta_data.FieldMetaData("score", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.DOUBLE))); + tmpMap.put(_Fields.STUDENTS, new org.apache.thrift.meta_data.FieldMetaData("students", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.SetMetaData(org.apache.thrift.protocol.TType.SET, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, Student.class)))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(practice_args.class, metaDataMap); + } + + public practice_args() { + } + + public practice_args( + int code, + double score, + java.util.Set students) + { + this(); + this.code = code; + setCodeIsSet(true); + this.score = score; + setScoreIsSet(true); + this.students = students; + } + + /** + * Performs a deep copy on other. + */ + public practice_args(practice_args other) { + __isset_bitfield = other.__isset_bitfield; + this.code = other.code; + this.score = other.score; + if (other.isSetStudents()) { + java.util.Set __this__students = new java.util.HashSet(other.students.size()); + for (Student other_element : other.students) { + __this__students.add(new Student(other_element)); + } + this.students = __this__students; + } + } + + public practice_args deepCopy() { + return new practice_args(this); + } + + @Override + public void clear() { + setCodeIsSet(false); + this.code = 0; + setScoreIsSet(false); + this.score = 0.0; + this.students = null; + } + + public int getCode() { + return this.code; + } + + public practice_args setCode(int code) { + this.code = code; + setCodeIsSet(true); + return this; + } + + public void unsetCode() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __CODE_ISSET_ID); + } + + /** Returns true if field code is set (has been assigned a value) and false otherwise */ + public boolean isSetCode() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __CODE_ISSET_ID); + } + + public void setCodeIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __CODE_ISSET_ID, value); + } + + public double getScore() { + return this.score; + } + + public practice_args setScore(double score) { + this.score = score; + setScoreIsSet(true); + return this; + } + + public void unsetScore() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __SCORE_ISSET_ID); + } + + /** Returns true if field score is set (has been assigned a value) and false otherwise */ + public boolean isSetScore() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __SCORE_ISSET_ID); + } + + public void setScoreIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __SCORE_ISSET_ID, value); + } + + public int getStudentsSize() { + return (this.students == null) ? 0 : this.students.size(); + } + + @org.apache.thrift.annotation.Nullable + public java.util.Iterator getStudentsIterator() { + return (this.students == null) ? null : this.students.iterator(); + } + + public void addToStudents(Student elem) { + if (this.students == null) { + this.students = new java.util.HashSet(); + } + this.students.add(elem); + } + + @org.apache.thrift.annotation.Nullable + public java.util.Set getStudents() { + return this.students; + } + + public practice_args setStudents(@org.apache.thrift.annotation.Nullable java.util.Set students) { + this.students = students; + return this; + } + + public void unsetStudents() { + this.students = null; + } + + /** Returns true if field students is set (has been assigned a value) and false otherwise */ + public boolean isSetStudents() { + return this.students != null; + } + + public void setStudentsIsSet(boolean value) { + if (!value) { + this.students = null; + } + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable Object value) { + switch (field) { + case CODE: + if (value == null) { + unsetCode(); + } else { + setCode((Integer)value); + } + break; + + case SCORE: + if (value == null) { + unsetScore(); + } else { + setScore((Double)value); + } + break; + + case STUDENTS: + if (value == null) { + unsetStudents(); + } else { + setStudents((java.util.Set)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public Object getFieldValue(_Fields field) { + switch (field) { + case CODE: + return getCode(); + + case SCORE: + return getScore(); + + case STUDENTS: + return getStudents(); + + } + 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 CODE: + return isSetCode(); + case SCORE: + return isSetScore(); + case STUDENTS: + return isSetStudents(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that instanceof practice_args) + return this.equals((practice_args)that); + return false; + } + + public boolean equals(practice_args that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_code = true; + boolean that_present_code = true; + if (this_present_code || that_present_code) { + if (!(this_present_code && that_present_code)) + return false; + if (this.code != that.code) + return false; + } + + boolean this_present_score = true; + boolean that_present_score = true; + if (this_present_score || that_present_score) { + if (!(this_present_score && that_present_score)) + return false; + if (this.score != that.score) + return false; + } + + boolean this_present_students = true && this.isSetStudents(); + boolean that_present_students = true && that.isSetStudents(); + if (this_present_students || that_present_students) { + if (!(this_present_students && that_present_students)) + return false; + if (!this.students.equals(that.students)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + code; + + hashCode = hashCode * 8191 + org.apache.thrift.TBaseHelper.hashCode(score); + + hashCode = hashCode * 8191 + ((isSetStudents()) ? 131071 : 524287); + if (isSetStudents()) + hashCode = hashCode * 8191 + students.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(practice_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.compare(isSetCode(), other.isSetCode()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetCode()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.code, other.code); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.compare(isSetScore(), other.isSetScore()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetScore()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.score, other.score); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.compare(isSetStudents(), other.isSetStudents()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetStudents()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.students, other.students); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("practice_args("); + boolean first = true; + + sb.append("code:"); + sb.append(this.code); + first = false; + if (!first) sb.append(", "); + sb.append("score:"); + sb.append(this.score); + first = false; + if (!first) sb.append(", "); + sb.append("students:"); + if (this.students == null) { + sb.append("null"); + } else { + sb.append(this.students); + } + 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 practice_argsStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public practice_argsStandardScheme getScheme() { + return new practice_argsStandardScheme(); + } + } + + private static class practice_argsStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, practice_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: // CODE + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.code = iprot.readI32(); + struct.setCodeIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case -1: // SCORE + if (schemeField.type == org.apache.thrift.protocol.TType.DOUBLE) { + struct.score = iprot.readDouble(); + struct.setScoreIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case -2: // STUDENTS + if (schemeField.type == org.apache.thrift.protocol.TType.SET) { + { + org.apache.thrift.protocol.TSet _set0 = iprot.readSetBegin(); + struct.students = new java.util.HashSet(2*_set0.size); + @org.apache.thrift.annotation.Nullable Student _elem1; + for (int _i2 = 0; _i2 < _set0.size; ++_i2) + { + _elem1 = new Student(); + _elem1.read(iprot); + struct.students.add(_elem1); + } + iprot.readSetEnd(); + } + struct.setStudentsIsSet(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, practice_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.students != null) { + oprot.writeFieldBegin(STUDENTS_FIELD_DESC); + { + oprot.writeSetBegin(new org.apache.thrift.protocol.TSet(org.apache.thrift.protocol.TType.STRUCT, struct.students.size())); + for (Student _iter3 : struct.students) + { + _iter3.write(oprot); + } + oprot.writeSetEnd(); + } + oprot.writeFieldEnd(); + } + oprot.writeFieldBegin(SCORE_FIELD_DESC); + oprot.writeDouble(struct.score); + oprot.writeFieldEnd(); + oprot.writeFieldBegin(CODE_FIELD_DESC); + oprot.writeI32(struct.code); + oprot.writeFieldEnd(); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class practice_argsTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public practice_argsTupleScheme getScheme() { + return new practice_argsTupleScheme(); + } + } + + private static class practice_argsTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, practice_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetCode()) { + optionals.set(0); + } + if (struct.isSetScore()) { + optionals.set(1); + } + if (struct.isSetStudents()) { + optionals.set(2); + } + oprot.writeBitSet(optionals, 3); + if (struct.isSetCode()) { + oprot.writeI32(struct.code); + } + if (struct.isSetScore()) { + oprot.writeDouble(struct.score); + } + if (struct.isSetStudents()) { + { + oprot.writeI32(struct.students.size()); + for (Student _iter4 : struct.students) + { + _iter4.write(oprot); + } + } + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, practice_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(3); + if (incoming.get(0)) { + struct.code = iprot.readI32(); + struct.setCodeIsSet(true); + } + if (incoming.get(1)) { + struct.score = iprot.readDouble(); + struct.setScoreIsSet(true); + } + if (incoming.get(2)) { + { + org.apache.thrift.protocol.TSet _set5 = iprot.readSetBegin(org.apache.thrift.protocol.TType.STRUCT); + struct.students = new java.util.HashSet(2*_set5.size); + @org.apache.thrift.annotation.Nullable Student _elem6; + for (int _i7 = 0; _i7 < _set5.size; ++_i7) + { + _elem6 = new Student(); + _elem6.read(iprot); + struct.students.add(_elem6); + } + } + struct.setStudentsIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + + public static class practice_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("practice_result"); + + private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.LIST, (short)0); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new practice_resultStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new practice_resultTupleSchemeFactory(); + + public @org.apache.thrift.annotation.Nullable java.util.List 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 java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + 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. + */ + @org.apache.thrift.annotation.Nullable + 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 java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.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.ListMetaData(org.apache.thrift.protocol.TType.LIST, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(practice_result.class, metaDataMap); + } + + public practice_result() { + } + + public practice_result( + java.util.List success) + { + this(); + this.success = success; + } + + /** + * Performs a deep copy on other. + */ + public practice_result(practice_result other) { + if (other.isSetSuccess()) { + java.util.List __this__success = new java.util.ArrayList(other.success); + this.success = __this__success; + } + } + + public practice_result deepCopy() { + return new practice_result(this); + } + + @Override + public void clear() { + this.success = null; + } + + public int getSuccessSize() { + return (this.success == null) ? 0 : this.success.size(); + } + + @org.apache.thrift.annotation.Nullable + public java.util.Iterator getSuccessIterator() { + return (this.success == null) ? null : this.success.iterator(); + } + + public void addToSuccess(String elem) { + if (this.success == null) { + this.success = new java.util.ArrayList(); + } + this.success.add(elem); + } + + @org.apache.thrift.annotation.Nullable + public java.util.List getSuccess() { + return this.success; + } + + public practice_result setSuccess(@org.apache.thrift.annotation.Nullable java.util.List 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, @org.apache.thrift.annotation.Nullable Object value) { + switch (field) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((java.util.List)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + 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 instanceof practice_result) + return this.equals((practice_result)that); + return false; + } + + public boolean equals(practice_result that) { + if (that == null) + return false; + if (this == that) + return true; + + 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() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetSuccess()) ? 131071 : 524287); + if (isSetSuccess()) + hashCode = hashCode * 8191 + success.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(practice_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.compare(isSetSuccess(), other.isSetSuccess()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSuccess()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, other.success); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("practice_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 practice_resultStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public practice_resultStandardScheme getScheme() { + return new practice_resultStandardScheme(); + } + } + + private static class practice_resultStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, practice_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.LIST) { + { + org.apache.thrift.protocol.TList _list8 = iprot.readListBegin(); + struct.success = new java.util.ArrayList(_list8.size); + @org.apache.thrift.annotation.Nullable String _elem9; + for (int _i10 = 0; _i10 < _list8.size; ++_i10) + { + _elem9 = iprot.readString(); + struct.success.add(_elem9); + } + iprot.readListEnd(); + } + 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, practice_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.success != null) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + { + oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRING, struct.success.size())); + for (String _iter11 : struct.success) + { + oprot.writeString(_iter11); + } + oprot.writeListEnd(); + } + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class practice_resultTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public practice_resultTupleScheme getScheme() { + return new practice_resultTupleScheme(); + } + } + + private static class practice_resultTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, practice_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetSuccess()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetSuccess()) { + { + oprot.writeI32(struct.success.size()); + for (String _iter12 : struct.success) + { + oprot.writeString(_iter12); + } + } + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, practice_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + { + org.apache.thrift.protocol.TList _list13 = iprot.readListBegin(org.apache.thrift.protocol.TType.STRING); + struct.success = new java.util.ArrayList(_list13.size); + @org.apache.thrift.annotation.Nullable String _elem14; + for (int _i15 = 0; _i15 < _list13.size; ++_i15) + { + _elem14 = iprot.readString(); + struct.success.add(_elem14); + } + } + struct.setSuccessIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + +} diff --git a/src/main/java/org/exercise/work/ex4/service/impl/ExerciseService.java b/src/main/java/org/exercise/work/ex4/service/impl/ExerciseService.java new file mode 100644 index 0000000000000000000000000000000000000000..db239e62250c28068d59510495cab1574b7d93a1 --- /dev/null +++ b/src/main/java/org/exercise/work/ex4/service/impl/ExerciseService.java @@ -0,0 +1,24 @@ +package org.exercise.work.ex4.service.impl; + +import org.apache.thrift.TException; +import org.exercise.work.ex4.model.Student; +import org.exercise.work.ex4.service.Exercise1; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +public class ExerciseService implements Exercise1.Iface { + @Override + public List practice(int code, double score, Set students) throws TException { + List result = new ArrayList(); +// if(students == null || students.size() == 0){ +// return result; +// } + for (Student student :students + ) { + result.add(student.getBookNoListSize()+"-"+code+":"+score); + } + return result; + } +} diff --git a/src/main/java/org/exercise/work/ex5/client/RpcClient.java b/src/main/java/org/exercise/work/ex5/client/RpcClient.java new file mode 100644 index 0000000000000000000000000000000000000000..4e95b9d7b2c55ae146b7c62010a3d89c2604080b --- /dev/null +++ b/src/main/java/org/exercise/work/ex5/client/RpcClient.java @@ -0,0 +1,41 @@ +package org.exercise.work.ex5.client; + +import org.apache.thrift.TConfiguration; +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.exercise.work.ex5.model.Student; +import org.exercise.work.ex5.service.Exercise1; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class RpcClient { + private static final String SERVER_IP="127.0.0.1"; + private static final int SERVER_PORT=9888; + private static final int TIMEOUT=1551; + + public static void main(String[] args) { + TTransport transport = null; + try{ + transport = new TSocket(new TConfiguration(), SERVER_IP, SERVER_PORT, TIMEOUT); + TProtocol protocol = new TBinaryProtocol(transport); + Exercise1.Client client = new Exercise1.Client(protocol); + transport.open(); + + Student student = new Student(); + student.setStudentName("zj"); + Set students = new HashSet(); + students.add(student); + List result = client.practice(99,61,students); + System.out.println("!!!"+result); + }catch (TException e){ + e.printStackTrace(); + }finally { + transport.close(); + } + } +} diff --git a/src/main/java/org/exercise/work/ex5/model/Student.java b/src/main/java/org/exercise/work/ex5/model/Student.java new file mode 100644 index 0000000000000000000000000000000000000000..31b077162eddf3b94e8a8662863017486178853c --- /dev/null +++ b/src/main/java/org/exercise/work/ex5/model/Student.java @@ -0,0 +1,632 @@ +/** + * Autogenerated by Thrift Compiler (0.15.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package org.exercise.work.ex5.model; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.15.0)", date = "2021-11-15") +public class Student implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("Student"); + + private static final org.apache.thrift.protocol.TField STUDENT_NO_FIELD_DESC = new org.apache.thrift.protocol.TField("studentNo", org.apache.thrift.protocol.TType.I64, (short)1); + private static final org.apache.thrift.protocol.TField STUDENT_NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("studentName", org.apache.thrift.protocol.TType.STRING, (short)2); + private static final org.apache.thrift.protocol.TField BOOK_NO_LIST_FIELD_DESC = new org.apache.thrift.protocol.TField("bookNoList", org.apache.thrift.protocol.TType.LIST, (short)3); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new StudentStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new StudentTupleSchemeFactory(); + + public long studentNo; // required + public @org.apache.thrift.annotation.Nullable String studentName; // optional + public @org.apache.thrift.annotation.Nullable java.util.List bookNoList; // optional + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + STUDENT_NO((short)1, "studentNo"), + STUDENT_NAME((short)2, "studentName"), + BOOK_NO_LIST((short)3, "bookNoList"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // STUDENT_NO + return STUDENT_NO; + case 2: // STUDENT_NAME + return STUDENT_NAME; + case 3: // BOOK_NO_LIST + return BOOK_NO_LIST; + 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. + */ + @org.apache.thrift.annotation.Nullable + 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 __STUDENTNO_ISSET_ID = 0; + private byte __isset_bitfield = 0; + private static final _Fields optionals[] = {_Fields.STUDENT_NAME, _Fields.BOOK_NO_LIST}; + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.STUDENT_NO, new org.apache.thrift.meta_data.FieldMetaData("studentNo", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))); + tmpMap.put(_Fields.STUDENT_NAME, new org.apache.thrift.meta_data.FieldMetaData("studentName", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + tmpMap.put(_Fields.BOOK_NO_LIST, new org.apache.thrift.meta_data.FieldMetaData("bookNoList", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(Student.class, metaDataMap); + } + + public Student() { + } + + public Student( + long studentNo) + { + this(); + this.studentNo = studentNo; + setStudentNoIsSet(true); + } + + /** + * Performs a deep copy on other. + */ + public Student(Student other) { + __isset_bitfield = other.__isset_bitfield; + this.studentNo = other.studentNo; + if (other.isSetStudentName()) { + this.studentName = other.studentName; + } + if (other.isSetBookNoList()) { + java.util.List __this__bookNoList = new java.util.ArrayList(other.bookNoList); + this.bookNoList = __this__bookNoList; + } + } + + public Student deepCopy() { + return new Student(this); + } + + @Override + public void clear() { + setStudentNoIsSet(false); + this.studentNo = 0; + this.studentName = null; + this.bookNoList = null; + } + + public long getStudentNo() { + return this.studentNo; + } + + public Student setStudentNo(long studentNo) { + this.studentNo = studentNo; + setStudentNoIsSet(true); + return this; + } + + public void unsetStudentNo() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __STUDENTNO_ISSET_ID); + } + + /** Returns true if field studentNo is set (has been assigned a value) and false otherwise */ + public boolean isSetStudentNo() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __STUDENTNO_ISSET_ID); + } + + public void setStudentNoIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __STUDENTNO_ISSET_ID, value); + } + + @org.apache.thrift.annotation.Nullable + public String getStudentName() { + return this.studentName; + } + + public Student setStudentName(@org.apache.thrift.annotation.Nullable String studentName) { + this.studentName = studentName; + return this; + } + + public void unsetStudentName() { + this.studentName = null; + } + + /** Returns true if field studentName is set (has been assigned a value) and false otherwise */ + public boolean isSetStudentName() { + return this.studentName != null; + } + + public void setStudentNameIsSet(boolean value) { + if (!value) { + this.studentName = null; + } + } + + public int getBookNoListSize() { + return (this.bookNoList == null) ? 0 : this.bookNoList.size(); + } + + @org.apache.thrift.annotation.Nullable + public java.util.Iterator getBookNoListIterator() { + return (this.bookNoList == null) ? null : this.bookNoList.iterator(); + } + + public void addToBookNoList(int elem) { + if (this.bookNoList == null) { + this.bookNoList = new java.util.ArrayList(); + } + this.bookNoList.add(elem); + } + + @org.apache.thrift.annotation.Nullable + public java.util.List getBookNoList() { + return this.bookNoList; + } + + public Student setBookNoList(@org.apache.thrift.annotation.Nullable java.util.List bookNoList) { + this.bookNoList = bookNoList; + return this; + } + + public void unsetBookNoList() { + this.bookNoList = null; + } + + /** Returns true if field bookNoList is set (has been assigned a value) and false otherwise */ + public boolean isSetBookNoList() { + return this.bookNoList != null; + } + + public void setBookNoListIsSet(boolean value) { + if (!value) { + this.bookNoList = null; + } + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable Object value) { + switch (field) { + case STUDENT_NO: + if (value == null) { + unsetStudentNo(); + } else { + setStudentNo((Long)value); + } + break; + + case STUDENT_NAME: + if (value == null) { + unsetStudentName(); + } else { + setStudentName((String)value); + } + break; + + case BOOK_NO_LIST: + if (value == null) { + unsetBookNoList(); + } else { + setBookNoList((java.util.List)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public Object getFieldValue(_Fields field) { + switch (field) { + case STUDENT_NO: + return getStudentNo(); + + case STUDENT_NAME: + return getStudentName(); + + case BOOK_NO_LIST: + return getBookNoList(); + + } + 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 STUDENT_NO: + return isSetStudentNo(); + case STUDENT_NAME: + return isSetStudentName(); + case BOOK_NO_LIST: + return isSetBookNoList(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that instanceof Student) + return this.equals((Student)that); + return false; + } + + public boolean equals(Student that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_studentNo = true; + boolean that_present_studentNo = true; + if (this_present_studentNo || that_present_studentNo) { + if (!(this_present_studentNo && that_present_studentNo)) + return false; + if (this.studentNo != that.studentNo) + return false; + } + + boolean this_present_studentName = true && this.isSetStudentName(); + boolean that_present_studentName = true && that.isSetStudentName(); + if (this_present_studentName || that_present_studentName) { + if (!(this_present_studentName && that_present_studentName)) + return false; + if (!this.studentName.equals(that.studentName)) + return false; + } + + boolean this_present_bookNoList = true && this.isSetBookNoList(); + boolean that_present_bookNoList = true && that.isSetBookNoList(); + if (this_present_bookNoList || that_present_bookNoList) { + if (!(this_present_bookNoList && that_present_bookNoList)) + return false; + if (!this.bookNoList.equals(that.bookNoList)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + org.apache.thrift.TBaseHelper.hashCode(studentNo); + + hashCode = hashCode * 8191 + ((isSetStudentName()) ? 131071 : 524287); + if (isSetStudentName()) + hashCode = hashCode * 8191 + studentName.hashCode(); + + hashCode = hashCode * 8191 + ((isSetBookNoList()) ? 131071 : 524287); + if (isSetBookNoList()) + hashCode = hashCode * 8191 + bookNoList.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(Student other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.compare(isSetStudentNo(), other.isSetStudentNo()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetStudentNo()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.studentNo, other.studentNo); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.compare(isSetStudentName(), other.isSetStudentName()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetStudentName()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.studentName, other.studentName); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.compare(isSetBookNoList(), other.isSetBookNoList()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetBookNoList()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.bookNoList, other.bookNoList); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("Student("); + boolean first = true; + + sb.append("studentNo:"); + sb.append(this.studentNo); + first = false; + if (isSetStudentName()) { + if (!first) sb.append(", "); + sb.append("studentName:"); + if (this.studentName == null) { + sb.append("null"); + } else { + sb.append(this.studentName); + } + first = false; + } + if (isSetBookNoList()) { + if (!first) sb.append(", "); + sb.append("bookNoList:"); + if (this.bookNoList == null) { + sb.append("null"); + } else { + sb.append(this.bookNoList); + } + first = false; + } + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // alas, we cannot check 'studentNo' because it's a primitive and you chose the non-beans generator. + // 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 StudentStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public StudentStandardScheme getScheme() { + return new StudentStandardScheme(); + } + } + + private static class StudentStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, Student 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: // STUDENT_NO + if (schemeField.type == org.apache.thrift.protocol.TType.I64) { + struct.studentNo = iprot.readI64(); + struct.setStudentNoIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // STUDENT_NAME + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.studentName = iprot.readString(); + struct.setStudentNameIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 3: // BOOK_NO_LIST + if (schemeField.type == org.apache.thrift.protocol.TType.LIST) { + { + org.apache.thrift.protocol.TList _list0 = iprot.readListBegin(); + struct.bookNoList = new java.util.ArrayList(_list0.size); + int _elem1; + for (int _i2 = 0; _i2 < _list0.size; ++_i2) + { + _elem1 = iprot.readI32(); + struct.bookNoList.add(_elem1); + } + iprot.readListEnd(); + } + struct.setBookNoListIsSet(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 + if (!struct.isSetStudentNo()) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'studentNo' was not found in serialized data! Struct: " + toString()); + } + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, Student struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldBegin(STUDENT_NO_FIELD_DESC); + oprot.writeI64(struct.studentNo); + oprot.writeFieldEnd(); + if (struct.studentName != null) { + if (struct.isSetStudentName()) { + oprot.writeFieldBegin(STUDENT_NAME_FIELD_DESC); + oprot.writeString(struct.studentName); + oprot.writeFieldEnd(); + } + } + if (struct.bookNoList != null) { + if (struct.isSetBookNoList()) { + oprot.writeFieldBegin(BOOK_NO_LIST_FIELD_DESC); + { + oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.I32, struct.bookNoList.size())); + for (int _iter3 : struct.bookNoList) + { + oprot.writeI32(_iter3); + } + oprot.writeListEnd(); + } + oprot.writeFieldEnd(); + } + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class StudentTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public StudentTupleScheme getScheme() { + return new StudentTupleScheme(); + } + } + + private static class StudentTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, Student struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + oprot.writeI64(struct.studentNo); + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetStudentName()) { + optionals.set(0); + } + if (struct.isSetBookNoList()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetStudentName()) { + oprot.writeString(struct.studentName); + } + if (struct.isSetBookNoList()) { + { + oprot.writeI32(struct.bookNoList.size()); + for (int _iter4 : struct.bookNoList) + { + oprot.writeI32(_iter4); + } + } + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, Student struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + struct.studentNo = iprot.readI64(); + struct.setStudentNoIsSet(true); + java.util.BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.studentName = iprot.readString(); + struct.setStudentNameIsSet(true); + } + if (incoming.get(1)) { + { + org.apache.thrift.protocol.TList _list5 = iprot.readListBegin(org.apache.thrift.protocol.TType.I32); + struct.bookNoList = new java.util.ArrayList(_list5.size); + int _elem6; + for (int _i7 = 0; _i7 < _list5.size; ++_i7) + { + _elem6 = iprot.readI32(); + struct.bookNoList.add(_elem6); + } + } + struct.setBookNoListIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } +} + diff --git a/src/main/java/org/exercise/work/ex5/server/RpcServer.java b/src/main/java/org/exercise/work/ex5/server/RpcServer.java new file mode 100644 index 0000000000000000000000000000000000000000..e05e2ca24e9ca32220714531ab6f8bcd1fa9e698 --- /dev/null +++ b/src/main/java/org/exercise/work/ex5/server/RpcServer.java @@ -0,0 +1,38 @@ +package org.exercise.work.ex5.server; + +import org.apache.thrift.protocol.TBinaryProtocol; +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 org.exercise.work.ex5.service.Exercise1; +import org.exercise.work.ex5.service.impl.ExerciseService; + +import java.io.IOException; +import java.net.ServerSocket; + +public class RpcServer { + public static final int SERVER_PORT = 9888; + public static void main(String[] args) throws IOException, TTransportException { + //设置服务端口 + ServerSocket serverSocket = new ServerSocket(SERVER_PORT); + TServerSocket serverTransport = new TServerSocket(serverSocket); + +//设置接口实现类 + Exercise1.Processor processor = new Exercise1.Processor(new ExerciseService()); + +//设置传输协议 + TBinaryProtocol.Factory protocolFactory = new TBinaryProtocol.Factory(); + +//初始化服务器启动参数 + TSimpleServer.Args tArgs = new TSimpleServer.Args(serverTransport); + tArgs.processor(processor); + tArgs.protocolFactory(protocolFactory); + +//启动服务 + TServer tServer = new TSimpleServer(tArgs); + System.out.println("Server Started"); + tServer.serve(); + + } +} diff --git a/src/main/java/org/exercise/work/ex5/service/Exercise1.java b/src/main/java/org/exercise/work/ex5/service/Exercise1.java new file mode 100644 index 0000000000000000000000000000000000000000..8fb5f1ca1ef92402cdae58fbe8b307ed5e753b95 --- /dev/null +++ b/src/main/java/org/exercise/work/ex5/service/Exercise1.java @@ -0,0 +1,1281 @@ +/** + * Autogenerated by Thrift Compiler (0.15.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package org.exercise.work.ex5.service; + +import org.exercise.work.ex5.model.Student; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.15.0)", date = "2021-11-15") +public class Exercise1 { + + public interface Iface { + + public java.util.List practice(int code, double score, java.util.Set students) throws org.apache.thrift.TException; + + } + + public interface AsyncIface { + + public void practice(int code, double score, java.util.Set students, org.apache.thrift.async.AsyncMethodCallback> 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 { + 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 java.util.List practice(int code, double score, java.util.Set students) throws org.apache.thrift.TException + { + send_practice(code, score, students); + return recv_practice(); + } + + public void send_practice(int code, double score, java.util.Set students) throws org.apache.thrift.TException + { + practice_args args = new practice_args(); + args.setCode(code); + args.setScore(score); + args.setStudents(students); + sendBase("practice", args); + } + + public java.util.List recv_practice() throws org.apache.thrift.TException + { + practice_result result = new practice_result(); + receiveBase(result, "practice"); + if (result.isSetSuccess()) { + return result.success; + } + throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "practice failed: unknown result"); + } + + } + public static class AsyncClient extends org.apache.thrift.async.TAsyncClient implements AsyncIface { + public static class Factory implements org.apache.thrift.async.TAsyncClientFactory { + 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 practice(int code, double score, java.util.Set students, org.apache.thrift.async.AsyncMethodCallback> resultHandler) throws org.apache.thrift.TException { + checkReady(); + practice_call method_call = new practice_call(code, score, students, resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class practice_call extends org.apache.thrift.async.TAsyncMethodCall> { + private int code; + private double score; + private java.util.Set students; + public practice_call(int code, double score, java.util.Set students, org.apache.thrift.async.AsyncMethodCallback> 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.code = code; + this.score = score; + this.students = students; + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("practice", org.apache.thrift.protocol.TMessageType.CALL, 0)); + practice_args args = new practice_args(); + args.setCode(code); + args.setScore(score); + args.setStudents(students); + args.write(prot); + prot.writeMessageEnd(); + } + + public java.util.List getResult() throws org.apache.thrift.TException { + if (getState() != 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_practice(); + } + } + + } + + public static class Processor extends org.apache.thrift.TBaseProcessor implements org.apache.thrift.TProcessor { + private static final org.slf4j.Logger _LOGGER = org.slf4j.LoggerFactory.getLogger(Processor.class.getName()); + public Processor(I iface) { + super(iface, getProcessMap(new java.util.HashMap>())); + } + + protected Processor(I iface, java.util.Map> processMap) { + super(iface, getProcessMap(processMap)); + } + + private static java.util.Map> getProcessMap(java.util.Map> processMap) { + processMap.put("practice", new practice()); + return processMap; + } + + public static class practice extends org.apache.thrift.ProcessFunction { + public practice() { + super("practice"); + } + + public practice_args getEmptyArgsInstance() { + return new practice_args(); + } + + protected boolean isOneway() { + return false; + } + + @Override + protected boolean rethrowUnhandledExceptions() { + return false; + } + + public practice_result getResult(I iface, practice_args args) throws org.apache.thrift.TException { + practice_result result = new practice_result(); + result.success = iface.practice(args.code, args.score, args.students); + return result; + } + } + + } + + public static class AsyncProcessor extends org.apache.thrift.TBaseAsyncProcessor { + private static final org.slf4j.Logger _LOGGER = org.slf4j.LoggerFactory.getLogger(AsyncProcessor.class.getName()); + public AsyncProcessor(I iface) { + super(iface, getProcessMap(new java.util.HashMap>())); + } + + protected AsyncProcessor(I iface, java.util.Map> processMap) { + super(iface, getProcessMap(processMap)); + } + + private static java.util.Map> getProcessMap(java.util.Map> processMap) { + processMap.put("practice", new practice()); + return processMap; + } + + public static class practice extends org.apache.thrift.AsyncProcessFunction> { + public practice() { + super("practice"); + } + + public practice_args getEmptyArgsInstance() { + return new practice_args(); + } + + public org.apache.thrift.async.AsyncMethodCallback> getResultHandler(final org.apache.thrift.server.AbstractNonblockingServer.AsyncFrameBuffer fb, final int seqid) { + final org.apache.thrift.AsyncProcessFunction fcall = this; + return new org.apache.thrift.async.AsyncMethodCallback>() { + public void onComplete(java.util.List o) { + practice_result result = new practice_result(); + result.success = o; + try { + fcall.sendResponse(fb, result, org.apache.thrift.protocol.TMessageType.REPLY,seqid); + } catch (org.apache.thrift.transport.TTransportException e) { + _LOGGER.error("TTransportException writing to internal frame buffer", e); + fb.close(); + } catch (Exception e) { + _LOGGER.error("Exception writing to internal frame buffer", e); + onError(e); + } + } + public void onError(Exception e) { + byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; + org.apache.thrift.TSerializable msg; + practice_result result = new practice_result(); + if (e instanceof org.apache.thrift.transport.TTransportException) { + _LOGGER.error("TTransportException inside handler", e); + fb.close(); + return; + } else if (e instanceof org.apache.thrift.TApplicationException) { + _LOGGER.error("TApplicationException inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = (org.apache.thrift.TApplicationException)e; + } else { + _LOGGER.error("Exception inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage()); + } + try { + fcall.sendResponse(fb,msg,msgType,seqid); + } catch (Exception ex) { + _LOGGER.error("Exception writing to internal frame buffer", ex); + fb.close(); + } + } + }; + } + + protected boolean isOneway() { + return false; + } + + public void start(I iface, practice_args args, org.apache.thrift.async.AsyncMethodCallback> resultHandler) throws org.apache.thrift.TException { + iface.practice(args.code, args.score, args.students,resultHandler); + } + } + + } + + public static class practice_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("practice_args"); + + private static final org.apache.thrift.protocol.TField CODE_FIELD_DESC = new org.apache.thrift.protocol.TField("code", org.apache.thrift.protocol.TType.I32, (short)1); + private static final org.apache.thrift.protocol.TField SCORE_FIELD_DESC = new org.apache.thrift.protocol.TField("score", org.apache.thrift.protocol.TType.DOUBLE, (short)-1); + private static final org.apache.thrift.protocol.TField STUDENTS_FIELD_DESC = new org.apache.thrift.protocol.TField("students", org.apache.thrift.protocol.TType.SET, (short)-2); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new practice_argsStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new practice_argsTupleSchemeFactory(); + + public int code; // required + public double score; // required + public @org.apache.thrift.annotation.Nullable java.util.Set students; // 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 { + CODE((short)1, "code"), + SCORE((short)-1, "score"), + STUDENTS((short)-2, "students"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // CODE + return CODE; + case -1: // SCORE + return SCORE; + case -2: // STUDENTS + return STUDENTS; + 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. + */ + @org.apache.thrift.annotation.Nullable + 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 __CODE_ISSET_ID = 0; + private static final int __SCORE_ISSET_ID = 1; + private byte __isset_bitfield = 0; + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.CODE, new org.apache.thrift.meta_data.FieldMetaData("code", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))); + tmpMap.put(_Fields.SCORE, new org.apache.thrift.meta_data.FieldMetaData("score", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.DOUBLE))); + tmpMap.put(_Fields.STUDENTS, new org.apache.thrift.meta_data.FieldMetaData("students", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.SetMetaData(org.apache.thrift.protocol.TType.SET, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, Student.class)))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(practice_args.class, metaDataMap); + } + + public practice_args() { + } + + public practice_args( + int code, + double score, + java.util.Set students) + { + this(); + this.code = code; + setCodeIsSet(true); + this.score = score; + setScoreIsSet(true); + this.students = students; + } + + /** + * Performs a deep copy on other. + */ + public practice_args(practice_args other) { + __isset_bitfield = other.__isset_bitfield; + this.code = other.code; + this.score = other.score; + if (other.isSetStudents()) { + java.util.Set __this__students = new java.util.HashSet(other.students.size()); + for (Student other_element : other.students) { + __this__students.add(new Student(other_element)); + } + this.students = __this__students; + } + } + + public practice_args deepCopy() { + return new practice_args(this); + } + + @Override + public void clear() { + setCodeIsSet(false); + this.code = 0; + setScoreIsSet(false); + this.score = 0.0; + this.students = null; + } + + public int getCode() { + return this.code; + } + + public practice_args setCode(int code) { + this.code = code; + setCodeIsSet(true); + return this; + } + + public void unsetCode() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __CODE_ISSET_ID); + } + + /** Returns true if field code is set (has been assigned a value) and false otherwise */ + public boolean isSetCode() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __CODE_ISSET_ID); + } + + public void setCodeIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __CODE_ISSET_ID, value); + } + + public double getScore() { + return this.score; + } + + public practice_args setScore(double score) { + this.score = score; + setScoreIsSet(true); + return this; + } + + public void unsetScore() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __SCORE_ISSET_ID); + } + + /** Returns true if field score is set (has been assigned a value) and false otherwise */ + public boolean isSetScore() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __SCORE_ISSET_ID); + } + + public void setScoreIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __SCORE_ISSET_ID, value); + } + + public int getStudentsSize() { + return (this.students == null) ? 0 : this.students.size(); + } + + @org.apache.thrift.annotation.Nullable + public java.util.Iterator getStudentsIterator() { + return (this.students == null) ? null : this.students.iterator(); + } + + public void addToStudents(Student elem) { + if (this.students == null) { + this.students = new java.util.HashSet(); + } + this.students.add(elem); + } + + @org.apache.thrift.annotation.Nullable + public java.util.Set getStudents() { + return this.students; + } + + public practice_args setStudents(@org.apache.thrift.annotation.Nullable java.util.Set students) { + this.students = students; + return this; + } + + public void unsetStudents() { + this.students = null; + } + + /** Returns true if field students is set (has been assigned a value) and false otherwise */ + public boolean isSetStudents() { + return this.students != null; + } + + public void setStudentsIsSet(boolean value) { + if (!value) { + this.students = null; + } + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable Object value) { + switch (field) { + case CODE: + if (value == null) { + unsetCode(); + } else { + setCode((Integer)value); + } + break; + + case SCORE: + if (value == null) { + unsetScore(); + } else { + setScore((Double)value); + } + break; + + case STUDENTS: + if (value == null) { + unsetStudents(); + } else { + setStudents((java.util.Set)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public Object getFieldValue(_Fields field) { + switch (field) { + case CODE: + return getCode(); + + case SCORE: + return getScore(); + + case STUDENTS: + return getStudents(); + + } + 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 CODE: + return isSetCode(); + case SCORE: + return isSetScore(); + case STUDENTS: + return isSetStudents(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that instanceof practice_args) + return this.equals((practice_args)that); + return false; + } + + public boolean equals(practice_args that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_code = true; + boolean that_present_code = true; + if (this_present_code || that_present_code) { + if (!(this_present_code && that_present_code)) + return false; + if (this.code != that.code) + return false; + } + + boolean this_present_score = true; + boolean that_present_score = true; + if (this_present_score || that_present_score) { + if (!(this_present_score && that_present_score)) + return false; + if (this.score != that.score) + return false; + } + + boolean this_present_students = true && this.isSetStudents(); + boolean that_present_students = true && that.isSetStudents(); + if (this_present_students || that_present_students) { + if (!(this_present_students && that_present_students)) + return false; + if (!this.students.equals(that.students)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + code; + + hashCode = hashCode * 8191 + org.apache.thrift.TBaseHelper.hashCode(score); + + hashCode = hashCode * 8191 + ((isSetStudents()) ? 131071 : 524287); + if (isSetStudents()) + hashCode = hashCode * 8191 + students.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(practice_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.compare(isSetCode(), other.isSetCode()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetCode()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.code, other.code); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.compare(isSetScore(), other.isSetScore()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetScore()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.score, other.score); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.compare(isSetStudents(), other.isSetStudents()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetStudents()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.students, other.students); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("practice_args("); + boolean first = true; + + sb.append("code:"); + sb.append(this.code); + first = false; + if (!first) sb.append(", "); + sb.append("score:"); + sb.append(this.score); + first = false; + if (!first) sb.append(", "); + sb.append("students:"); + if (this.students == null) { + sb.append("null"); + } else { + sb.append(this.students); + } + 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 practice_argsStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public practice_argsStandardScheme getScheme() { + return new practice_argsStandardScheme(); + } + } + + private static class practice_argsStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, practice_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: // CODE + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.code = iprot.readI32(); + struct.setCodeIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case -1: // SCORE + if (schemeField.type == org.apache.thrift.protocol.TType.DOUBLE) { + struct.score = iprot.readDouble(); + struct.setScoreIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case -2: // STUDENTS + if (schemeField.type == org.apache.thrift.protocol.TType.SET) { + { + org.apache.thrift.protocol.TSet _set0 = iprot.readSetBegin(); + struct.students = new java.util.HashSet(2*_set0.size); + @org.apache.thrift.annotation.Nullable Student _elem1; + for (int _i2 = 0; _i2 < _set0.size; ++_i2) + { + _elem1 = new Student(); + _elem1.read(iprot); + struct.students.add(_elem1); + } + iprot.readSetEnd(); + } + struct.setStudentsIsSet(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, practice_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.students != null) { + oprot.writeFieldBegin(STUDENTS_FIELD_DESC); + { + oprot.writeSetBegin(new org.apache.thrift.protocol.TSet(org.apache.thrift.protocol.TType.STRUCT, struct.students.size())); + for (Student _iter3 : struct.students) + { + _iter3.write(oprot); + } + oprot.writeSetEnd(); + } + oprot.writeFieldEnd(); + } + oprot.writeFieldBegin(SCORE_FIELD_DESC); + oprot.writeDouble(struct.score); + oprot.writeFieldEnd(); + oprot.writeFieldBegin(CODE_FIELD_DESC); + oprot.writeI32(struct.code); + oprot.writeFieldEnd(); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class practice_argsTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public practice_argsTupleScheme getScheme() { + return new practice_argsTupleScheme(); + } + } + + private static class practice_argsTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, practice_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetCode()) { + optionals.set(0); + } + if (struct.isSetScore()) { + optionals.set(1); + } + if (struct.isSetStudents()) { + optionals.set(2); + } + oprot.writeBitSet(optionals, 3); + if (struct.isSetCode()) { + oprot.writeI32(struct.code); + } + if (struct.isSetScore()) { + oprot.writeDouble(struct.score); + } + if (struct.isSetStudents()) { + { + oprot.writeI32(struct.students.size()); + for (Student _iter4 : struct.students) + { + _iter4.write(oprot); + } + } + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, practice_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(3); + if (incoming.get(0)) { + struct.code = iprot.readI32(); + struct.setCodeIsSet(true); + } + if (incoming.get(1)) { + struct.score = iprot.readDouble(); + struct.setScoreIsSet(true); + } + if (incoming.get(2)) { + { + org.apache.thrift.protocol.TSet _set5 = iprot.readSetBegin(org.apache.thrift.protocol.TType.STRUCT); + struct.students = new java.util.HashSet(2*_set5.size); + @org.apache.thrift.annotation.Nullable Student _elem6; + for (int _i7 = 0; _i7 < _set5.size; ++_i7) + { + _elem6 = new Student(); + _elem6.read(iprot); + struct.students.add(_elem6); + } + } + struct.setStudentsIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + + public static class practice_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("practice_result"); + + private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.LIST, (short)0); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new practice_resultStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new practice_resultTupleSchemeFactory(); + + public @org.apache.thrift.annotation.Nullable java.util.List 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 java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + 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. + */ + @org.apache.thrift.annotation.Nullable + 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 java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.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.ListMetaData(org.apache.thrift.protocol.TType.LIST, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(practice_result.class, metaDataMap); + } + + public practice_result() { + } + + public practice_result( + java.util.List success) + { + this(); + this.success = success; + } + + /** + * Performs a deep copy on other. + */ + public practice_result(practice_result other) { + if (other.isSetSuccess()) { + java.util.List __this__success = new java.util.ArrayList(other.success); + this.success = __this__success; + } + } + + public practice_result deepCopy() { + return new practice_result(this); + } + + @Override + public void clear() { + this.success = null; + } + + public int getSuccessSize() { + return (this.success == null) ? 0 : this.success.size(); + } + + @org.apache.thrift.annotation.Nullable + public java.util.Iterator getSuccessIterator() { + return (this.success == null) ? null : this.success.iterator(); + } + + public void addToSuccess(String elem) { + if (this.success == null) { + this.success = new java.util.ArrayList(); + } + this.success.add(elem); + } + + @org.apache.thrift.annotation.Nullable + public java.util.List getSuccess() { + return this.success; + } + + public practice_result setSuccess(@org.apache.thrift.annotation.Nullable java.util.List 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, @org.apache.thrift.annotation.Nullable Object value) { + switch (field) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((java.util.List)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + 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 instanceof practice_result) + return this.equals((practice_result)that); + return false; + } + + public boolean equals(practice_result that) { + if (that == null) + return false; + if (this == that) + return true; + + 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() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetSuccess()) ? 131071 : 524287); + if (isSetSuccess()) + hashCode = hashCode * 8191 + success.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(practice_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.compare(isSetSuccess(), other.isSetSuccess()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSuccess()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, other.success); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("practice_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 practice_resultStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public practice_resultStandardScheme getScheme() { + return new practice_resultStandardScheme(); + } + } + + private static class practice_resultStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, practice_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.LIST) { + { + org.apache.thrift.protocol.TList _list8 = iprot.readListBegin(); + struct.success = new java.util.ArrayList(_list8.size); + @org.apache.thrift.annotation.Nullable String _elem9; + for (int _i10 = 0; _i10 < _list8.size; ++_i10) + { + _elem9 = iprot.readString(); + struct.success.add(_elem9); + } + iprot.readListEnd(); + } + 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, practice_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.success != null) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + { + oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRING, struct.success.size())); + for (String _iter11 : struct.success) + { + oprot.writeString(_iter11); + } + oprot.writeListEnd(); + } + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class practice_resultTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public practice_resultTupleScheme getScheme() { + return new practice_resultTupleScheme(); + } + } + + private static class practice_resultTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, practice_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetSuccess()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetSuccess()) { + { + oprot.writeI32(struct.success.size()); + for (String _iter12 : struct.success) + { + oprot.writeString(_iter12); + } + } + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, practice_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + { + org.apache.thrift.protocol.TList _list13 = iprot.readListBegin(org.apache.thrift.protocol.TType.STRING); + struct.success = new java.util.ArrayList(_list13.size); + @org.apache.thrift.annotation.Nullable String _elem14; + for (int _i15 = 0; _i15 < _list13.size; ++_i15) + { + _elem14 = iprot.readString(); + struct.success.add(_elem14); + } + } + struct.setSuccessIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + +} diff --git a/src/main/java/org/exercise/work/ex5/service/impl/ExerciseService.java b/src/main/java/org/exercise/work/ex5/service/impl/ExerciseService.java new file mode 100644 index 0000000000000000000000000000000000000000..7532bb20fcf6fef9198058b123b16dc564d0adac --- /dev/null +++ b/src/main/java/org/exercise/work/ex5/service/impl/ExerciseService.java @@ -0,0 +1,24 @@ +package org.exercise.work.ex5.service.impl; + +import org.apache.thrift.TException; +import org.exercise.work.ex5.model.Student; +import org.exercise.work.ex5.service.Exercise1; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +public class ExerciseService implements Exercise1.Iface { + @Override + public List practice(int code, double score, Set students) throws TException { + List result = new ArrayList(); + if(students == null || students.size() == 0){ + return result; + } + for (Student student :students + ) { + result.add(student.getBookNoListSize()+"-"+code+":"+score); + } + return result; + } +} diff --git a/src/main/thrift/ex1/Exercise1.thrift b/src/main/thrift/ex1/Exercise1.thrift new file mode 100644 index 0000000000000000000000000000000000000000..0064b9130a4de703fafbdfc357313ad5c3ee8dc5 --- /dev/null +++ b/src/main/thrift/ex1/Exercise1.thrift @@ -0,0 +1,5 @@ +namespace java org.exercise.ex1 +include "Student.thrift" +service Exercise1{ + list practice(1:i32 code,double score, set students) +} \ No newline at end of file diff --git a/src/main/thrift/ex1/Student.thrift b/src/main/thrift/ex1/Student.thrift new file mode 100644 index 0000000000000000000000000000000000000000..d3eaa2dcaf54bb96917a78e5e5e3a0659f411719 --- /dev/null +++ b/src/main/thrift/ex1/Student.thrift @@ -0,0 +1,6 @@ +namespace java org.exercise.ex1 +struct Student{ + 1:required i64 studentNo; + 2:optional string studentName; + 3:optional list bookNoList; +} \ No newline at end of file diff --git a/src/main/thrift/ex2/CustomNumber.thrift b/src/main/thrift/ex2/CustomNumber.thrift new file mode 100644 index 0000000000000000000000000000000000000000..0b2db5fa73182d60902a6bc6935e7ee6bb5c42a5 --- /dev/null +++ b/src/main/thrift/ex2/CustomNumber.thrift @@ -0,0 +1,9 @@ +namespace java org.example.exercise.ex2.model + +struct CustomNumber { + + 1: required i32 no; + + 2: required string desc; + +} \ No newline at end of file diff --git a/src/main/thrift/ex2/Exercise2Service.thrift b/src/main/thrift/ex2/Exercise2Service.thrift new file mode 100644 index 0000000000000000000000000000000000000000..edca2df238a2ec2cfc5f4df9d808d63faac1180a --- /dev/null +++ b/src/main/thrift/ex2/Exercise2Service.thrift @@ -0,0 +1,9 @@ +namespace java org.example.exercise.ex2.service + +include "CustomNumber.thrift" + +service Exercise2Service { + + string fetchNo(1:list numbers); + +} \ No newline at end of file diff --git a/src/main/thrift/ex4/Exercise1.thrift b/src/main/thrift/ex4/Exercise1.thrift new file mode 100644 index 0000000000000000000000000000000000000000..598821e3339ea0805185279d177f7eafff20d778 --- /dev/null +++ b/src/main/thrift/ex4/Exercise1.thrift @@ -0,0 +1,7 @@ +namespace java org.exercise.ex1 +include "Student.thrift" +include "PracticeReq.thrift" +include "PracticeResp.thrift" +service Exercise1{ + PracticeResp.PracticeResp practice(1:PracticeReq.PracticeReq req); +} \ No newline at end of file diff --git a/src/main/thrift/ex4/PracticeReq.thrift b/src/main/thrift/ex4/PracticeReq.thrift new file mode 100644 index 0000000000000000000000000000000000000000..92c0caea69118fe08e08a4ad9cefdc11a68e5145 --- /dev/null +++ b/src/main/thrift/ex4/PracticeReq.thrift @@ -0,0 +1,6 @@ +include "Student.thrift" +struct PracticeReq{ + 1:required i32 code; + 2:required double score; + 3:required set students; +} \ No newline at end of file diff --git a/src/main/thrift/ex4/PracticeResp.thrift b/src/main/thrift/ex4/PracticeResp.thrift new file mode 100644 index 0000000000000000000000000000000000000000..ea9bdce08550d29940772344f1f734b6223a5bf2 --- /dev/null +++ b/src/main/thrift/ex4/PracticeResp.thrift @@ -0,0 +1,5 @@ +include"Statu.thrift" +struct PracticeResp{ + 1:required list strlist; + 2:required Statu.Statu status; +} \ No newline at end of file diff --git a/src/main/thrift/ex4/Statu.thrift b/src/main/thrift/ex4/Statu.thrift new file mode 100644 index 0000000000000000000000000000000000000000..96211eb36cc45f1ecd8d4002fb151e9aa5e509b9 --- /dev/null +++ b/src/main/thrift/ex4/Statu.thrift @@ -0,0 +1,4 @@ +struct Statu{ +1:required i32 code; +2:required string desc; +} \ No newline at end of file diff --git a/src/main/thrift/ex4/Student.thrift b/src/main/thrift/ex4/Student.thrift new file mode 100644 index 0000000000000000000000000000000000000000..d3eaa2dcaf54bb96917a78e5e5e3a0659f411719 --- /dev/null +++ b/src/main/thrift/ex4/Student.thrift @@ -0,0 +1,6 @@ +namespace java org.exercise.ex1 +struct Student{ + 1:required i64 studentNo; + 2:optional string studentName; + 3:optional list bookNoList; +} \ No newline at end of file