├── .gitignore ├── src ├── main │ └── java │ │ └── me │ │ └── srhang │ │ └── libs │ │ └── spring │ │ └── remoting │ │ ├── thrift │ │ ├── ThriftContextHolder.java │ │ ├── ThriftProxyFactoryBean.java │ │ ├── ThriftServiceExporter.java │ │ ├── ThriftClientInterceptor.java │ │ └── ThriftUtil.java │ │ └── exception │ │ └── ThriftRuntimeException.java └── test │ └── java │ └── me │ └── srhang │ └── libs │ └── spring │ └── remoting │ ├── HelloWorldImp.java │ ├── ThriftUtilTest.java │ └── HelloWorldService.java ├── README.md ├── LICENSE └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | .DS_Store 13 | .idea 14 | *.iml 15 | .classpath 16 | .project 17 | out 18 | target 19 | build 20 | -------------------------------------------------------------------------------- /src/main/java/me/srhang/libs/spring/remoting/thrift/ThriftContextHolder.java: -------------------------------------------------------------------------------- 1 | package me.srhang.libs.spring.remoting.thrift; 2 | 3 | /** 4 | * Author: Bryant Hang 5 | * Date: 15/5/21 6 | * Time: 15:31 7 | */ 8 | public class ThriftContextHolder { 9 | public static void init() { 10 | } 11 | 12 | public static void reset() { 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/me/srhang/libs/spring/remoting/HelloWorldImp.java: -------------------------------------------------------------------------------- 1 | package me.srhang.libs.spring.remoting; 2 | 3 | import org.apache.thrift.TException; 4 | 5 | /** 6 | * Author: Bryant Hang 7 | * Date: 15/5/22 8 | * Time: 10:05 9 | */ 10 | public class HelloWorldImp implements HelloWorldService.Iface { 11 | 12 | public HelloWorldImp() { 13 | } 14 | 15 | @Override 16 | public String sayHello(String username) throws TException { 17 | return "Hi," + username; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/me/srhang/libs/spring/remoting/exception/ThriftRuntimeException.java: -------------------------------------------------------------------------------- 1 | package me.srhang.libs.spring.remoting.exception; 2 | 3 | /** 4 | * Author: Bryant Hang 5 | * Date: 15/5/22 6 | * Time: 09:27 7 | */ 8 | public class ThriftRuntimeException extends RuntimeException { 9 | public ThriftRuntimeException() { 10 | } 11 | 12 | public ThriftRuntimeException(String message) { 13 | super(message); 14 | } 15 | 16 | public ThriftRuntimeException(Throwable cause) { 17 | super(cause); 18 | } 19 | 20 | public ThriftRuntimeException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/me/srhang/libs/spring/remoting/ThriftUtilTest.java: -------------------------------------------------------------------------------- 1 | package me.srhang.libs.spring.remoting; 2 | 3 | import me.srhang.libs.spring.remoting.thrift.ThriftUtil; 4 | import me.srhang.libs.util.HttpClientUtil; 5 | import org.apache.thrift.protocol.TBinaryProtocol; 6 | import org.apache.thrift.transport.THttpClient; 7 | import org.junit.Test; 8 | 9 | /** 10 | * Author: Bryant Hang 11 | * Date: 15/5/22 12 | * Time: 10:04 13 | */ 14 | public class ThriftUtilTest { 15 | @Test 16 | public void testBuildProcessor() throws Exception { 17 | ThriftUtil.buildProcessor(HelloWorldService.Iface.class, new HelloWorldImp()); 18 | } 19 | 20 | @Test() 21 | public void testBuildClient() throws Exception { 22 | // ThriftUtil.buildClient(HelloWorldService.Iface.class, new TBinaryProtocol.Factory().getProtocol( 23 | // new THttpClient("", new HttpClientUtil().getHttpClient()))); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/me/srhang/libs/spring/remoting/thrift/ThriftProxyFactoryBean.java: -------------------------------------------------------------------------------- 1 | package me.srhang.libs.spring.remoting.thrift; 2 | 3 | import org.springframework.aop.framework.ProxyFactory; 4 | import org.springframework.beans.factory.FactoryBean; 5 | 6 | /** 7 | * Author: Bryant Hang 8 | * Date: 15/5/21 9 | * Time: 15:43 10 | */ 11 | public class ThriftProxyFactoryBean extends ThriftClientInterceptor implements FactoryBean { 12 | private Object serviceProxy; 13 | 14 | 15 | @Override 16 | public void afterPropertiesSet() { 17 | super.afterPropertiesSet(); 18 | this.serviceProxy = new ProxyFactory(getServiceInterface(), this).getProxy(getBeanClassLoader()); 19 | } 20 | 21 | @Override 22 | public Object getObject() throws Exception { 23 | return this.serviceProxy; 24 | } 25 | 26 | @Override 27 | public Class getObjectType() { 28 | return getServiceInterface(); 29 | } 30 | 31 | @Override 32 | public boolean isSingleton() { 33 | return true; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **The repository is deprecated, moved to https://github.com/superhj1987/awesome-libs/blob/master/doc/spring-remoting-thrift.md** 2 | 3 | # spring-remoting-thrift 4 | thrift rpc support in spring: ThriftServiceExporter;ThriftFactoryBean 5 | 6 | ## Github Url 7 | 8 | [https://github.com/superhj1987/spring-remoting-thrift](https://github.com/superhj1987/spring-remoting-thrift) 9 | 10 | ## Usage 11 | 12 | ### Server 13 | 14 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | ### Client 24 | 25 | 27 | 28 | ${api.url} 29 | 30 | 32 | 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Bryant Hang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /src/main/java/me/srhang/libs/spring/remoting/thrift/ThriftServiceExporter.java: -------------------------------------------------------------------------------- 1 | package me.srhang.libs.spring.remoting.thrift; 2 | 3 | import org.apache.thrift.TProcessor; 4 | import org.apache.thrift.protocol.TBinaryProtocol; 5 | import org.apache.thrift.protocol.TProtocol; 6 | import org.apache.thrift.protocol.TProtocolFactory; 7 | import org.apache.thrift.transport.TIOStreamTransport; 8 | import org.apache.thrift.transport.TTransport; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | import org.springframework.remoting.support.RemoteExporter; 12 | import org.springframework.web.HttpRequestHandler; 13 | import org.springframework.web.HttpRequestMethodNotSupportedException; 14 | 15 | import javax.servlet.ServletException; 16 | import javax.servlet.http.HttpServletRequest; 17 | import javax.servlet.http.HttpServletResponse; 18 | import java.io.IOException; 19 | import java.io.InputStream; 20 | import java.io.OutputStream; 21 | import java.io.PrintWriter; 22 | 23 | /** 24 | * Author: Bryant Hang 25 | * Date: 15/5/21 26 | * Time: 15:03 27 | */ 28 | public class ThriftServiceExporter extends RemoteExporter 29 | implements HttpRequestHandler { 30 | Logger LOGGER = LoggerFactory.getLogger(ThriftServiceExporter.class); 31 | private TProtocolFactory protocolFactory = new TBinaryProtocol.Factory(); 32 | 33 | @Override 34 | public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 35 | if (!"POST".equals(request.getMethod())) { 36 | throw new HttpRequestMethodNotSupportedException(request.getMethod(), 37 | new String[]{"POST"}, "ThriftServiceExporter only supports POST requests"); 38 | } 39 | 40 | InputStream in = request.getInputStream(); 41 | OutputStream out = response.getOutputStream(); 42 | try { 43 | ThriftContextHolder.init(); 44 | response.setContentType("application/x-thrift"); 45 | TTransport transport = new TIOStreamTransport(in, out); 46 | 47 | TProtocol protocol = getProtocolFactory().getProtocol(transport); 48 | TProcessor processor = ThriftUtil.buildProcessor(getServiceInterface(), getProxyForService()); 49 | processor.process(protocol, protocol); 50 | } catch (Throwable e) { 51 | response.setContentType("text/plain; charset=UTF-8"); 52 | response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 53 | e.printStackTrace(new PrintWriter(out, true)); 54 | if (LOGGER.isErrorEnabled()) { 55 | LOGGER.error("Thrift server direct error", e); 56 | } 57 | } finally { 58 | ThriftContextHolder.reset(); 59 | } 60 | } 61 | 62 | public TProtocolFactory getProtocolFactory() { 63 | return protocolFactory; 64 | } 65 | 66 | public void setProtocolFactory(TProtocolFactory protocolFactory) { 67 | this.protocolFactory = protocolFactory; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/me/srhang/libs/spring/remoting/thrift/ThriftClientInterceptor.java: -------------------------------------------------------------------------------- 1 | package me.srhang.libs.spring.remoting.thrift; 2 | 3 | import me.srhang.libs.util.HttpClientUtil; 4 | import org.aopalliance.intercept.MethodInterceptor; 5 | import org.aopalliance.intercept.MethodInvocation; 6 | import org.apache.thrift.TApplicationException; 7 | import org.apache.thrift.protocol.TBinaryProtocol; 8 | import org.apache.thrift.protocol.TProtocolFactory; 9 | import org.apache.thrift.transport.THttpClient; 10 | import org.apache.thrift.transport.TTransport; 11 | import org.apache.thrift.transport.TTransportException; 12 | import org.springframework.remoting.RemoteLookupFailureException; 13 | import org.springframework.remoting.RemoteProxyFailureException; 14 | import org.springframework.remoting.support.UrlBasedRemoteAccessor; 15 | 16 | import java.lang.reflect.InvocationTargetException; 17 | 18 | /** 19 | * Author: Bryant Hang 20 | * Date: 15/5/21 21 | * Time: 16:02 22 | */ 23 | public class ThriftClientInterceptor extends UrlBasedRemoteAccessor implements MethodInterceptor { 24 | private TProtocolFactory protocolFactory = new TBinaryProtocol.Factory(); 25 | 26 | private Object thriftProxy; 27 | 28 | HttpClientUtil httpClientUtil; 29 | 30 | @Override 31 | public void afterPropertiesSet() { 32 | super.afterPropertiesSet(); 33 | prepare(); 34 | } 35 | 36 | /** 37 | * Initialize the Hessian proxy for this interceptor. 38 | * 39 | * @throws org.springframework.remoting.RemoteLookupFailureException if the service URL is invalid 40 | */ 41 | public void prepare() throws RemoteLookupFailureException { 42 | if (httpClientUtil == null) { 43 | this.httpClientUtil = new HttpClientUtil(); 44 | } 45 | 46 | try { 47 | thriftProxy = ThriftUtil.buildClient(getServiceInterface(), protocolFactory.getProtocol(getTransport())); 48 | } catch (Exception e) { 49 | throw new RuntimeException(e); 50 | } 51 | } 52 | 53 | @Override 54 | public Object invoke(MethodInvocation methodInvocation) throws Throwable { 55 | if (this.thriftProxy == null) { 56 | throw new IllegalStateException("ThriftClientInterceptor is not properly initialized - " + 57 | "invoke 'prepare' before attempting any operations"); 58 | } 59 | 60 | ClassLoader originalClassLoader = overrideThreadContextClassLoader(); 61 | try { 62 | return methodInvocation.getMethod().invoke(thriftProxy, methodInvocation.getArguments()); 63 | } catch (InvocationTargetException e) { 64 | Throwable targetEx = e.getTargetException(); 65 | if (targetEx instanceof InvocationTargetException) { 66 | targetEx = ((InvocationTargetException) targetEx).getTargetException(); 67 | } 68 | if (targetEx instanceof TApplicationException && ((TApplicationException) targetEx).getType() == TApplicationException.MISSING_RESULT) { 69 | return null; 70 | } else { 71 | throw targetEx; 72 | } 73 | } catch (Throwable ex) { 74 | throw new RemoteProxyFailureException( 75 | "Failed to invoke Thrift proxy for remote service [" + getServiceUrl() + "]", ex); 76 | } finally { 77 | resetThreadContextClassLoader(originalClassLoader); 78 | } 79 | } 80 | 81 | protected TTransport getTransport() throws TTransportException { 82 | return new THttpClient(getServiceUrl(), httpClientUtil.getHttpClient()); 83 | } 84 | 85 | public void setHttpClientUtil(HttpClientUtil httpClientUtil) { 86 | this.httpClientUtil = httpClientUtil; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/me/srhang/libs/spring/remoting/thrift/ThriftUtil.java: -------------------------------------------------------------------------------- 1 | package me.srhang.libs.spring.remoting.thrift; 2 | 3 | import me.srhang.libs.spring.remoting.exception.ThriftRuntimeException; 4 | import org.apache.thrift.TProcessor; 5 | import org.apache.thrift.async.TAsyncClientManager; 6 | import org.apache.thrift.protocol.TProtocol; 7 | import org.apache.thrift.protocol.TProtocolFactory; 8 | import org.apache.thrift.transport.TNonblockingTransport; 9 | import org.springframework.util.ClassUtils; 10 | 11 | import java.lang.reflect.Constructor; 12 | 13 | /** 14 | * Author: Bryant Hang 15 | * Date: 15/5/21 16 | * Time: 15:31 17 | */ 18 | public class ThriftUtil { 19 | /** 20 | * string to find the {@link org.apache.thrift.TProcessor} implementation 21 | * inside the Thrift class 22 | */ 23 | public static String PROCESSOR_NAME = "$Processor"; 24 | /** 25 | * String to find interface of the class inside the Thrift class 26 | */ 27 | public static String IFACE_NAME = "$Iface"; 28 | /** 29 | * String to find client inside the Thrift class 30 | */ 31 | public static String CLIENT_NAME = "$Client"; 32 | 33 | public static String ASYNC_CLIENT_NAME = "$AsyncClient"; 34 | 35 | public static Class getThriftServiceInnerClassOrNull(Class thriftServiceClass, String match, boolean isInterface) { 36 | if (thriftServiceClass == null) { 37 | return null; 38 | } 39 | 40 | Class[] declaredClasses = thriftServiceClass.getDeclaredClasses(); 41 | for (Class declaredClass : declaredClasses) { 42 | if (declaredClass.isInterface()) { 43 | if (isInterface && declaredClass.getName().contains(match)) { 44 | return declaredClass; 45 | } 46 | } else { 47 | if (!isInterface && declaredClass.getName().contains(match)) { 48 | return declaredClass; 49 | } 50 | } 51 | } 52 | return null; 53 | } 54 | 55 | public static TProcessor buildProcessor(Class svcInterface, Object service) throws Exception { 56 | Class processorClass = (Class) getThriftServiceInnerClassOrNull(svcInterface.getEnclosingClass(), PROCESSOR_NAME, false); 57 | if (processorClass == null) { 58 | throw new ThriftRuntimeException("the processor is null"); 59 | } 60 | 61 | Constructor constructor = ClassUtils.getConstructorIfAvailable(processorClass, svcInterface); 62 | if (constructor == null) { 63 | throw new ThriftRuntimeException("the processor constructor is null"); 64 | } 65 | 66 | return constructor.newInstance(service); 67 | } 68 | 69 | public static Constructor getClientConstructor(Class svcInterface) { 70 | String client = svcInterface.getName().indexOf("Async") > 0 ? ASYNC_CLIENT_NAME : CLIENT_NAME; 71 | Class[] args = svcInterface.getName().indexOf("Async") > 0 ? new Class[]{TProtocolFactory.class, TAsyncClientManager.class, TNonblockingTransport.class} : new Class[]{TProtocol.class}; 72 | 73 | Class clientClass = getThriftServiceInnerClassOrNull(svcInterface.getEnclosingClass(), client, false); 74 | if (clientClass == null) { 75 | throw new ThriftRuntimeException("the client class is null"); 76 | } 77 | 78 | Constructor constructor = ClassUtils.getConstructorIfAvailable(clientClass, args); 79 | if (constructor == null) { 80 | throw new ThriftRuntimeException("the clientClass constructor is null"); 81 | } 82 | 83 | return constructor; 84 | } 85 | 86 | public static Object buildClient(Class svcInterface, TProtocol protocol) throws Exception { 87 | return getClientConstructor(svcInterface).newInstance(protocol); 88 | } 89 | } -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | me.srhang 8 | spring-remoting-thrift 9 | 0.0.1 10 | 11 | 12 | 13 | nexus-osc 14 | Nexus osc 15 | http://maven.oschina.net/content/groups/public/ 16 | 17 | true 18 | 19 | 20 | false 21 | 22 | 23 | 24 | 25 | nexus-third 26 | Nexus osc third 27 | http://maven.oschina.net/content/repositories/thirdparty/ 28 | 29 | true 30 | 31 | 32 | false 33 | 34 | 35 | 36 | 37 | 38 | spring-maven-milestone 39 | Springframework Maven Milestone Repository 40 | http://repo.springsource.org/libs-milestone 41 | 42 | 43 | 44 | maven 45 | Slowly office site 46 | http://repo1.maven.org/maven2 47 | 48 | 49 | 50 | 51 | 1.2.0.RELEASE 52 | 4.3.18.RELEASE 53 | 3.1.4.RELEASE 54 | UTF-8 55 | 56 | 57 | 58 | 59 | org.springframework 60 | spring-core 61 | ${spring.version} 62 | 63 | 64 | commons-logging 65 | commons-logging 66 | 67 | 68 | 69 | 70 | 71 | javax.servlet 72 | javax.servlet-api 73 | 3.0.1 74 | provided 75 | 76 | 77 | 78 | org.springframework 79 | spring-context-support 80 | ${spring.version} 81 | 82 | 83 | 84 | org.slf4j 85 | jcl-over-slf4j 86 | 1.6.2 87 | 88 | 89 | 90 | org.slf4j 91 | slf4j-api 92 | 1.6.2 93 | 94 | 95 | 96 | org.slf4j 97 | slf4j-log4j12 98 | 1.6.2 99 | 100 | 101 | 102 | log4j 103 | log4j 104 | 1.2.16 105 | 106 | 107 | 108 | junit 109 | junit 110 | 4.8.2 111 | test 112 | 113 | 114 | 115 | org.apache.commons 116 | commons-lang3 117 | 3.1 118 | 119 | 120 | 121 | commons-lang 122 | commons-lang 123 | 2.5 124 | 125 | 126 | 127 | commons-beanutils 128 | commons-beanutils 129 | 1.8.3 130 | 131 | 132 | commons-logging 133 | commons-logging 134 | 135 | 136 | 137 | 138 | 139 | javax.servlet.jsp 140 | jsp-api 141 | 2.1 142 | provided 143 | 144 | 145 | 146 | org.springframework 147 | spring-web 148 | ${spring.version} 149 | 150 | 151 | 152 | org.springframework 153 | spring-webmvc 154 | ${spring.version} 155 | 156 | 157 | 158 | com.google.guava 159 | guava 160 | 18.0 161 | 162 | 163 | 164 | org.apache.thrift 165 | libthrift 166 | 0.9.2 167 | 168 | 169 | 170 | me.srhang 171 | jlibs 172 | 0.0.1 173 | 174 | 175 | 176 | 177 | 178 | 179 | org.apache.maven.plugins 180 | maven-compiler-plugin 181 | 182 | 1.6 183 | 1.6 184 | UTF-8 185 | false 186 | false 187 | 188 | 189 | 190 | maven-source-plugin 191 | 2.1 192 | 193 | true 194 | 195 | 196 | 197 | compile 198 | 199 | jar 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | org.apache.maven.plugins 211 | maven-javadoc-plugin 212 | 213 | UTF-8 214 | UTF-8 215 | UTF-8 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | osc-release 224 | osc-Releases 225 | http://maven.oschina.net/content/repositories/thirdparty/ 226 | 227 | 228 | 229 | osc-snapshot 230 | osc-Snapshots 231 | http://maven.oschina.net/content/repositories/thirdparty/ 232 | 233 | 234 | 235 | 236 | -------------------------------------------------------------------------------- /src/test/java/me/srhang/libs/spring/remoting/HelloWorldService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.9.2) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | package me.srhang.libs.spring.remoting; 8 | 9 | import org.apache.thrift.scheme.IScheme; 10 | import org.apache.thrift.scheme.SchemeFactory; 11 | import org.apache.thrift.scheme.StandardScheme; 12 | 13 | import org.apache.thrift.scheme.TupleScheme; 14 | import org.apache.thrift.protocol.TTupleProtocol; 15 | import org.apache.thrift.protocol.TProtocolException; 16 | import org.apache.thrift.EncodingUtils; 17 | import org.apache.thrift.TException; 18 | import org.apache.thrift.async.AsyncMethodCallback; 19 | import org.apache.thrift.server.AbstractNonblockingServer.*; 20 | import java.util.List; 21 | import java.util.ArrayList; 22 | import java.util.Map; 23 | import java.util.HashMap; 24 | import java.util.EnumMap; 25 | import java.util.Set; 26 | import java.util.HashSet; 27 | import java.util.EnumSet; 28 | import java.util.Collections; 29 | import java.util.BitSet; 30 | import java.nio.ByteBuffer; 31 | import java.util.Arrays; 32 | import javax.annotation.Generated; 33 | import org.slf4j.Logger; 34 | import org.slf4j.LoggerFactory; 35 | 36 | @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) 37 | @Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2015-5-22") 38 | public class HelloWorldService { 39 | 40 | public interface Iface { 41 | 42 | public String sayHello(String username) throws TException; 43 | 44 | } 45 | 46 | public interface AsyncIface { 47 | 48 | public void sayHello(String username, AsyncMethodCallback resultHandler) throws TException; 49 | 50 | } 51 | 52 | public static class Client extends org.apache.thrift.TServiceClient implements Iface { 53 | public static class Factory implements org.apache.thrift.TServiceClientFactory { 54 | public Factory() {} 55 | public Client getClient(org.apache.thrift.protocol.TProtocol prot) { 56 | return new Client(prot); 57 | } 58 | public Client getClient(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) { 59 | return new Client(iprot, oprot); 60 | } 61 | } 62 | 63 | public Client(org.apache.thrift.protocol.TProtocol prot) 64 | { 65 | super(prot, prot); 66 | } 67 | 68 | public Client(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) { 69 | super(iprot, oprot); 70 | } 71 | 72 | public String sayHello(String username) throws TException 73 | { 74 | send_sayHello(username); 75 | return recv_sayHello(); 76 | } 77 | 78 | public void send_sayHello(String username) throws TException 79 | { 80 | sayHello_args args = new sayHello_args(); 81 | args.setUsername(username); 82 | sendBase("sayHello", args); 83 | } 84 | 85 | public String recv_sayHello() throws TException 86 | { 87 | sayHello_result result = new sayHello_result(); 88 | receiveBase(result, "sayHello"); 89 | if (result.isSetSuccess()) { 90 | return result.success; 91 | } 92 | throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "sayHello failed: unknown result"); 93 | } 94 | 95 | } 96 | public static class AsyncClient extends org.apache.thrift.async.TAsyncClient implements AsyncIface { 97 | public static class Factory implements org.apache.thrift.async.TAsyncClientFactory { 98 | private org.apache.thrift.async.TAsyncClientManager clientManager; 99 | private org.apache.thrift.protocol.TProtocolFactory protocolFactory; 100 | public Factory(org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.protocol.TProtocolFactory protocolFactory) { 101 | this.clientManager = clientManager; 102 | this.protocolFactory = protocolFactory; 103 | } 104 | public AsyncClient getAsyncClient(org.apache.thrift.transport.TNonblockingTransport transport) { 105 | return new AsyncClient(protocolFactory, clientManager, transport); 106 | } 107 | } 108 | 109 | public AsyncClient(org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.transport.TNonblockingTransport transport) { 110 | super(protocolFactory, clientManager, transport); 111 | } 112 | 113 | public void sayHello(String username, AsyncMethodCallback resultHandler) throws TException { 114 | checkReady(); 115 | sayHello_call method_call = new sayHello_call(username, resultHandler, this, ___protocolFactory, ___transport); 116 | this.___currentMethod = method_call; 117 | ___manager.call(method_call); 118 | } 119 | 120 | public static class sayHello_call extends org.apache.thrift.async.TAsyncMethodCall { 121 | private String username; 122 | public sayHello_call(String username, AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws TException { 123 | super(client, protocolFactory, transport, resultHandler, false); 124 | this.username = username; 125 | } 126 | 127 | public void write_args(org.apache.thrift.protocol.TProtocol prot) throws TException { 128 | prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("sayHello", org.apache.thrift.protocol.TMessageType.CALL, 0)); 129 | sayHello_args args = new sayHello_args(); 130 | args.setUsername(username); 131 | args.write(prot); 132 | prot.writeMessageEnd(); 133 | } 134 | 135 | public String getResult() throws TException { 136 | if (getState() != State.RESPONSE_READ) { 137 | throw new IllegalStateException("Method call not finished!"); 138 | } 139 | org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); 140 | org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); 141 | return (new Client(prot)).recv_sayHello(); 142 | } 143 | } 144 | 145 | } 146 | 147 | public static class Processor extends org.apache.thrift.TBaseProcessor implements org.apache.thrift.TProcessor { 148 | private static final Logger LOGGER = LoggerFactory.getLogger(Processor.class.getName()); 149 | public Processor(I iface) { 150 | super(iface, getProcessMap(new HashMap>())); 151 | } 152 | 153 | protected Processor(I iface, Map> processMap) { 154 | super(iface, getProcessMap(processMap)); 155 | } 156 | 157 | private static Map> getProcessMap(Map> processMap) { 158 | processMap.put("sayHello", new sayHello()); 159 | return processMap; 160 | } 161 | 162 | public static class sayHello extends org.apache.thrift.ProcessFunction { 163 | public sayHello() { 164 | super("sayHello"); 165 | } 166 | 167 | public sayHello_args getEmptyArgsInstance() { 168 | return new sayHello_args(); 169 | } 170 | 171 | protected boolean isOneway() { 172 | return false; 173 | } 174 | 175 | public sayHello_result getResult(I iface, sayHello_args args) throws TException { 176 | sayHello_result result = new sayHello_result(); 177 | result.success = iface.sayHello(args.username); 178 | return result; 179 | } 180 | } 181 | 182 | } 183 | 184 | public static class AsyncProcessor extends org.apache.thrift.TBaseAsyncProcessor { 185 | private static final Logger LOGGER = LoggerFactory.getLogger(AsyncProcessor.class.getName()); 186 | public AsyncProcessor(I iface) { 187 | super(iface, getProcessMap(new HashMap>())); 188 | } 189 | 190 | protected AsyncProcessor(I iface, Map> processMap) { 191 | super(iface, getProcessMap(processMap)); 192 | } 193 | 194 | private static Map> getProcessMap(Map> processMap) { 195 | processMap.put("sayHello", new sayHello()); 196 | return processMap; 197 | } 198 | 199 | public static class sayHello extends org.apache.thrift.AsyncProcessFunction { 200 | public sayHello() { 201 | super("sayHello"); 202 | } 203 | 204 | public sayHello_args getEmptyArgsInstance() { 205 | return new sayHello_args(); 206 | } 207 | 208 | public AsyncMethodCallback getResultHandler(final AsyncFrameBuffer fb, final int seqid) { 209 | final org.apache.thrift.AsyncProcessFunction fcall = this; 210 | return new AsyncMethodCallback() { 211 | public void onComplete(String o) { 212 | sayHello_result result = new sayHello_result(); 213 | result.success = o; 214 | try { 215 | fcall.sendResponse(fb,result, org.apache.thrift.protocol.TMessageType.REPLY,seqid); 216 | return; 217 | } catch (Exception e) { 218 | LOGGER.error("Exception writing to internal frame buffer", e); 219 | } 220 | fb.close(); 221 | } 222 | public void onError(Exception e) { 223 | byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; 224 | org.apache.thrift.TBase msg; 225 | sayHello_result result = new sayHello_result(); 226 | { 227 | msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; 228 | msg = (org.apache.thrift.TBase)new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage()); 229 | } 230 | try { 231 | fcall.sendResponse(fb,msg,msgType,seqid); 232 | return; 233 | } catch (Exception ex) { 234 | LOGGER.error("Exception writing to internal frame buffer", ex); 235 | } 236 | fb.close(); 237 | } 238 | }; 239 | } 240 | 241 | protected boolean isOneway() { 242 | return false; 243 | } 244 | 245 | public void start(I iface, sayHello_args args, AsyncMethodCallback resultHandler) throws TException { 246 | iface.sayHello(args.username,resultHandler); 247 | } 248 | } 249 | 250 | } 251 | 252 | public static class sayHello_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { 253 | private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("sayHello_args"); 254 | 255 | private static final org.apache.thrift.protocol.TField USERNAME_FIELD_DESC = new org.apache.thrift.protocol.TField("username", org.apache.thrift.protocol.TType.STRING, (short)1); 256 | 257 | private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); 258 | static { 259 | schemes.put(StandardScheme.class, new sayHello_argsStandardSchemeFactory()); 260 | schemes.put(TupleScheme.class, new sayHello_argsTupleSchemeFactory()); 261 | } 262 | 263 | public String username; // required 264 | 265 | /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ 266 | public enum _Fields implements org.apache.thrift.TFieldIdEnum { 267 | USERNAME((short)1, "username"); 268 | 269 | private static final Map byName = new HashMap(); 270 | 271 | static { 272 | for (_Fields field : EnumSet.allOf(_Fields.class)) { 273 | byName.put(field.getFieldName(), field); 274 | } 275 | } 276 | 277 | /** 278 | * Find the _Fields constant that matches fieldId, or null if its not found. 279 | */ 280 | public static _Fields findByThriftId(int fieldId) { 281 | switch(fieldId) { 282 | case 1: // USERNAME 283 | return USERNAME; 284 | default: 285 | return null; 286 | } 287 | } 288 | 289 | /** 290 | * Find the _Fields constant that matches fieldId, throwing an exception 291 | * if it is not found. 292 | */ 293 | public static _Fields findByThriftIdOrThrow(int fieldId) { 294 | _Fields fields = findByThriftId(fieldId); 295 | if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); 296 | return fields; 297 | } 298 | 299 | /** 300 | * Find the _Fields constant that matches name, or null if its not found. 301 | */ 302 | public static _Fields findByName(String name) { 303 | return byName.get(name); 304 | } 305 | 306 | private final short _thriftId; 307 | private final String _fieldName; 308 | 309 | _Fields(short thriftId, String fieldName) { 310 | _thriftId = thriftId; 311 | _fieldName = fieldName; 312 | } 313 | 314 | public short getThriftFieldId() { 315 | return _thriftId; 316 | } 317 | 318 | public String getFieldName() { 319 | return _fieldName; 320 | } 321 | } 322 | 323 | // isset id assignments 324 | public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; 325 | static { 326 | Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); 327 | tmpMap.put(_Fields.USERNAME, new org.apache.thrift.meta_data.FieldMetaData("username", org.apache.thrift.TFieldRequirementType.DEFAULT, 328 | new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); 329 | metaDataMap = Collections.unmodifiableMap(tmpMap); 330 | org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(sayHello_args.class, metaDataMap); 331 | } 332 | 333 | public sayHello_args() { 334 | } 335 | 336 | public sayHello_args( 337 | String username) 338 | { 339 | this(); 340 | this.username = username; 341 | } 342 | 343 | /** 344 | * Performs a deep copy on other. 345 | */ 346 | public sayHello_args(sayHello_args other) { 347 | if (other.isSetUsername()) { 348 | this.username = other.username; 349 | } 350 | } 351 | 352 | public sayHello_args deepCopy() { 353 | return new sayHello_args(this); 354 | } 355 | 356 | @Override 357 | public void clear() { 358 | this.username = null; 359 | } 360 | 361 | public String getUsername() { 362 | return this.username; 363 | } 364 | 365 | public sayHello_args setUsername(String username) { 366 | this.username = username; 367 | return this; 368 | } 369 | 370 | public void unsetUsername() { 371 | this.username = null; 372 | } 373 | 374 | /** Returns true if field username is set (has been assigned a value) and false otherwise */ 375 | public boolean isSetUsername() { 376 | return this.username != null; 377 | } 378 | 379 | public void setUsernameIsSet(boolean value) { 380 | if (!value) { 381 | this.username = null; 382 | } 383 | } 384 | 385 | public void setFieldValue(_Fields field, Object value) { 386 | switch (field) { 387 | case USERNAME: 388 | if (value == null) { 389 | unsetUsername(); 390 | } else { 391 | setUsername((String)value); 392 | } 393 | break; 394 | 395 | } 396 | } 397 | 398 | public Object getFieldValue(_Fields field) { 399 | switch (field) { 400 | case USERNAME: 401 | return getUsername(); 402 | 403 | } 404 | throw new IllegalStateException(); 405 | } 406 | 407 | /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ 408 | public boolean isSet(_Fields field) { 409 | if (field == null) { 410 | throw new IllegalArgumentException(); 411 | } 412 | 413 | switch (field) { 414 | case USERNAME: 415 | return isSetUsername(); 416 | } 417 | throw new IllegalStateException(); 418 | } 419 | 420 | @Override 421 | public boolean equals(Object that) { 422 | if (that == null) 423 | return false; 424 | if (that instanceof sayHello_args) 425 | return this.equals((sayHello_args)that); 426 | return false; 427 | } 428 | 429 | public boolean equals(sayHello_args that) { 430 | if (that == null) 431 | return false; 432 | 433 | boolean this_present_username = true && this.isSetUsername(); 434 | boolean that_present_username = true && that.isSetUsername(); 435 | if (this_present_username || that_present_username) { 436 | if (!(this_present_username && that_present_username)) 437 | return false; 438 | if (!this.username.equals(that.username)) 439 | return false; 440 | } 441 | 442 | return true; 443 | } 444 | 445 | @Override 446 | public int hashCode() { 447 | List list = new ArrayList(); 448 | 449 | boolean present_username = true && (isSetUsername()); 450 | list.add(present_username); 451 | if (present_username) 452 | list.add(username); 453 | 454 | return list.hashCode(); 455 | } 456 | 457 | @Override 458 | public int compareTo(sayHello_args other) { 459 | if (!getClass().equals(other.getClass())) { 460 | return getClass().getName().compareTo(other.getClass().getName()); 461 | } 462 | 463 | int lastComparison = 0; 464 | 465 | lastComparison = Boolean.valueOf(isSetUsername()).compareTo(other.isSetUsername()); 466 | if (lastComparison != 0) { 467 | return lastComparison; 468 | } 469 | if (isSetUsername()) { 470 | lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.username, other.username); 471 | if (lastComparison != 0) { 472 | return lastComparison; 473 | } 474 | } 475 | return 0; 476 | } 477 | 478 | public _Fields fieldForId(int fieldId) { 479 | return _Fields.findByThriftId(fieldId); 480 | } 481 | 482 | public void read(org.apache.thrift.protocol.TProtocol iprot) throws TException { 483 | schemes.get(iprot.getScheme()).getScheme().read(iprot, this); 484 | } 485 | 486 | public void write(org.apache.thrift.protocol.TProtocol oprot) throws TException { 487 | schemes.get(oprot.getScheme()).getScheme().write(oprot, this); 488 | } 489 | 490 | @Override 491 | public String toString() { 492 | StringBuilder sb = new StringBuilder("sayHello_args("); 493 | boolean first = true; 494 | 495 | sb.append("username:"); 496 | if (this.username == null) { 497 | sb.append("null"); 498 | } else { 499 | sb.append(this.username); 500 | } 501 | first = false; 502 | sb.append(")"); 503 | return sb.toString(); 504 | } 505 | 506 | public void validate() throws TException { 507 | // check for required fields 508 | // check for sub-struct validity 509 | } 510 | 511 | private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { 512 | try { 513 | write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); 514 | } catch (TException te) { 515 | throw new java.io.IOException(te); 516 | } 517 | } 518 | 519 | private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { 520 | try { 521 | read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); 522 | } catch (TException te) { 523 | throw new java.io.IOException(te); 524 | } 525 | } 526 | 527 | private static class sayHello_argsStandardSchemeFactory implements SchemeFactory { 528 | public sayHello_argsStandardScheme getScheme() { 529 | return new sayHello_argsStandardScheme(); 530 | } 531 | } 532 | 533 | private static class sayHello_argsStandardScheme extends StandardScheme { 534 | 535 | public void read(org.apache.thrift.protocol.TProtocol iprot, sayHello_args struct) throws TException { 536 | org.apache.thrift.protocol.TField schemeField; 537 | iprot.readStructBegin(); 538 | while (true) 539 | { 540 | schemeField = iprot.readFieldBegin(); 541 | if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 542 | break; 543 | } 544 | switch (schemeField.id) { 545 | case 1: // USERNAME 546 | if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { 547 | struct.username = iprot.readString(); 548 | struct.setUsernameIsSet(true); 549 | } else { 550 | org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); 551 | } 552 | break; 553 | default: 554 | org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); 555 | } 556 | iprot.readFieldEnd(); 557 | } 558 | iprot.readStructEnd(); 559 | 560 | // check for required fields of primitive type, which can't be checked in the validate method 561 | struct.validate(); 562 | } 563 | 564 | public void write(org.apache.thrift.protocol.TProtocol oprot, sayHello_args struct) throws TException { 565 | struct.validate(); 566 | 567 | oprot.writeStructBegin(STRUCT_DESC); 568 | if (struct.username != null) { 569 | oprot.writeFieldBegin(USERNAME_FIELD_DESC); 570 | oprot.writeString(struct.username); 571 | oprot.writeFieldEnd(); 572 | } 573 | oprot.writeFieldStop(); 574 | oprot.writeStructEnd(); 575 | } 576 | 577 | } 578 | 579 | private static class sayHello_argsTupleSchemeFactory implements SchemeFactory { 580 | public sayHello_argsTupleScheme getScheme() { 581 | return new sayHello_argsTupleScheme(); 582 | } 583 | } 584 | 585 | private static class sayHello_argsTupleScheme extends TupleScheme { 586 | 587 | @Override 588 | public void write(org.apache.thrift.protocol.TProtocol prot, sayHello_args struct) throws TException { 589 | TTupleProtocol oprot = (TTupleProtocol) prot; 590 | BitSet optionals = new BitSet(); 591 | if (struct.isSetUsername()) { 592 | optionals.set(0); 593 | } 594 | oprot.writeBitSet(optionals, 1); 595 | if (struct.isSetUsername()) { 596 | oprot.writeString(struct.username); 597 | } 598 | } 599 | 600 | @Override 601 | public void read(org.apache.thrift.protocol.TProtocol prot, sayHello_args struct) throws TException { 602 | TTupleProtocol iprot = (TTupleProtocol) prot; 603 | BitSet incoming = iprot.readBitSet(1); 604 | if (incoming.get(0)) { 605 | struct.username = iprot.readString(); 606 | struct.setUsernameIsSet(true); 607 | } 608 | } 609 | } 610 | 611 | } 612 | 613 | public static class sayHello_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { 614 | private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("sayHello_result"); 615 | 616 | private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.STRING, (short)0); 617 | 618 | private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); 619 | static { 620 | schemes.put(StandardScheme.class, new sayHello_resultStandardSchemeFactory()); 621 | schemes.put(TupleScheme.class, new sayHello_resultTupleSchemeFactory()); 622 | } 623 | 624 | public String success; // required 625 | 626 | /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ 627 | public enum _Fields implements org.apache.thrift.TFieldIdEnum { 628 | SUCCESS((short)0, "success"); 629 | 630 | private static final Map byName = new HashMap(); 631 | 632 | static { 633 | for (_Fields field : EnumSet.allOf(_Fields.class)) { 634 | byName.put(field.getFieldName(), field); 635 | } 636 | } 637 | 638 | /** 639 | * Find the _Fields constant that matches fieldId, or null if its not found. 640 | */ 641 | public static _Fields findByThriftId(int fieldId) { 642 | switch(fieldId) { 643 | case 0: // SUCCESS 644 | return SUCCESS; 645 | default: 646 | return null; 647 | } 648 | } 649 | 650 | /** 651 | * Find the _Fields constant that matches fieldId, throwing an exception 652 | * if it is not found. 653 | */ 654 | public static _Fields findByThriftIdOrThrow(int fieldId) { 655 | _Fields fields = findByThriftId(fieldId); 656 | if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); 657 | return fields; 658 | } 659 | 660 | /** 661 | * Find the _Fields constant that matches name, or null if its not found. 662 | */ 663 | public static _Fields findByName(String name) { 664 | return byName.get(name); 665 | } 666 | 667 | private final short _thriftId; 668 | private final String _fieldName; 669 | 670 | _Fields(short thriftId, String fieldName) { 671 | _thriftId = thriftId; 672 | _fieldName = fieldName; 673 | } 674 | 675 | public short getThriftFieldId() { 676 | return _thriftId; 677 | } 678 | 679 | public String getFieldName() { 680 | return _fieldName; 681 | } 682 | } 683 | 684 | // isset id assignments 685 | public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; 686 | static { 687 | Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); 688 | tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, 689 | new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); 690 | metaDataMap = Collections.unmodifiableMap(tmpMap); 691 | org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(sayHello_result.class, metaDataMap); 692 | } 693 | 694 | public sayHello_result() { 695 | } 696 | 697 | public sayHello_result( 698 | String success) 699 | { 700 | this(); 701 | this.success = success; 702 | } 703 | 704 | /** 705 | * Performs a deep copy on other. 706 | */ 707 | public sayHello_result(sayHello_result other) { 708 | if (other.isSetSuccess()) { 709 | this.success = other.success; 710 | } 711 | } 712 | 713 | public sayHello_result deepCopy() { 714 | return new sayHello_result(this); 715 | } 716 | 717 | @Override 718 | public void clear() { 719 | this.success = null; 720 | } 721 | 722 | public String getSuccess() { 723 | return this.success; 724 | } 725 | 726 | public sayHello_result setSuccess(String success) { 727 | this.success = success; 728 | return this; 729 | } 730 | 731 | public void unsetSuccess() { 732 | this.success = null; 733 | } 734 | 735 | /** Returns true if field success is set (has been assigned a value) and false otherwise */ 736 | public boolean isSetSuccess() { 737 | return this.success != null; 738 | } 739 | 740 | public void setSuccessIsSet(boolean value) { 741 | if (!value) { 742 | this.success = null; 743 | } 744 | } 745 | 746 | public void setFieldValue(_Fields field, Object value) { 747 | switch (field) { 748 | case SUCCESS: 749 | if (value == null) { 750 | unsetSuccess(); 751 | } else { 752 | setSuccess((String)value); 753 | } 754 | break; 755 | 756 | } 757 | } 758 | 759 | public Object getFieldValue(_Fields field) { 760 | switch (field) { 761 | case SUCCESS: 762 | return getSuccess(); 763 | 764 | } 765 | throw new IllegalStateException(); 766 | } 767 | 768 | /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ 769 | public boolean isSet(_Fields field) { 770 | if (field == null) { 771 | throw new IllegalArgumentException(); 772 | } 773 | 774 | switch (field) { 775 | case SUCCESS: 776 | return isSetSuccess(); 777 | } 778 | throw new IllegalStateException(); 779 | } 780 | 781 | @Override 782 | public boolean equals(Object that) { 783 | if (that == null) 784 | return false; 785 | if (that instanceof sayHello_result) 786 | return this.equals((sayHello_result)that); 787 | return false; 788 | } 789 | 790 | public boolean equals(sayHello_result that) { 791 | if (that == null) 792 | return false; 793 | 794 | boolean this_present_success = true && this.isSetSuccess(); 795 | boolean that_present_success = true && that.isSetSuccess(); 796 | if (this_present_success || that_present_success) { 797 | if (!(this_present_success && that_present_success)) 798 | return false; 799 | if (!this.success.equals(that.success)) 800 | return false; 801 | } 802 | 803 | return true; 804 | } 805 | 806 | @Override 807 | public int hashCode() { 808 | List list = new ArrayList(); 809 | 810 | boolean present_success = true && (isSetSuccess()); 811 | list.add(present_success); 812 | if (present_success) 813 | list.add(success); 814 | 815 | return list.hashCode(); 816 | } 817 | 818 | @Override 819 | public int compareTo(sayHello_result other) { 820 | if (!getClass().equals(other.getClass())) { 821 | return getClass().getName().compareTo(other.getClass().getName()); 822 | } 823 | 824 | int lastComparison = 0; 825 | 826 | lastComparison = Boolean.valueOf(isSetSuccess()).compareTo(other.isSetSuccess()); 827 | if (lastComparison != 0) { 828 | return lastComparison; 829 | } 830 | if (isSetSuccess()) { 831 | lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, other.success); 832 | if (lastComparison != 0) { 833 | return lastComparison; 834 | } 835 | } 836 | return 0; 837 | } 838 | 839 | public _Fields fieldForId(int fieldId) { 840 | return _Fields.findByThriftId(fieldId); 841 | } 842 | 843 | public void read(org.apache.thrift.protocol.TProtocol iprot) throws TException { 844 | schemes.get(iprot.getScheme()).getScheme().read(iprot, this); 845 | } 846 | 847 | public void write(org.apache.thrift.protocol.TProtocol oprot) throws TException { 848 | schemes.get(oprot.getScheme()).getScheme().write(oprot, this); 849 | } 850 | 851 | @Override 852 | public String toString() { 853 | StringBuilder sb = new StringBuilder("sayHello_result("); 854 | boolean first = true; 855 | 856 | sb.append("success:"); 857 | if (this.success == null) { 858 | sb.append("null"); 859 | } else { 860 | sb.append(this.success); 861 | } 862 | first = false; 863 | sb.append(")"); 864 | return sb.toString(); 865 | } 866 | 867 | public void validate() throws TException { 868 | // check for required fields 869 | // check for sub-struct validity 870 | } 871 | 872 | private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { 873 | try { 874 | write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); 875 | } catch (TException te) { 876 | throw new java.io.IOException(te); 877 | } 878 | } 879 | 880 | private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { 881 | try { 882 | read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); 883 | } catch (TException te) { 884 | throw new java.io.IOException(te); 885 | } 886 | } 887 | 888 | private static class sayHello_resultStandardSchemeFactory implements SchemeFactory { 889 | public sayHello_resultStandardScheme getScheme() { 890 | return new sayHello_resultStandardScheme(); 891 | } 892 | } 893 | 894 | private static class sayHello_resultStandardScheme extends StandardScheme { 895 | 896 | public void read(org.apache.thrift.protocol.TProtocol iprot, sayHello_result struct) throws TException { 897 | org.apache.thrift.protocol.TField schemeField; 898 | iprot.readStructBegin(); 899 | while (true) 900 | { 901 | schemeField = iprot.readFieldBegin(); 902 | if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 903 | break; 904 | } 905 | switch (schemeField.id) { 906 | case 0: // SUCCESS 907 | if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { 908 | struct.success = iprot.readString(); 909 | struct.setSuccessIsSet(true); 910 | } else { 911 | org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); 912 | } 913 | break; 914 | default: 915 | org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); 916 | } 917 | iprot.readFieldEnd(); 918 | } 919 | iprot.readStructEnd(); 920 | 921 | // check for required fields of primitive type, which can't be checked in the validate method 922 | struct.validate(); 923 | } 924 | 925 | public void write(org.apache.thrift.protocol.TProtocol oprot, sayHello_result struct) throws TException { 926 | struct.validate(); 927 | 928 | oprot.writeStructBegin(STRUCT_DESC); 929 | if (struct.success != null) { 930 | oprot.writeFieldBegin(SUCCESS_FIELD_DESC); 931 | oprot.writeString(struct.success); 932 | oprot.writeFieldEnd(); 933 | } 934 | oprot.writeFieldStop(); 935 | oprot.writeStructEnd(); 936 | } 937 | 938 | } 939 | 940 | private static class sayHello_resultTupleSchemeFactory implements SchemeFactory { 941 | public sayHello_resultTupleScheme getScheme() { 942 | return new sayHello_resultTupleScheme(); 943 | } 944 | } 945 | 946 | private static class sayHello_resultTupleScheme extends TupleScheme { 947 | 948 | @Override 949 | public void write(org.apache.thrift.protocol.TProtocol prot, sayHello_result struct) throws TException { 950 | TTupleProtocol oprot = (TTupleProtocol) prot; 951 | BitSet optionals = new BitSet(); 952 | if (struct.isSetSuccess()) { 953 | optionals.set(0); 954 | } 955 | oprot.writeBitSet(optionals, 1); 956 | if (struct.isSetSuccess()) { 957 | oprot.writeString(struct.success); 958 | } 959 | } 960 | 961 | @Override 962 | public void read(org.apache.thrift.protocol.TProtocol prot, sayHello_result struct) throws TException { 963 | TTupleProtocol iprot = (TTupleProtocol) prot; 964 | BitSet incoming = iprot.readBitSet(1); 965 | if (incoming.get(0)) { 966 | struct.success = iprot.readString(); 967 | struct.setSuccessIsSet(true); 968 | } 969 | } 970 | } 971 | 972 | } 973 | 974 | } 975 | --------------------------------------------------------------------------------