add: nutzboot-starter-thrift-server

This commit is contained in:
Wendal Chen 2019-08-02 13:55:11 +08:00
parent e8063bdf64
commit 8ce8f4eb98
33 changed files with 12512 additions and 0 deletions

View File

@ -1,5 +1,14 @@
# NB进化史
# 2.3.8.vX
* 变更:
* add: 添加starter-thrift-server
# 2.3.7.v20190731 "无名"
# 2.3.6.v20190621 "千と千尋の神隠"
今天夏至啊,今天千与千寻在大陆上映啦,所以要发新版本啊!!!

View File

@ -172,6 +172,8 @@ public class MainLauncher {
- [x] starter-[feign](https://github.com/OpenFeign/feign) makes writing java http clients easier, by [haoqoo](https://github.com/haoqoo) and [wendal](https://github.com/wendal)
- [x] [ribbon](https://github.com/Netflix/ribbon) ,集成在feign中,配合erueka-client实现负载均衡
- [x] [servicecomb](http://servicecomb.apache.org) Apache ServiceComb
- [x] starter-[thrift](https://thrift.apache.org/)-server Thrift服务器端
- [ ] starter-[thrift](https://thrift.apache.org/)-client Thrift客户端
- [x] starter-zkclient zookeeper的封装
- [x] **starter-[sentinel-dubbo](https://github.com/alibaba/Sentinel)** 阿里出品的分布式系统的流量防卫兵,集成dubbo by [大鲨鱼](https://github.com/Wizzercn)
- [x] starter-[sentinel-annotation](https://github.com/alibaba/Sentinel) 阿里出品的分布式系统的流量防卫兵,基于原生注解

View File

@ -0,0 +1,9 @@
# 如何搭建一个thrift服务端
分几个步骤:
1. 获取thrift环境
2. 编写thrift文件
3. 生成java服务器端/python客户端
算了, 还是看demo吧

View File

@ -0,0 +1,39 @@
package io.nutz.demo.simple;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import org.nutz.boot.AppContext;
import org.nutz.dao.Dao;
import org.nutz.dao.impl.NutDao;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Streams;
import io.shardingjdbc.core.api.ShardingDataSourceFactory;
@IocBean
public class MyBeans{
@Inject
protected PropertiesProxy conf;
@Inject
protected AppContext appContext;
@IocBean(name="dao2")
public Dao getDao2() throws Exception {
String path = "shardingjdbc2.yaml";
InputStream ins = appContext.getResourceLoader().get(path);
if (ins == null) {
File f = new File(path);
if (f.exists() && f.canRead()) {
ins = new FileInputStream(f);
} else {
throw new RuntimeException("no such shardingjdbc configure file=" + path);
}
}
return new NutDao(ShardingDataSourceFactory.createDataSource(Streams.readBytesAndClose(ins)));
}
}

View File

@ -0,0 +1,22 @@
dataSources:
ds_0: !!com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/ds_0
username: root
password: root
ds_1: !!com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/ds_1
username: root
password: root
shardingRule:
tables:
t_order:
actualDataNodes: ds_${0..1}.t_order_${0..1}
databaseStrategy:
inline:
shardingColumn: user_id
algorithmExpression: ds_${user_id % 2}
tableStrategy:
inline:
shardingColumn: order_id
algorithmExpression: t_order_${order_id % 2}

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>nutzboot-demo-simple</artifactId>
<groupId>org.nutz</groupId>
<version>2.3.8-SNAPSHOT</version>
</parent>
<artifactId>nutzboot-demo-simple-thrift-server</artifactId>
<dependencies>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter-thrift-server</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,974 @@
/**
* Autogenerated by Thrift Compiler (0.12.0)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
package shared;
@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"})
@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.12.0)", date = "2019-08-02")
public class SharedService {
public interface Iface {
public SharedStruct getStruct(int key) throws org.apache.thrift.TException;
}
public interface AsyncIface {
public void getStruct(int key, org.apache.thrift.async.AsyncMethodCallback<SharedStruct> resultHandler) throws org.apache.thrift.TException;
}
public static class Client extends org.apache.thrift.TServiceClient implements Iface {
public static class Factory implements org.apache.thrift.TServiceClientFactory<Client> {
public Factory() {}
public Client getClient(org.apache.thrift.protocol.TProtocol prot) {
return new Client(prot);
}
public Client getClient(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) {
return new Client(iprot, oprot);
}
}
public Client(org.apache.thrift.protocol.TProtocol prot)
{
super(prot, prot);
}
public Client(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) {
super(iprot, oprot);
}
public SharedStruct getStruct(int key) throws org.apache.thrift.TException
{
send_getStruct(key);
return recv_getStruct();
}
public void send_getStruct(int key) throws org.apache.thrift.TException
{
getStruct_args args = new getStruct_args();
args.setKey(key);
sendBase("getStruct", args);
}
public SharedStruct recv_getStruct() throws org.apache.thrift.TException
{
getStruct_result result = new getStruct_result();
receiveBase(result, "getStruct");
if (result.isSetSuccess()) {
return result.success;
}
throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "getStruct 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<AsyncClient> {
private org.apache.thrift.async.TAsyncClientManager clientManager;
private org.apache.thrift.protocol.TProtocolFactory protocolFactory;
public Factory(org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.protocol.TProtocolFactory protocolFactory) {
this.clientManager = clientManager;
this.protocolFactory = protocolFactory;
}
public AsyncClient getAsyncClient(org.apache.thrift.transport.TNonblockingTransport transport) {
return new AsyncClient(protocolFactory, clientManager, transport);
}
}
public AsyncClient(org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.transport.TNonblockingTransport transport) {
super(protocolFactory, clientManager, transport);
}
public void getStruct(int key, org.apache.thrift.async.AsyncMethodCallback<SharedStruct> resultHandler) throws org.apache.thrift.TException {
checkReady();
getStruct_call method_call = new getStruct_call(key, resultHandler, this, ___protocolFactory, ___transport);
this.___currentMethod = method_call;
___manager.call(method_call);
}
public static class getStruct_call extends org.apache.thrift.async.TAsyncMethodCall<SharedStruct> {
private int key;
public getStruct_call(int key, org.apache.thrift.async.AsyncMethodCallback<SharedStruct> 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.key = key;
}
public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException {
prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("getStruct", org.apache.thrift.protocol.TMessageType.CALL, 0));
getStruct_args args = new getStruct_args();
args.setKey(key);
args.write(prot);
prot.writeMessageEnd();
}
public SharedStruct 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_getStruct();
}
}
}
public static class Processor<I extends Iface> extends org.apache.thrift.TBaseProcessor<I> 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<java.lang.String, org.apache.thrift.ProcessFunction<I, ? extends org.apache.thrift.TBase>>()));
}
protected Processor(I iface, java.util.Map<java.lang.String, org.apache.thrift.ProcessFunction<I, ? extends org.apache.thrift.TBase>> processMap) {
super(iface, getProcessMap(processMap));
}
private static <I extends Iface> java.util.Map<java.lang.String, org.apache.thrift.ProcessFunction<I, ? extends org.apache.thrift.TBase>> getProcessMap(java.util.Map<java.lang.String, org.apache.thrift.ProcessFunction<I, ? extends org.apache.thrift.TBase>> processMap) {
processMap.put("getStruct", new getStruct());
return processMap;
}
public static class getStruct<I extends Iface> extends org.apache.thrift.ProcessFunction<I, getStruct_args> {
public getStruct() {
super("getStruct");
}
public getStruct_args getEmptyArgsInstance() {
return new getStruct_args();
}
protected boolean isOneway() {
return false;
}
@Override
protected boolean rethrowUnhandledExceptions() {
return false;
}
public getStruct_result getResult(I iface, getStruct_args args) throws org.apache.thrift.TException {
getStruct_result result = new getStruct_result();
result.success = iface.getStruct(args.key);
return result;
}
}
}
public static class AsyncProcessor<I extends AsyncIface> extends org.apache.thrift.TBaseAsyncProcessor<I> {
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<java.lang.String, org.apache.thrift.AsyncProcessFunction<I, ? extends org.apache.thrift.TBase, ?>>()));
}
protected AsyncProcessor(I iface, java.util.Map<java.lang.String, org.apache.thrift.AsyncProcessFunction<I, ? extends org.apache.thrift.TBase, ?>> processMap) {
super(iface, getProcessMap(processMap));
}
private static <I extends AsyncIface> java.util.Map<java.lang.String, org.apache.thrift.AsyncProcessFunction<I, ? extends org.apache.thrift.TBase,?>> getProcessMap(java.util.Map<java.lang.String, org.apache.thrift.AsyncProcessFunction<I, ? extends org.apache.thrift.TBase, ?>> processMap) {
processMap.put("getStruct", new getStruct());
return processMap;
}
public static class getStruct<I extends AsyncIface> extends org.apache.thrift.AsyncProcessFunction<I, getStruct_args, SharedStruct> {
public getStruct() {
super("getStruct");
}
public getStruct_args getEmptyArgsInstance() {
return new getStruct_args();
}
public org.apache.thrift.async.AsyncMethodCallback<SharedStruct> 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<SharedStruct>() {
public void onComplete(SharedStruct o) {
getStruct_result result = new getStruct_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;
getStruct_result result = new getStruct_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, getStruct_args args, org.apache.thrift.async.AsyncMethodCallback<SharedStruct> resultHandler) throws org.apache.thrift.TException {
iface.getStruct(args.key,resultHandler);
}
}
}
public static class getStruct_args implements org.apache.thrift.TBase<getStruct_args, getStruct_args._Fields>, java.io.Serializable, Cloneable, Comparable<getStruct_args> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("getStruct_args");
private static final org.apache.thrift.protocol.TField KEY_FIELD_DESC = new org.apache.thrift.protocol.TField("key", org.apache.thrift.protocol.TType.I32, (short)1);
private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new getStruct_argsStandardSchemeFactory();
private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new getStruct_argsTupleSchemeFactory();
public int key; // 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 {
KEY((short)1, "key");
private static final java.util.Map<java.lang.String, _Fields> byName = new java.util.HashMap<java.lang.String, _Fields>();
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: // KEY
return KEY;
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 __KEY_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.KEY, new org.apache.thrift.meta_data.FieldMetaData("key", org.apache.thrift.TFieldRequirementType.DEFAULT,
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(getStruct_args.class, metaDataMap);
}
public getStruct_args() {
}
public getStruct_args(
int key)
{
this();
this.key = key;
setKeyIsSet(true);
}
/**
* Performs a deep copy on <i>other</i>.
*/
public getStruct_args(getStruct_args other) {
__isset_bitfield = other.__isset_bitfield;
this.key = other.key;
}
public getStruct_args deepCopy() {
return new getStruct_args(this);
}
@Override
public void clear() {
setKeyIsSet(false);
this.key = 0;
}
public int getKey() {
return this.key;
}
public getStruct_args setKey(int key) {
this.key = key;
setKeyIsSet(true);
return this;
}
public void unsetKey() {
__isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __KEY_ISSET_ID);
}
/** Returns true if field key is set (has been assigned a value) and false otherwise */
public boolean isSetKey() {
return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __KEY_ISSET_ID);
}
public void setKeyIsSet(boolean value) {
__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __KEY_ISSET_ID, value);
}
public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) {
switch (field) {
case KEY:
if (value == null) {
unsetKey();
} else {
setKey((java.lang.Integer)value);
}
break;
}
}
@org.apache.thrift.annotation.Nullable
public java.lang.Object getFieldValue(_Fields field) {
switch (field) {
case KEY:
return getKey();
}
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 KEY:
return isSetKey();
}
throw new java.lang.IllegalStateException();
}
@Override
public boolean equals(java.lang.Object that) {
if (that == null)
return false;
if (that instanceof getStruct_args)
return this.equals((getStruct_args)that);
return false;
}
public boolean equals(getStruct_args that) {
if (that == null)
return false;
if (this == that)
return true;
boolean this_present_key = true;
boolean that_present_key = true;
if (this_present_key || that_present_key) {
if (!(this_present_key && that_present_key))
return false;
if (this.key != that.key)
return false;
}
return true;
}
@Override
public int hashCode() {
int hashCode = 1;
hashCode = hashCode * 8191 + key;
return hashCode;
}
@Override
public int compareTo(getStruct_args other) {
if (!getClass().equals(other.getClass())) {
return getClass().getName().compareTo(other.getClass().getName());
}
int lastComparison = 0;
lastComparison = java.lang.Boolean.valueOf(isSetKey()).compareTo(other.isSetKey());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetKey()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.key, other.key);
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("getStruct_args(");
boolean first = true;
sb.append("key:");
sb.append(this.key);
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 getStruct_argsStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public getStruct_argsStandardScheme getScheme() {
return new getStruct_argsStandardScheme();
}
}
private static class getStruct_argsStandardScheme extends org.apache.thrift.scheme.StandardScheme<getStruct_args> {
public void read(org.apache.thrift.protocol.TProtocol iprot, getStruct_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: // KEY
if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
struct.key = iprot.readI32();
struct.setKeyIsSet(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, getStruct_args struct) throws org.apache.thrift.TException {
struct.validate();
oprot.writeStructBegin(STRUCT_DESC);
oprot.writeFieldBegin(KEY_FIELD_DESC);
oprot.writeI32(struct.key);
oprot.writeFieldEnd();
oprot.writeFieldStop();
oprot.writeStructEnd();
}
}
private static class getStruct_argsTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public getStruct_argsTupleScheme getScheme() {
return new getStruct_argsTupleScheme();
}
}
private static class getStruct_argsTupleScheme extends org.apache.thrift.scheme.TupleScheme<getStruct_args> {
@Override
public void write(org.apache.thrift.protocol.TProtocol prot, getStruct_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.isSetKey()) {
optionals.set(0);
}
oprot.writeBitSet(optionals, 1);
if (struct.isSetKey()) {
oprot.writeI32(struct.key);
}
}
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, getStruct_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)) {
struct.key = iprot.readI32();
struct.setKeyIsSet(true);
}
}
}
private static <S extends org.apache.thrift.scheme.IScheme> 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 getStruct_result implements org.apache.thrift.TBase<getStruct_result, getStruct_result._Fields>, java.io.Serializable, Cloneable, Comparable<getStruct_result> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("getStruct_result");
private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.STRUCT, (short)0);
private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new getStruct_resultStandardSchemeFactory();
private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new getStruct_resultTupleSchemeFactory();
public @org.apache.thrift.annotation.Nullable SharedStruct 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<java.lang.String, _Fields> byName = new java.util.HashMap<java.lang.String, _Fields>();
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.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, SharedStruct.class)));
metaDataMap = java.util.Collections.unmodifiableMap(tmpMap);
org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(getStruct_result.class, metaDataMap);
}
public getStruct_result() {
}
public getStruct_result(
SharedStruct success)
{
this();
this.success = success;
}
/**
* Performs a deep copy on <i>other</i>.
*/
public getStruct_result(getStruct_result other) {
if (other.isSetSuccess()) {
this.success = new SharedStruct(other.success);
}
}
public getStruct_result deepCopy() {
return new getStruct_result(this);
}
@Override
public void clear() {
this.success = null;
}
@org.apache.thrift.annotation.Nullable
public SharedStruct getSuccess() {
return this.success;
}
public getStruct_result setSuccess(@org.apache.thrift.annotation.Nullable SharedStruct 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((SharedStruct)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 == null)
return false;
if (that instanceof getStruct_result)
return this.equals((getStruct_result)that);
return false;
}
public boolean equals(getStruct_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(getStruct_result other) {
if (!getClass().equals(other.getClass())) {
return getClass().getName().compareTo(other.getClass().getName());
}
int lastComparison = 0;
lastComparison = java.lang.Boolean.valueOf(isSetSuccess()).compareTo(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("getStruct_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
if (success != null) {
success.validate();
}
}
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 getStruct_resultStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public getStruct_resultStandardScheme getScheme() {
return new getStruct_resultStandardScheme();
}
}
private static class getStruct_resultStandardScheme extends org.apache.thrift.scheme.StandardScheme<getStruct_result> {
public void read(org.apache.thrift.protocol.TProtocol iprot, getStruct_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.STRUCT) {
struct.success = new SharedStruct();
struct.success.read(iprot);
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, getStruct_result struct) throws org.apache.thrift.TException {
struct.validate();
oprot.writeStructBegin(STRUCT_DESC);
if (struct.success != null) {
oprot.writeFieldBegin(SUCCESS_FIELD_DESC);
struct.success.write(oprot);
oprot.writeFieldEnd();
}
oprot.writeFieldStop();
oprot.writeStructEnd();
}
}
private static class getStruct_resultTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public getStruct_resultTupleScheme getScheme() {
return new getStruct_resultTupleScheme();
}
}
private static class getStruct_resultTupleScheme extends org.apache.thrift.scheme.TupleScheme<getStruct_result> {
@Override
public void write(org.apache.thrift.protocol.TProtocol prot, getStruct_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()) {
struct.success.write(oprot);
}
}
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, getStruct_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 = new SharedStruct();
struct.success.read(iprot);
struct.setSuccessIsSet(true);
}
}
}
private static <S extends org.apache.thrift.scheme.IScheme> 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();
}
}
}

View File

@ -0,0 +1,477 @@
/**
* Autogenerated by Thrift Compiler (0.12.0)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
package shared;
@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"})
@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.12.0)", date = "2019-08-02")
public class SharedStruct implements org.apache.thrift.TBase<SharedStruct, SharedStruct._Fields>, java.io.Serializable, Cloneable, Comparable<SharedStruct> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("SharedStruct");
private static final org.apache.thrift.protocol.TField KEY_FIELD_DESC = new org.apache.thrift.protocol.TField("key", org.apache.thrift.protocol.TType.I32, (short)1);
private static final org.apache.thrift.protocol.TField VALUE_FIELD_DESC = new org.apache.thrift.protocol.TField("value", org.apache.thrift.protocol.TType.STRING, (short)2);
private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new SharedStructStandardSchemeFactory();
private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new SharedStructTupleSchemeFactory();
public int key; // required
public @org.apache.thrift.annotation.Nullable java.lang.String value; // 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 {
KEY((short)1, "key"),
VALUE((short)2, "value");
private static final java.util.Map<java.lang.String, _Fields> byName = new java.util.HashMap<java.lang.String, _Fields>();
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: // KEY
return KEY;
case 2: // VALUE
return VALUE;
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 __KEY_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.KEY, new org.apache.thrift.meta_data.FieldMetaData("key", org.apache.thrift.TFieldRequirementType.DEFAULT,
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
tmpMap.put(_Fields.VALUE, new org.apache.thrift.meta_data.FieldMetaData("value", 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(SharedStruct.class, metaDataMap);
}
public SharedStruct() {
}
public SharedStruct(
int key,
java.lang.String value)
{
this();
this.key = key;
setKeyIsSet(true);
this.value = value;
}
/**
* Performs a deep copy on <i>other</i>.
*/
public SharedStruct(SharedStruct other) {
__isset_bitfield = other.__isset_bitfield;
this.key = other.key;
if (other.isSetValue()) {
this.value = other.value;
}
}
public SharedStruct deepCopy() {
return new SharedStruct(this);
}
@Override
public void clear() {
setKeyIsSet(false);
this.key = 0;
this.value = null;
}
public int getKey() {
return this.key;
}
public SharedStruct setKey(int key) {
this.key = key;
setKeyIsSet(true);
return this;
}
public void unsetKey() {
__isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __KEY_ISSET_ID);
}
/** Returns true if field key is set (has been assigned a value) and false otherwise */
public boolean isSetKey() {
return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __KEY_ISSET_ID);
}
public void setKeyIsSet(boolean value) {
__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __KEY_ISSET_ID, value);
}
@org.apache.thrift.annotation.Nullable
public java.lang.String getValue() {
return this.value;
}
public SharedStruct setValue(@org.apache.thrift.annotation.Nullable java.lang.String value) {
this.value = value;
return this;
}
public void unsetValue() {
this.value = null;
}
/** Returns true if field value is set (has been assigned a value) and false otherwise */
public boolean isSetValue() {
return this.value != null;
}
public void setValueIsSet(boolean value) {
if (!value) {
this.value = null;
}
}
public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) {
switch (field) {
case KEY:
if (value == null) {
unsetKey();
} else {
setKey((java.lang.Integer)value);
}
break;
case VALUE:
if (value == null) {
unsetValue();
} else {
setValue((java.lang.String)value);
}
break;
}
}
@org.apache.thrift.annotation.Nullable
public java.lang.Object getFieldValue(_Fields field) {
switch (field) {
case KEY:
return getKey();
case VALUE:
return getValue();
}
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 KEY:
return isSetKey();
case VALUE:
return isSetValue();
}
throw new java.lang.IllegalStateException();
}
@Override
public boolean equals(java.lang.Object that) {
if (that == null)
return false;
if (that instanceof SharedStruct)
return this.equals((SharedStruct)that);
return false;
}
public boolean equals(SharedStruct that) {
if (that == null)
return false;
if (this == that)
return true;
boolean this_present_key = true;
boolean that_present_key = true;
if (this_present_key || that_present_key) {
if (!(this_present_key && that_present_key))
return false;
if (this.key != that.key)
return false;
}
boolean this_present_value = true && this.isSetValue();
boolean that_present_value = true && that.isSetValue();
if (this_present_value || that_present_value) {
if (!(this_present_value && that_present_value))
return false;
if (!this.value.equals(that.value))
return false;
}
return true;
}
@Override
public int hashCode() {
int hashCode = 1;
hashCode = hashCode * 8191 + key;
hashCode = hashCode * 8191 + ((isSetValue()) ? 131071 : 524287);
if (isSetValue())
hashCode = hashCode * 8191 + value.hashCode();
return hashCode;
}
@Override
public int compareTo(SharedStruct other) {
if (!getClass().equals(other.getClass())) {
return getClass().getName().compareTo(other.getClass().getName());
}
int lastComparison = 0;
lastComparison = java.lang.Boolean.valueOf(isSetKey()).compareTo(other.isSetKey());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetKey()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.key, other.key);
if (lastComparison != 0) {
return lastComparison;
}
}
lastComparison = java.lang.Boolean.valueOf(isSetValue()).compareTo(other.isSetValue());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetValue()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.value, other.value);
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("SharedStruct(");
boolean first = true;
sb.append("key:");
sb.append(this.key);
first = false;
if (!first) sb.append(", ");
sb.append("value:");
if (this.value == null) {
sb.append("null");
} else {
sb.append(this.value);
}
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 SharedStructStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public SharedStructStandardScheme getScheme() {
return new SharedStructStandardScheme();
}
}
private static class SharedStructStandardScheme extends org.apache.thrift.scheme.StandardScheme<SharedStruct> {
public void read(org.apache.thrift.protocol.TProtocol iprot, SharedStruct 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: // KEY
if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
struct.key = iprot.readI32();
struct.setKeyIsSet(true);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
break;
case 2: // VALUE
if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
struct.value = iprot.readString();
struct.setValueIsSet(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, SharedStruct struct) throws org.apache.thrift.TException {
struct.validate();
oprot.writeStructBegin(STRUCT_DESC);
oprot.writeFieldBegin(KEY_FIELD_DESC);
oprot.writeI32(struct.key);
oprot.writeFieldEnd();
if (struct.value != null) {
oprot.writeFieldBegin(VALUE_FIELD_DESC);
oprot.writeString(struct.value);
oprot.writeFieldEnd();
}
oprot.writeFieldStop();
oprot.writeStructEnd();
}
}
private static class SharedStructTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public SharedStructTupleScheme getScheme() {
return new SharedStructTupleScheme();
}
}
private static class SharedStructTupleScheme extends org.apache.thrift.scheme.TupleScheme<SharedStruct> {
@Override
public void write(org.apache.thrift.protocol.TProtocol prot, SharedStruct 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.isSetKey()) {
optionals.set(0);
}
if (struct.isSetValue()) {
optionals.set(1);
}
oprot.writeBitSet(optionals, 2);
if (struct.isSetKey()) {
oprot.writeI32(struct.key);
}
if (struct.isSetValue()) {
oprot.writeString(struct.value);
}
}
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, SharedStruct struct) throws org.apache.thrift.TException {
org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
java.util.BitSet incoming = iprot.readBitSet(2);
if (incoming.get(0)) {
struct.key = iprot.readI32();
struct.setKeyIsSet(true);
}
if (incoming.get(1)) {
struct.value = iprot.readString();
struct.setValueIsSet(true);
}
}
}
private static <S extends org.apache.thrift.scheme.IScheme> 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();
}
}

View File

@ -0,0 +1,100 @@
package tutorial;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.thrift.TProcessor;
import org.nutz.ioc.loader.annotation.IocBean;
// Generated code
import shared.*;
import java.util.HashMap;
@SuppressWarnings({"unchecked", "rawtypes"})
@IocBean // 增加Ioc配置
public class CalculatorHandler implements Calculator.Iface {
// 声明一个IocBean工厂方法,返回TProcessor实例,就这么简单
@IocBean
public TProcessor createCalculatorTProcessor() {
return new Calculator.Processor(this);
}
private HashMap<Integer,SharedStruct> log;
public CalculatorHandler() {
log = new HashMap<Integer, SharedStruct>();
}
public void ping() {
System.out.println("ping()");
}
public int add(int n1, int n2) {
System.out.println("add(" + n1 + "," + n2 + ")");
return n1 + n2;
}
public int calculate(int logid, Work work) throws InvalidOperation {
System.out.println("calculate(" + logid + ", {" + work.op + "," + work.num1 + "," + work.num2 + "})");
int val = 0;
switch (work.op) {
case ADD:
val = work.num1 + work.num2;
break;
case SUBTRACT:
val = work.num1 - work.num2;
break;
case MULTIPLY:
val = work.num1 * work.num2;
break;
case DIVIDE:
if (work.num2 == 0) {
InvalidOperation io = new InvalidOperation();
io.whatOp = work.op.getValue();
io.why = "Cannot divide by 0";
throw io;
}
val = work.num1 / work.num2;
break;
default:
InvalidOperation io = new InvalidOperation();
io.whatOp = work.op.getValue();
io.why = "Unknown operation";
throw io;
}
SharedStruct entry = new SharedStruct();
entry.key = logid;
entry.value = Integer.toString(val);
log.put(logid, entry);
return val;
}
public SharedStruct getStruct(int key) {
System.out.println("getStruct(" + key + ")");
return log.get(key);
}
public void zip() {
System.out.println("zip()");
}
}

View File

@ -0,0 +1,11 @@
package tutorial;
import org.nutz.boot.NbApp;
public class CalculatorLauncher {
public static void main(String[] args) {
new NbApp().setPrintProcDoc(true).run();
}
}

View File

@ -0,0 +1,480 @@
/**
* Autogenerated by Thrift Compiler (0.12.0)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
package tutorial;
@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"})
/**
* Structs can also be exceptions, if they are nasty.
*/
@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.12.0)", date = "2019-08-01")
public class InvalidOperation extends org.apache.thrift.TException implements org.apache.thrift.TBase<InvalidOperation, InvalidOperation._Fields>, java.io.Serializable, Cloneable, Comparable<InvalidOperation> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("InvalidOperation");
private static final org.apache.thrift.protocol.TField WHAT_OP_FIELD_DESC = new org.apache.thrift.protocol.TField("whatOp", org.apache.thrift.protocol.TType.I32, (short)1);
private static final org.apache.thrift.protocol.TField WHY_FIELD_DESC = new org.apache.thrift.protocol.TField("why", org.apache.thrift.protocol.TType.STRING, (short)2);
private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new InvalidOperationStandardSchemeFactory();
private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new InvalidOperationTupleSchemeFactory();
public int whatOp; // required
public @org.apache.thrift.annotation.Nullable java.lang.String why; // 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 {
WHAT_OP((short)1, "whatOp"),
WHY((short)2, "why");
private static final java.util.Map<java.lang.String, _Fields> byName = new java.util.HashMap<java.lang.String, _Fields>();
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: // WHAT_OP
return WHAT_OP;
case 2: // WHY
return WHY;
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 __WHATOP_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.WHAT_OP, new org.apache.thrift.meta_data.FieldMetaData("whatOp", org.apache.thrift.TFieldRequirementType.DEFAULT,
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
tmpMap.put(_Fields.WHY, new org.apache.thrift.meta_data.FieldMetaData("why", 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(InvalidOperation.class, metaDataMap);
}
public InvalidOperation() {
}
public InvalidOperation(
int whatOp,
java.lang.String why)
{
this();
this.whatOp = whatOp;
setWhatOpIsSet(true);
this.why = why;
}
/**
* Performs a deep copy on <i>other</i>.
*/
public InvalidOperation(InvalidOperation other) {
__isset_bitfield = other.__isset_bitfield;
this.whatOp = other.whatOp;
if (other.isSetWhy()) {
this.why = other.why;
}
}
public InvalidOperation deepCopy() {
return new InvalidOperation(this);
}
@Override
public void clear() {
setWhatOpIsSet(false);
this.whatOp = 0;
this.why = null;
}
public int getWhatOp() {
return this.whatOp;
}
public InvalidOperation setWhatOp(int whatOp) {
this.whatOp = whatOp;
setWhatOpIsSet(true);
return this;
}
public void unsetWhatOp() {
__isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __WHATOP_ISSET_ID);
}
/** Returns true if field whatOp is set (has been assigned a value) and false otherwise */
public boolean isSetWhatOp() {
return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __WHATOP_ISSET_ID);
}
public void setWhatOpIsSet(boolean value) {
__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __WHATOP_ISSET_ID, value);
}
@org.apache.thrift.annotation.Nullable
public java.lang.String getWhy() {
return this.why;
}
public InvalidOperation setWhy(@org.apache.thrift.annotation.Nullable java.lang.String why) {
this.why = why;
return this;
}
public void unsetWhy() {
this.why = null;
}
/** Returns true if field why is set (has been assigned a value) and false otherwise */
public boolean isSetWhy() {
return this.why != null;
}
public void setWhyIsSet(boolean value) {
if (!value) {
this.why = null;
}
}
public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) {
switch (field) {
case WHAT_OP:
if (value == null) {
unsetWhatOp();
} else {
setWhatOp((java.lang.Integer)value);
}
break;
case WHY:
if (value == null) {
unsetWhy();
} else {
setWhy((java.lang.String)value);
}
break;
}
}
@org.apache.thrift.annotation.Nullable
public java.lang.Object getFieldValue(_Fields field) {
switch (field) {
case WHAT_OP:
return getWhatOp();
case WHY:
return getWhy();
}
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 WHAT_OP:
return isSetWhatOp();
case WHY:
return isSetWhy();
}
throw new java.lang.IllegalStateException();
}
@Override
public boolean equals(java.lang.Object that) {
if (that == null)
return false;
if (that instanceof InvalidOperation)
return this.equals((InvalidOperation)that);
return false;
}
public boolean equals(InvalidOperation that) {
if (that == null)
return false;
if (this == that)
return true;
boolean this_present_whatOp = true;
boolean that_present_whatOp = true;
if (this_present_whatOp || that_present_whatOp) {
if (!(this_present_whatOp && that_present_whatOp))
return false;
if (this.whatOp != that.whatOp)
return false;
}
boolean this_present_why = true && this.isSetWhy();
boolean that_present_why = true && that.isSetWhy();
if (this_present_why || that_present_why) {
if (!(this_present_why && that_present_why))
return false;
if (!this.why.equals(that.why))
return false;
}
return true;
}
@Override
public int hashCode() {
int hashCode = 1;
hashCode = hashCode * 8191 + whatOp;
hashCode = hashCode * 8191 + ((isSetWhy()) ? 131071 : 524287);
if (isSetWhy())
hashCode = hashCode * 8191 + why.hashCode();
return hashCode;
}
@Override
public int compareTo(InvalidOperation other) {
if (!getClass().equals(other.getClass())) {
return getClass().getName().compareTo(other.getClass().getName());
}
int lastComparison = 0;
lastComparison = java.lang.Boolean.valueOf(isSetWhatOp()).compareTo(other.isSetWhatOp());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetWhatOp()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.whatOp, other.whatOp);
if (lastComparison != 0) {
return lastComparison;
}
}
lastComparison = java.lang.Boolean.valueOf(isSetWhy()).compareTo(other.isSetWhy());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetWhy()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.why, other.why);
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("InvalidOperation(");
boolean first = true;
sb.append("whatOp:");
sb.append(this.whatOp);
first = false;
if (!first) sb.append(", ");
sb.append("why:");
if (this.why == null) {
sb.append("null");
} else {
sb.append(this.why);
}
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 InvalidOperationStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public InvalidOperationStandardScheme getScheme() {
return new InvalidOperationStandardScheme();
}
}
private static class InvalidOperationStandardScheme extends org.apache.thrift.scheme.StandardScheme<InvalidOperation> {
public void read(org.apache.thrift.protocol.TProtocol iprot, InvalidOperation 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: // WHAT_OP
if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
struct.whatOp = iprot.readI32();
struct.setWhatOpIsSet(true);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
break;
case 2: // WHY
if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
struct.why = iprot.readString();
struct.setWhyIsSet(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, InvalidOperation struct) throws org.apache.thrift.TException {
struct.validate();
oprot.writeStructBegin(STRUCT_DESC);
oprot.writeFieldBegin(WHAT_OP_FIELD_DESC);
oprot.writeI32(struct.whatOp);
oprot.writeFieldEnd();
if (struct.why != null) {
oprot.writeFieldBegin(WHY_FIELD_DESC);
oprot.writeString(struct.why);
oprot.writeFieldEnd();
}
oprot.writeFieldStop();
oprot.writeStructEnd();
}
}
private static class InvalidOperationTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public InvalidOperationTupleScheme getScheme() {
return new InvalidOperationTupleScheme();
}
}
private static class InvalidOperationTupleScheme extends org.apache.thrift.scheme.TupleScheme<InvalidOperation> {
@Override
public void write(org.apache.thrift.protocol.TProtocol prot, InvalidOperation 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.isSetWhatOp()) {
optionals.set(0);
}
if (struct.isSetWhy()) {
optionals.set(1);
}
oprot.writeBitSet(optionals, 2);
if (struct.isSetWhatOp()) {
oprot.writeI32(struct.whatOp);
}
if (struct.isSetWhy()) {
oprot.writeString(struct.why);
}
}
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, InvalidOperation struct) throws org.apache.thrift.TException {
org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
java.util.BitSet incoming = iprot.readBitSet(2);
if (incoming.get(0)) {
struct.whatOp = iprot.readI32();
struct.setWhatOpIsSet(true);
}
if (incoming.get(1)) {
struct.why = iprot.readString();
struct.setWhyIsSet(true);
}
}
}
private static <S extends org.apache.thrift.scheme.IScheme> 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();
}
}

View File

@ -0,0 +1,53 @@
/**
* Autogenerated by Thrift Compiler (0.12.0)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
package tutorial;
/**
* You can define enums, which are just 32 bit integers. Values are optional
* and start at 1 if not supplied, C style again.
*/
@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.12.0)", date = "2019-08-01")
public enum Operation implements org.apache.thrift.TEnum {
ADD(1),
SUBTRACT(2),
MULTIPLY(3),
DIVIDE(4);
private final int value;
private Operation(int value) {
this.value = value;
}
/**
* Get the integer value of this enum value, as defined in the Thrift IDL.
*/
public int getValue() {
return value;
}
/**
* Find a the enum type by its integer value, as defined in the Thrift IDL.
* @return null if the value is not found.
*/
@org.apache.thrift.annotation.Nullable
public static Operation findByValue(int value) {
switch (value) {
case 1:
return ADD;
case 2:
return SUBTRACT;
case 3:
return MULTIPLY;
case 4:
return DIVIDE;
default:
return null;
}
}
}

View File

@ -0,0 +1,708 @@
/**
* Autogenerated by Thrift Compiler (0.12.0)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
package tutorial;
@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"})
/**
* Structs are the basic complex data structures. They are comprised of fields
* which each have an integer identifier, a type, a symbolic name, and an
* optional default value.
*
* Fields can be declared "optional", which ensures they will not be included
* in the serialized output if they aren't set. Note that this requires some
* manual management in some languages.
*/
@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.12.0)", date = "2019-08-01")
public class Work implements org.apache.thrift.TBase<Work, Work._Fields>, java.io.Serializable, Cloneable, Comparable<Work> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("Work");
private static final org.apache.thrift.protocol.TField NUM1_FIELD_DESC = new org.apache.thrift.protocol.TField("num1", org.apache.thrift.protocol.TType.I32, (short)1);
private static final org.apache.thrift.protocol.TField NUM2_FIELD_DESC = new org.apache.thrift.protocol.TField("num2", org.apache.thrift.protocol.TType.I32, (short)2);
private static final org.apache.thrift.protocol.TField OP_FIELD_DESC = new org.apache.thrift.protocol.TField("op", org.apache.thrift.protocol.TType.I32, (short)3);
private static final org.apache.thrift.protocol.TField COMMENT_FIELD_DESC = new org.apache.thrift.protocol.TField("comment", org.apache.thrift.protocol.TType.STRING, (short)4);
private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new WorkStandardSchemeFactory();
private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new WorkTupleSchemeFactory();
public int num1; // required
public int num2; // required
/**
*
* @see Operation
*/
public @org.apache.thrift.annotation.Nullable Operation op; // required
public @org.apache.thrift.annotation.Nullable java.lang.String comment; // 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 {
NUM1((short)1, "num1"),
NUM2((short)2, "num2"),
/**
*
* @see Operation
*/
OP((short)3, "op"),
COMMENT((short)4, "comment");
private static final java.util.Map<java.lang.String, _Fields> byName = new java.util.HashMap<java.lang.String, _Fields>();
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: // NUM1
return NUM1;
case 2: // NUM2
return NUM2;
case 3: // OP
return OP;
case 4: // COMMENT
return COMMENT;
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 __NUM1_ISSET_ID = 0;
private static final int __NUM2_ISSET_ID = 1;
private byte __isset_bitfield = 0;
private static final _Fields optionals[] = {_Fields.COMMENT};
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.NUM1, new org.apache.thrift.meta_data.FieldMetaData("num1", org.apache.thrift.TFieldRequirementType.DEFAULT,
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
tmpMap.put(_Fields.NUM2, new org.apache.thrift.meta_data.FieldMetaData("num2", org.apache.thrift.TFieldRequirementType.DEFAULT,
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
tmpMap.put(_Fields.OP, new org.apache.thrift.meta_data.FieldMetaData("op", org.apache.thrift.TFieldRequirementType.DEFAULT,
new org.apache.thrift.meta_data.EnumMetaData(org.apache.thrift.protocol.TType.ENUM, Operation.class)));
tmpMap.put(_Fields.COMMENT, new org.apache.thrift.meta_data.FieldMetaData("comment", org.apache.thrift.TFieldRequirementType.OPTIONAL,
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(Work.class, metaDataMap);
}
public Work() {
this.num1 = 0;
}
public Work(
int num1,
int num2,
Operation op)
{
this();
this.num1 = num1;
setNum1IsSet(true);
this.num2 = num2;
setNum2IsSet(true);
this.op = op;
}
/**
* Performs a deep copy on <i>other</i>.
*/
public Work(Work other) {
__isset_bitfield = other.__isset_bitfield;
this.num1 = other.num1;
this.num2 = other.num2;
if (other.isSetOp()) {
this.op = other.op;
}
if (other.isSetComment()) {
this.comment = other.comment;
}
}
public Work deepCopy() {
return new Work(this);
}
@Override
public void clear() {
this.num1 = 0;
setNum2IsSet(false);
this.num2 = 0;
this.op = null;
this.comment = null;
}
public int getNum1() {
return this.num1;
}
public Work setNum1(int num1) {
this.num1 = num1;
setNum1IsSet(true);
return this;
}
public void unsetNum1() {
__isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __NUM1_ISSET_ID);
}
/** Returns true if field num1 is set (has been assigned a value) and false otherwise */
public boolean isSetNum1() {
return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __NUM1_ISSET_ID);
}
public void setNum1IsSet(boolean value) {
__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __NUM1_ISSET_ID, value);
}
public int getNum2() {
return this.num2;
}
public Work setNum2(int num2) {
this.num2 = num2;
setNum2IsSet(true);
return this;
}
public void unsetNum2() {
__isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __NUM2_ISSET_ID);
}
/** Returns true if field num2 is set (has been assigned a value) and false otherwise */
public boolean isSetNum2() {
return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __NUM2_ISSET_ID);
}
public void setNum2IsSet(boolean value) {
__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __NUM2_ISSET_ID, value);
}
/**
*
* @see Operation
*/
@org.apache.thrift.annotation.Nullable
public Operation getOp() {
return this.op;
}
/**
*
* @see Operation
*/
public Work setOp(@org.apache.thrift.annotation.Nullable Operation op) {
this.op = op;
return this;
}
public void unsetOp() {
this.op = null;
}
/** Returns true if field op is set (has been assigned a value) and false otherwise */
public boolean isSetOp() {
return this.op != null;
}
public void setOpIsSet(boolean value) {
if (!value) {
this.op = null;
}
}
@org.apache.thrift.annotation.Nullable
public java.lang.String getComment() {
return this.comment;
}
public Work setComment(@org.apache.thrift.annotation.Nullable java.lang.String comment) {
this.comment = comment;
return this;
}
public void unsetComment() {
this.comment = null;
}
/** Returns true if field comment is set (has been assigned a value) and false otherwise */
public boolean isSetComment() {
return this.comment != null;
}
public void setCommentIsSet(boolean value) {
if (!value) {
this.comment = null;
}
}
public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) {
switch (field) {
case NUM1:
if (value == null) {
unsetNum1();
} else {
setNum1((java.lang.Integer)value);
}
break;
case NUM2:
if (value == null) {
unsetNum2();
} else {
setNum2((java.lang.Integer)value);
}
break;
case OP:
if (value == null) {
unsetOp();
} else {
setOp((Operation)value);
}
break;
case COMMENT:
if (value == null) {
unsetComment();
} else {
setComment((java.lang.String)value);
}
break;
}
}
@org.apache.thrift.annotation.Nullable
public java.lang.Object getFieldValue(_Fields field) {
switch (field) {
case NUM1:
return getNum1();
case NUM2:
return getNum2();
case OP:
return getOp();
case COMMENT:
return getComment();
}
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 NUM1:
return isSetNum1();
case NUM2:
return isSetNum2();
case OP:
return isSetOp();
case COMMENT:
return isSetComment();
}
throw new java.lang.IllegalStateException();
}
@Override
public boolean equals(java.lang.Object that) {
if (that == null)
return false;
if (that instanceof Work)
return this.equals((Work)that);
return false;
}
public boolean equals(Work that) {
if (that == null)
return false;
if (this == that)
return true;
boolean this_present_num1 = true;
boolean that_present_num1 = true;
if (this_present_num1 || that_present_num1) {
if (!(this_present_num1 && that_present_num1))
return false;
if (this.num1 != that.num1)
return false;
}
boolean this_present_num2 = true;
boolean that_present_num2 = true;
if (this_present_num2 || that_present_num2) {
if (!(this_present_num2 && that_present_num2))
return false;
if (this.num2 != that.num2)
return false;
}
boolean this_present_op = true && this.isSetOp();
boolean that_present_op = true && that.isSetOp();
if (this_present_op || that_present_op) {
if (!(this_present_op && that_present_op))
return false;
if (!this.op.equals(that.op))
return false;
}
boolean this_present_comment = true && this.isSetComment();
boolean that_present_comment = true && that.isSetComment();
if (this_present_comment || that_present_comment) {
if (!(this_present_comment && that_present_comment))
return false;
if (!this.comment.equals(that.comment))
return false;
}
return true;
}
@Override
public int hashCode() {
int hashCode = 1;
hashCode = hashCode * 8191 + num1;
hashCode = hashCode * 8191 + num2;
hashCode = hashCode * 8191 + ((isSetOp()) ? 131071 : 524287);
if (isSetOp())
hashCode = hashCode * 8191 + op.getValue();
hashCode = hashCode * 8191 + ((isSetComment()) ? 131071 : 524287);
if (isSetComment())
hashCode = hashCode * 8191 + comment.hashCode();
return hashCode;
}
@Override
public int compareTo(Work other) {
if (!getClass().equals(other.getClass())) {
return getClass().getName().compareTo(other.getClass().getName());
}
int lastComparison = 0;
lastComparison = java.lang.Boolean.valueOf(isSetNum1()).compareTo(other.isSetNum1());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetNum1()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.num1, other.num1);
if (lastComparison != 0) {
return lastComparison;
}
}
lastComparison = java.lang.Boolean.valueOf(isSetNum2()).compareTo(other.isSetNum2());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetNum2()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.num2, other.num2);
if (lastComparison != 0) {
return lastComparison;
}
}
lastComparison = java.lang.Boolean.valueOf(isSetOp()).compareTo(other.isSetOp());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetOp()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.op, other.op);
if (lastComparison != 0) {
return lastComparison;
}
}
lastComparison = java.lang.Boolean.valueOf(isSetComment()).compareTo(other.isSetComment());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetComment()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.comment, other.comment);
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("Work(");
boolean first = true;
sb.append("num1:");
sb.append(this.num1);
first = false;
if (!first) sb.append(", ");
sb.append("num2:");
sb.append(this.num2);
first = false;
if (!first) sb.append(", ");
sb.append("op:");
if (this.op == null) {
sb.append("null");
} else {
sb.append(this.op);
}
first = false;
if (isSetComment()) {
if (!first) sb.append(", ");
sb.append("comment:");
if (this.comment == null) {
sb.append("null");
} else {
sb.append(this.comment);
}
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 WorkStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public WorkStandardScheme getScheme() {
return new WorkStandardScheme();
}
}
private static class WorkStandardScheme extends org.apache.thrift.scheme.StandardScheme<Work> {
public void read(org.apache.thrift.protocol.TProtocol iprot, Work 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: // NUM1
if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
struct.num1 = iprot.readI32();
struct.setNum1IsSet(true);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
break;
case 2: // NUM2
if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
struct.num2 = iprot.readI32();
struct.setNum2IsSet(true);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
break;
case 3: // OP
if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
struct.op = tutorial.Operation.findByValue(iprot.readI32());
struct.setOpIsSet(true);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
break;
case 4: // COMMENT
if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
struct.comment = iprot.readString();
struct.setCommentIsSet(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, Work struct) throws org.apache.thrift.TException {
struct.validate();
oprot.writeStructBegin(STRUCT_DESC);
oprot.writeFieldBegin(NUM1_FIELD_DESC);
oprot.writeI32(struct.num1);
oprot.writeFieldEnd();
oprot.writeFieldBegin(NUM2_FIELD_DESC);
oprot.writeI32(struct.num2);
oprot.writeFieldEnd();
if (struct.op != null) {
oprot.writeFieldBegin(OP_FIELD_DESC);
oprot.writeI32(struct.op.getValue());
oprot.writeFieldEnd();
}
if (struct.comment != null) {
if (struct.isSetComment()) {
oprot.writeFieldBegin(COMMENT_FIELD_DESC);
oprot.writeString(struct.comment);
oprot.writeFieldEnd();
}
}
oprot.writeFieldStop();
oprot.writeStructEnd();
}
}
private static class WorkTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public WorkTupleScheme getScheme() {
return new WorkTupleScheme();
}
}
private static class WorkTupleScheme extends org.apache.thrift.scheme.TupleScheme<Work> {
@Override
public void write(org.apache.thrift.protocol.TProtocol prot, Work 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.isSetNum1()) {
optionals.set(0);
}
if (struct.isSetNum2()) {
optionals.set(1);
}
if (struct.isSetOp()) {
optionals.set(2);
}
if (struct.isSetComment()) {
optionals.set(3);
}
oprot.writeBitSet(optionals, 4);
if (struct.isSetNum1()) {
oprot.writeI32(struct.num1);
}
if (struct.isSetNum2()) {
oprot.writeI32(struct.num2);
}
if (struct.isSetOp()) {
oprot.writeI32(struct.op.getValue());
}
if (struct.isSetComment()) {
oprot.writeString(struct.comment);
}
}
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, Work struct) throws org.apache.thrift.TException {
org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
java.util.BitSet incoming = iprot.readBitSet(4);
if (incoming.get(0)) {
struct.num1 = iprot.readI32();
struct.setNum1IsSet(true);
}
if (incoming.get(1)) {
struct.num2 = iprot.readI32();
struct.setNum2IsSet(true);
}
if (incoming.get(2)) {
struct.op = tutorial.Operation.findByValue(iprot.readI32());
struct.setOpIsSet(true);
}
if (incoming.get(3)) {
struct.comment = iprot.readString();
struct.setCommentIsSet(true);
}
}
}
private static <S extends org.apache.thrift.scheme.IScheme> 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();
}
}

View File

@ -0,0 +1,24 @@
/**
* Autogenerated by Thrift Compiler (0.12.0)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
package tutorial;
@SuppressWarnings({"cast", "unused"})
public class tutorialConstants {
/**
* Thrift also lets you define constants for use across languages. Complex
* types and structs are specified using JSON notation.
*/
public static final int INT32CONSTANT = 9853;
public static final java.util.Map<java.lang.String,java.lang.String> MAPCONSTANT = new java.util.HashMap<java.lang.String,java.lang.String>();
static {
MAPCONSTANT.put("goodnight", "moon");
MAPCONSTANT.put("hello", "world");
}
}

View File

@ -0,0 +1,12 @@
# default configure for all
#thrift.servers=default
#thrift.server.default.type=threadpool
#thrift.server.default.transport=socket
#thrift.server.default.port=9090
#thrift.server.default.protocol=binary
# default configure for servlet, need jetty/tomcat/undertow
#thrift.server.servlet.protocol=binary
#thrift.server.servlet.pathspec=/thrift

View File

@ -0,0 +1,7 @@
log4j.rootLogger=debug,Console
log4j.logger.org.eclipse.jetty=info
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%-5p] %d{HH:mm:ss.SSS} %l - %m%n

View File

@ -0,0 +1,68 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter</artifactId>
<version>2.3.8-SNAPSHOT</version>
</parent>
<artifactId>nutzboot-starter-thrift-server</artifactId>
<packaging>jar</packaging>
<name>nutzboot-starter-thrift-server</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<description>NutzBoot, micoservice base on Nutz</description>
<url>http://nutzam.com</url>
<issueManagement>
<system>Github Issue</system>
<url>http://github.com/nutzam/nutzboot/issues</url>
</issueManagement>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<scm>
<connection>scm:git:git://github.com/nutzam/nutzboot.git</connection>
<developerConnection>scm:git:git://github.com/nutzam/nutzboot.git</developerConnection>
<url>git://github.com/nutzam/nutzboot.git</url>
</scm>
<distributionManagement>
<snapshotRepository>
<id>nutzcn-snapshots</id>
<name>NutzCN snapshot repository</name>
<url>https://jfrog.nutz.cn/artifactory/snapshots</url>
</snapshotRepository>
<repository>
<id>sonatype-release-staging</id>
<name>Sonatype Nexus release repository</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId>
<version>0.12.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,220 @@
package org.nutz.boot.starter.thrift.server;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.thrift.TMultiplexedProcessor;
import org.apache.thrift.TProcessor;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TJSONProtocol;
import org.apache.thrift.protocol.TProtocolFactory;
import org.apache.thrift.server.TNonblockingServer;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TSimpleServer;
import org.apache.thrift.server.TThreadPoolServer;
import org.apache.thrift.server.TThreadedSelectorServer;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TNonblockingServerSocket;
import org.apache.thrift.transport.TNonblockingServerTransport;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TServerTransport;
import org.apache.thrift.transport.TTransportException;
import org.apache.thrift.transport.TTransportFactory;
import org.nutz.boot.AppContext;
import org.nutz.boot.annotation.PropDoc;
import org.nutz.boot.starter.MonitorObject;
import org.nutz.boot.starter.ServerFace;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Lang;
import org.nutz.lang.Strings;
import org.nutz.lang.util.NutMap;
import org.nutz.log.Log;
import org.nutz.log.Logs;
@IocBean(create = "init")
public class ThriftServerStarter implements ServerFace, MonitorObject {
private static final Log log = Logs.get();
protected static final String PRE = "thrift";
@PropDoc(defaultValue = "default", value = "TServer名称,可以多个TServer配置,名称用逗号分割")
public static final String PROP_SERVERS = PRE + ".servers";
@PropDoc(value = "TServer类型", defaultValue = "threadpool", possible = {"threadpool", "simple", "threadedSelector", "nonblocking"})
public static final String PROP_SERVER_TYPE = ".server.${name}.type";
@PropDoc(value = "TServer监听的端口", defaultValue = "9090")
public static final String PROP_SERVER_PORT = ".server.${name}.port";
@PropDoc(value = "TServerTransport类型", defaultValue = "socket", possible = {"socket"})
public static final String PROP_SERVER_TRANSPORT = ".server.${name}.transport";
@PropDoc(value = "TProtocol类型", defaultValue = "binary", possible = {"binary", "compact", "json", "disable"})
public static final String PROP_SERVER_DEFAULT_TYPE = ".server.${name}.protocol";
@Inject
protected PropertiesProxy conf;
@Inject
protected AppContext appContext;
protected List<TServer> servers = new ArrayList<>();
protected NutMap monitorProps = new NutMap();
protected TProcessor getTProcessor() {
List<TProcessor> list = appContext.getBeans(TProcessor.class);
if (list.isEmpty()) {
return null;
}
TMultiplexedProcessor multi = new TMultiplexedProcessor();
for (TProcessor processor : list) {
String name = processor.getClass().getEnclosingClass().getSimpleName();
log.debugf("add processor/service name=%s", name);
multi.registerProcessor(name, processor);
}
multi.registerDefault(list.get(0));
updateMonitorValue(PRE + ".processor_count", list.size());
return multi;
}
/**
* 选用不同的服务器实现类
*/
protected TServer getTServer(String prefix, TProcessor processor) throws TTransportException {
TProtocolFactory protocolFactory = getTProtocol(prefix);
String type = conf.get(prefix + ".type", "threadpool");
updateMonitorValue(prefix + ".type", type);
switch (type) {
case "threadpool": {
TThreadPoolServer.Args args = new TThreadPoolServer.Args(getTServerTransport(prefix, false));
args.processor(processor);
args.protocolFactory(protocolFactory);
args.transportFactory(new TTransportFactory());
return new TThreadPoolServer(args);
}
case "simple": {
TSimpleServer.Args args = new TSimpleServer.Args(getTServerTransport(prefix, false));
args.processor(processor);
args.protocolFactory(protocolFactory);
args.transportFactory(new TTransportFactory());
return new TSimpleServer(args);
}
case "threadedSelector": {
TThreadedSelectorServer.Args args = new TThreadedSelectorServer.Args((TNonblockingServerTransport) getTServerTransport(prefix, true));
args.processor(processor);
args.protocolFactory(protocolFactory);
args.transportFactory(new TFramedTransport.Factory());
return new TThreadedSelectorServer(args);
}
case "nonblocking": {
TNonblockingServer.Args args = new TNonblockingServer.Args((TNonblockingServerTransport) getTServerTransport(prefix, true));
args.processor(processor);
args.protocolFactory(protocolFactory);
args.transportFactory(new TFramedTransport.Factory());
return new TNonblockingServer(args);
}
case "servlet": {
log.info("using servlet init, nop");
return null;
}
default:
break;
}
throw Lang.noImplement();
}
protected TServerTransport getTServerTransport(String prefix, boolean nonblock) throws TTransportException {
String transport = conf.get(prefix + ".transport", "socket");
switch (transport) {
case "socket": {
int port = conf.getInt(prefix + ".port", 9090);
int clientTimeout = conf.getInt(prefix + ".clientTimeout", 0);
updateMonitorValue(prefix + ".port", port);
updateMonitorValue(prefix + ".clientTimeout", clientTimeout);
if (nonblock) {
return new TNonblockingServerSocket(port, clientTimeout);
} else {
return new TServerSocket(port, clientTimeout);
}
}
default:
break;
}
throw Lang.noImplement();
}
protected TProtocolFactory getTProtocol(String prefix) {
String protocol = conf.get(prefix + ".protocol", "binary");
switch (protocol) {
case "binary":
return new TBinaryProtocol.Factory(true, true);
case "json":
return new TJSONProtocol.Factory();
case "compact":
return new TCompactProtocol.Factory();
case "disable":
return null;
default:
break;
}
throw Lang.noImplement();
}
public void init() throws Exception {
TProcessor processor = getTProcessor();
if (processor == null) {
log.warn("none TProcessor found, thrift.service will not start!!!!!");
return;
}
for (String serverName : Strings.splitIgnoreBlank(conf.get(PROP_SERVERS, "default"))) {
String prefix = PRE + ".server." + serverName;
TServer server = getTServer(prefix, processor);
if (server != null)
servers.add(server);
}
}
public void start() throws Exception {
if (servers.isEmpty())
return;
for (TServer tServer : servers) {
Thread t = new Thread("thrift.service." + tServer.getClass().getSimpleName() + "." + System.currentTimeMillis()) {
public void run() {
tServer.serve();
}
};
t.setDaemon(true);
t.start();
}
if (log.isDebugEnabled())
log.debug("Thrift monitor props:\r\n"+getMonitorForPrint());
}
public void stop() throws Exception {
for (TServer tServer : servers) {
tServer.stop();
}
}
// 监控相关的方法
public Collection<String> getMonitorKeys() {
return monitorProps.keySet();
}
public Object getMonitorValue(String key) {
return monitorProps.get(key);
}
public void updateMonitorValue(String key, Object value) {
monitorProps.put(key, value);
}
public String getMonitorName() {
return "thrift";
}
}

View File

@ -0,0 +1,44 @@
package org.nutz.boot.starter.thrift.server;
import javax.servlet.Servlet;
import org.apache.thrift.TProcessor;
import org.apache.thrift.protocol.TProtocolFactory;
import org.apache.thrift.server.TServlet;
import org.nutz.boot.starter.WebServletFace;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
@IocBean
public class ThriftWebServletFace implements WebServletFace {
@Inject
protected ThriftServerStarter thriftServerStarter;
@Inject
protected PropertiesProxy conf;
protected TServlet tServlet;
public void setThriftServiceStarter(ThriftServerStarter thriftServerStarter) {
this.thriftServerStarter = thriftServerStarter;
TProtocolFactory factory = thriftServerStarter.getTProtocol(conf.get(ThriftServerStarter.PRE + "server.servlet.protocol", "binary"));
TProcessor processor = thriftServerStarter.getTProcessor();
if (processor != null && factory != null)
tServlet = new TServlet(processor, factory);
}
public String getName() {
return "thrify";
}
public String getPathSpec() {
return conf.get("thrift.server.servlet.pathspec", "/thrify");
}
public Servlet getServlet() {
return tServlet;
}
}

View File

@ -0,0 +1 @@
org.nutz.boot.starter.thrift.server.ThriftServerStarter

View File

@ -0,0 +1,974 @@
/**
* Autogenerated by Thrift Compiler (0.12.0)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
package shared;
@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"})
@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.12.0)", date = "2019-08-02")
public class SharedService {
public interface Iface {
public SharedStruct getStruct(int key) throws org.apache.thrift.TException;
}
public interface AsyncIface {
public void getStruct(int key, org.apache.thrift.async.AsyncMethodCallback<SharedStruct> resultHandler) throws org.apache.thrift.TException;
}
public static class Client extends org.apache.thrift.TServiceClient implements Iface {
public static class Factory implements org.apache.thrift.TServiceClientFactory<Client> {
public Factory() {}
public Client getClient(org.apache.thrift.protocol.TProtocol prot) {
return new Client(prot);
}
public Client getClient(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) {
return new Client(iprot, oprot);
}
}
public Client(org.apache.thrift.protocol.TProtocol prot)
{
super(prot, prot);
}
public Client(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) {
super(iprot, oprot);
}
public SharedStruct getStruct(int key) throws org.apache.thrift.TException
{
send_getStruct(key);
return recv_getStruct();
}
public void send_getStruct(int key) throws org.apache.thrift.TException
{
getStruct_args args = new getStruct_args();
args.setKey(key);
sendBase("getStruct", args);
}
public SharedStruct recv_getStruct() throws org.apache.thrift.TException
{
getStruct_result result = new getStruct_result();
receiveBase(result, "getStruct");
if (result.isSetSuccess()) {
return result.success;
}
throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "getStruct 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<AsyncClient> {
private org.apache.thrift.async.TAsyncClientManager clientManager;
private org.apache.thrift.protocol.TProtocolFactory protocolFactory;
public Factory(org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.protocol.TProtocolFactory protocolFactory) {
this.clientManager = clientManager;
this.protocolFactory = protocolFactory;
}
public AsyncClient getAsyncClient(org.apache.thrift.transport.TNonblockingTransport transport) {
return new AsyncClient(protocolFactory, clientManager, transport);
}
}
public AsyncClient(org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.transport.TNonblockingTransport transport) {
super(protocolFactory, clientManager, transport);
}
public void getStruct(int key, org.apache.thrift.async.AsyncMethodCallback<SharedStruct> resultHandler) throws org.apache.thrift.TException {
checkReady();
getStruct_call method_call = new getStruct_call(key, resultHandler, this, ___protocolFactory, ___transport);
this.___currentMethod = method_call;
___manager.call(method_call);
}
public static class getStruct_call extends org.apache.thrift.async.TAsyncMethodCall<SharedStruct> {
private int key;
public getStruct_call(int key, org.apache.thrift.async.AsyncMethodCallback<SharedStruct> 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.key = key;
}
public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException {
prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("getStruct", org.apache.thrift.protocol.TMessageType.CALL, 0));
getStruct_args args = new getStruct_args();
args.setKey(key);
args.write(prot);
prot.writeMessageEnd();
}
public SharedStruct 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_getStruct();
}
}
}
public static class Processor<I extends Iface> extends org.apache.thrift.TBaseProcessor<I> 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<java.lang.String, org.apache.thrift.ProcessFunction<I, ? extends org.apache.thrift.TBase>>()));
}
protected Processor(I iface, java.util.Map<java.lang.String, org.apache.thrift.ProcessFunction<I, ? extends org.apache.thrift.TBase>> processMap) {
super(iface, getProcessMap(processMap));
}
private static <I extends Iface> java.util.Map<java.lang.String, org.apache.thrift.ProcessFunction<I, ? extends org.apache.thrift.TBase>> getProcessMap(java.util.Map<java.lang.String, org.apache.thrift.ProcessFunction<I, ? extends org.apache.thrift.TBase>> processMap) {
processMap.put("getStruct", new getStruct());
return processMap;
}
public static class getStruct<I extends Iface> extends org.apache.thrift.ProcessFunction<I, getStruct_args> {
public getStruct() {
super("getStruct");
}
public getStruct_args getEmptyArgsInstance() {
return new getStruct_args();
}
protected boolean isOneway() {
return false;
}
@Override
protected boolean rethrowUnhandledExceptions() {
return false;
}
public getStruct_result getResult(I iface, getStruct_args args) throws org.apache.thrift.TException {
getStruct_result result = new getStruct_result();
result.success = iface.getStruct(args.key);
return result;
}
}
}
public static class AsyncProcessor<I extends AsyncIface> extends org.apache.thrift.TBaseAsyncProcessor<I> {
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<java.lang.String, org.apache.thrift.AsyncProcessFunction<I, ? extends org.apache.thrift.TBase, ?>>()));
}
protected AsyncProcessor(I iface, java.util.Map<java.lang.String, org.apache.thrift.AsyncProcessFunction<I, ? extends org.apache.thrift.TBase, ?>> processMap) {
super(iface, getProcessMap(processMap));
}
private static <I extends AsyncIface> java.util.Map<java.lang.String, org.apache.thrift.AsyncProcessFunction<I, ? extends org.apache.thrift.TBase,?>> getProcessMap(java.util.Map<java.lang.String, org.apache.thrift.AsyncProcessFunction<I, ? extends org.apache.thrift.TBase, ?>> processMap) {
processMap.put("getStruct", new getStruct());
return processMap;
}
public static class getStruct<I extends AsyncIface> extends org.apache.thrift.AsyncProcessFunction<I, getStruct_args, SharedStruct> {
public getStruct() {
super("getStruct");
}
public getStruct_args getEmptyArgsInstance() {
return new getStruct_args();
}
public org.apache.thrift.async.AsyncMethodCallback<SharedStruct> 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<SharedStruct>() {
public void onComplete(SharedStruct o) {
getStruct_result result = new getStruct_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;
getStruct_result result = new getStruct_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, getStruct_args args, org.apache.thrift.async.AsyncMethodCallback<SharedStruct> resultHandler) throws org.apache.thrift.TException {
iface.getStruct(args.key,resultHandler);
}
}
}
public static class getStruct_args implements org.apache.thrift.TBase<getStruct_args, getStruct_args._Fields>, java.io.Serializable, Cloneable, Comparable<getStruct_args> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("getStruct_args");
private static final org.apache.thrift.protocol.TField KEY_FIELD_DESC = new org.apache.thrift.protocol.TField("key", org.apache.thrift.protocol.TType.I32, (short)1);
private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new getStruct_argsStandardSchemeFactory();
private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new getStruct_argsTupleSchemeFactory();
public int key; // 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 {
KEY((short)1, "key");
private static final java.util.Map<java.lang.String, _Fields> byName = new java.util.HashMap<java.lang.String, _Fields>();
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: // KEY
return KEY;
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 __KEY_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.KEY, new org.apache.thrift.meta_data.FieldMetaData("key", org.apache.thrift.TFieldRequirementType.DEFAULT,
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(getStruct_args.class, metaDataMap);
}
public getStruct_args() {
}
public getStruct_args(
int key)
{
this();
this.key = key;
setKeyIsSet(true);
}
/**
* Performs a deep copy on <i>other</i>.
*/
public getStruct_args(getStruct_args other) {
__isset_bitfield = other.__isset_bitfield;
this.key = other.key;
}
public getStruct_args deepCopy() {
return new getStruct_args(this);
}
@Override
public void clear() {
setKeyIsSet(false);
this.key = 0;
}
public int getKey() {
return this.key;
}
public getStruct_args setKey(int key) {
this.key = key;
setKeyIsSet(true);
return this;
}
public void unsetKey() {
__isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __KEY_ISSET_ID);
}
/** Returns true if field key is set (has been assigned a value) and false otherwise */
public boolean isSetKey() {
return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __KEY_ISSET_ID);
}
public void setKeyIsSet(boolean value) {
__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __KEY_ISSET_ID, value);
}
public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) {
switch (field) {
case KEY:
if (value == null) {
unsetKey();
} else {
setKey((java.lang.Integer)value);
}
break;
}
}
@org.apache.thrift.annotation.Nullable
public java.lang.Object getFieldValue(_Fields field) {
switch (field) {
case KEY:
return getKey();
}
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 KEY:
return isSetKey();
}
throw new java.lang.IllegalStateException();
}
@Override
public boolean equals(java.lang.Object that) {
if (that == null)
return false;
if (that instanceof getStruct_args)
return this.equals((getStruct_args)that);
return false;
}
public boolean equals(getStruct_args that) {
if (that == null)
return false;
if (this == that)
return true;
boolean this_present_key = true;
boolean that_present_key = true;
if (this_present_key || that_present_key) {
if (!(this_present_key && that_present_key))
return false;
if (this.key != that.key)
return false;
}
return true;
}
@Override
public int hashCode() {
int hashCode = 1;
hashCode = hashCode * 8191 + key;
return hashCode;
}
@Override
public int compareTo(getStruct_args other) {
if (!getClass().equals(other.getClass())) {
return getClass().getName().compareTo(other.getClass().getName());
}
int lastComparison = 0;
lastComparison = java.lang.Boolean.valueOf(isSetKey()).compareTo(other.isSetKey());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetKey()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.key, other.key);
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("getStruct_args(");
boolean first = true;
sb.append("key:");
sb.append(this.key);
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 getStruct_argsStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public getStruct_argsStandardScheme getScheme() {
return new getStruct_argsStandardScheme();
}
}
private static class getStruct_argsStandardScheme extends org.apache.thrift.scheme.StandardScheme<getStruct_args> {
public void read(org.apache.thrift.protocol.TProtocol iprot, getStruct_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: // KEY
if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
struct.key = iprot.readI32();
struct.setKeyIsSet(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, getStruct_args struct) throws org.apache.thrift.TException {
struct.validate();
oprot.writeStructBegin(STRUCT_DESC);
oprot.writeFieldBegin(KEY_FIELD_DESC);
oprot.writeI32(struct.key);
oprot.writeFieldEnd();
oprot.writeFieldStop();
oprot.writeStructEnd();
}
}
private static class getStruct_argsTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public getStruct_argsTupleScheme getScheme() {
return new getStruct_argsTupleScheme();
}
}
private static class getStruct_argsTupleScheme extends org.apache.thrift.scheme.TupleScheme<getStruct_args> {
@Override
public void write(org.apache.thrift.protocol.TProtocol prot, getStruct_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.isSetKey()) {
optionals.set(0);
}
oprot.writeBitSet(optionals, 1);
if (struct.isSetKey()) {
oprot.writeI32(struct.key);
}
}
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, getStruct_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)) {
struct.key = iprot.readI32();
struct.setKeyIsSet(true);
}
}
}
private static <S extends org.apache.thrift.scheme.IScheme> 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 getStruct_result implements org.apache.thrift.TBase<getStruct_result, getStruct_result._Fields>, java.io.Serializable, Cloneable, Comparable<getStruct_result> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("getStruct_result");
private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.STRUCT, (short)0);
private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new getStruct_resultStandardSchemeFactory();
private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new getStruct_resultTupleSchemeFactory();
public @org.apache.thrift.annotation.Nullable SharedStruct 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<java.lang.String, _Fields> byName = new java.util.HashMap<java.lang.String, _Fields>();
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.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, SharedStruct.class)));
metaDataMap = java.util.Collections.unmodifiableMap(tmpMap);
org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(getStruct_result.class, metaDataMap);
}
public getStruct_result() {
}
public getStruct_result(
SharedStruct success)
{
this();
this.success = success;
}
/**
* Performs a deep copy on <i>other</i>.
*/
public getStruct_result(getStruct_result other) {
if (other.isSetSuccess()) {
this.success = new SharedStruct(other.success);
}
}
public getStruct_result deepCopy() {
return new getStruct_result(this);
}
@Override
public void clear() {
this.success = null;
}
@org.apache.thrift.annotation.Nullable
public SharedStruct getSuccess() {
return this.success;
}
public getStruct_result setSuccess(@org.apache.thrift.annotation.Nullable SharedStruct 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((SharedStruct)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 == null)
return false;
if (that instanceof getStruct_result)
return this.equals((getStruct_result)that);
return false;
}
public boolean equals(getStruct_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(getStruct_result other) {
if (!getClass().equals(other.getClass())) {
return getClass().getName().compareTo(other.getClass().getName());
}
int lastComparison = 0;
lastComparison = java.lang.Boolean.valueOf(isSetSuccess()).compareTo(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("getStruct_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
if (success != null) {
success.validate();
}
}
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 getStruct_resultStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public getStruct_resultStandardScheme getScheme() {
return new getStruct_resultStandardScheme();
}
}
private static class getStruct_resultStandardScheme extends org.apache.thrift.scheme.StandardScheme<getStruct_result> {
public void read(org.apache.thrift.protocol.TProtocol iprot, getStruct_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.STRUCT) {
struct.success = new SharedStruct();
struct.success.read(iprot);
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, getStruct_result struct) throws org.apache.thrift.TException {
struct.validate();
oprot.writeStructBegin(STRUCT_DESC);
if (struct.success != null) {
oprot.writeFieldBegin(SUCCESS_FIELD_DESC);
struct.success.write(oprot);
oprot.writeFieldEnd();
}
oprot.writeFieldStop();
oprot.writeStructEnd();
}
}
private static class getStruct_resultTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public getStruct_resultTupleScheme getScheme() {
return new getStruct_resultTupleScheme();
}
}
private static class getStruct_resultTupleScheme extends org.apache.thrift.scheme.TupleScheme<getStruct_result> {
@Override
public void write(org.apache.thrift.protocol.TProtocol prot, getStruct_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()) {
struct.success.write(oprot);
}
}
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, getStruct_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 = new SharedStruct();
struct.success.read(iprot);
struct.setSuccessIsSet(true);
}
}
}
private static <S extends org.apache.thrift.scheme.IScheme> 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();
}
}
}

View File

@ -0,0 +1,477 @@
/**
* Autogenerated by Thrift Compiler (0.12.0)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
package shared;
@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"})
@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.12.0)", date = "2019-08-02")
public class SharedStruct implements org.apache.thrift.TBase<SharedStruct, SharedStruct._Fields>, java.io.Serializable, Cloneable, Comparable<SharedStruct> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("SharedStruct");
private static final org.apache.thrift.protocol.TField KEY_FIELD_DESC = new org.apache.thrift.protocol.TField("key", org.apache.thrift.protocol.TType.I32, (short)1);
private static final org.apache.thrift.protocol.TField VALUE_FIELD_DESC = new org.apache.thrift.protocol.TField("value", org.apache.thrift.protocol.TType.STRING, (short)2);
private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new SharedStructStandardSchemeFactory();
private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new SharedStructTupleSchemeFactory();
public int key; // required
public @org.apache.thrift.annotation.Nullable java.lang.String value; // 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 {
KEY((short)1, "key"),
VALUE((short)2, "value");
private static final java.util.Map<java.lang.String, _Fields> byName = new java.util.HashMap<java.lang.String, _Fields>();
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: // KEY
return KEY;
case 2: // VALUE
return VALUE;
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 __KEY_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.KEY, new org.apache.thrift.meta_data.FieldMetaData("key", org.apache.thrift.TFieldRequirementType.DEFAULT,
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
tmpMap.put(_Fields.VALUE, new org.apache.thrift.meta_data.FieldMetaData("value", 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(SharedStruct.class, metaDataMap);
}
public SharedStruct() {
}
public SharedStruct(
int key,
java.lang.String value)
{
this();
this.key = key;
setKeyIsSet(true);
this.value = value;
}
/**
* Performs a deep copy on <i>other</i>.
*/
public SharedStruct(SharedStruct other) {
__isset_bitfield = other.__isset_bitfield;
this.key = other.key;
if (other.isSetValue()) {
this.value = other.value;
}
}
public SharedStruct deepCopy() {
return new SharedStruct(this);
}
@Override
public void clear() {
setKeyIsSet(false);
this.key = 0;
this.value = null;
}
public int getKey() {
return this.key;
}
public SharedStruct setKey(int key) {
this.key = key;
setKeyIsSet(true);
return this;
}
public void unsetKey() {
__isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __KEY_ISSET_ID);
}
/** Returns true if field key is set (has been assigned a value) and false otherwise */
public boolean isSetKey() {
return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __KEY_ISSET_ID);
}
public void setKeyIsSet(boolean value) {
__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __KEY_ISSET_ID, value);
}
@org.apache.thrift.annotation.Nullable
public java.lang.String getValue() {
return this.value;
}
public SharedStruct setValue(@org.apache.thrift.annotation.Nullable java.lang.String value) {
this.value = value;
return this;
}
public void unsetValue() {
this.value = null;
}
/** Returns true if field value is set (has been assigned a value) and false otherwise */
public boolean isSetValue() {
return this.value != null;
}
public void setValueIsSet(boolean value) {
if (!value) {
this.value = null;
}
}
public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) {
switch (field) {
case KEY:
if (value == null) {
unsetKey();
} else {
setKey((java.lang.Integer)value);
}
break;
case VALUE:
if (value == null) {
unsetValue();
} else {
setValue((java.lang.String)value);
}
break;
}
}
@org.apache.thrift.annotation.Nullable
public java.lang.Object getFieldValue(_Fields field) {
switch (field) {
case KEY:
return getKey();
case VALUE:
return getValue();
}
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 KEY:
return isSetKey();
case VALUE:
return isSetValue();
}
throw new java.lang.IllegalStateException();
}
@Override
public boolean equals(java.lang.Object that) {
if (that == null)
return false;
if (that instanceof SharedStruct)
return this.equals((SharedStruct)that);
return false;
}
public boolean equals(SharedStruct that) {
if (that == null)
return false;
if (this == that)
return true;
boolean this_present_key = true;
boolean that_present_key = true;
if (this_present_key || that_present_key) {
if (!(this_present_key && that_present_key))
return false;
if (this.key != that.key)
return false;
}
boolean this_present_value = true && this.isSetValue();
boolean that_present_value = true && that.isSetValue();
if (this_present_value || that_present_value) {
if (!(this_present_value && that_present_value))
return false;
if (!this.value.equals(that.value))
return false;
}
return true;
}
@Override
public int hashCode() {
int hashCode = 1;
hashCode = hashCode * 8191 + key;
hashCode = hashCode * 8191 + ((isSetValue()) ? 131071 : 524287);
if (isSetValue())
hashCode = hashCode * 8191 + value.hashCode();
return hashCode;
}
@Override
public int compareTo(SharedStruct other) {
if (!getClass().equals(other.getClass())) {
return getClass().getName().compareTo(other.getClass().getName());
}
int lastComparison = 0;
lastComparison = java.lang.Boolean.valueOf(isSetKey()).compareTo(other.isSetKey());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetKey()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.key, other.key);
if (lastComparison != 0) {
return lastComparison;
}
}
lastComparison = java.lang.Boolean.valueOf(isSetValue()).compareTo(other.isSetValue());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetValue()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.value, other.value);
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("SharedStruct(");
boolean first = true;
sb.append("key:");
sb.append(this.key);
first = false;
if (!first) sb.append(", ");
sb.append("value:");
if (this.value == null) {
sb.append("null");
} else {
sb.append(this.value);
}
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 SharedStructStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public SharedStructStandardScheme getScheme() {
return new SharedStructStandardScheme();
}
}
private static class SharedStructStandardScheme extends org.apache.thrift.scheme.StandardScheme<SharedStruct> {
public void read(org.apache.thrift.protocol.TProtocol iprot, SharedStruct 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: // KEY
if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
struct.key = iprot.readI32();
struct.setKeyIsSet(true);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
break;
case 2: // VALUE
if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
struct.value = iprot.readString();
struct.setValueIsSet(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, SharedStruct struct) throws org.apache.thrift.TException {
struct.validate();
oprot.writeStructBegin(STRUCT_DESC);
oprot.writeFieldBegin(KEY_FIELD_DESC);
oprot.writeI32(struct.key);
oprot.writeFieldEnd();
if (struct.value != null) {
oprot.writeFieldBegin(VALUE_FIELD_DESC);
oprot.writeString(struct.value);
oprot.writeFieldEnd();
}
oprot.writeFieldStop();
oprot.writeStructEnd();
}
}
private static class SharedStructTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public SharedStructTupleScheme getScheme() {
return new SharedStructTupleScheme();
}
}
private static class SharedStructTupleScheme extends org.apache.thrift.scheme.TupleScheme<SharedStruct> {
@Override
public void write(org.apache.thrift.protocol.TProtocol prot, SharedStruct 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.isSetKey()) {
optionals.set(0);
}
if (struct.isSetValue()) {
optionals.set(1);
}
oprot.writeBitSet(optionals, 2);
if (struct.isSetKey()) {
oprot.writeI32(struct.key);
}
if (struct.isSetValue()) {
oprot.writeString(struct.value);
}
}
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, SharedStruct struct) throws org.apache.thrift.TException {
org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
java.util.BitSet incoming = iprot.readBitSet(2);
if (incoming.get(0)) {
struct.key = iprot.readI32();
struct.setKeyIsSet(true);
}
if (incoming.get(1)) {
struct.value = iprot.readString();
struct.setValueIsSet(true);
}
}
}
private static <S extends org.apache.thrift.scheme.IScheme> 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();
}
}

View File

@ -0,0 +1,100 @@
package tutorial;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.thrift.TProcessor;
import org.nutz.ioc.loader.annotation.IocBean;
// Generated code
import shared.*;
import java.util.HashMap;
@SuppressWarnings({"unchecked", "rawtypes"})
@IocBean // 增加Ioc配置
public class CalculatorHandler implements Calculator.Iface {
// 声明一个IocBean工厂方法,返回TProcessor实例,就这么简单
@IocBean
public TProcessor createCalculatorTProcessor() {
return new Calculator.Processor(this);
}
private HashMap<Integer,SharedStruct> log;
public CalculatorHandler() {
log = new HashMap<Integer, SharedStruct>();
}
public void ping() {
System.out.println("ping()");
}
public int add(int n1, int n2) {
System.out.println("add(" + n1 + "," + n2 + ")");
return n1 + n2;
}
public int calculate(int logid, Work work) throws InvalidOperation {
System.out.println("calculate(" + logid + ", {" + work.op + "," + work.num1 + "," + work.num2 + "})");
int val = 0;
switch (work.op) {
case ADD:
val = work.num1 + work.num2;
break;
case SUBTRACT:
val = work.num1 - work.num2;
break;
case MULTIPLY:
val = work.num1 * work.num2;
break;
case DIVIDE:
if (work.num2 == 0) {
InvalidOperation io = new InvalidOperation();
io.whatOp = work.op.getValue();
io.why = "Cannot divide by 0";
throw io;
}
val = work.num1 / work.num2;
break;
default:
InvalidOperation io = new InvalidOperation();
io.whatOp = work.op.getValue();
io.why = "Unknown operation";
throw io;
}
SharedStruct entry = new SharedStruct();
entry.key = logid;
entry.value = Integer.toString(val);
log.put(logid, entry);
return val;
}
public SharedStruct getStruct(int key) {
System.out.println("getStruct(" + key + ")");
return log.get(key);
}
public void zip() {
System.out.println("zip()");
}
}

View File

@ -0,0 +1,11 @@
package tutorial;
import org.nutz.boot.NbApp;
public class CalculatorLauncher {
public static void main(String[] args) {
new NbApp().run();
}
}

View File

@ -0,0 +1,480 @@
/**
* Autogenerated by Thrift Compiler (0.12.0)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
package tutorial;
@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"})
/**
* Structs can also be exceptions, if they are nasty.
*/
@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.12.0)", date = "2019-08-01")
public class InvalidOperation extends org.apache.thrift.TException implements org.apache.thrift.TBase<InvalidOperation, InvalidOperation._Fields>, java.io.Serializable, Cloneable, Comparable<InvalidOperation> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("InvalidOperation");
private static final org.apache.thrift.protocol.TField WHAT_OP_FIELD_DESC = new org.apache.thrift.protocol.TField("whatOp", org.apache.thrift.protocol.TType.I32, (short)1);
private static final org.apache.thrift.protocol.TField WHY_FIELD_DESC = new org.apache.thrift.protocol.TField("why", org.apache.thrift.protocol.TType.STRING, (short)2);
private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new InvalidOperationStandardSchemeFactory();
private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new InvalidOperationTupleSchemeFactory();
public int whatOp; // required
public @org.apache.thrift.annotation.Nullable java.lang.String why; // 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 {
WHAT_OP((short)1, "whatOp"),
WHY((short)2, "why");
private static final java.util.Map<java.lang.String, _Fields> byName = new java.util.HashMap<java.lang.String, _Fields>();
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: // WHAT_OP
return WHAT_OP;
case 2: // WHY
return WHY;
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 __WHATOP_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.WHAT_OP, new org.apache.thrift.meta_data.FieldMetaData("whatOp", org.apache.thrift.TFieldRequirementType.DEFAULT,
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
tmpMap.put(_Fields.WHY, new org.apache.thrift.meta_data.FieldMetaData("why", 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(InvalidOperation.class, metaDataMap);
}
public InvalidOperation() {
}
public InvalidOperation(
int whatOp,
java.lang.String why)
{
this();
this.whatOp = whatOp;
setWhatOpIsSet(true);
this.why = why;
}
/**
* Performs a deep copy on <i>other</i>.
*/
public InvalidOperation(InvalidOperation other) {
__isset_bitfield = other.__isset_bitfield;
this.whatOp = other.whatOp;
if (other.isSetWhy()) {
this.why = other.why;
}
}
public InvalidOperation deepCopy() {
return new InvalidOperation(this);
}
@Override
public void clear() {
setWhatOpIsSet(false);
this.whatOp = 0;
this.why = null;
}
public int getWhatOp() {
return this.whatOp;
}
public InvalidOperation setWhatOp(int whatOp) {
this.whatOp = whatOp;
setWhatOpIsSet(true);
return this;
}
public void unsetWhatOp() {
__isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __WHATOP_ISSET_ID);
}
/** Returns true if field whatOp is set (has been assigned a value) and false otherwise */
public boolean isSetWhatOp() {
return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __WHATOP_ISSET_ID);
}
public void setWhatOpIsSet(boolean value) {
__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __WHATOP_ISSET_ID, value);
}
@org.apache.thrift.annotation.Nullable
public java.lang.String getWhy() {
return this.why;
}
public InvalidOperation setWhy(@org.apache.thrift.annotation.Nullable java.lang.String why) {
this.why = why;
return this;
}
public void unsetWhy() {
this.why = null;
}
/** Returns true if field why is set (has been assigned a value) and false otherwise */
public boolean isSetWhy() {
return this.why != null;
}
public void setWhyIsSet(boolean value) {
if (!value) {
this.why = null;
}
}
public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) {
switch (field) {
case WHAT_OP:
if (value == null) {
unsetWhatOp();
} else {
setWhatOp((java.lang.Integer)value);
}
break;
case WHY:
if (value == null) {
unsetWhy();
} else {
setWhy((java.lang.String)value);
}
break;
}
}
@org.apache.thrift.annotation.Nullable
public java.lang.Object getFieldValue(_Fields field) {
switch (field) {
case WHAT_OP:
return getWhatOp();
case WHY:
return getWhy();
}
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 WHAT_OP:
return isSetWhatOp();
case WHY:
return isSetWhy();
}
throw new java.lang.IllegalStateException();
}
@Override
public boolean equals(java.lang.Object that) {
if (that == null)
return false;
if (that instanceof InvalidOperation)
return this.equals((InvalidOperation)that);
return false;
}
public boolean equals(InvalidOperation that) {
if (that == null)
return false;
if (this == that)
return true;
boolean this_present_whatOp = true;
boolean that_present_whatOp = true;
if (this_present_whatOp || that_present_whatOp) {
if (!(this_present_whatOp && that_present_whatOp))
return false;
if (this.whatOp != that.whatOp)
return false;
}
boolean this_present_why = true && this.isSetWhy();
boolean that_present_why = true && that.isSetWhy();
if (this_present_why || that_present_why) {
if (!(this_present_why && that_present_why))
return false;
if (!this.why.equals(that.why))
return false;
}
return true;
}
@Override
public int hashCode() {
int hashCode = 1;
hashCode = hashCode * 8191 + whatOp;
hashCode = hashCode * 8191 + ((isSetWhy()) ? 131071 : 524287);
if (isSetWhy())
hashCode = hashCode * 8191 + why.hashCode();
return hashCode;
}
@Override
public int compareTo(InvalidOperation other) {
if (!getClass().equals(other.getClass())) {
return getClass().getName().compareTo(other.getClass().getName());
}
int lastComparison = 0;
lastComparison = java.lang.Boolean.valueOf(isSetWhatOp()).compareTo(other.isSetWhatOp());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetWhatOp()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.whatOp, other.whatOp);
if (lastComparison != 0) {
return lastComparison;
}
}
lastComparison = java.lang.Boolean.valueOf(isSetWhy()).compareTo(other.isSetWhy());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetWhy()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.why, other.why);
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("InvalidOperation(");
boolean first = true;
sb.append("whatOp:");
sb.append(this.whatOp);
first = false;
if (!first) sb.append(", ");
sb.append("why:");
if (this.why == null) {
sb.append("null");
} else {
sb.append(this.why);
}
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 InvalidOperationStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public InvalidOperationStandardScheme getScheme() {
return new InvalidOperationStandardScheme();
}
}
private static class InvalidOperationStandardScheme extends org.apache.thrift.scheme.StandardScheme<InvalidOperation> {
public void read(org.apache.thrift.protocol.TProtocol iprot, InvalidOperation 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: // WHAT_OP
if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
struct.whatOp = iprot.readI32();
struct.setWhatOpIsSet(true);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
break;
case 2: // WHY
if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
struct.why = iprot.readString();
struct.setWhyIsSet(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, InvalidOperation struct) throws org.apache.thrift.TException {
struct.validate();
oprot.writeStructBegin(STRUCT_DESC);
oprot.writeFieldBegin(WHAT_OP_FIELD_DESC);
oprot.writeI32(struct.whatOp);
oprot.writeFieldEnd();
if (struct.why != null) {
oprot.writeFieldBegin(WHY_FIELD_DESC);
oprot.writeString(struct.why);
oprot.writeFieldEnd();
}
oprot.writeFieldStop();
oprot.writeStructEnd();
}
}
private static class InvalidOperationTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public InvalidOperationTupleScheme getScheme() {
return new InvalidOperationTupleScheme();
}
}
private static class InvalidOperationTupleScheme extends org.apache.thrift.scheme.TupleScheme<InvalidOperation> {
@Override
public void write(org.apache.thrift.protocol.TProtocol prot, InvalidOperation 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.isSetWhatOp()) {
optionals.set(0);
}
if (struct.isSetWhy()) {
optionals.set(1);
}
oprot.writeBitSet(optionals, 2);
if (struct.isSetWhatOp()) {
oprot.writeI32(struct.whatOp);
}
if (struct.isSetWhy()) {
oprot.writeString(struct.why);
}
}
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, InvalidOperation struct) throws org.apache.thrift.TException {
org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
java.util.BitSet incoming = iprot.readBitSet(2);
if (incoming.get(0)) {
struct.whatOp = iprot.readI32();
struct.setWhatOpIsSet(true);
}
if (incoming.get(1)) {
struct.why = iprot.readString();
struct.setWhyIsSet(true);
}
}
}
private static <S extends org.apache.thrift.scheme.IScheme> 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();
}
}

View File

@ -0,0 +1,53 @@
/**
* Autogenerated by Thrift Compiler (0.12.0)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
package tutorial;
/**
* You can define enums, which are just 32 bit integers. Values are optional
* and start at 1 if not supplied, C style again.
*/
@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.12.0)", date = "2019-08-01")
public enum Operation implements org.apache.thrift.TEnum {
ADD(1),
SUBTRACT(2),
MULTIPLY(3),
DIVIDE(4);
private final int value;
private Operation(int value) {
this.value = value;
}
/**
* Get the integer value of this enum value, as defined in the Thrift IDL.
*/
public int getValue() {
return value;
}
/**
* Find a the enum type by its integer value, as defined in the Thrift IDL.
* @return null if the value is not found.
*/
@org.apache.thrift.annotation.Nullable
public static Operation findByValue(int value) {
switch (value) {
case 1:
return ADD;
case 2:
return SUBTRACT;
case 3:
return MULTIPLY;
case 4:
return DIVIDE;
default:
return null;
}
}
}

View File

@ -0,0 +1,708 @@
/**
* Autogenerated by Thrift Compiler (0.12.0)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
package tutorial;
@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"})
/**
* Structs are the basic complex data structures. They are comprised of fields
* which each have an integer identifier, a type, a symbolic name, and an
* optional default value.
*
* Fields can be declared "optional", which ensures they will not be included
* in the serialized output if they aren't set. Note that this requires some
* manual management in some languages.
*/
@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.12.0)", date = "2019-08-01")
public class Work implements org.apache.thrift.TBase<Work, Work._Fields>, java.io.Serializable, Cloneable, Comparable<Work> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("Work");
private static final org.apache.thrift.protocol.TField NUM1_FIELD_DESC = new org.apache.thrift.protocol.TField("num1", org.apache.thrift.protocol.TType.I32, (short)1);
private static final org.apache.thrift.protocol.TField NUM2_FIELD_DESC = new org.apache.thrift.protocol.TField("num2", org.apache.thrift.protocol.TType.I32, (short)2);
private static final org.apache.thrift.protocol.TField OP_FIELD_DESC = new org.apache.thrift.protocol.TField("op", org.apache.thrift.protocol.TType.I32, (short)3);
private static final org.apache.thrift.protocol.TField COMMENT_FIELD_DESC = new org.apache.thrift.protocol.TField("comment", org.apache.thrift.protocol.TType.STRING, (short)4);
private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new WorkStandardSchemeFactory();
private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new WorkTupleSchemeFactory();
public int num1; // required
public int num2; // required
/**
*
* @see Operation
*/
public @org.apache.thrift.annotation.Nullable Operation op; // required
public @org.apache.thrift.annotation.Nullable java.lang.String comment; // 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 {
NUM1((short)1, "num1"),
NUM2((short)2, "num2"),
/**
*
* @see Operation
*/
OP((short)3, "op"),
COMMENT((short)4, "comment");
private static final java.util.Map<java.lang.String, _Fields> byName = new java.util.HashMap<java.lang.String, _Fields>();
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: // NUM1
return NUM1;
case 2: // NUM2
return NUM2;
case 3: // OP
return OP;
case 4: // COMMENT
return COMMENT;
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 __NUM1_ISSET_ID = 0;
private static final int __NUM2_ISSET_ID = 1;
private byte __isset_bitfield = 0;
private static final _Fields optionals[] = {_Fields.COMMENT};
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.NUM1, new org.apache.thrift.meta_data.FieldMetaData("num1", org.apache.thrift.TFieldRequirementType.DEFAULT,
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
tmpMap.put(_Fields.NUM2, new org.apache.thrift.meta_data.FieldMetaData("num2", org.apache.thrift.TFieldRequirementType.DEFAULT,
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
tmpMap.put(_Fields.OP, new org.apache.thrift.meta_data.FieldMetaData("op", org.apache.thrift.TFieldRequirementType.DEFAULT,
new org.apache.thrift.meta_data.EnumMetaData(org.apache.thrift.protocol.TType.ENUM, Operation.class)));
tmpMap.put(_Fields.COMMENT, new org.apache.thrift.meta_data.FieldMetaData("comment", org.apache.thrift.TFieldRequirementType.OPTIONAL,
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(Work.class, metaDataMap);
}
public Work() {
this.num1 = 0;
}
public Work(
int num1,
int num2,
Operation op)
{
this();
this.num1 = num1;
setNum1IsSet(true);
this.num2 = num2;
setNum2IsSet(true);
this.op = op;
}
/**
* Performs a deep copy on <i>other</i>.
*/
public Work(Work other) {
__isset_bitfield = other.__isset_bitfield;
this.num1 = other.num1;
this.num2 = other.num2;
if (other.isSetOp()) {
this.op = other.op;
}
if (other.isSetComment()) {
this.comment = other.comment;
}
}
public Work deepCopy() {
return new Work(this);
}
@Override
public void clear() {
this.num1 = 0;
setNum2IsSet(false);
this.num2 = 0;
this.op = null;
this.comment = null;
}
public int getNum1() {
return this.num1;
}
public Work setNum1(int num1) {
this.num1 = num1;
setNum1IsSet(true);
return this;
}
public void unsetNum1() {
__isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __NUM1_ISSET_ID);
}
/** Returns true if field num1 is set (has been assigned a value) and false otherwise */
public boolean isSetNum1() {
return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __NUM1_ISSET_ID);
}
public void setNum1IsSet(boolean value) {
__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __NUM1_ISSET_ID, value);
}
public int getNum2() {
return this.num2;
}
public Work setNum2(int num2) {
this.num2 = num2;
setNum2IsSet(true);
return this;
}
public void unsetNum2() {
__isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __NUM2_ISSET_ID);
}
/** Returns true if field num2 is set (has been assigned a value) and false otherwise */
public boolean isSetNum2() {
return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __NUM2_ISSET_ID);
}
public void setNum2IsSet(boolean value) {
__isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __NUM2_ISSET_ID, value);
}
/**
*
* @see Operation
*/
@org.apache.thrift.annotation.Nullable
public Operation getOp() {
return this.op;
}
/**
*
* @see Operation
*/
public Work setOp(@org.apache.thrift.annotation.Nullable Operation op) {
this.op = op;
return this;
}
public void unsetOp() {
this.op = null;
}
/** Returns true if field op is set (has been assigned a value) and false otherwise */
public boolean isSetOp() {
return this.op != null;
}
public void setOpIsSet(boolean value) {
if (!value) {
this.op = null;
}
}
@org.apache.thrift.annotation.Nullable
public java.lang.String getComment() {
return this.comment;
}
public Work setComment(@org.apache.thrift.annotation.Nullable java.lang.String comment) {
this.comment = comment;
return this;
}
public void unsetComment() {
this.comment = null;
}
/** Returns true if field comment is set (has been assigned a value) and false otherwise */
public boolean isSetComment() {
return this.comment != null;
}
public void setCommentIsSet(boolean value) {
if (!value) {
this.comment = null;
}
}
public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) {
switch (field) {
case NUM1:
if (value == null) {
unsetNum1();
} else {
setNum1((java.lang.Integer)value);
}
break;
case NUM2:
if (value == null) {
unsetNum2();
} else {
setNum2((java.lang.Integer)value);
}
break;
case OP:
if (value == null) {
unsetOp();
} else {
setOp((Operation)value);
}
break;
case COMMENT:
if (value == null) {
unsetComment();
} else {
setComment((java.lang.String)value);
}
break;
}
}
@org.apache.thrift.annotation.Nullable
public java.lang.Object getFieldValue(_Fields field) {
switch (field) {
case NUM1:
return getNum1();
case NUM2:
return getNum2();
case OP:
return getOp();
case COMMENT:
return getComment();
}
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 NUM1:
return isSetNum1();
case NUM2:
return isSetNum2();
case OP:
return isSetOp();
case COMMENT:
return isSetComment();
}
throw new java.lang.IllegalStateException();
}
@Override
public boolean equals(java.lang.Object that) {
if (that == null)
return false;
if (that instanceof Work)
return this.equals((Work)that);
return false;
}
public boolean equals(Work that) {
if (that == null)
return false;
if (this == that)
return true;
boolean this_present_num1 = true;
boolean that_present_num1 = true;
if (this_present_num1 || that_present_num1) {
if (!(this_present_num1 && that_present_num1))
return false;
if (this.num1 != that.num1)
return false;
}
boolean this_present_num2 = true;
boolean that_present_num2 = true;
if (this_present_num2 || that_present_num2) {
if (!(this_present_num2 && that_present_num2))
return false;
if (this.num2 != that.num2)
return false;
}
boolean this_present_op = true && this.isSetOp();
boolean that_present_op = true && that.isSetOp();
if (this_present_op || that_present_op) {
if (!(this_present_op && that_present_op))
return false;
if (!this.op.equals(that.op))
return false;
}
boolean this_present_comment = true && this.isSetComment();
boolean that_present_comment = true && that.isSetComment();
if (this_present_comment || that_present_comment) {
if (!(this_present_comment && that_present_comment))
return false;
if (!this.comment.equals(that.comment))
return false;
}
return true;
}
@Override
public int hashCode() {
int hashCode = 1;
hashCode = hashCode * 8191 + num1;
hashCode = hashCode * 8191 + num2;
hashCode = hashCode * 8191 + ((isSetOp()) ? 131071 : 524287);
if (isSetOp())
hashCode = hashCode * 8191 + op.getValue();
hashCode = hashCode * 8191 + ((isSetComment()) ? 131071 : 524287);
if (isSetComment())
hashCode = hashCode * 8191 + comment.hashCode();
return hashCode;
}
@Override
public int compareTo(Work other) {
if (!getClass().equals(other.getClass())) {
return getClass().getName().compareTo(other.getClass().getName());
}
int lastComparison = 0;
lastComparison = java.lang.Boolean.valueOf(isSetNum1()).compareTo(other.isSetNum1());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetNum1()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.num1, other.num1);
if (lastComparison != 0) {
return lastComparison;
}
}
lastComparison = java.lang.Boolean.valueOf(isSetNum2()).compareTo(other.isSetNum2());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetNum2()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.num2, other.num2);
if (lastComparison != 0) {
return lastComparison;
}
}
lastComparison = java.lang.Boolean.valueOf(isSetOp()).compareTo(other.isSetOp());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetOp()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.op, other.op);
if (lastComparison != 0) {
return lastComparison;
}
}
lastComparison = java.lang.Boolean.valueOf(isSetComment()).compareTo(other.isSetComment());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetComment()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.comment, other.comment);
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("Work(");
boolean first = true;
sb.append("num1:");
sb.append(this.num1);
first = false;
if (!first) sb.append(", ");
sb.append("num2:");
sb.append(this.num2);
first = false;
if (!first) sb.append(", ");
sb.append("op:");
if (this.op == null) {
sb.append("null");
} else {
sb.append(this.op);
}
first = false;
if (isSetComment()) {
if (!first) sb.append(", ");
sb.append("comment:");
if (this.comment == null) {
sb.append("null");
} else {
sb.append(this.comment);
}
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 WorkStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public WorkStandardScheme getScheme() {
return new WorkStandardScheme();
}
}
private static class WorkStandardScheme extends org.apache.thrift.scheme.StandardScheme<Work> {
public void read(org.apache.thrift.protocol.TProtocol iprot, Work 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: // NUM1
if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
struct.num1 = iprot.readI32();
struct.setNum1IsSet(true);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
break;
case 2: // NUM2
if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
struct.num2 = iprot.readI32();
struct.setNum2IsSet(true);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
break;
case 3: // OP
if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
struct.op = tutorial.Operation.findByValue(iprot.readI32());
struct.setOpIsSet(true);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
break;
case 4: // COMMENT
if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
struct.comment = iprot.readString();
struct.setCommentIsSet(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, Work struct) throws org.apache.thrift.TException {
struct.validate();
oprot.writeStructBegin(STRUCT_DESC);
oprot.writeFieldBegin(NUM1_FIELD_DESC);
oprot.writeI32(struct.num1);
oprot.writeFieldEnd();
oprot.writeFieldBegin(NUM2_FIELD_DESC);
oprot.writeI32(struct.num2);
oprot.writeFieldEnd();
if (struct.op != null) {
oprot.writeFieldBegin(OP_FIELD_DESC);
oprot.writeI32(struct.op.getValue());
oprot.writeFieldEnd();
}
if (struct.comment != null) {
if (struct.isSetComment()) {
oprot.writeFieldBegin(COMMENT_FIELD_DESC);
oprot.writeString(struct.comment);
oprot.writeFieldEnd();
}
}
oprot.writeFieldStop();
oprot.writeStructEnd();
}
}
private static class WorkTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
public WorkTupleScheme getScheme() {
return new WorkTupleScheme();
}
}
private static class WorkTupleScheme extends org.apache.thrift.scheme.TupleScheme<Work> {
@Override
public void write(org.apache.thrift.protocol.TProtocol prot, Work 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.isSetNum1()) {
optionals.set(0);
}
if (struct.isSetNum2()) {
optionals.set(1);
}
if (struct.isSetOp()) {
optionals.set(2);
}
if (struct.isSetComment()) {
optionals.set(3);
}
oprot.writeBitSet(optionals, 4);
if (struct.isSetNum1()) {
oprot.writeI32(struct.num1);
}
if (struct.isSetNum2()) {
oprot.writeI32(struct.num2);
}
if (struct.isSetOp()) {
oprot.writeI32(struct.op.getValue());
}
if (struct.isSetComment()) {
oprot.writeString(struct.comment);
}
}
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, Work struct) throws org.apache.thrift.TException {
org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
java.util.BitSet incoming = iprot.readBitSet(4);
if (incoming.get(0)) {
struct.num1 = iprot.readI32();
struct.setNum1IsSet(true);
}
if (incoming.get(1)) {
struct.num2 = iprot.readI32();
struct.setNum2IsSet(true);
}
if (incoming.get(2)) {
struct.op = tutorial.Operation.findByValue(iprot.readI32());
struct.setOpIsSet(true);
}
if (incoming.get(3)) {
struct.comment = iprot.readString();
struct.setCommentIsSet(true);
}
}
}
private static <S extends org.apache.thrift.scheme.IScheme> 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();
}
}

View File

@ -0,0 +1,24 @@
/**
* Autogenerated by Thrift Compiler (0.12.0)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
package tutorial;
@SuppressWarnings({"cast", "unused"})
public class tutorialConstants {
/**
* Thrift also lets you define constants for use across languages. Complex
* types and structs are specified using JSON notation.
*/
public static final int INT32CONSTANT = 9853;
public static final java.util.Map<java.lang.String,java.lang.String> MAPCONSTANT = new java.util.HashMap<java.lang.String,java.lang.String>();
static {
MAPCONSTANT.put("goodnight", "moon");
MAPCONSTANT.put("hello", "world");
}
}

View File

@ -0,0 +1,7 @@
log4j.rootLogger=debug,Console
log4j.logger.org.eclipse.jetty=info
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%-5p] %d{HH:mm:ss.SSS} %l - %m%n

View File

@ -78,6 +78,7 @@
<module>nutzboot-starter-seata</module>
<module>nutzboot-starter-sqlxmltpl</module>
<module>nutzboot-starter-redisson</module>
<module>nutzboot-starter-thrift-server</module>
</modules>
<dependencies>

View File

@ -971,6 +971,11 @@
<artifactId>nutzboot-starter-nacos-config-client</artifactId>
<version>${nutzboot.version}</version>
</dependency>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter-thrift-server</artifactId>
<version>${nutzboot.version}</version>
</dependency>
<!-- NutzCloud -->