From e66ce5fb2163d794c03850e86acc90fedd41882c Mon Sep 17 00:00:00 2001 From: WuXianChaoPin <1029559041@qq.com> Date: Tue, 19 Jun 2018 18:34:14 +0800 Subject: [PATCH] thrift --- .../core/thrift/ConnectionPoolFactory.java | 42 +- .../java/core/thrift/ThriftClientPool.java | 37 +- core/src/main/java/core/thrift/task/TSDM.java | 1603 +++++++++++++++++ core/src/test/resources/test.thrift | 5 + .../main/java/db/config/HibernateConfig.java | 27 +- .../java/web/controller/DataController.java | 33 +- .../main/java/web/service/BaseService.java | 7 +- web/src/main/java/web/util/DynamicTimer.java | 29 +- .../{SpringTest.java => SpringMVCTest.java} | 16 +- .../src/test/java}/ThriftServerDemo.java | 2 - web/src/test/java/ThriftTest.java | 14 +- 11 files changed, 1734 insertions(+), 81 deletions(-) create mode 100644 core/src/main/java/core/thrift/task/TSDM.java create mode 100644 core/src/test/resources/test.thrift rename web/src/test/java/{SpringTest.java => SpringMVCTest.java} (92%) rename {core/src/main/java/core/thrift => web/src/test/java}/ThriftServerDemo.java (98%) diff --git a/core/src/main/java/core/thrift/ConnectionPoolFactory.java b/core/src/main/java/core/thrift/ConnectionPoolFactory.java index 244cfe1..f3f4fcc 100644 --- a/core/src/main/java/core/thrift/ConnectionPoolFactory.java +++ b/core/src/main/java/core/thrift/ConnectionPoolFactory.java @@ -4,10 +4,11 @@ import org.apache.commons.pool2.BasePooledObjectFactory; import org.apache.commons.pool2.PooledObject; import org.apache.commons.pool2.impl.DefaultPooledObject; import org.apache.thrift.transport.TNonblockingSocket; -import org.apache.thrift.transport.TTransport; +import java.net.Socket; -public class ConnectionPoolFactory extends BasePooledObjectFactory { + +public class ConnectionPoolFactory extends BasePooledObjectFactory { private String ip; private int port; private int socketTimeout; @@ -19,19 +20,44 @@ public class ConnectionPoolFactory extends BasePooledObjectFactory { } @Override - //创建TTransport类型对象方法 - public TTransport create() throws Exception { + //创建TNonblockingSocket类型对象方法 + public TNonblockingSocket create() throws Exception { return new TNonblockingSocket(ip, port, socketTimeout); } - //把TTransport对象打包成池管理的对象PooledObject + //把TNonblockingSocket对象打包成池管理的对象PooledObject @Override - public PooledObject wrap(TTransport transport) { + public PooledObject wrap(TNonblockingSocket transport) { return new DefaultPooledObject<>(transport); } + /** + * 验证对象 + */ + @Override + public boolean validateObject(PooledObject p) { + Socket socket=p.getObject().getSocketChannel().socket(); + boolean closed = socket.isClosed(); + boolean connected = socket.isConnected(); + boolean outputShutdown = socket.isOutputShutdown(); + boolean inputShutdown = socket.isInputShutdown(); + + boolean urgentFlag = false; + try { + socket.sendUrgentData(0xFF); + urgentFlag = true; + } catch (Exception e) { + + } + + return urgentFlag && connected && !closed && !inputShutdown && !outputShutdown; + } + + /** + * 销毁对象 + */ @Override - public boolean validateObject(PooledObject p) { - return p.getObject().isOpen(); + public void destroyObject(PooledObject p) throws Exception { + p.getObject().close(); } } diff --git a/core/src/main/java/core/thrift/ThriftClientPool.java b/core/src/main/java/core/thrift/ThriftClientPool.java index e5078d7..261fb69 100644 --- a/core/src/main/java/core/thrift/ThriftClientPool.java +++ b/core/src/main/java/core/thrift/ThriftClientPool.java @@ -1,16 +1,21 @@ package core.thrift; -import core.thrift.comment.QueryComment; import org.apache.commons.pool2.impl.GenericObjectPool; +import org.apache.thrift.async.TAsyncClient; import org.apache.thrift.async.TAsyncClientManager; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TProtocolFactory; +import org.apache.thrift.transport.TNonblockingSocket; import org.apache.thrift.transport.TNonblockingTransport; -import org.apache.thrift.transport.TTransport; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; @Service public class ThriftClientPool { @@ -24,29 +29,37 @@ public class ThriftClientPool { @Value("${thrift.timeout}") private Integer timeout; - private static GenericObjectPool pool; + private static GenericObjectPool pool; + + private static final Map, Constructor> map = new HashMap<>(); @PostConstruct public void init() { pool = new GenericObjectPool<>(new ConnectionPoolFactory(ip, port, timeout)); - } - public static void doExecute(Thrift thrift) throws Exception { + public static void doExecute(Thrift thrift,Class c) throws Exception { //从池里获取一个Transport对象 - TTransport transport = pool.borrowObject(); + TNonblockingSocket socket = pool.borrowObject(); + thrift.doExecute(client(c,socket)); + //把一个Transport对象归还到池里 + pool.returnObject(socket); + } + + private static E client(Class c, TNonblockingSocket socket) throws NoSuchMethodException, IOException, IllegalAccessException, InvocationTargetException, InstantiationException { + if (!map.containsKey(c)) { + map.put(c, c.getConstructor(TProtocolFactory.class, TAsyncClientManager.class, TNonblockingTransport.class)); + } TAsyncClientManager clientManager = new TAsyncClientManager(); TProtocolFactory protocol = new TBinaryProtocol.Factory(); - QueryComment.AsyncClient asyncClient = new QueryComment.AsyncClient(protocol, clientManager, (TNonblockingTransport) transport); - thrift.doExecute(asyncClient); - //把一个Transport对象归还到池里 - pool.returnObject(transport); + return (E) map.get(c).newInstance(protocol,clientManager,socket); } - public interface Thrift { - void doExecute(QueryComment.AsyncClient client) throws Exception; + public interface Thrift { + void doExecute(E client) throws Exception; } + } diff --git a/core/src/main/java/core/thrift/task/TSDM.java b/core/src/main/java/core/thrift/task/TSDM.java new file mode 100644 index 0000000..70e5d14 --- /dev/null +++ b/core/src/main/java/core/thrift/task/TSDM.java @@ -0,0 +1,1603 @@ +package core.thrift.task; + +/** + * Autogenerated by Thrift Compiler (0.11.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.11.0)", date = "2018-06-19") +public class TSDM { + + public interface Iface { + + public boolean qiandao() throws org.apache.thrift.TException; + + public boolean word() throws org.apache.thrift.TException; + + } + + public interface AsyncIface { + + public void qiandao(org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + + public void word(org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + + } + + public static class Client extends org.apache.thrift.TServiceClient implements Iface { + public static class Factory implements org.apache.thrift.TServiceClientFactory { + public Factory() {} + public Client getClient(org.apache.thrift.protocol.TProtocol prot) { + return new Client(prot); + } + public Client getClient(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) { + return new Client(iprot, oprot); + } + } + + public Client(org.apache.thrift.protocol.TProtocol prot) + { + super(prot, prot); + } + + public Client(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) { + super(iprot, oprot); + } + + public boolean qiandao() throws org.apache.thrift.TException + { + send_qiandao(); + return recv_qiandao(); + } + + public void send_qiandao() throws org.apache.thrift.TException + { + qiandao_args args = new qiandao_args(); + sendBase("qiandao", args); + } + + public boolean recv_qiandao() throws org.apache.thrift.TException + { + qiandao_result result = new qiandao_result(); + receiveBase(result, "qiandao"); + if (result.isSetSuccess()) { + return result.success; + } + throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "qiandao failed: unknown result"); + } + + public boolean word() throws org.apache.thrift.TException + { + send_word(); + return recv_word(); + } + + public void send_word() throws org.apache.thrift.TException + { + word_args args = new word_args(); + sendBase("word", args); + } + + public boolean recv_word() throws org.apache.thrift.TException + { + word_result result = new word_result(); + receiveBase(result, "word"); + if (result.isSetSuccess()) { + return result.success; + } + throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "word failed: unknown result"); + } + + } + public static class AsyncClient extends org.apache.thrift.async.TAsyncClient implements AsyncIface { + public static class Factory implements org.apache.thrift.async.TAsyncClientFactory { + private org.apache.thrift.async.TAsyncClientManager clientManager; + private org.apache.thrift.protocol.TProtocolFactory protocolFactory; + public Factory(org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.protocol.TProtocolFactory protocolFactory) { + this.clientManager = clientManager; + this.protocolFactory = protocolFactory; + } + public AsyncClient getAsyncClient(org.apache.thrift.transport.TNonblockingTransport transport) { + return new AsyncClient(protocolFactory, clientManager, transport); + } + } + + public AsyncClient(org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.transport.TNonblockingTransport transport) { + super(protocolFactory, clientManager, transport); + } + + public void qiandao(org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + checkReady(); + qiandao_call method_call = new qiandao_call(resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class qiandao_call extends org.apache.thrift.async.TAsyncMethodCall { + public qiandao_call(org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + super(client, protocolFactory, transport, resultHandler, false); + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("qiandao", org.apache.thrift.protocol.TMessageType.CALL, 0)); + qiandao_args args = new qiandao_args(); + args.write(prot); + prot.writeMessageEnd(); + } + + public Boolean getResult() throws org.apache.thrift.TException { + if (getState() != State.RESPONSE_READ) { + throw new IllegalStateException("Method call not finished!"); + } + org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); + org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); + return (new Client(prot)).recv_qiandao(); + } + } + + public void word(org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + checkReady(); + word_call method_call = new word_call(resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class word_call extends org.apache.thrift.async.TAsyncMethodCall { + public word_call(org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + super(client, protocolFactory, transport, resultHandler, false); + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("word", org.apache.thrift.protocol.TMessageType.CALL, 0)); + word_args args = new word_args(); + args.write(prot); + prot.writeMessageEnd(); + } + + public Boolean getResult() throws org.apache.thrift.TException { + if (getState() != State.RESPONSE_READ) { + throw new IllegalStateException("Method call not finished!"); + } + org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); + org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); + return (new Client(prot)).recv_word(); + } + } + + } + + public static class Processor extends org.apache.thrift.TBaseProcessor implements org.apache.thrift.TProcessor { + private static final org.slf4j.Logger _LOGGER = org.slf4j.LoggerFactory.getLogger(Processor.class.getName()); + public Processor(I iface) { + super(iface, getProcessMap(new java.util.HashMap>())); + } + + protected Processor(I iface, java.util.Map> processMap) { + super(iface, getProcessMap(processMap)); + } + + private static java.util.Map> getProcessMap(java.util.Map> processMap) { + processMap.put("qiandao", new qiandao()); + processMap.put("word", new word()); + return processMap; + } + + public static class qiandao extends org.apache.thrift.ProcessFunction { + public qiandao() { + super("qiandao"); + } + + public qiandao_args getEmptyArgsInstance() { + return new qiandao_args(); + } + + protected boolean isOneway() { + return false; + } + + @Override + protected boolean handleRuntimeExceptions() { + return false; + } + + public qiandao_result getResult(I iface, qiandao_args args) throws org.apache.thrift.TException { + qiandao_result result = new qiandao_result(); + result.success = iface.qiandao(); + result.setSuccessIsSet(true); + return result; + } + } + + public static class word extends org.apache.thrift.ProcessFunction { + public word() { + super("word"); + } + + public word_args getEmptyArgsInstance() { + return new word_args(); + } + + protected boolean isOneway() { + return false; + } + + @Override + protected boolean handleRuntimeExceptions() { + return false; + } + + public word_result getResult(I iface, word_args args) throws org.apache.thrift.TException { + word_result result = new word_result(); + result.success = iface.word(); + result.setSuccessIsSet(true); + return result; + } + } + + } + + public static class AsyncProcessor extends org.apache.thrift.TBaseAsyncProcessor { + private static final org.slf4j.Logger _LOGGER = org.slf4j.LoggerFactory.getLogger(AsyncProcessor.class.getName()); + public AsyncProcessor(I iface) { + super(iface, getProcessMap(new java.util.HashMap>())); + } + + protected AsyncProcessor(I iface, java.util.Map> processMap) { + super(iface, getProcessMap(processMap)); + } + + private static java.util.Map> getProcessMap(java.util.Map> processMap) { + processMap.put("qiandao", new qiandao()); + processMap.put("word", new word()); + return processMap; + } + + public static class qiandao extends org.apache.thrift.AsyncProcessFunction { + public qiandao() { + super("qiandao"); + } + + public qiandao_args getEmptyArgsInstance() { + return new qiandao_args(); + } + + public org.apache.thrift.async.AsyncMethodCallback getResultHandler(final org.apache.thrift.server.AbstractNonblockingServer.AsyncFrameBuffer fb, final int seqid) { + final org.apache.thrift.AsyncProcessFunction fcall = this; + return new org.apache.thrift.async.AsyncMethodCallback() { + public void onComplete(Boolean o) { + qiandao_result result = new qiandao_result(); + result.success = o; + result.setSuccessIsSet(true); + try { + fcall.sendResponse(fb, result, org.apache.thrift.protocol.TMessageType.REPLY,seqid); + } catch (org.apache.thrift.transport.TTransportException e) { + _LOGGER.error("TTransportException writing to internal frame buffer", e); + fb.close(); + } catch (Exception e) { + _LOGGER.error("Exception writing to internal frame buffer", e); + onError(e); + } + } + public void onError(Exception e) { + byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; + org.apache.thrift.TSerializable msg; + qiandao_result result = new qiandao_result(); + if (e instanceof org.apache.thrift.transport.TTransportException) { + _LOGGER.error("TTransportException inside handler", e); + fb.close(); + return; + } else if (e instanceof org.apache.thrift.TApplicationException) { + _LOGGER.error("TApplicationException inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = (org.apache.thrift.TApplicationException)e; + } else { + _LOGGER.error("Exception inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage()); + } + try { + fcall.sendResponse(fb,msg,msgType,seqid); + } catch (Exception ex) { + _LOGGER.error("Exception writing to internal frame buffer", ex); + fb.close(); + } + } + }; + } + + protected boolean isOneway() { + return false; + } + + public void start(I iface, qiandao_args args, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + iface.qiandao(resultHandler); + } + } + + public static class word extends org.apache.thrift.AsyncProcessFunction { + public word() { + super("word"); + } + + public word_args getEmptyArgsInstance() { + return new word_args(); + } + + public org.apache.thrift.async.AsyncMethodCallback getResultHandler(final org.apache.thrift.server.AbstractNonblockingServer.AsyncFrameBuffer fb, final int seqid) { + final org.apache.thrift.AsyncProcessFunction fcall = this; + return new org.apache.thrift.async.AsyncMethodCallback() { + public void onComplete(Boolean o) { + word_result result = new word_result(); + result.success = o; + result.setSuccessIsSet(true); + try { + fcall.sendResponse(fb, result, org.apache.thrift.protocol.TMessageType.REPLY,seqid); + } catch (org.apache.thrift.transport.TTransportException e) { + _LOGGER.error("TTransportException writing to internal frame buffer", e); + fb.close(); + } catch (Exception e) { + _LOGGER.error("Exception writing to internal frame buffer", e); + onError(e); + } + } + public void onError(Exception e) { + byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; + org.apache.thrift.TSerializable msg; + word_result result = new word_result(); + if (e instanceof org.apache.thrift.transport.TTransportException) { + _LOGGER.error("TTransportException inside handler", e); + fb.close(); + return; + } else if (e instanceof org.apache.thrift.TApplicationException) { + _LOGGER.error("TApplicationException inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = (org.apache.thrift.TApplicationException)e; + } else { + _LOGGER.error("Exception inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage()); + } + try { + fcall.sendResponse(fb,msg,msgType,seqid); + } catch (Exception ex) { + _LOGGER.error("Exception writing to internal frame buffer", ex); + fb.close(); + } + } + }; + } + + protected boolean isOneway() { + return false; + } + + public void start(I iface, word_args args, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + iface.word(resultHandler); + } + } + + } + + public static class qiandao_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("qiandao_args"); + + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new qiandao_argsStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new qiandao_argsTupleSchemeFactory(); + + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { +; + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + 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); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(qiandao_args.class, metaDataMap); + } + + public qiandao_args() { + } + + /** + * Performs a deep copy on other. + */ + public qiandao_args(qiandao_args other) { + } + + public qiandao_args deepCopy() { + return new qiandao_args(this); + } + + @Override + public void clear() { + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof qiandao_args) + return this.equals((qiandao_args)that); + return false; + } + + public boolean equals(qiandao_args that) { + if (that == null) + return false; + if (this == that) + return true; + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + return hashCode; + } + + @Override + public int compareTo(qiandao_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("qiandao_args("); + boolean first = true; + + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class qiandao_argsStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public qiandao_argsStandardScheme getScheme() { + return new qiandao_argsStandardScheme(); + } + } + + private static class qiandao_argsStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, qiandao_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) { + 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, qiandao_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class qiandao_argsTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public qiandao_argsTupleScheme getScheme() { + return new qiandao_argsTupleScheme(); + } + } + + private static class qiandao_argsTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, qiandao_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, qiandao_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + + public static class qiandao_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("qiandao_result"); + + private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.BOOL, (short)0); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new qiandao_resultStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new qiandao_resultTupleSchemeFactory(); + + public boolean success; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + SUCCESS((short)0, "success"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 0: // SUCCESS + return SUCCESS; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __SUCCESS_ISSET_ID = 0; + private byte __isset_bitfield = 0; + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.BOOL))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(qiandao_result.class, metaDataMap); + } + + public qiandao_result() { + } + + public qiandao_result( + boolean success) + { + this(); + this.success = success; + setSuccessIsSet(true); + } + + /** + * Performs a deep copy on other. + */ + public qiandao_result(qiandao_result other) { + __isset_bitfield = other.__isset_bitfield; + this.success = other.success; + } + + public qiandao_result deepCopy() { + return new qiandao_result(this); + } + + @Override + public void clear() { + setSuccessIsSet(false); + this.success = false; + } + + public boolean isSuccess() { + return this.success; + } + + public qiandao_result setSuccess(boolean success) { + this.success = success; + setSuccessIsSet(true); + return this; + } + + public void unsetSuccess() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __SUCCESS_ISSET_ID); + } + + /** Returns true if field success is set (has been assigned a value) and false otherwise */ + public boolean isSetSuccess() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __SUCCESS_ISSET_ID); + } + + public void setSuccessIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __SUCCESS_ISSET_ID, value); + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((Boolean)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case SUCCESS: + return isSuccess(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case SUCCESS: + return isSetSuccess(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof qiandao_result) + return this.equals((qiandao_result)that); + return false; + } + + public boolean equals(qiandao_result that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_success = true; + boolean that_present_success = true; + if (this_present_success || that_present_success) { + if (!(this_present_success && that_present_success)) + return false; + if (this.success != that.success) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((success) ? 131071 : 524287); + + return hashCode; + } + + @Override + public int compareTo(qiandao_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = 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; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("qiandao_result("); + boolean first = true; + + sb.append("success:"); + sb.append(this.success); + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class qiandao_resultStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public qiandao_resultStandardScheme getScheme() { + return new qiandao_resultStandardScheme(); + } + } + + private static class qiandao_resultStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, qiandao_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.BOOL) { + struct.success = iprot.readBool(); + 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, qiandao_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.isSetSuccess()) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + oprot.writeBool(struct.success); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class qiandao_resultTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public qiandao_resultTupleScheme getScheme() { + return new qiandao_resultTupleScheme(); + } + } + + private static class qiandao_resultTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, qiandao_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetSuccess()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetSuccess()) { + oprot.writeBool(struct.success); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, qiandao_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + struct.success = iprot.readBool(); + struct.setSuccessIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + + public static class word_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("word_args"); + + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new word_argsStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new word_argsTupleSchemeFactory(); + + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { +; + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + 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); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(word_args.class, metaDataMap); + } + + public word_args() { + } + + /** + * Performs a deep copy on other. + */ + public word_args(word_args other) { + } + + public word_args deepCopy() { + return new word_args(this); + } + + @Override + public void clear() { + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof word_args) + return this.equals((word_args)that); + return false; + } + + public boolean equals(word_args that) { + if (that == null) + return false; + if (this == that) + return true; + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + return hashCode; + } + + @Override + public int compareTo(word_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("word_args("); + boolean first = true; + + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class word_argsStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public word_argsStandardScheme getScheme() { + return new word_argsStandardScheme(); + } + } + + private static class word_argsStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, word_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) { + 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, word_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class word_argsTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public word_argsTupleScheme getScheme() { + return new word_argsTupleScheme(); + } + } + + private static class word_argsTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, word_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, word_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + + public static class word_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("word_result"); + + private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.BOOL, (short)0); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new word_resultStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new word_resultTupleSchemeFactory(); + + public boolean success; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + SUCCESS((short)0, "success"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 0: // SUCCESS + return SUCCESS; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __SUCCESS_ISSET_ID = 0; + private byte __isset_bitfield = 0; + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.BOOL))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(word_result.class, metaDataMap); + } + + public word_result() { + } + + public word_result( + boolean success) + { + this(); + this.success = success; + setSuccessIsSet(true); + } + + /** + * Performs a deep copy on other. + */ + public word_result(word_result other) { + __isset_bitfield = other.__isset_bitfield; + this.success = other.success; + } + + public word_result deepCopy() { + return new word_result(this); + } + + @Override + public void clear() { + setSuccessIsSet(false); + this.success = false; + } + + public boolean isSuccess() { + return this.success; + } + + public word_result setSuccess(boolean success) { + this.success = success; + setSuccessIsSet(true); + return this; + } + + public void unsetSuccess() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __SUCCESS_ISSET_ID); + } + + /** Returns true if field success is set (has been assigned a value) and false otherwise */ + public boolean isSetSuccess() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __SUCCESS_ISSET_ID); + } + + public void setSuccessIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __SUCCESS_ISSET_ID, value); + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((Boolean)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case SUCCESS: + return isSuccess(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case SUCCESS: + return isSetSuccess(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof word_result) + return this.equals((word_result)that); + return false; + } + + public boolean equals(word_result that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_success = true; + boolean that_present_success = true; + if (this_present_success || that_present_success) { + if (!(this_present_success && that_present_success)) + return false; + if (this.success != that.success) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((success) ? 131071 : 524287); + + return hashCode; + } + + @Override + public int compareTo(word_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = 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; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("word_result("); + boolean first = true; + + sb.append("success:"); + sb.append(this.success); + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class word_resultStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public word_resultStandardScheme getScheme() { + return new word_resultStandardScheme(); + } + } + + private static class word_resultStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, word_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.BOOL) { + struct.success = iprot.readBool(); + 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, word_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.isSetSuccess()) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + oprot.writeBool(struct.success); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class word_resultTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public word_resultTupleScheme getScheme() { + return new word_resultTupleScheme(); + } + } + + private static class word_resultTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, word_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetSuccess()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetSuccess()) { + oprot.writeBool(struct.success); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, word_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + struct.success = iprot.readBool(); + struct.setSuccessIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + +} diff --git a/core/src/test/resources/test.thrift b/core/src/test/resources/test.thrift new file mode 100644 index 0000000..c5fdbcc --- /dev/null +++ b/core/src/test/resources/test.thrift @@ -0,0 +1,5 @@ +namespace py core.thrift.task + service TSDM{ + bool qiandao() + bool word() + } \ No newline at end of file diff --git a/db/src/main/java/db/config/HibernateConfig.java b/db/src/main/java/db/config/HibernateConfig.java index f957d60..317811c 100644 --- a/db/src/main/java/db/config/HibernateConfig.java +++ b/db/src/main/java/db/config/HibernateConfig.java @@ -174,7 +174,7 @@ public class HibernateConfig { * 初始化数据源,session工厂 */ @PostConstruct - private void init() throws ClassNotFoundException { + private void init() { //连接根数据源 rootHibernateTemplate = initRootDB(); @@ -188,11 +188,17 @@ public class HibernateConfig { beanFactory.registerSingleton(DBBeanNameManager.getName(dataSourceModel.getDbId(),DBBeanNameManager.hibernateTemplate),hibernateTemplate); - Class c=ClassUtils.getClass(dataSourceModel.getDbId()); + Class c; + try { + c = ClassUtils.getClass(dataSourceModel.getDbId()); + } catch (ClassNotFoundException e) { + throw new RuntimeException("类"+dataSourceModel.getDbId()+"不存在"); + } if(c.isAnnotationPresent(Model.class)){ - map.put(((Model) c.getAnnotation(Model.class)).value(), hibernateTemplate); + Model model= (Model) c.getAnnotation(Model.class); + map.put(model.value(), hibernateTemplate); }else{ - throw new RuntimeException(dataSourceModel.getAnnotation()+"不是注解标记!!"); + throw new RuntimeException(dataSourceModel.getDbId()+"缺少"+Model.class+"注解"); } } } @@ -229,17 +235,4 @@ public class HibernateConfig { return initSessionFactory(dataSource, config,null); } - - /** - * 遍历表备注信息注解 - * @param c - */ - private void checkClass(Class c) { - if(c.isAnnotationPresent(TableInfo.class)){ - TableInfo info= (TableInfo) c.getAnnotation(TableInfo.class); - tableNotes.put(c,info); - } - } - - } diff --git a/web/src/main/java/web/controller/DataController.java b/web/src/main/java/web/controller/DataController.java index 24b7e43..aaebd93 100644 --- a/web/src/main/java/web/controller/DataController.java +++ b/web/src/main/java/web/controller/DataController.java @@ -2,6 +2,7 @@ package web.controller; import core.thrift.MyAsyncMethodCallback; import core.thrift.ThriftClientPool; +import core.thrift.comment.QueryComment; import db.form.DBAction; import db.model.bilibili.DataModel; import org.apache.commons.io.FileUtils; @@ -33,11 +34,11 @@ import java.util.List; @Controller @RequestMapping("/data") -public class DataController extends TableController> { +public class DataController extends TableController> { private final String regionJson = IOUtils.toString(DataController.class.getResourceAsStream("/region.json"), Charset.forName("UTF-8")); - private static final String key="regionJson"; + private static final String key = "regionJson"; public DataController() throws IOException, InstantiationException, IllegalAccessException { super(); @@ -54,10 +55,10 @@ public class DataController extends TableController call= new MyAsyncMethodCallback<>(); - ThriftClientPool.doExecute(client -> client.commentSum(cid,call)); + MyAsyncMethodCallback call = new MyAsyncMethodCallback<>(); + ThriftClientPool.doExecute(client -> client.commentSum(cid, call),QueryComment.AsyncClient.class); return call.getResult(); - }catch (Exception e){ + } catch (Exception e) { log.error(e); } return null; @@ -65,20 +66,20 @@ public class DataController extends TableController call= new MyAsyncMethodCallback<>(); - ThriftClientPool.doExecute(client -> client.download(form.getCids(),form.getFileName(),call)); - String filePath=call.getResult(); - if(filePath!=null) { + headers.setContentDispositionFormData("attachment", form.getFileName() + ".zip"); + MyAsyncMethodCallback call = new MyAsyncMethodCallback<>(); + ThriftClientPool.doExecute(client -> client.download(form.getCids(), form.getFileName(), call),QueryComment.AsyncClient.class); + String filePath = call.getResult(); + if (filePath != null) { return new ResponseEntity<>(FileUtils.readFileToByteArray(new File(filePath)), headers, HttpStatus.CREATED); - }else{ + } else { return new ResponseEntity<>("弹幕下载失败", HttpStatus.INTERNAL_SERVER_ERROR); } - }else{ - return new ResponseEntity("参数异常",HttpStatus.BAD_REQUEST); + } else { + return new ResponseEntity("参数异常", HttpStatus.BAD_REQUEST); } } @@ -114,13 +115,13 @@ public class DataController extends TableController otherDatas(DataModelForm command) { - return new ArrayList(){{ + return new ArrayList() {{ add(new OtherDataResult()); }}; } @Override protected void setModel(Model model) { - model.addAttribute(key,regionJson); + model.addAttribute(key, regionJson); } } diff --git a/web/src/main/java/web/service/BaseService.java b/web/src/main/java/web/service/BaseService.java index 1949eb2..3a238f5 100644 --- a/web/src/main/java/web/service/BaseService.java +++ b/web/src/main/java/web/service/BaseService.java @@ -10,6 +10,7 @@ import org.hibernate.criterion.DetachedCriteria; import org.hibernate.criterion.Projections; import org.springframework.dao.DataAccessException; import org.springframework.orm.hibernate5.HibernateTemplate; +import org.springframework.util.ClassUtils; import java.util.List; @@ -25,7 +26,7 @@ public abstract class BaseService{ public final HibernateTemplate getHibernateTemplate() { if(hibernateTemplate==null) { - hibernateTemplate=HibernateConfig.get(this.getClass().getAnnotation(Model.class).value()); + hibernateTemplate=HibernateConfig.get(ClassUtils.getUserClass(this.getClass()).getAnnotation(Model.class).value()); } return hibernateTemplate; } @@ -54,6 +55,10 @@ public abstract class BaseService{ return getHibernateTemplate().findByCriteria(criteria,firstResult,maxResults { - private static Logger log=LogManager.getLogger(); - - @Resource - private HibernateTemplate hibernateTemplate; + @Resource + private BiliService biliService; - @PostConstruct - public void init(){ - hibernateTemplate.loadAll(ScheduledTaskEntity.class).forEach(this::addTriggerTask); - } + private static Logger log=LogManager.getLogger(); public void addTriggerTask(ScheduledTaskEntity scheduledTaskEntity) { - super.scheduleTriggerTask(new TriggerTask(()->{ - },(TriggerContext triggerContext)->{ CronTrigger trigger = new CronTrigger(scheduledTaskEntity.getExpression()); log.debug(triggerContext+""); Date nextExec = trigger.nextExecutionTime(triggerContext); return nextExec; })); - } + @Override + public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) { + biliService.find(DetachedCriteria.forClass(ScheduledTaskEntity.class)).forEach(entity->addTriggerTask((ScheduledTaskEntity)entity)); + } } \ No newline at end of file diff --git a/web/src/test/java/SpringTest.java b/web/src/test/java/SpringMVCTest.java similarity index 92% rename from web/src/test/java/SpringTest.java rename to web/src/test/java/SpringMVCTest.java index 0c919c7..acadbb0 100644 --- a/web/src/test/java/SpringTest.java +++ b/web/src/test/java/SpringMVCTest.java @@ -1,8 +1,10 @@ import core.thrift.MyAsyncMethodCallback; import core.thrift.ThriftClientPool; +import db.model.bilibili.ScheduledTaskEntity; import db.util.ExportUtil; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.hibernate.criterion.DetachedCriteria; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -32,7 +34,7 @@ import java.util.ArrayList; @RunWith(SpringJUnit4ClassRunner.class) @SpringJUnitWebConfig @ContextConfiguration(classes = {AppConfig.class, SpringConfig.class}) -public class SpringTest { +public class SpringMVCTest { private static Logger log = LogManager.getLogger(); private MockMvc mockMvc; @@ -40,19 +42,12 @@ public class SpringTest { @Autowired WebApplicationContext wac; - @Autowired - private DefaultListableBeanFactory beanFactory; - @Autowired private DataService dataService; @Autowired private BiliService biliService; - @Autowired - @Qualifier("Hweb.service.DataService") - private HibernateTemplate template1; - @Autowired @Qualifier("Hweb.service.BiliService") private HibernateTemplate template2; @@ -106,5 +101,10 @@ public class SpringTest { resultActions.andDo(MockMvcResultHandlers.print()).andReturn(); } + @Test + public void test7(){ + biliService.find(DetachedCriteria.forClass(ScheduledTaskEntity.class)).forEach(a->log.info(a)); + } + } diff --git a/core/src/main/java/core/thrift/ThriftServerDemo.java b/web/src/test/java/ThriftServerDemo.java similarity index 98% rename from core/src/main/java/core/thrift/ThriftServerDemo.java rename to web/src/test/java/ThriftServerDemo.java index dab3012..100a6d1 100644 --- a/core/src/main/java/core/thrift/ThriftServerDemo.java +++ b/web/src/test/java/ThriftServerDemo.java @@ -1,5 +1,3 @@ -package core.thrift; - import core.thrift.comment.QueryComment; import org.apache.thrift.TProcessorFactory; import org.apache.thrift.protocol.TBinaryProtocol; diff --git a/web/src/test/java/ThriftTest.java b/web/src/test/java/ThriftTest.java index ded3a34..b1018ce 100644 --- a/web/src/test/java/ThriftTest.java +++ b/web/src/test/java/ThriftTest.java @@ -1,5 +1,7 @@ import core.thrift.MyAsyncMethodCallback; import core.thrift.ThriftClientPool; +import core.thrift.comment.QueryComment; +import core.thrift.task.TSDM; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.Test; @@ -22,7 +24,7 @@ public class ThriftTest { @Test public void commentSum() throws Exception { MyAsyncMethodCallback call = new MyAsyncMethodCallback<>(); - ThriftClientPool.doExecute(client -> client.commentSum(49052, call)); + ThriftClientPool.doExecute(client -> client.commentSum(49052,call),QueryComment.AsyncClient.class); log.info(call.getResult()); } @@ -31,7 +33,15 @@ public class ThriftTest { MyAsyncMethodCallback call = new MyAsyncMethodCallback<>(); ThriftClientPool.doExecute(client ->client.download(new ArrayList(){{ add(49052); - }},"test",call)); + }},"test",call),QueryComment.AsyncClient.class); log.info(call.getResult()); } + + @Test + public void work() throws Exception { + MyAsyncMethodCallback call = new MyAsyncMethodCallback<>(); + ThriftClientPool.doExecute(client -> client.qiandao(call),TSDM.AsyncClient.class); + log.info(call.getResult()); + } + }