├── src └── main │ ├── thrift │ └── haver.thrift │ └── java │ └── jghoman │ ├── Server.java │ ├── Client.java │ └── Haver.java ├── generate_thrift.sh ├── readme.md └── pom.xml /src/main/thrift/haver.thrift: -------------------------------------------------------------------------------- 1 | namespace java jghoman 2 | 3 | service Haver { 4 | string hi(); 5 | 6 | i32 add(1: i32 a, 2: i32 b); 7 | 8 | i32 blocking_call(); 9 | } -------------------------------------------------------------------------------- /generate_thrift.sh: -------------------------------------------------------------------------------- 1 | ../thrift-0.5.0-finagle/compiler/cpp/thrift --gen java -o src/main/ src/main/thrift/haver.thrift 2 | 3 | mv src/main/gen-java/jghoman/Haver.java src/main/java/jghoman/Haver.java 4 | 5 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | Quick example of building a Thrift-based client and server in Java with Finagle. 2 | 3 | The examples provided with Finagle itself are geared toward Scala, so this code covers some stumbling blocks I encountered while getting up and running. 4 | 5 | This is just a quick program I run through IntelliJ to create a server and clients, which issue a series of blocking and non-blocking requests, all while being quite chatty about it, to demonstrate the basic flow of a Finagle server. 6 | 7 | Notes: 8 | 9 | * The Finagle pom points to several internal Twitter locations. I've excluded those references that caused compilation to fail. 10 | 11 | * Finagle uses a custom thrift compiler that emits Finagle-specific classes. It can be downloaded from here: https://github.com/mariusaeriksen/thrift-0.5.0-finagle and is built and used in the usual way. 12 | 13 | * I'm moving the generated thrift code into java/main just to avoid hassles with maven finding it, not for a finagle reason 14 | 15 | * thrift:libthrift:pom:0.5.0 from Twitter doesn't have a pom associated with it, so Maven will complain about not being able to find one, but this doesn't prevent compilation or cause problems. 16 | 17 | * One needs to include the whole finagle package in maven. Just including finagle-thrift doesn't actually bring in the thrift package necessary for compilation 18 | 19 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | jghoman 8 | finagle_java_example 9 | 1.0 10 | 11 | 12 | scala-tools.org 13 | Scala-tools Maven2 Repository 14 | http://scala-tools.org/repo-releases 15 | 16 | 17 | twitter 18 | http://maven.twttr.com/ 19 | 20 | 21 | mvnrepository 22 | http://mvnrepository.com/ 23 | 24 | 25 | 26 | 27 | junit 28 | junit 29 | 3.8.1 30 | test 31 | 32 | 33 | 34 | com.twitter 35 | finagle 36 | pom 37 | 1.9.0 38 | 39 | 40 | org.scala-tools 41 | vscaladoc 42 | 43 | 44 | com.codahale 45 | jerkson_2.8.1 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | org.apache.maven.plugins 54 | maven-compiler-plugin 55 | 2.3.2 56 | 57 | 1.6 58 | 1.6 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /src/main/java/jghoman/Server.java: -------------------------------------------------------------------------------- 1 | package jghoman; 2 | 3 | import com.twitter.finagle.builder.ServerBuilder; 4 | import com.twitter.finagle.thrift.ThriftServerFramedCodec; 5 | import com.twitter.util.ExecutorServiceFuturePool; 6 | import com.twitter.util.Function0; 7 | import com.twitter.util.Future; 8 | import org.apache.thrift.protocol.TBinaryProtocol; 9 | 10 | import java.net.InetSocketAddress; 11 | import java.util.Random; 12 | import java.util.concurrent.ExecutorService; 13 | import java.util.concurrent.Executors; 14 | 15 | public class Server { 16 | // Function0 implementations - how to do blocking work on the server: 17 | // In Scala, Finagle passes closures to to a threadpool to execute long-running calls on another thread. 18 | // In Java, the closure is simulated by passing an instance of a Function0 (which is a wrapper around 19 | // how Scala actually implements closures, and should probably be named something more Java friendly). 20 | // The only method to implement is apply, which is where the long-running calculation lines. 21 | // This example just burns through CPU for the specified number of seconds, simulating some Big Important Work 22 | public static class ExampleBlockingCall extends com.twitter.util.Function0 { 23 | private int delayForSeconds; 24 | 25 | public ExampleBlockingCall(int delayForSeconds) { 26 | this.delayForSeconds = delayForSeconds; 27 | } 28 | 29 | public Integer apply() { 30 | System.out.println("Blocking call will now do some busy work for " + delayForSeconds + " seconds"); 31 | long delayUntil = System.currentTimeMillis() + (delayForSeconds * 1000); 32 | 33 | long acc = 0; 34 | while(System.currentTimeMillis() < delayUntil) { 35 | // Let's bind and gag the CPU 36 | for(int i = 0; i < 1000; i++) { 37 | for(int j = 0; j < 1000; j++) { 38 | acc += delayForSeconds + j + i; 39 | } 40 | } 41 | } 42 | 43 | return acc == System.currentTimeMillis() ? 42 : delayForSeconds; // whatever, doesn't matter 44 | } 45 | } 46 | 47 | public static class HaverServer implements Haver.ServiceIface /* Special Interface added by Finagle's thrift compiler */ { 48 | // In Scala, one can call directly to the FuturePool, but Java gets confused 49 | // between the object and class, so it's best to instantiate an ExecutorServiceFuturePool directly 50 | ExecutorService es = Executors.newFixedThreadPool(4); // Number of threads to devote to blocking requests 51 | ExecutorServiceFuturePool esfp = new ExecutorServiceFuturePool(es); // Pool to process blockng requests so server thread doesn't 52 | 53 | Random r = new Random(); 54 | 55 | // Simple call that returns a value 56 | @Override 57 | public Future hi() { 58 | System.out.println("HaverServer:hi request received."); 59 | // Future.value is an immediate return of the expression, suitable for non-blocking calls 60 | return Future.value("Hello, Stonehenge! At the beep, the time will be " + System.currentTimeMillis()); 61 | } 62 | 63 | // Very fast, non-blocking computation that the server can respond to immediately 64 | @Override 65 | public Future add(int a, int b) { 66 | System.out.println("HaverServer:add(" + a + " ," + b + ") request received"); 67 | return Future.value(a + b); 68 | } 69 | 70 | // Call that will take some time and should be moved off of the server's main event loop 71 | @Override 72 | public Future blocking_call() { 73 | int delay = r.nextInt(10); // blocking calls will take between 0 and 10 seconds 74 | System.out.println("HaverServer:blocking_call requested. Will block for " + delay + " seconds"); 75 | Function0 blockingWork = new ExampleBlockingCall(delay); 76 | // Load the blocking call on the threadpool to be scheduled and eventually executed. Once complete, 77 | // the result will be returned to the client 78 | return esfp.apply(blockingWork); 79 | } 80 | } 81 | 82 | public static void main(String[] args) { 83 | Haver.ServiceIface server = new HaverServer(); 84 | 85 | ServerBuilder.safeBuild( 86 | new Haver.Service(server, new TBinaryProtocol.Factory()), 87 | ServerBuilder.get() 88 | .name("HaverServer") 89 | .codec(ThriftServerFramedCodec.get()) // IntelliJ shows this as a type error, but compiles 90 | .bindTo(new InetSocketAddress(8080)) 91 | ); 92 | System.out.println("HaverServer's up!"); 93 | 94 | } 95 | } -------------------------------------------------------------------------------- /src/main/java/jghoman/Client.java: -------------------------------------------------------------------------------- 1 | package jghoman; 2 | 3 | import com.twitter.finagle.Service; 4 | import com.twitter.finagle.builder.ClientBuilder; 5 | import com.twitter.finagle.thrift.ThriftClientFramedCodecFactory; 6 | import com.twitter.finagle.thrift.ThriftClientRequest; 7 | import com.twitter.util.FutureEventListener; 8 | import org.apache.thrift.protocol.TBinaryProtocol; 9 | 10 | import java.net.InetSocketAddress; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | import java.util.concurrent.atomic.AtomicBoolean; 14 | 15 | public class Client { 16 | public static void main(String[] args) { 17 | Service client = ClientBuilder.safeBuild(ClientBuilder.get() 18 | .hosts(new InetSocketAddress(8080)) 19 | .codec(new ThriftClientFramedCodecFactory()) 20 | .hostConnectionLimit(100)); // IMPORTANT: this determines how many rpc's are sent in at once. 21 | // If set to 1, you get no parallelism on for this client. 22 | 23 | 24 | Haver.ServiceIface haverClient = new Haver.ServiceToClient(client, new TBinaryProtocol.Factory()); 25 | 26 | // Simple call to ask the server to say hi. 27 | haverClient.hi().addEventListener(new FutureEventListener() { 28 | @Override 29 | public void onFailure(Throwable cause) { 30 | System.out.println("Hi call. Failure: " + cause); 31 | } 32 | 33 | @Override 34 | public void onSuccess(String value) { 35 | System.out.println("Hi call. Success: " + value); 36 | } 37 | }); 38 | 39 | // Simple call to as the server to add a couple numbers 40 | haverClient.add(40, 2).addEventListener(new FutureEventListener() { 41 | @Override 42 | public void onSuccess(Integer integer) { 43 | System.out.println("Add call success. Answer: " + integer); 44 | } 45 | 46 | @Override 47 | public void onFailure(Throwable throwable) { 48 | System.out.println("Add call fail because: " + throwable); 49 | } 50 | }); 51 | 52 | // Now let's inundate the server with lots of blocking calls and watch as it handles them 53 | int numCalls = 1000; 54 | List responses = new ArrayList(numCalls); 55 | 56 | for (int i = 0; i < numCalls; i++) { 57 | BlockingCallResponse blockingCallResponse = new BlockingCallResponse(i); 58 | // Send call to the server, return its result handler 59 | haverClient.blocking_call().addEventListener(blockingCallResponse); 60 | responses.add(blockingCallResponse); 61 | System.out.println("Queued up request #" + i); 62 | 63 | // Just for fun, throw in some non-blocking calls to ensure the server responds quickly. 64 | haverClient.add(i, i).addEventListener(new FutureEventListener() { 65 | @Override 66 | public void onSuccess(Integer integer) { 67 | System.out.println("Extra Add call success. Answer: " + integer); 68 | } 69 | 70 | @Override 71 | public void onFailure(Throwable throwable) { 72 | System.out.println("Extra Add call fail because: " + throwable); 73 | } 74 | }); 75 | } 76 | System.out.println("Waiting until everyone is done"); 77 | boolean done = false; 78 | 79 | while (!done) { 80 | // Check to see how many results we've received, report on the number 81 | int count = 0; 82 | for (BlockingCallResponse blockingCallResponse : responses) { 83 | if (blockingCallResponse.isDone()) count++; 84 | 85 | done = true; 86 | } 87 | done = count == numCalls; // We're done when everyone has gotten a result back 88 | if (!done) { 89 | try { 90 | Thread.sleep(1 * 1000); 91 | } catch (InterruptedException e) { 92 | e.printStackTrace(); 93 | } 94 | } 95 | } 96 | 97 | client.release(); // Close down the clinet 98 | System.out.println("Everybody is done, let's see what they got: "); 99 | for (BlockingCallResponse blockingCallResponse : responses) { 100 | System.out.println("Answer = " + blockingCallResponse.getAnswer()); 101 | } 102 | 103 | System.out.println("Done"); 104 | return; 105 | } 106 | 107 | public static class BlockingCallResponse implements FutureEventListener { 108 | int num; // this was call number 109 | 110 | public BlockingCallResponse(int num) { 111 | this.num = num; 112 | } 113 | 114 | AtomicBoolean b = new AtomicBoolean(false); // Have we got a response yet? 115 | Integer answer = null; 116 | 117 | public void onFailure(Throwable cause) { 118 | b.set(true); 119 | System.out.println("Failure in BlockingCallResponse for #" + num + ": " + cause); 120 | } 121 | 122 | public void onSuccess(Integer value) { 123 | answer = value; 124 | b.set(true); 125 | System.out.println("Got a response back for #" + num + ": " + value); 126 | } 127 | 128 | public int getAnswer() { 129 | return answer; 130 | } 131 | 132 | public boolean isDone() { 133 | return b.get(); 134 | } 135 | } 136 | } -------------------------------------------------------------------------------- /src/main/java/jghoman/Haver.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | */ 6 | package jghoman; 7 | 8 | import java.util.List; 9 | import java.util.ArrayList; 10 | import java.util.Map; 11 | import java.util.HashMap; 12 | import java.util.EnumMap; 13 | import java.util.Set; 14 | import java.util.HashSet; 15 | import java.util.EnumSet; 16 | import java.util.Collections; 17 | import java.util.BitSet; 18 | import java.nio.ByteBuffer; 19 | import java.util.Arrays; 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | 23 | import org.apache.thrift.*; 24 | import org.apache.thrift.async.*; 25 | import org.apache.thrift.meta_data.*; 26 | import org.apache.thrift.transport.*; 27 | import org.apache.thrift.protocol.*; 28 | 29 | import com.twitter.util.Future; 30 | import com.twitter.util.Function; 31 | import com.twitter.util.Function2; 32 | import com.twitter.util.Try; 33 | import com.twitter.util.Return; 34 | import com.twitter.util.Throw; 35 | import com.twitter.finagle.thrift.ThriftClientRequest; 36 | 37 | public class Haver { 38 | 39 | public interface Iface { 40 | 41 | public String hi() throws TException; 42 | 43 | public int add(int a, int b) throws TException; 44 | 45 | public int blocking_call() throws TException; 46 | 47 | } 48 | 49 | public interface AsyncIface { 50 | 51 | public void hi(AsyncMethodCallback resultHandler) throws TException; 52 | 53 | public void add(int a, int b, AsyncMethodCallback resultHandler) throws TException; 54 | 55 | public void blocking_call(AsyncMethodCallback resultHandler) throws TException; 56 | 57 | } 58 | 59 | public interface ServiceIface { 60 | 61 | public Future hi(); 62 | 63 | public Future add(int a, int b); 64 | 65 | public Future blocking_call(); 66 | 67 | } 68 | 69 | public static class Client implements TServiceClient, Iface { 70 | public static class Factory implements TServiceClientFactory { 71 | public Factory() {} 72 | public Client getClient(TProtocol prot) { 73 | return new Client(prot); 74 | } 75 | public Client getClient(TProtocol iprot, TProtocol oprot) { 76 | return new Client(iprot, oprot); 77 | } 78 | } 79 | 80 | public Client(TProtocol prot) 81 | { 82 | this(prot, prot); 83 | } 84 | 85 | public Client(TProtocol iprot, TProtocol oprot) 86 | { 87 | iprot_ = iprot; 88 | oprot_ = oprot; 89 | } 90 | 91 | protected TProtocol iprot_; 92 | protected TProtocol oprot_; 93 | 94 | protected int seqid_; 95 | 96 | public TProtocol getInputProtocol() 97 | { 98 | return this.iprot_; 99 | } 100 | 101 | public TProtocol getOutputProtocol() 102 | { 103 | return this.oprot_; 104 | } 105 | 106 | public String hi() throws TException 107 | { 108 | send_hi(); 109 | return recv_hi(); 110 | } 111 | 112 | public void send_hi() throws TException 113 | { 114 | oprot_.writeMessageBegin(new TMessage("hi", TMessageType.CALL, ++seqid_)); 115 | hi_args args = new hi_args(); 116 | args.write(oprot_); 117 | oprot_.writeMessageEnd(); 118 | oprot_.getTransport().flush(); 119 | } 120 | 121 | public String recv_hi() throws TException 122 | { 123 | TMessage msg = iprot_.readMessageBegin(); 124 | if (msg.type == TMessageType.EXCEPTION) { 125 | TApplicationException x = TApplicationException.read(iprot_); 126 | iprot_.readMessageEnd(); 127 | throw x; 128 | } 129 | if (msg.seqid != seqid_) { 130 | throw new TApplicationException(TApplicationException.BAD_SEQUENCE_ID, "hi failed: out of sequence response"); 131 | } 132 | hi_result result = new hi_result(); 133 | result.read(iprot_); 134 | iprot_.readMessageEnd(); 135 | if (result.isSetSuccess()) { 136 | return result.success; 137 | } 138 | throw new TApplicationException(TApplicationException.MISSING_RESULT, "hi failed: unknown result"); 139 | } 140 | 141 | public int add(int a, int b) throws TException 142 | { 143 | send_add(a, b); 144 | return recv_add(); 145 | } 146 | 147 | public void send_add(int a, int b) throws TException 148 | { 149 | oprot_.writeMessageBegin(new TMessage("add", TMessageType.CALL, ++seqid_)); 150 | add_args args = new add_args(); 151 | args.setA(a); 152 | args.setB(b); 153 | args.write(oprot_); 154 | oprot_.writeMessageEnd(); 155 | oprot_.getTransport().flush(); 156 | } 157 | 158 | public int recv_add() throws TException 159 | { 160 | TMessage msg = iprot_.readMessageBegin(); 161 | if (msg.type == TMessageType.EXCEPTION) { 162 | TApplicationException x = TApplicationException.read(iprot_); 163 | iprot_.readMessageEnd(); 164 | throw x; 165 | } 166 | if (msg.seqid != seqid_) { 167 | throw new TApplicationException(TApplicationException.BAD_SEQUENCE_ID, "add failed: out of sequence response"); 168 | } 169 | add_result result = new add_result(); 170 | result.read(iprot_); 171 | iprot_.readMessageEnd(); 172 | if (result.isSetSuccess()) { 173 | return result.success; 174 | } 175 | throw new TApplicationException(TApplicationException.MISSING_RESULT, "add failed: unknown result"); 176 | } 177 | 178 | public int blocking_call() throws TException 179 | { 180 | send_blocking_call(); 181 | return recv_blocking_call(); 182 | } 183 | 184 | public void send_blocking_call() throws TException 185 | { 186 | oprot_.writeMessageBegin(new TMessage("blocking_call", TMessageType.CALL, ++seqid_)); 187 | blocking_call_args args = new blocking_call_args(); 188 | args.write(oprot_); 189 | oprot_.writeMessageEnd(); 190 | oprot_.getTransport().flush(); 191 | } 192 | 193 | public int recv_blocking_call() throws TException 194 | { 195 | TMessage msg = iprot_.readMessageBegin(); 196 | if (msg.type == TMessageType.EXCEPTION) { 197 | TApplicationException x = TApplicationException.read(iprot_); 198 | iprot_.readMessageEnd(); 199 | throw x; 200 | } 201 | if (msg.seqid != seqid_) { 202 | throw new TApplicationException(TApplicationException.BAD_SEQUENCE_ID, "blocking_call failed: out of sequence response"); 203 | } 204 | blocking_call_result result = new blocking_call_result(); 205 | result.read(iprot_); 206 | iprot_.readMessageEnd(); 207 | if (result.isSetSuccess()) { 208 | return result.success; 209 | } 210 | throw new TApplicationException(TApplicationException.MISSING_RESULT, "blocking_call failed: unknown result"); 211 | } 212 | 213 | } 214 | public static class AsyncClient extends TAsyncClient implements AsyncIface { 215 | public static class Factory implements TAsyncClientFactory { 216 | private TAsyncClientManager clientManager; 217 | private TProtocolFactory protocolFactory; 218 | public Factory(TAsyncClientManager clientManager, TProtocolFactory protocolFactory) { 219 | this.clientManager = clientManager; 220 | this.protocolFactory = protocolFactory; 221 | } 222 | public AsyncClient getAsyncClient(TNonblockingTransport transport) { 223 | return new AsyncClient(protocolFactory, clientManager, transport); 224 | } 225 | } 226 | 227 | public AsyncClient(TProtocolFactory protocolFactory, TAsyncClientManager clientManager, TNonblockingTransport transport) { 228 | super(protocolFactory, clientManager, transport); 229 | } 230 | 231 | public void hi(AsyncMethodCallback resultHandler) throws TException { 232 | checkReady(); 233 | hi_call method_call = new hi_call(resultHandler, this, protocolFactory, transport); 234 | manager.call(method_call); 235 | } 236 | 237 | public static class hi_call extends TAsyncMethodCall { 238 | public hi_call(AsyncMethodCallback resultHandler, TAsyncClient client, TProtocolFactory protocolFactory, TNonblockingTransport transport) throws TException { 239 | super(client, protocolFactory, transport, resultHandler, false); 240 | } 241 | 242 | public void write_args(TProtocol prot) throws TException { 243 | prot.writeMessageBegin(new TMessage("hi", TMessageType.CALL, 0)); 244 | hi_args args = new hi_args(); 245 | args.write(prot); 246 | prot.writeMessageEnd(); 247 | } 248 | 249 | public String getResult() throws TException { 250 | if (getState() != State.RESPONSE_READ) { 251 | throw new IllegalStateException("Method call not finished!"); 252 | } 253 | TMemoryInputTransport memoryTransport = new TMemoryInputTransport(getFrameBuffer().array()); 254 | TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); 255 | return (new Client(prot)).recv_hi(); 256 | } 257 | } 258 | 259 | public void add(int a, int b, AsyncMethodCallback resultHandler) throws TException { 260 | checkReady(); 261 | add_call method_call = new add_call(a, b, resultHandler, this, protocolFactory, transport); 262 | manager.call(method_call); 263 | } 264 | 265 | public static class add_call extends TAsyncMethodCall { 266 | private int a; 267 | private int b; 268 | public add_call(int a, int b, AsyncMethodCallback resultHandler, TAsyncClient client, TProtocolFactory protocolFactory, TNonblockingTransport transport) throws TException { 269 | super(client, protocolFactory, transport, resultHandler, false); 270 | this.a = a; 271 | this.b = b; 272 | } 273 | 274 | public void write_args(TProtocol prot) throws TException { 275 | prot.writeMessageBegin(new TMessage("add", TMessageType.CALL, 0)); 276 | add_args args = new add_args(); 277 | args.setA(a); 278 | args.setB(b); 279 | args.write(prot); 280 | prot.writeMessageEnd(); 281 | } 282 | 283 | public int getResult() throws TException { 284 | if (getState() != State.RESPONSE_READ) { 285 | throw new IllegalStateException("Method call not finished!"); 286 | } 287 | TMemoryInputTransport memoryTransport = new TMemoryInputTransport(getFrameBuffer().array()); 288 | TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); 289 | return (new Client(prot)).recv_add(); 290 | } 291 | } 292 | 293 | public void blocking_call(AsyncMethodCallback resultHandler) throws TException { 294 | checkReady(); 295 | blocking_call_call method_call = new blocking_call_call(resultHandler, this, protocolFactory, transport); 296 | manager.call(method_call); 297 | } 298 | 299 | public static class blocking_call_call extends TAsyncMethodCall { 300 | public blocking_call_call(AsyncMethodCallback resultHandler, TAsyncClient client, TProtocolFactory protocolFactory, TNonblockingTransport transport) throws TException { 301 | super(client, protocolFactory, transport, resultHandler, false); 302 | } 303 | 304 | public void write_args(TProtocol prot) throws TException { 305 | prot.writeMessageBegin(new TMessage("blocking_call", TMessageType.CALL, 0)); 306 | blocking_call_args args = new blocking_call_args(); 307 | args.write(prot); 308 | prot.writeMessageEnd(); 309 | } 310 | 311 | public int getResult() throws TException { 312 | if (getState() != State.RESPONSE_READ) { 313 | throw new IllegalStateException("Method call not finished!"); 314 | } 315 | TMemoryInputTransport memoryTransport = new TMemoryInputTransport(getFrameBuffer().array()); 316 | TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); 317 | return (new Client(prot)).recv_blocking_call(); 318 | } 319 | } 320 | 321 | } 322 | 323 | public static class ServiceToClient implements ServiceIface { 324 | private com.twitter.finagle.Service service; 325 | private TProtocolFactory protocolFactory; 326 | public ServiceToClient(com.twitter.finagle.Service service, TProtocolFactory protocolFactory) { 327 | this.service = service; 328 | this.protocolFactory = protocolFactory; 329 | } 330 | 331 | public Future hi() { 332 | try { 333 | // TODO: size 334 | TMemoryBuffer __memoryTransport__ = new TMemoryBuffer(512); 335 | TProtocol __prot__ = this.protocolFactory.getProtocol(__memoryTransport__); 336 | __prot__.writeMessageBegin(new TMessage("hi", TMessageType.CALL, 0)); 337 | hi_args __args__ = new hi_args(); 338 | __args__.write(__prot__); 339 | __prot__.writeMessageEnd(); 340 | 341 | 342 | byte[] __buffer__ = Arrays.copyOfRange(__memoryTransport__.getArray(), 0, __memoryTransport__.length()); 343 | ThriftClientRequest __request__ = new ThriftClientRequest(__buffer__, false); 344 | Future __done__ = this.service.apply(__request__); 345 | return __done__.flatMap(new Function>() { 346 | public Future apply(byte[] __buffer__) { 347 | TMemoryInputTransport __memoryTransport__ = new TMemoryInputTransport(__buffer__); 348 | TProtocol __prot__ = ServiceToClient.this.protocolFactory.getProtocol(__memoryTransport__); 349 | try { 350 | return Future.value((new Client(__prot__)).recv_hi()); 351 | } catch (Exception e) { 352 | return Future.exception(e); 353 | } 354 | } 355 | }); 356 | } catch (TException e) { 357 | return Future.exception(e); 358 | } 359 | } 360 | public Future add(int a, int b) { 361 | try { 362 | // TODO: size 363 | TMemoryBuffer __memoryTransport__ = new TMemoryBuffer(512); 364 | TProtocol __prot__ = this.protocolFactory.getProtocol(__memoryTransport__); 365 | __prot__.writeMessageBegin(new TMessage("add", TMessageType.CALL, 0)); 366 | add_args __args__ = new add_args(); 367 | __args__.setA(a); 368 | __args__.setB(b); 369 | __args__.write(__prot__); 370 | __prot__.writeMessageEnd(); 371 | 372 | 373 | byte[] __buffer__ = Arrays.copyOfRange(__memoryTransport__.getArray(), 0, __memoryTransport__.length()); 374 | ThriftClientRequest __request__ = new ThriftClientRequest(__buffer__, false); 375 | Future __done__ = this.service.apply(__request__); 376 | return __done__.flatMap(new Function>() { 377 | public Future apply(byte[] __buffer__) { 378 | TMemoryInputTransport __memoryTransport__ = new TMemoryInputTransport(__buffer__); 379 | TProtocol __prot__ = ServiceToClient.this.protocolFactory.getProtocol(__memoryTransport__); 380 | try { 381 | return Future.value((new Client(__prot__)).recv_add()); 382 | } catch (Exception e) { 383 | return Future.exception(e); 384 | } 385 | } 386 | }); 387 | } catch (TException e) { 388 | return Future.exception(e); 389 | } 390 | } 391 | public Future blocking_call() { 392 | try { 393 | // TODO: size 394 | TMemoryBuffer __memoryTransport__ = new TMemoryBuffer(512); 395 | TProtocol __prot__ = this.protocolFactory.getProtocol(__memoryTransport__); 396 | __prot__.writeMessageBegin(new TMessage("blocking_call", TMessageType.CALL, 0)); 397 | blocking_call_args __args__ = new blocking_call_args(); 398 | __args__.write(__prot__); 399 | __prot__.writeMessageEnd(); 400 | 401 | 402 | byte[] __buffer__ = Arrays.copyOfRange(__memoryTransport__.getArray(), 0, __memoryTransport__.length()); 403 | ThriftClientRequest __request__ = new ThriftClientRequest(__buffer__, false); 404 | Future __done__ = this.service.apply(__request__); 405 | return __done__.flatMap(new Function>() { 406 | public Future apply(byte[] __buffer__) { 407 | TMemoryInputTransport __memoryTransport__ = new TMemoryInputTransport(__buffer__); 408 | TProtocol __prot__ = ServiceToClient.this.protocolFactory.getProtocol(__memoryTransport__); 409 | try { 410 | return Future.value((new Client(__prot__)).recv_blocking_call()); 411 | } catch (Exception e) { 412 | return Future.exception(e); 413 | } 414 | } 415 | }); 416 | } catch (TException e) { 417 | return Future.exception(e); 418 | } 419 | } 420 | } 421 | 422 | public static class Processor implements TProcessor { 423 | private static final Logger LOGGER = LoggerFactory.getLogger(Processor.class.getName()); 424 | public Processor(Iface iface) 425 | { 426 | iface_ = iface; 427 | processMap_.put("hi", new hi()); 428 | processMap_.put("add", new add()); 429 | processMap_.put("blocking_call", new blocking_call()); 430 | } 431 | 432 | protected static interface ProcessFunction { 433 | public void process(int seqid, TProtocol iprot, TProtocol oprot) throws TException; 434 | } 435 | 436 | private Iface iface_; 437 | protected final HashMap processMap_ = new HashMap(); 438 | 439 | public boolean process(TProtocol iprot, TProtocol oprot) throws TException 440 | { 441 | TMessage msg = iprot.readMessageBegin(); 442 | ProcessFunction fn = processMap_.get(msg.name); 443 | if (fn == null) { 444 | TProtocolUtil.skip(iprot, TType.STRUCT); 445 | iprot.readMessageEnd(); 446 | TApplicationException x = new TApplicationException(TApplicationException.UNKNOWN_METHOD, "Invalid method name: '"+msg.name+"'"); 447 | oprot.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION, msg.seqid)); 448 | x.write(oprot); 449 | oprot.writeMessageEnd(); 450 | oprot.getTransport().flush(); 451 | return true; 452 | } 453 | fn.process(msg.seqid, iprot, oprot); 454 | return true; 455 | } 456 | 457 | private class hi implements ProcessFunction { 458 | public void process(int seqid, TProtocol iprot, TProtocol oprot) throws TException 459 | { 460 | hi_args args = new hi_args(); 461 | try { 462 | args.read(iprot); 463 | } catch (TProtocolException e) { 464 | iprot.readMessageEnd(); 465 | TApplicationException x = new TApplicationException(TApplicationException.PROTOCOL_ERROR, e.getMessage()); 466 | oprot.writeMessageBegin(new TMessage("hi", TMessageType.EXCEPTION, seqid)); 467 | x.write(oprot); 468 | oprot.writeMessageEnd(); 469 | oprot.getTransport().flush(); 470 | return; 471 | } 472 | iprot.readMessageEnd(); 473 | hi_result result = new hi_result(); 474 | result.success = iface_.hi(); 475 | oprot.writeMessageBegin(new TMessage("hi", TMessageType.REPLY, seqid)); 476 | result.write(oprot); 477 | oprot.writeMessageEnd(); 478 | oprot.getTransport().flush(); 479 | } 480 | 481 | } 482 | 483 | private class add implements ProcessFunction { 484 | public void process(int seqid, TProtocol iprot, TProtocol oprot) throws TException 485 | { 486 | add_args args = new add_args(); 487 | try { 488 | args.read(iprot); 489 | } catch (TProtocolException e) { 490 | iprot.readMessageEnd(); 491 | TApplicationException x = new TApplicationException(TApplicationException.PROTOCOL_ERROR, e.getMessage()); 492 | oprot.writeMessageBegin(new TMessage("add", TMessageType.EXCEPTION, seqid)); 493 | x.write(oprot); 494 | oprot.writeMessageEnd(); 495 | oprot.getTransport().flush(); 496 | return; 497 | } 498 | iprot.readMessageEnd(); 499 | add_result result = new add_result(); 500 | result.success = iface_.add(args.a, args.b); 501 | result.setSuccessIsSet(true); 502 | oprot.writeMessageBegin(new TMessage("add", TMessageType.REPLY, seqid)); 503 | result.write(oprot); 504 | oprot.writeMessageEnd(); 505 | oprot.getTransport().flush(); 506 | } 507 | 508 | } 509 | 510 | private class blocking_call implements ProcessFunction { 511 | public void process(int seqid, TProtocol iprot, TProtocol oprot) throws TException 512 | { 513 | blocking_call_args args = new blocking_call_args(); 514 | try { 515 | args.read(iprot); 516 | } catch (TProtocolException e) { 517 | iprot.readMessageEnd(); 518 | TApplicationException x = new TApplicationException(TApplicationException.PROTOCOL_ERROR, e.getMessage()); 519 | oprot.writeMessageBegin(new TMessage("blocking_call", TMessageType.EXCEPTION, seqid)); 520 | x.write(oprot); 521 | oprot.writeMessageEnd(); 522 | oprot.getTransport().flush(); 523 | return; 524 | } 525 | iprot.readMessageEnd(); 526 | blocking_call_result result = new blocking_call_result(); 527 | result.success = iface_.blocking_call(); 528 | result.setSuccessIsSet(true); 529 | oprot.writeMessageBegin(new TMessage("blocking_call", TMessageType.REPLY, seqid)); 530 | result.write(oprot); 531 | oprot.writeMessageEnd(); 532 | oprot.getTransport().flush(); 533 | } 534 | 535 | } 536 | 537 | } 538 | 539 | public static class Service extends com.twitter.finagle.Service { 540 | private final ServiceIface iface; 541 | private final TProtocolFactory protocolFactory; 542 | protected HashMap>> functionMap = new HashMap>>(); 543 | public Service(final ServiceIface iface, final TProtocolFactory protocolFactory) { 544 | this.iface = iface; 545 | this.protocolFactory = protocolFactory; 546 | functionMap.put("hi", new Function2>() { 547 | public Future apply(final TProtocol iprot, final Integer seqid) { 548 | hi_args args = new hi_args(); 549 | try { 550 | args.read(iprot); 551 | } catch (TProtocolException e) { 552 | try { 553 | iprot.readMessageEnd(); 554 | TApplicationException x = new TApplicationException(TApplicationException.PROTOCOL_ERROR, e.getMessage()); 555 | TMemoryBuffer memoryBuffer = new TMemoryBuffer(512); 556 | TProtocol oprot = protocolFactory.getProtocol(memoryBuffer); 557 | 558 | oprot.writeMessageBegin(new TMessage("hi", TMessageType.EXCEPTION, seqid)); 559 | x.write(oprot); 560 | oprot.writeMessageEnd(); 561 | oprot.getTransport().flush(); 562 | byte[] buffer = Arrays.copyOfRange(memoryBuffer.getArray(), 0, memoryBuffer.length()); 563 | return Future.value(buffer); 564 | } catch (Exception e1) { 565 | return Future.exception(e1); 566 | } 567 | } catch (Exception e) { 568 | return Future.exception(e); 569 | } 570 | 571 | try { 572 | iprot.readMessageEnd(); 573 | } catch (Exception e) { 574 | return Future.exception(e); 575 | } 576 | Future future; 577 | try { 578 | future = iface.hi(); 579 | } catch (Exception e) { 580 | future = Future.exception(e); 581 | } 582 | try { 583 | return future.flatMap(new Function>() { 584 | public Future apply(String value) { 585 | hi_result result = new hi_result(); 586 | result.success = value; 587 | result.setSuccessIsSet(true); 588 | 589 | try { 590 | TMemoryBuffer memoryBuffer = new TMemoryBuffer(512); 591 | TProtocol oprot = protocolFactory.getProtocol(memoryBuffer); 592 | 593 | oprot.writeMessageBegin(new TMessage("hi", TMessageType.REPLY, seqid)); 594 | result.write(oprot); 595 | oprot.writeMessageEnd(); 596 | 597 | return Future.value(Arrays.copyOfRange(memoryBuffer.getArray(), 0, memoryBuffer.length())); 598 | } catch (Exception e) { 599 | return Future.exception(e); 600 | } 601 | } 602 | }).rescue(new Function>() { 603 | public Future apply(Throwable t) { 604 | TMemoryBuffer memoryBuffer = new TMemoryBuffer(512); 605 | TProtocol oprot = protocolFactory.getProtocol(memoryBuffer); 606 | try { 607 | TApplicationException x = new TApplicationException(TApplicationException.INTERNAL_ERROR, "Internal error processing hi"); 608 | oprot.writeMessageBegin(new TMessage("hi", TMessageType.EXCEPTION, seqid)); 609 | x.write(oprot); 610 | oprot.writeMessageEnd(); 611 | oprot.getTransport().flush(); 612 | return Future.value(Arrays.copyOfRange(memoryBuffer.getArray(), 0, memoryBuffer.length())); 613 | } catch (Exception e) { 614 | return Future.exception(e); 615 | } 616 | } 617 | }); 618 | } catch (Exception e) { 619 | return Future.exception(e); 620 | } 621 | } 622 | }); 623 | 624 | functionMap.put("add", new Function2>() { 625 | public Future apply(final TProtocol iprot, final Integer seqid) { 626 | add_args args = new add_args(); 627 | try { 628 | args.read(iprot); 629 | } catch (TProtocolException e) { 630 | try { 631 | iprot.readMessageEnd(); 632 | TApplicationException x = new TApplicationException(TApplicationException.PROTOCOL_ERROR, e.getMessage()); 633 | TMemoryBuffer memoryBuffer = new TMemoryBuffer(512); 634 | TProtocol oprot = protocolFactory.getProtocol(memoryBuffer); 635 | 636 | oprot.writeMessageBegin(new TMessage("add", TMessageType.EXCEPTION, seqid)); 637 | x.write(oprot); 638 | oprot.writeMessageEnd(); 639 | oprot.getTransport().flush(); 640 | byte[] buffer = Arrays.copyOfRange(memoryBuffer.getArray(), 0, memoryBuffer.length()); 641 | return Future.value(buffer); 642 | } catch (Exception e1) { 643 | return Future.exception(e1); 644 | } 645 | } catch (Exception e) { 646 | return Future.exception(e); 647 | } 648 | 649 | try { 650 | iprot.readMessageEnd(); 651 | } catch (Exception e) { 652 | return Future.exception(e); 653 | } 654 | Future future; 655 | try { 656 | future = iface.add(args.a, args.b); 657 | } catch (Exception e) { 658 | future = Future.exception(e); 659 | } 660 | try { 661 | return future.flatMap(new Function>() { 662 | public Future apply(Integer value) { 663 | add_result result = new add_result(); 664 | result.success = value; 665 | result.setSuccessIsSet(true); 666 | 667 | try { 668 | TMemoryBuffer memoryBuffer = new TMemoryBuffer(512); 669 | TProtocol oprot = protocolFactory.getProtocol(memoryBuffer); 670 | 671 | oprot.writeMessageBegin(new TMessage("add", TMessageType.REPLY, seqid)); 672 | result.write(oprot); 673 | oprot.writeMessageEnd(); 674 | 675 | return Future.value(Arrays.copyOfRange(memoryBuffer.getArray(), 0, memoryBuffer.length())); 676 | } catch (Exception e) { 677 | return Future.exception(e); 678 | } 679 | } 680 | }).rescue(new Function>() { 681 | public Future apply(Throwable t) { 682 | TMemoryBuffer memoryBuffer = new TMemoryBuffer(512); 683 | TProtocol oprot = protocolFactory.getProtocol(memoryBuffer); 684 | try { 685 | TApplicationException x = new TApplicationException(TApplicationException.INTERNAL_ERROR, "Internal error processing add"); 686 | oprot.writeMessageBegin(new TMessage("add", TMessageType.EXCEPTION, seqid)); 687 | x.write(oprot); 688 | oprot.writeMessageEnd(); 689 | oprot.getTransport().flush(); 690 | return Future.value(Arrays.copyOfRange(memoryBuffer.getArray(), 0, memoryBuffer.length())); 691 | } catch (Exception e) { 692 | return Future.exception(e); 693 | } 694 | } 695 | }); 696 | } catch (Exception e) { 697 | return Future.exception(e); 698 | } 699 | } 700 | }); 701 | 702 | functionMap.put("blocking_call", new Function2>() { 703 | public Future apply(final TProtocol iprot, final Integer seqid) { 704 | blocking_call_args args = new blocking_call_args(); 705 | try { 706 | args.read(iprot); 707 | } catch (TProtocolException e) { 708 | try { 709 | iprot.readMessageEnd(); 710 | TApplicationException x = new TApplicationException(TApplicationException.PROTOCOL_ERROR, e.getMessage()); 711 | TMemoryBuffer memoryBuffer = new TMemoryBuffer(512); 712 | TProtocol oprot = protocolFactory.getProtocol(memoryBuffer); 713 | 714 | oprot.writeMessageBegin(new TMessage("blocking_call", TMessageType.EXCEPTION, seqid)); 715 | x.write(oprot); 716 | oprot.writeMessageEnd(); 717 | oprot.getTransport().flush(); 718 | byte[] buffer = Arrays.copyOfRange(memoryBuffer.getArray(), 0, memoryBuffer.length()); 719 | return Future.value(buffer); 720 | } catch (Exception e1) { 721 | return Future.exception(e1); 722 | } 723 | } catch (Exception e) { 724 | return Future.exception(e); 725 | } 726 | 727 | try { 728 | iprot.readMessageEnd(); 729 | } catch (Exception e) { 730 | return Future.exception(e); 731 | } 732 | Future future; 733 | try { 734 | future = iface.blocking_call(); 735 | } catch (Exception e) { 736 | future = Future.exception(e); 737 | } 738 | try { 739 | return future.flatMap(new Function>() { 740 | public Future apply(Integer value) { 741 | blocking_call_result result = new blocking_call_result(); 742 | result.success = value; 743 | result.setSuccessIsSet(true); 744 | 745 | try { 746 | TMemoryBuffer memoryBuffer = new TMemoryBuffer(512); 747 | TProtocol oprot = protocolFactory.getProtocol(memoryBuffer); 748 | 749 | oprot.writeMessageBegin(new TMessage("blocking_call", TMessageType.REPLY, seqid)); 750 | result.write(oprot); 751 | oprot.writeMessageEnd(); 752 | 753 | return Future.value(Arrays.copyOfRange(memoryBuffer.getArray(), 0, memoryBuffer.length())); 754 | } catch (Exception e) { 755 | return Future.exception(e); 756 | } 757 | } 758 | }).rescue(new Function>() { 759 | public Future apply(Throwable t) { 760 | TMemoryBuffer memoryBuffer = new TMemoryBuffer(512); 761 | TProtocol oprot = protocolFactory.getProtocol(memoryBuffer); 762 | try { 763 | TApplicationException x = new TApplicationException(TApplicationException.INTERNAL_ERROR, "Internal error processing blocking_call"); 764 | oprot.writeMessageBegin(new TMessage("blocking_call", TMessageType.EXCEPTION, seqid)); 765 | x.write(oprot); 766 | oprot.writeMessageEnd(); 767 | oprot.getTransport().flush(); 768 | return Future.value(Arrays.copyOfRange(memoryBuffer.getArray(), 0, memoryBuffer.length())); 769 | } catch (Exception e) { 770 | return Future.exception(e); 771 | } 772 | } 773 | }); 774 | } catch (Exception e) { 775 | return Future.exception(e); 776 | } 777 | } 778 | }); 779 | 780 | } 781 | 782 | public Future apply(byte[] request) { 783 | TTransport inputTransport = new TMemoryInputTransport(request); 784 | TProtocol iprot = protocolFactory.getProtocol(inputTransport); 785 | 786 | TMessage msg; 787 | try { 788 | msg = iprot.readMessageBegin(); 789 | } catch (Exception e) { 790 | return Future.exception(e); 791 | } 792 | 793 | Function2> fn = functionMap.get(msg.name); 794 | if (fn == null) { 795 | try { 796 | TProtocolUtil.skip(iprot, TType.STRUCT); 797 | iprot.readMessageEnd(); 798 | TApplicationException x = new TApplicationException(TApplicationException.UNKNOWN_METHOD, "Invalid method name: '"+msg.name+"'"); 799 | TMemoryBuffer memoryBuffer = new TMemoryBuffer(512); 800 | TProtocol oprot = protocolFactory.getProtocol(memoryBuffer); 801 | oprot.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION, msg.seqid)); 802 | x.write(oprot); 803 | oprot.writeMessageEnd(); 804 | oprot.getTransport().flush(); 805 | return Future.value(Arrays.copyOfRange(memoryBuffer.getArray(), 0, memoryBuffer.length())); 806 | } catch (Exception e) { 807 | return Future.exception(e); 808 | } 809 | } 810 | 811 | return fn.apply(iprot, msg.seqid); 812 | } 813 | 814 | } 815 | 816 | public static class hi_args implements TBase, java.io.Serializable, Cloneable { 817 | private static final TStruct STRUCT_DESC = new TStruct("hi_args"); 818 | 819 | 820 | 821 | /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ 822 | public enum _Fields implements TFieldIdEnum { 823 | ; 824 | 825 | private static final Map byName = new HashMap(); 826 | 827 | static { 828 | for (_Fields field : EnumSet.allOf(_Fields.class)) { 829 | byName.put(field.getFieldName(), field); 830 | } 831 | } 832 | 833 | /** 834 | * Find the _Fields constant that matches fieldId, or null if its not found. 835 | */ 836 | public static _Fields findByThriftId(int fieldId) { 837 | switch(fieldId) { 838 | default: 839 | return null; 840 | } 841 | } 842 | 843 | /** 844 | * Find the _Fields constant that matches fieldId, throwing an exception 845 | * if it is not found. 846 | */ 847 | public static _Fields findByThriftIdOrThrow(int fieldId) { 848 | _Fields fields = findByThriftId(fieldId); 849 | if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); 850 | return fields; 851 | } 852 | 853 | /** 854 | * Find the _Fields constant that matches name, or null if its not found. 855 | */ 856 | public static _Fields findByName(String name) { 857 | return byName.get(name); 858 | } 859 | 860 | private final short _thriftId; 861 | private final String _fieldName; 862 | 863 | _Fields(short thriftId, String fieldName) { 864 | _thriftId = thriftId; 865 | _fieldName = fieldName; 866 | } 867 | 868 | public short getThriftFieldId() { 869 | return _thriftId; 870 | } 871 | 872 | public String getFieldName() { 873 | return _fieldName; 874 | } 875 | } 876 | public static final Map<_Fields, FieldMetaData> metaDataMap; 877 | static { 878 | Map<_Fields, FieldMetaData> tmpMap = new EnumMap<_Fields, FieldMetaData>(_Fields.class); 879 | metaDataMap = Collections.unmodifiableMap(tmpMap); 880 | FieldMetaData.addStructMetaDataMap(hi_args.class, metaDataMap); 881 | } 882 | 883 | public hi_args() { 884 | } 885 | 886 | /** 887 | * Performs a deep copy on other. 888 | */ 889 | public hi_args(hi_args other) { 890 | } 891 | 892 | public hi_args deepCopy() { 893 | return new hi_args(this); 894 | } 895 | 896 | @Override 897 | public void clear() { 898 | } 899 | 900 | public void setFieldValue(_Fields field, Object value) { 901 | switch (field) { 902 | } 903 | } 904 | 905 | public Object getFieldValue(_Fields field) { 906 | switch (field) { 907 | } 908 | throw new IllegalStateException(); 909 | } 910 | 911 | /** Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise */ 912 | public boolean isSet(_Fields field) { 913 | if (field == null) { 914 | throw new IllegalArgumentException(); 915 | } 916 | 917 | switch (field) { 918 | } 919 | throw new IllegalStateException(); 920 | } 921 | 922 | @Override 923 | public boolean equals(Object that) { 924 | if (that == null) 925 | return false; 926 | if (that instanceof hi_args) 927 | return this.equals((hi_args)that); 928 | return false; 929 | } 930 | 931 | public boolean equals(hi_args that) { 932 | if (that == null) 933 | return false; 934 | 935 | return true; 936 | } 937 | 938 | @Override 939 | public int hashCode() { 940 | return 0; 941 | } 942 | 943 | public int compareTo(hi_args other) { 944 | if (!getClass().equals(other.getClass())) { 945 | return getClass().getName().compareTo(other.getClass().getName()); 946 | } 947 | 948 | int lastComparison = 0; 949 | hi_args typedOther = (hi_args)other; 950 | 951 | return 0; 952 | } 953 | 954 | public _Fields fieldForId(int fieldId) { 955 | return _Fields.findByThriftId(fieldId); 956 | } 957 | 958 | public void read(TProtocol iprot) throws TException { 959 | TField field; 960 | iprot.readStructBegin(); 961 | while (true) 962 | { 963 | field = iprot.readFieldBegin(); 964 | if (field.type == TType.STOP) { 965 | break; 966 | } 967 | switch (field.id) { 968 | default: 969 | TProtocolUtil.skip(iprot, field.type); 970 | } 971 | iprot.readFieldEnd(); 972 | } 973 | iprot.readStructEnd(); 974 | 975 | // check for required fields of primitive type, which can't be checked in the validate method 976 | validate(); 977 | } 978 | 979 | public void write(TProtocol oprot) throws TException { 980 | validate(); 981 | 982 | oprot.writeStructBegin(STRUCT_DESC); 983 | oprot.writeFieldStop(); 984 | oprot.writeStructEnd(); 985 | } 986 | 987 | @Override 988 | public String toString() { 989 | StringBuilder sb = new StringBuilder("hi_args("); 990 | boolean first = true; 991 | 992 | sb.append(")"); 993 | return sb.toString(); 994 | } 995 | 996 | public void validate() throws TException { 997 | // check for required fields 998 | } 999 | 1000 | } 1001 | 1002 | public static class hi_result implements TBase, java.io.Serializable, Cloneable { 1003 | private static final TStruct STRUCT_DESC = new TStruct("hi_result"); 1004 | 1005 | private static final TField SUCCESS_FIELD_DESC = new TField("success", TType.STRING, (short)0); 1006 | 1007 | public String success; 1008 | 1009 | /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ 1010 | public enum _Fields implements TFieldIdEnum { 1011 | SUCCESS((short)0, "success"); 1012 | 1013 | private static final Map byName = new HashMap(); 1014 | 1015 | static { 1016 | for (_Fields field : EnumSet.allOf(_Fields.class)) { 1017 | byName.put(field.getFieldName(), field); 1018 | } 1019 | } 1020 | 1021 | /** 1022 | * Find the _Fields constant that matches fieldId, or null if its not found. 1023 | */ 1024 | public static _Fields findByThriftId(int fieldId) { 1025 | switch(fieldId) { 1026 | case 0: // SUCCESS 1027 | return SUCCESS; 1028 | default: 1029 | return null; 1030 | } 1031 | } 1032 | 1033 | /** 1034 | * Find the _Fields constant that matches fieldId, throwing an exception 1035 | * if it is not found. 1036 | */ 1037 | public static _Fields findByThriftIdOrThrow(int fieldId) { 1038 | _Fields fields = findByThriftId(fieldId); 1039 | if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); 1040 | return fields; 1041 | } 1042 | 1043 | /** 1044 | * Find the _Fields constant that matches name, or null if its not found. 1045 | */ 1046 | public static _Fields findByName(String name) { 1047 | return byName.get(name); 1048 | } 1049 | 1050 | private final short _thriftId; 1051 | private final String _fieldName; 1052 | 1053 | _Fields(short thriftId, String fieldName) { 1054 | _thriftId = thriftId; 1055 | _fieldName = fieldName; 1056 | } 1057 | 1058 | public short getThriftFieldId() { 1059 | return _thriftId; 1060 | } 1061 | 1062 | public String getFieldName() { 1063 | return _fieldName; 1064 | } 1065 | } 1066 | 1067 | // isset id assignments 1068 | 1069 | public static final Map<_Fields, FieldMetaData> metaDataMap; 1070 | static { 1071 | Map<_Fields, FieldMetaData> tmpMap = new EnumMap<_Fields, FieldMetaData>(_Fields.class); 1072 | tmpMap.put(_Fields.SUCCESS, new FieldMetaData("success", TFieldRequirementType.DEFAULT, 1073 | new FieldValueMetaData(TType.STRING))); 1074 | metaDataMap = Collections.unmodifiableMap(tmpMap); 1075 | FieldMetaData.addStructMetaDataMap(hi_result.class, metaDataMap); 1076 | } 1077 | 1078 | public hi_result() { 1079 | } 1080 | 1081 | public hi_result( 1082 | String success) 1083 | { 1084 | this(); 1085 | this.success = success; 1086 | } 1087 | 1088 | /** 1089 | * Performs a deep copy on other. 1090 | */ 1091 | public hi_result(hi_result other) { 1092 | if (other.isSetSuccess()) { 1093 | this.success = other.success; 1094 | } 1095 | } 1096 | 1097 | public hi_result deepCopy() { 1098 | return new hi_result(this); 1099 | } 1100 | 1101 | @Override 1102 | public void clear() { 1103 | this.success = null; 1104 | } 1105 | 1106 | public String getSuccess() { 1107 | return this.success; 1108 | } 1109 | 1110 | public hi_result setSuccess(String success) { 1111 | this.success = success; 1112 | return this; 1113 | } 1114 | 1115 | public void unsetSuccess() { 1116 | this.success = null; 1117 | } 1118 | 1119 | /** Returns true if field success is set (has been asigned a value) and false otherwise */ 1120 | public boolean isSetSuccess() { 1121 | return this.success != null; 1122 | } 1123 | 1124 | public void setSuccessIsSet(boolean value) { 1125 | if (!value) { 1126 | this.success = null; 1127 | } 1128 | } 1129 | 1130 | public void setFieldValue(_Fields field, Object value) { 1131 | switch (field) { 1132 | case SUCCESS: 1133 | if (value == null) { 1134 | unsetSuccess(); 1135 | } else { 1136 | setSuccess((String)value); 1137 | } 1138 | break; 1139 | 1140 | } 1141 | } 1142 | 1143 | public Object getFieldValue(_Fields field) { 1144 | switch (field) { 1145 | case SUCCESS: 1146 | return getSuccess(); 1147 | 1148 | } 1149 | throw new IllegalStateException(); 1150 | } 1151 | 1152 | /** Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise */ 1153 | public boolean isSet(_Fields field) { 1154 | if (field == null) { 1155 | throw new IllegalArgumentException(); 1156 | } 1157 | 1158 | switch (field) { 1159 | case SUCCESS: 1160 | return isSetSuccess(); 1161 | } 1162 | throw new IllegalStateException(); 1163 | } 1164 | 1165 | @Override 1166 | public boolean equals(Object that) { 1167 | if (that == null) 1168 | return false; 1169 | if (that instanceof hi_result) 1170 | return this.equals((hi_result)that); 1171 | return false; 1172 | } 1173 | 1174 | public boolean equals(hi_result that) { 1175 | if (that == null) 1176 | return false; 1177 | 1178 | boolean this_present_success = true && this.isSetSuccess(); 1179 | boolean that_present_success = true && that.isSetSuccess(); 1180 | if (this_present_success || that_present_success) { 1181 | if (!(this_present_success && that_present_success)) 1182 | return false; 1183 | if (!this.success.equals(that.success)) 1184 | return false; 1185 | } 1186 | 1187 | return true; 1188 | } 1189 | 1190 | @Override 1191 | public int hashCode() { 1192 | return 0; 1193 | } 1194 | 1195 | public int compareTo(hi_result other) { 1196 | if (!getClass().equals(other.getClass())) { 1197 | return getClass().getName().compareTo(other.getClass().getName()); 1198 | } 1199 | 1200 | int lastComparison = 0; 1201 | hi_result typedOther = (hi_result)other; 1202 | 1203 | lastComparison = Boolean.valueOf(isSetSuccess()).compareTo(typedOther.isSetSuccess()); 1204 | if (lastComparison != 0) { 1205 | return lastComparison; 1206 | } 1207 | if (isSetSuccess()) { 1208 | lastComparison = TBaseHelper.compareTo(this.success, typedOther.success); 1209 | if (lastComparison != 0) { 1210 | return lastComparison; 1211 | } 1212 | } 1213 | return 0; 1214 | } 1215 | 1216 | public _Fields fieldForId(int fieldId) { 1217 | return _Fields.findByThriftId(fieldId); 1218 | } 1219 | 1220 | public void read(TProtocol iprot) throws TException { 1221 | TField field; 1222 | iprot.readStructBegin(); 1223 | while (true) 1224 | { 1225 | field = iprot.readFieldBegin(); 1226 | if (field.type == TType.STOP) { 1227 | break; 1228 | } 1229 | switch (field.id) { 1230 | case 0: // SUCCESS 1231 | if (field.type == TType.STRING) { 1232 | this.success = iprot.readString(); 1233 | } else { 1234 | TProtocolUtil.skip(iprot, field.type); 1235 | } 1236 | break; 1237 | default: 1238 | TProtocolUtil.skip(iprot, field.type); 1239 | } 1240 | iprot.readFieldEnd(); 1241 | } 1242 | iprot.readStructEnd(); 1243 | 1244 | // check for required fields of primitive type, which can't be checked in the validate method 1245 | validate(); 1246 | } 1247 | 1248 | public void write(TProtocol oprot) throws TException { 1249 | oprot.writeStructBegin(STRUCT_DESC); 1250 | 1251 | if (this.isSetSuccess()) { 1252 | oprot.writeFieldBegin(SUCCESS_FIELD_DESC); 1253 | oprot.writeString(this.success); 1254 | oprot.writeFieldEnd(); 1255 | } 1256 | oprot.writeFieldStop(); 1257 | oprot.writeStructEnd(); 1258 | } 1259 | 1260 | @Override 1261 | public String toString() { 1262 | StringBuilder sb = new StringBuilder("hi_result("); 1263 | boolean first = true; 1264 | 1265 | sb.append("success:"); 1266 | if (this.success == null) { 1267 | sb.append("null"); 1268 | } else { 1269 | sb.append(this.success); 1270 | } 1271 | first = false; 1272 | sb.append(")"); 1273 | return sb.toString(); 1274 | } 1275 | 1276 | public void validate() throws TException { 1277 | // check for required fields 1278 | } 1279 | 1280 | } 1281 | 1282 | public static class add_args implements TBase, java.io.Serializable, Cloneable { 1283 | private static final TStruct STRUCT_DESC = new TStruct("add_args"); 1284 | 1285 | private static final TField A_FIELD_DESC = new TField("a", TType.I32, (short)1); 1286 | private static final TField B_FIELD_DESC = new TField("b", TType.I32, (short)2); 1287 | 1288 | public int a; 1289 | public int b; 1290 | 1291 | /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ 1292 | public enum _Fields implements TFieldIdEnum { 1293 | A((short)1, "a"), 1294 | B((short)2, "b"); 1295 | 1296 | private static final Map byName = new HashMap(); 1297 | 1298 | static { 1299 | for (_Fields field : EnumSet.allOf(_Fields.class)) { 1300 | byName.put(field.getFieldName(), field); 1301 | } 1302 | } 1303 | 1304 | /** 1305 | * Find the _Fields constant that matches fieldId, or null if its not found. 1306 | */ 1307 | public static _Fields findByThriftId(int fieldId) { 1308 | switch(fieldId) { 1309 | case 1: // A 1310 | return A; 1311 | case 2: // B 1312 | return B; 1313 | default: 1314 | return null; 1315 | } 1316 | } 1317 | 1318 | /** 1319 | * Find the _Fields constant that matches fieldId, throwing an exception 1320 | * if it is not found. 1321 | */ 1322 | public static _Fields findByThriftIdOrThrow(int fieldId) { 1323 | _Fields fields = findByThriftId(fieldId); 1324 | if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); 1325 | return fields; 1326 | } 1327 | 1328 | /** 1329 | * Find the _Fields constant that matches name, or null if its not found. 1330 | */ 1331 | public static _Fields findByName(String name) { 1332 | return byName.get(name); 1333 | } 1334 | 1335 | private final short _thriftId; 1336 | private final String _fieldName; 1337 | 1338 | _Fields(short thriftId, String fieldName) { 1339 | _thriftId = thriftId; 1340 | _fieldName = fieldName; 1341 | } 1342 | 1343 | public short getThriftFieldId() { 1344 | return _thriftId; 1345 | } 1346 | 1347 | public String getFieldName() { 1348 | return _fieldName; 1349 | } 1350 | } 1351 | 1352 | // isset id assignments 1353 | private static final int __A_ISSET_ID = 0; 1354 | private static final int __B_ISSET_ID = 1; 1355 | private BitSet __isset_bit_vector = new BitSet(2); 1356 | 1357 | public static final Map<_Fields, FieldMetaData> metaDataMap; 1358 | static { 1359 | Map<_Fields, FieldMetaData> tmpMap = new EnumMap<_Fields, FieldMetaData>(_Fields.class); 1360 | tmpMap.put(_Fields.A, new FieldMetaData("a", TFieldRequirementType.DEFAULT, 1361 | new FieldValueMetaData(TType.I32))); 1362 | tmpMap.put(_Fields.B, new FieldMetaData("b", TFieldRequirementType.DEFAULT, 1363 | new FieldValueMetaData(TType.I32))); 1364 | metaDataMap = Collections.unmodifiableMap(tmpMap); 1365 | FieldMetaData.addStructMetaDataMap(add_args.class, metaDataMap); 1366 | } 1367 | 1368 | public add_args() { 1369 | } 1370 | 1371 | public add_args( 1372 | int a, 1373 | int b) 1374 | { 1375 | this(); 1376 | this.a = a; 1377 | setAIsSet(true); 1378 | this.b = b; 1379 | setBIsSet(true); 1380 | } 1381 | 1382 | /** 1383 | * Performs a deep copy on other. 1384 | */ 1385 | public add_args(add_args other) { 1386 | __isset_bit_vector.clear(); 1387 | __isset_bit_vector.or(other.__isset_bit_vector); 1388 | this.a = other.a; 1389 | this.b = other.b; 1390 | } 1391 | 1392 | public add_args deepCopy() { 1393 | return new add_args(this); 1394 | } 1395 | 1396 | @Override 1397 | public void clear() { 1398 | setAIsSet(false); 1399 | this.a = 0; 1400 | setBIsSet(false); 1401 | this.b = 0; 1402 | } 1403 | 1404 | public int getA() { 1405 | return this.a; 1406 | } 1407 | 1408 | public add_args setA(int a) { 1409 | this.a = a; 1410 | setAIsSet(true); 1411 | return this; 1412 | } 1413 | 1414 | public void unsetA() { 1415 | __isset_bit_vector.clear(__A_ISSET_ID); 1416 | } 1417 | 1418 | /** Returns true if field a is set (has been asigned a value) and false otherwise */ 1419 | public boolean isSetA() { 1420 | return __isset_bit_vector.get(__A_ISSET_ID); 1421 | } 1422 | 1423 | public void setAIsSet(boolean value) { 1424 | __isset_bit_vector.set(__A_ISSET_ID, value); 1425 | } 1426 | 1427 | public int getB() { 1428 | return this.b; 1429 | } 1430 | 1431 | public add_args setB(int b) { 1432 | this.b = b; 1433 | setBIsSet(true); 1434 | return this; 1435 | } 1436 | 1437 | public void unsetB() { 1438 | __isset_bit_vector.clear(__B_ISSET_ID); 1439 | } 1440 | 1441 | /** Returns true if field b is set (has been asigned a value) and false otherwise */ 1442 | public boolean isSetB() { 1443 | return __isset_bit_vector.get(__B_ISSET_ID); 1444 | } 1445 | 1446 | public void setBIsSet(boolean value) { 1447 | __isset_bit_vector.set(__B_ISSET_ID, value); 1448 | } 1449 | 1450 | public void setFieldValue(_Fields field, Object value) { 1451 | switch (field) { 1452 | case A: 1453 | if (value == null) { 1454 | unsetA(); 1455 | } else { 1456 | setA((Integer)value); 1457 | } 1458 | break; 1459 | 1460 | case B: 1461 | if (value == null) { 1462 | unsetB(); 1463 | } else { 1464 | setB((Integer)value); 1465 | } 1466 | break; 1467 | 1468 | } 1469 | } 1470 | 1471 | public Object getFieldValue(_Fields field) { 1472 | switch (field) { 1473 | case A: 1474 | return new Integer(getA()); 1475 | 1476 | case B: 1477 | return new Integer(getB()); 1478 | 1479 | } 1480 | throw new IllegalStateException(); 1481 | } 1482 | 1483 | /** Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise */ 1484 | public boolean isSet(_Fields field) { 1485 | if (field == null) { 1486 | throw new IllegalArgumentException(); 1487 | } 1488 | 1489 | switch (field) { 1490 | case A: 1491 | return isSetA(); 1492 | case B: 1493 | return isSetB(); 1494 | } 1495 | throw new IllegalStateException(); 1496 | } 1497 | 1498 | @Override 1499 | public boolean equals(Object that) { 1500 | if (that == null) 1501 | return false; 1502 | if (that instanceof add_args) 1503 | return this.equals((add_args)that); 1504 | return false; 1505 | } 1506 | 1507 | public boolean equals(add_args that) { 1508 | if (that == null) 1509 | return false; 1510 | 1511 | boolean this_present_a = true; 1512 | boolean that_present_a = true; 1513 | if (this_present_a || that_present_a) { 1514 | if (!(this_present_a && that_present_a)) 1515 | return false; 1516 | if (this.a != that.a) 1517 | return false; 1518 | } 1519 | 1520 | boolean this_present_b = true; 1521 | boolean that_present_b = true; 1522 | if (this_present_b || that_present_b) { 1523 | if (!(this_present_b && that_present_b)) 1524 | return false; 1525 | if (this.b != that.b) 1526 | return false; 1527 | } 1528 | 1529 | return true; 1530 | } 1531 | 1532 | @Override 1533 | public int hashCode() { 1534 | return 0; 1535 | } 1536 | 1537 | public int compareTo(add_args other) { 1538 | if (!getClass().equals(other.getClass())) { 1539 | return getClass().getName().compareTo(other.getClass().getName()); 1540 | } 1541 | 1542 | int lastComparison = 0; 1543 | add_args typedOther = (add_args)other; 1544 | 1545 | lastComparison = Boolean.valueOf(isSetA()).compareTo(typedOther.isSetA()); 1546 | if (lastComparison != 0) { 1547 | return lastComparison; 1548 | } 1549 | if (isSetA()) { 1550 | lastComparison = TBaseHelper.compareTo(this.a, typedOther.a); 1551 | if (lastComparison != 0) { 1552 | return lastComparison; 1553 | } 1554 | } 1555 | lastComparison = Boolean.valueOf(isSetB()).compareTo(typedOther.isSetB()); 1556 | if (lastComparison != 0) { 1557 | return lastComparison; 1558 | } 1559 | if (isSetB()) { 1560 | lastComparison = TBaseHelper.compareTo(this.b, typedOther.b); 1561 | if (lastComparison != 0) { 1562 | return lastComparison; 1563 | } 1564 | } 1565 | return 0; 1566 | } 1567 | 1568 | public _Fields fieldForId(int fieldId) { 1569 | return _Fields.findByThriftId(fieldId); 1570 | } 1571 | 1572 | public void read(TProtocol iprot) throws TException { 1573 | TField field; 1574 | iprot.readStructBegin(); 1575 | while (true) 1576 | { 1577 | field = iprot.readFieldBegin(); 1578 | if (field.type == TType.STOP) { 1579 | break; 1580 | } 1581 | switch (field.id) { 1582 | case 1: // A 1583 | if (field.type == TType.I32) { 1584 | this.a = iprot.readI32(); 1585 | setAIsSet(true); 1586 | } else { 1587 | TProtocolUtil.skip(iprot, field.type); 1588 | } 1589 | break; 1590 | case 2: // B 1591 | if (field.type == TType.I32) { 1592 | this.b = iprot.readI32(); 1593 | setBIsSet(true); 1594 | } else { 1595 | TProtocolUtil.skip(iprot, field.type); 1596 | } 1597 | break; 1598 | default: 1599 | TProtocolUtil.skip(iprot, field.type); 1600 | } 1601 | iprot.readFieldEnd(); 1602 | } 1603 | iprot.readStructEnd(); 1604 | 1605 | // check for required fields of primitive type, which can't be checked in the validate method 1606 | validate(); 1607 | } 1608 | 1609 | public void write(TProtocol oprot) throws TException { 1610 | validate(); 1611 | 1612 | oprot.writeStructBegin(STRUCT_DESC); 1613 | oprot.writeFieldBegin(A_FIELD_DESC); 1614 | oprot.writeI32(this.a); 1615 | oprot.writeFieldEnd(); 1616 | oprot.writeFieldBegin(B_FIELD_DESC); 1617 | oprot.writeI32(this.b); 1618 | oprot.writeFieldEnd(); 1619 | oprot.writeFieldStop(); 1620 | oprot.writeStructEnd(); 1621 | } 1622 | 1623 | @Override 1624 | public String toString() { 1625 | StringBuilder sb = new StringBuilder("add_args("); 1626 | boolean first = true; 1627 | 1628 | sb.append("a:"); 1629 | sb.append(this.a); 1630 | first = false; 1631 | if (!first) sb.append(", "); 1632 | sb.append("b:"); 1633 | sb.append(this.b); 1634 | first = false; 1635 | sb.append(")"); 1636 | return sb.toString(); 1637 | } 1638 | 1639 | public void validate() throws TException { 1640 | // check for required fields 1641 | } 1642 | 1643 | } 1644 | 1645 | public static class add_result implements TBase, java.io.Serializable, Cloneable { 1646 | private static final TStruct STRUCT_DESC = new TStruct("add_result"); 1647 | 1648 | private static final TField SUCCESS_FIELD_DESC = new TField("success", TType.I32, (short)0); 1649 | 1650 | public int success; 1651 | 1652 | /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ 1653 | public enum _Fields implements TFieldIdEnum { 1654 | SUCCESS((short)0, "success"); 1655 | 1656 | private static final Map byName = new HashMap(); 1657 | 1658 | static { 1659 | for (_Fields field : EnumSet.allOf(_Fields.class)) { 1660 | byName.put(field.getFieldName(), field); 1661 | } 1662 | } 1663 | 1664 | /** 1665 | * Find the _Fields constant that matches fieldId, or null if its not found. 1666 | */ 1667 | public static _Fields findByThriftId(int fieldId) { 1668 | switch(fieldId) { 1669 | case 0: // SUCCESS 1670 | return SUCCESS; 1671 | default: 1672 | return null; 1673 | } 1674 | } 1675 | 1676 | /** 1677 | * Find the _Fields constant that matches fieldId, throwing an exception 1678 | * if it is not found. 1679 | */ 1680 | public static _Fields findByThriftIdOrThrow(int fieldId) { 1681 | _Fields fields = findByThriftId(fieldId); 1682 | if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); 1683 | return fields; 1684 | } 1685 | 1686 | /** 1687 | * Find the _Fields constant that matches name, or null if its not found. 1688 | */ 1689 | public static _Fields findByName(String name) { 1690 | return byName.get(name); 1691 | } 1692 | 1693 | private final short _thriftId; 1694 | private final String _fieldName; 1695 | 1696 | _Fields(short thriftId, String fieldName) { 1697 | _thriftId = thriftId; 1698 | _fieldName = fieldName; 1699 | } 1700 | 1701 | public short getThriftFieldId() { 1702 | return _thriftId; 1703 | } 1704 | 1705 | public String getFieldName() { 1706 | return _fieldName; 1707 | } 1708 | } 1709 | 1710 | // isset id assignments 1711 | private static final int __SUCCESS_ISSET_ID = 0; 1712 | private BitSet __isset_bit_vector = new BitSet(1); 1713 | 1714 | public static final Map<_Fields, FieldMetaData> metaDataMap; 1715 | static { 1716 | Map<_Fields, FieldMetaData> tmpMap = new EnumMap<_Fields, FieldMetaData>(_Fields.class); 1717 | tmpMap.put(_Fields.SUCCESS, new FieldMetaData("success", TFieldRequirementType.DEFAULT, 1718 | new FieldValueMetaData(TType.I32))); 1719 | metaDataMap = Collections.unmodifiableMap(tmpMap); 1720 | FieldMetaData.addStructMetaDataMap(add_result.class, metaDataMap); 1721 | } 1722 | 1723 | public add_result() { 1724 | } 1725 | 1726 | public add_result( 1727 | int success) 1728 | { 1729 | this(); 1730 | this.success = success; 1731 | setSuccessIsSet(true); 1732 | } 1733 | 1734 | /** 1735 | * Performs a deep copy on other. 1736 | */ 1737 | public add_result(add_result other) { 1738 | __isset_bit_vector.clear(); 1739 | __isset_bit_vector.or(other.__isset_bit_vector); 1740 | this.success = other.success; 1741 | } 1742 | 1743 | public add_result deepCopy() { 1744 | return new add_result(this); 1745 | } 1746 | 1747 | @Override 1748 | public void clear() { 1749 | setSuccessIsSet(false); 1750 | this.success = 0; 1751 | } 1752 | 1753 | public int getSuccess() { 1754 | return this.success; 1755 | } 1756 | 1757 | public add_result setSuccess(int success) { 1758 | this.success = success; 1759 | setSuccessIsSet(true); 1760 | return this; 1761 | } 1762 | 1763 | public void unsetSuccess() { 1764 | __isset_bit_vector.clear(__SUCCESS_ISSET_ID); 1765 | } 1766 | 1767 | /** Returns true if field success is set (has been asigned a value) and false otherwise */ 1768 | public boolean isSetSuccess() { 1769 | return __isset_bit_vector.get(__SUCCESS_ISSET_ID); 1770 | } 1771 | 1772 | public void setSuccessIsSet(boolean value) { 1773 | __isset_bit_vector.set(__SUCCESS_ISSET_ID, value); 1774 | } 1775 | 1776 | public void setFieldValue(_Fields field, Object value) { 1777 | switch (field) { 1778 | case SUCCESS: 1779 | if (value == null) { 1780 | unsetSuccess(); 1781 | } else { 1782 | setSuccess((Integer)value); 1783 | } 1784 | break; 1785 | 1786 | } 1787 | } 1788 | 1789 | public Object getFieldValue(_Fields field) { 1790 | switch (field) { 1791 | case SUCCESS: 1792 | return new Integer(getSuccess()); 1793 | 1794 | } 1795 | throw new IllegalStateException(); 1796 | } 1797 | 1798 | /** Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise */ 1799 | public boolean isSet(_Fields field) { 1800 | if (field == null) { 1801 | throw new IllegalArgumentException(); 1802 | } 1803 | 1804 | switch (field) { 1805 | case SUCCESS: 1806 | return isSetSuccess(); 1807 | } 1808 | throw new IllegalStateException(); 1809 | } 1810 | 1811 | @Override 1812 | public boolean equals(Object that) { 1813 | if (that == null) 1814 | return false; 1815 | if (that instanceof add_result) 1816 | return this.equals((add_result)that); 1817 | return false; 1818 | } 1819 | 1820 | public boolean equals(add_result that) { 1821 | if (that == null) 1822 | return false; 1823 | 1824 | boolean this_present_success = true; 1825 | boolean that_present_success = true; 1826 | if (this_present_success || that_present_success) { 1827 | if (!(this_present_success && that_present_success)) 1828 | return false; 1829 | if (this.success != that.success) 1830 | return false; 1831 | } 1832 | 1833 | return true; 1834 | } 1835 | 1836 | @Override 1837 | public int hashCode() { 1838 | return 0; 1839 | } 1840 | 1841 | public int compareTo(add_result other) { 1842 | if (!getClass().equals(other.getClass())) { 1843 | return getClass().getName().compareTo(other.getClass().getName()); 1844 | } 1845 | 1846 | int lastComparison = 0; 1847 | add_result typedOther = (add_result)other; 1848 | 1849 | lastComparison = Boolean.valueOf(isSetSuccess()).compareTo(typedOther.isSetSuccess()); 1850 | if (lastComparison != 0) { 1851 | return lastComparison; 1852 | } 1853 | if (isSetSuccess()) { 1854 | lastComparison = TBaseHelper.compareTo(this.success, typedOther.success); 1855 | if (lastComparison != 0) { 1856 | return lastComparison; 1857 | } 1858 | } 1859 | return 0; 1860 | } 1861 | 1862 | public _Fields fieldForId(int fieldId) { 1863 | return _Fields.findByThriftId(fieldId); 1864 | } 1865 | 1866 | public void read(TProtocol iprot) throws TException { 1867 | TField field; 1868 | iprot.readStructBegin(); 1869 | while (true) 1870 | { 1871 | field = iprot.readFieldBegin(); 1872 | if (field.type == TType.STOP) { 1873 | break; 1874 | } 1875 | switch (field.id) { 1876 | case 0: // SUCCESS 1877 | if (field.type == TType.I32) { 1878 | this.success = iprot.readI32(); 1879 | setSuccessIsSet(true); 1880 | } else { 1881 | TProtocolUtil.skip(iprot, field.type); 1882 | } 1883 | break; 1884 | default: 1885 | TProtocolUtil.skip(iprot, field.type); 1886 | } 1887 | iprot.readFieldEnd(); 1888 | } 1889 | iprot.readStructEnd(); 1890 | 1891 | // check for required fields of primitive type, which can't be checked in the validate method 1892 | validate(); 1893 | } 1894 | 1895 | public void write(TProtocol oprot) throws TException { 1896 | oprot.writeStructBegin(STRUCT_DESC); 1897 | 1898 | if (this.isSetSuccess()) { 1899 | oprot.writeFieldBegin(SUCCESS_FIELD_DESC); 1900 | oprot.writeI32(this.success); 1901 | oprot.writeFieldEnd(); 1902 | } 1903 | oprot.writeFieldStop(); 1904 | oprot.writeStructEnd(); 1905 | } 1906 | 1907 | @Override 1908 | public String toString() { 1909 | StringBuilder sb = new StringBuilder("add_result("); 1910 | boolean first = true; 1911 | 1912 | sb.append("success:"); 1913 | sb.append(this.success); 1914 | first = false; 1915 | sb.append(")"); 1916 | return sb.toString(); 1917 | } 1918 | 1919 | public void validate() throws TException { 1920 | // check for required fields 1921 | } 1922 | 1923 | } 1924 | 1925 | public static class blocking_call_args implements TBase, java.io.Serializable, Cloneable { 1926 | private static final TStruct STRUCT_DESC = new TStruct("blocking_call_args"); 1927 | 1928 | 1929 | 1930 | /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ 1931 | public enum _Fields implements TFieldIdEnum { 1932 | ; 1933 | 1934 | private static final Map byName = new HashMap(); 1935 | 1936 | static { 1937 | for (_Fields field : EnumSet.allOf(_Fields.class)) { 1938 | byName.put(field.getFieldName(), field); 1939 | } 1940 | } 1941 | 1942 | /** 1943 | * Find the _Fields constant that matches fieldId, or null if its not found. 1944 | */ 1945 | public static _Fields findByThriftId(int fieldId) { 1946 | switch(fieldId) { 1947 | default: 1948 | return null; 1949 | } 1950 | } 1951 | 1952 | /** 1953 | * Find the _Fields constant that matches fieldId, throwing an exception 1954 | * if it is not found. 1955 | */ 1956 | public static _Fields findByThriftIdOrThrow(int fieldId) { 1957 | _Fields fields = findByThriftId(fieldId); 1958 | if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); 1959 | return fields; 1960 | } 1961 | 1962 | /** 1963 | * Find the _Fields constant that matches name, or null if its not found. 1964 | */ 1965 | public static _Fields findByName(String name) { 1966 | return byName.get(name); 1967 | } 1968 | 1969 | private final short _thriftId; 1970 | private final String _fieldName; 1971 | 1972 | _Fields(short thriftId, String fieldName) { 1973 | _thriftId = thriftId; 1974 | _fieldName = fieldName; 1975 | } 1976 | 1977 | public short getThriftFieldId() { 1978 | return _thriftId; 1979 | } 1980 | 1981 | public String getFieldName() { 1982 | return _fieldName; 1983 | } 1984 | } 1985 | public static final Map<_Fields, FieldMetaData> metaDataMap; 1986 | static { 1987 | Map<_Fields, FieldMetaData> tmpMap = new EnumMap<_Fields, FieldMetaData>(_Fields.class); 1988 | metaDataMap = Collections.unmodifiableMap(tmpMap); 1989 | FieldMetaData.addStructMetaDataMap(blocking_call_args.class, metaDataMap); 1990 | } 1991 | 1992 | public blocking_call_args() { 1993 | } 1994 | 1995 | /** 1996 | * Performs a deep copy on other. 1997 | */ 1998 | public blocking_call_args(blocking_call_args other) { 1999 | } 2000 | 2001 | public blocking_call_args deepCopy() { 2002 | return new blocking_call_args(this); 2003 | } 2004 | 2005 | @Override 2006 | public void clear() { 2007 | } 2008 | 2009 | public void setFieldValue(_Fields field, Object value) { 2010 | switch (field) { 2011 | } 2012 | } 2013 | 2014 | public Object getFieldValue(_Fields field) { 2015 | switch (field) { 2016 | } 2017 | throw new IllegalStateException(); 2018 | } 2019 | 2020 | /** Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise */ 2021 | public boolean isSet(_Fields field) { 2022 | if (field == null) { 2023 | throw new IllegalArgumentException(); 2024 | } 2025 | 2026 | switch (field) { 2027 | } 2028 | throw new IllegalStateException(); 2029 | } 2030 | 2031 | @Override 2032 | public boolean equals(Object that) { 2033 | if (that == null) 2034 | return false; 2035 | if (that instanceof blocking_call_args) 2036 | return this.equals((blocking_call_args)that); 2037 | return false; 2038 | } 2039 | 2040 | public boolean equals(blocking_call_args that) { 2041 | if (that == null) 2042 | return false; 2043 | 2044 | return true; 2045 | } 2046 | 2047 | @Override 2048 | public int hashCode() { 2049 | return 0; 2050 | } 2051 | 2052 | public int compareTo(blocking_call_args other) { 2053 | if (!getClass().equals(other.getClass())) { 2054 | return getClass().getName().compareTo(other.getClass().getName()); 2055 | } 2056 | 2057 | int lastComparison = 0; 2058 | blocking_call_args typedOther = (blocking_call_args)other; 2059 | 2060 | return 0; 2061 | } 2062 | 2063 | public _Fields fieldForId(int fieldId) { 2064 | return _Fields.findByThriftId(fieldId); 2065 | } 2066 | 2067 | public void read(TProtocol iprot) throws TException { 2068 | TField field; 2069 | iprot.readStructBegin(); 2070 | while (true) 2071 | { 2072 | field = iprot.readFieldBegin(); 2073 | if (field.type == TType.STOP) { 2074 | break; 2075 | } 2076 | switch (field.id) { 2077 | default: 2078 | TProtocolUtil.skip(iprot, field.type); 2079 | } 2080 | iprot.readFieldEnd(); 2081 | } 2082 | iprot.readStructEnd(); 2083 | 2084 | // check for required fields of primitive type, which can't be checked in the validate method 2085 | validate(); 2086 | } 2087 | 2088 | public void write(TProtocol oprot) throws TException { 2089 | validate(); 2090 | 2091 | oprot.writeStructBegin(STRUCT_DESC); 2092 | oprot.writeFieldStop(); 2093 | oprot.writeStructEnd(); 2094 | } 2095 | 2096 | @Override 2097 | public String toString() { 2098 | StringBuilder sb = new StringBuilder("blocking_call_args("); 2099 | boolean first = true; 2100 | 2101 | sb.append(")"); 2102 | return sb.toString(); 2103 | } 2104 | 2105 | public void validate() throws TException { 2106 | // check for required fields 2107 | } 2108 | 2109 | } 2110 | 2111 | public static class blocking_call_result implements TBase, java.io.Serializable, Cloneable { 2112 | private static final TStruct STRUCT_DESC = new TStruct("blocking_call_result"); 2113 | 2114 | private static final TField SUCCESS_FIELD_DESC = new TField("success", TType.I32, (short)0); 2115 | 2116 | public int success; 2117 | 2118 | /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ 2119 | public enum _Fields implements TFieldIdEnum { 2120 | SUCCESS((short)0, "success"); 2121 | 2122 | private static final Map byName = new HashMap(); 2123 | 2124 | static { 2125 | for (_Fields field : EnumSet.allOf(_Fields.class)) { 2126 | byName.put(field.getFieldName(), field); 2127 | } 2128 | } 2129 | 2130 | /** 2131 | * Find the _Fields constant that matches fieldId, or null if its not found. 2132 | */ 2133 | public static _Fields findByThriftId(int fieldId) { 2134 | switch(fieldId) { 2135 | case 0: // SUCCESS 2136 | return SUCCESS; 2137 | default: 2138 | return null; 2139 | } 2140 | } 2141 | 2142 | /** 2143 | * Find the _Fields constant that matches fieldId, throwing an exception 2144 | * if it is not found. 2145 | */ 2146 | public static _Fields findByThriftIdOrThrow(int fieldId) { 2147 | _Fields fields = findByThriftId(fieldId); 2148 | if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); 2149 | return fields; 2150 | } 2151 | 2152 | /** 2153 | * Find the _Fields constant that matches name, or null if its not found. 2154 | */ 2155 | public static _Fields findByName(String name) { 2156 | return byName.get(name); 2157 | } 2158 | 2159 | private final short _thriftId; 2160 | private final String _fieldName; 2161 | 2162 | _Fields(short thriftId, String fieldName) { 2163 | _thriftId = thriftId; 2164 | _fieldName = fieldName; 2165 | } 2166 | 2167 | public short getThriftFieldId() { 2168 | return _thriftId; 2169 | } 2170 | 2171 | public String getFieldName() { 2172 | return _fieldName; 2173 | } 2174 | } 2175 | 2176 | // isset id assignments 2177 | private static final int __SUCCESS_ISSET_ID = 0; 2178 | private BitSet __isset_bit_vector = new BitSet(1); 2179 | 2180 | public static final Map<_Fields, FieldMetaData> metaDataMap; 2181 | static { 2182 | Map<_Fields, FieldMetaData> tmpMap = new EnumMap<_Fields, FieldMetaData>(_Fields.class); 2183 | tmpMap.put(_Fields.SUCCESS, new FieldMetaData("success", TFieldRequirementType.DEFAULT, 2184 | new FieldValueMetaData(TType.I32))); 2185 | metaDataMap = Collections.unmodifiableMap(tmpMap); 2186 | FieldMetaData.addStructMetaDataMap(blocking_call_result.class, metaDataMap); 2187 | } 2188 | 2189 | public blocking_call_result() { 2190 | } 2191 | 2192 | public blocking_call_result( 2193 | int success) 2194 | { 2195 | this(); 2196 | this.success = success; 2197 | setSuccessIsSet(true); 2198 | } 2199 | 2200 | /** 2201 | * Performs a deep copy on other. 2202 | */ 2203 | public blocking_call_result(blocking_call_result other) { 2204 | __isset_bit_vector.clear(); 2205 | __isset_bit_vector.or(other.__isset_bit_vector); 2206 | this.success = other.success; 2207 | } 2208 | 2209 | public blocking_call_result deepCopy() { 2210 | return new blocking_call_result(this); 2211 | } 2212 | 2213 | @Override 2214 | public void clear() { 2215 | setSuccessIsSet(false); 2216 | this.success = 0; 2217 | } 2218 | 2219 | public int getSuccess() { 2220 | return this.success; 2221 | } 2222 | 2223 | public blocking_call_result setSuccess(int success) { 2224 | this.success = success; 2225 | setSuccessIsSet(true); 2226 | return this; 2227 | } 2228 | 2229 | public void unsetSuccess() { 2230 | __isset_bit_vector.clear(__SUCCESS_ISSET_ID); 2231 | } 2232 | 2233 | /** Returns true if field success is set (has been asigned a value) and false otherwise */ 2234 | public boolean isSetSuccess() { 2235 | return __isset_bit_vector.get(__SUCCESS_ISSET_ID); 2236 | } 2237 | 2238 | public void setSuccessIsSet(boolean value) { 2239 | __isset_bit_vector.set(__SUCCESS_ISSET_ID, value); 2240 | } 2241 | 2242 | public void setFieldValue(_Fields field, Object value) { 2243 | switch (field) { 2244 | case SUCCESS: 2245 | if (value == null) { 2246 | unsetSuccess(); 2247 | } else { 2248 | setSuccess((Integer)value); 2249 | } 2250 | break; 2251 | 2252 | } 2253 | } 2254 | 2255 | public Object getFieldValue(_Fields field) { 2256 | switch (field) { 2257 | case SUCCESS: 2258 | return new Integer(getSuccess()); 2259 | 2260 | } 2261 | throw new IllegalStateException(); 2262 | } 2263 | 2264 | /** Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise */ 2265 | public boolean isSet(_Fields field) { 2266 | if (field == null) { 2267 | throw new IllegalArgumentException(); 2268 | } 2269 | 2270 | switch (field) { 2271 | case SUCCESS: 2272 | return isSetSuccess(); 2273 | } 2274 | throw new IllegalStateException(); 2275 | } 2276 | 2277 | @Override 2278 | public boolean equals(Object that) { 2279 | if (that == null) 2280 | return false; 2281 | if (that instanceof blocking_call_result) 2282 | return this.equals((blocking_call_result)that); 2283 | return false; 2284 | } 2285 | 2286 | public boolean equals(blocking_call_result that) { 2287 | if (that == null) 2288 | return false; 2289 | 2290 | boolean this_present_success = true; 2291 | boolean that_present_success = true; 2292 | if (this_present_success || that_present_success) { 2293 | if (!(this_present_success && that_present_success)) 2294 | return false; 2295 | if (this.success != that.success) 2296 | return false; 2297 | } 2298 | 2299 | return true; 2300 | } 2301 | 2302 | @Override 2303 | public int hashCode() { 2304 | return 0; 2305 | } 2306 | 2307 | public int compareTo(blocking_call_result other) { 2308 | if (!getClass().equals(other.getClass())) { 2309 | return getClass().getName().compareTo(other.getClass().getName()); 2310 | } 2311 | 2312 | int lastComparison = 0; 2313 | blocking_call_result typedOther = (blocking_call_result)other; 2314 | 2315 | lastComparison = Boolean.valueOf(isSetSuccess()).compareTo(typedOther.isSetSuccess()); 2316 | if (lastComparison != 0) { 2317 | return lastComparison; 2318 | } 2319 | if (isSetSuccess()) { 2320 | lastComparison = TBaseHelper.compareTo(this.success, typedOther.success); 2321 | if (lastComparison != 0) { 2322 | return lastComparison; 2323 | } 2324 | } 2325 | return 0; 2326 | } 2327 | 2328 | public _Fields fieldForId(int fieldId) { 2329 | return _Fields.findByThriftId(fieldId); 2330 | } 2331 | 2332 | public void read(TProtocol iprot) throws TException { 2333 | TField field; 2334 | iprot.readStructBegin(); 2335 | while (true) 2336 | { 2337 | field = iprot.readFieldBegin(); 2338 | if (field.type == TType.STOP) { 2339 | break; 2340 | } 2341 | switch (field.id) { 2342 | case 0: // SUCCESS 2343 | if (field.type == TType.I32) { 2344 | this.success = iprot.readI32(); 2345 | setSuccessIsSet(true); 2346 | } else { 2347 | TProtocolUtil.skip(iprot, field.type); 2348 | } 2349 | break; 2350 | default: 2351 | TProtocolUtil.skip(iprot, field.type); 2352 | } 2353 | iprot.readFieldEnd(); 2354 | } 2355 | iprot.readStructEnd(); 2356 | 2357 | // check for required fields of primitive type, which can't be checked in the validate method 2358 | validate(); 2359 | } 2360 | 2361 | public void write(TProtocol oprot) throws TException { 2362 | oprot.writeStructBegin(STRUCT_DESC); 2363 | 2364 | if (this.isSetSuccess()) { 2365 | oprot.writeFieldBegin(SUCCESS_FIELD_DESC); 2366 | oprot.writeI32(this.success); 2367 | oprot.writeFieldEnd(); 2368 | } 2369 | oprot.writeFieldStop(); 2370 | oprot.writeStructEnd(); 2371 | } 2372 | 2373 | @Override 2374 | public String toString() { 2375 | StringBuilder sb = new StringBuilder("blocking_call_result("); 2376 | boolean first = true; 2377 | 2378 | sb.append("success:"); 2379 | sb.append(this.success); 2380 | first = false; 2381 | sb.append(")"); 2382 | return sb.toString(); 2383 | } 2384 | 2385 | public void validate() throws TException { 2386 | // check for required fields 2387 | } 2388 | 2389 | } 2390 | 2391 | } 2392 | --------------------------------------------------------------------------------