public Future<byte[]> apply(byte[] request) { TTransport inputTransport = new TMemoryInputTransport(request); TProtocol iprot = protocolFactory.getProtocol(inputTransport); TMessage msg; try { msg = iprot.readMessageBegin(); } catch (Exception e) { return Future.exception(e); } Function2<TProtocol, Integer, Future<byte[]>> fn = functionMap.get(msg.name); if (fn == null) { try { TProtocolUtil.skip(iprot, TType.STRUCT); iprot.readMessageEnd(); TApplicationException x = new TApplicationException(TApplicationException.UNKNOWN_METHOD, "Invalid method name: '"+msg.name+"'"); TMemoryBuffer memoryBuffer = new TMemoryBuffer(512); TProtocol oprot = protocolFactory.getProtocol(memoryBuffer); oprot.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION, msg.seqid)); x.write(oprot); oprot.writeMessageEnd(); oprot.getTransport().flush(); return Future.value(Arrays.copyOfRange(memoryBuffer.getArray(), 0, memoryBuffer.length())); } catch (Exception e) { return Future.exception(e); } } return fn.apply(iprot, msg.seqid); } }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } return header.equals(((ThriftMessage) o).header); }
@Override public int hashCode() { return header.hashCode(); }
public boolean process(TProtocol iprot, TProtocol oprot) throws TException { TMessage msg = iprot.readMessageBegin(); ProcessFunction fn = processMap_.get(msg.name); if (fn == null) { TProtocolUtil.skip(iprot, TType.STRUCT); iprot.readMessageEnd(); TApplicationException x = new TApplicationException(TApplicationException.UNKNOWN_METHOD, "Invalid method name: '"+msg.name+"'"); oprot.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION, msg.seqid)); x.write(oprot); oprot.writeMessageEnd(); oprot.getTransport().flush(); return true; } fn.process(msg.seqid, iprot, oprot); return true; }
public Future<ServerInfo> handshake() { try { // TODO: size TMemoryBuffer __memoryTransport__ = new TMemoryBuffer(512); TProtocol __prot__ = this.protocolFactory.getProtocol(__memoryTransport__); __prot__.writeMessageBegin(new TMessage("handshake", TMessageType.CALL, 0)); handshake_args __args__ = new handshake_args(); __args__.write(__prot__); __prot__.writeMessageEnd(); byte[] __buffer__ = Arrays.copyOfRange(__memoryTransport__.getArray(), 0, __memoryTransport__.length()); ThriftClientRequest __request__ = new ThriftClientRequest(__buffer__, false); Future<byte[]> __done__ = this.service.apply(__request__); return __done__.flatMap(new Function<byte[], Future<ServerInfo>>() { public Future<ServerInfo> apply(byte[] __buffer__) { TMemoryInputTransport __memoryTransport__ = new TMemoryInputTransport(__buffer__); TProtocol __prot__ = ServiceToClient.this.protocolFactory.getProtocol(__memoryTransport__); try { return Future.value((new Client(__prot__)).recv_handshake()); } catch (Exception e) { return Future.exception(e); } } }); } catch (TException e) { return Future.exception(e); } } public Future<ServerInfo> handshakeWithClientInfo(ClientInfo clientInfo) {
public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("shutdown", org.apache.thrift.protocol.TMessageType.CALL, 0)); shutdown_args args = new shutdown_args(); args.write(prot); prot.writeMessageEnd(); }
public void send_handshake() throws TException { oprot_.writeMessageBegin(new TMessage("handshake", TMessageType.CALL, ++seqid_)); handshake_args args = new handshake_args(); args.write(oprot_); oprot_.writeMessageEnd(); oprot_.getTransport().flush(); }
} else { if (ctx.server().config().verboseResponses()) { appException = new TApplicationException( TApplicationException.INTERNAL_ERROR, "\n---- BEGIN server-side trace ----\n" + "---- END server-side trace ----"); } else { appException = new TApplicationException(TApplicationException.INTERNAL_ERROR); appException.initCause(cause); try { final TTransport transport = new TByteBufTransport(buf); final TProtocol outProto = ThriftProtocolFactories.get(serializationFormat).getProtocol(transport); final TMessage header = new TMessage(methodName, TMessageType.EXCEPTION, seqId); outProto.writeMessageBegin(header); appException.write(outProto); outProto.writeMessageEnd();
private void handleException(int seqid, TProtocol oprot) throws TException { if (!isOneway()) { TApplicationException x = new TApplicationException(TApplicationException.INTERNAL_ERROR, "Internal error processing " + getMethodName()); oprot.writeMessageBegin(new TMessage(getMethodName(), TMessageType.EXCEPTION, seqid)); x.write(oprot); oprot.writeMessageEnd(); oprot.getTransport().flush(); } }
protected void encodeRequest(Channel channel, ChannelBuffer buffer, Request request) throws IOException { Invocation invocation = (Invocation) request.getData(); TProtocol protocol = newProtocol(channel.getUrl(), buffer); try { protocol.writeMessageBegin(new TMessage( invocation.getMethodName(), TMessageType.CALL, thriftSeq.getAndIncrement())); protocol.writeStructBegin(new TStruct(invocation.getMethodName() + "_args")); for (int i = 0; i < invocation.getParameterTypes().length; i++) { Class<?> type = invocation.getParameterTypes()[i]; } } catch (TException e) { throw new IOException(e.getMessage(), e); } }
private static HttpData encodeSuccess(ServiceRequestContext ctx, RpcResponse reply, SerializationFormat serializationFormat, String methodName, int seqId, TBase<?, ?> result) { final ByteBuf buf = ctx.alloc().buffer(128); boolean success = false; try { final TTransport transport = new TByteBufTransport(buf); final TProtocol outProto = ThriftProtocolFactories.get(serializationFormat).getProtocol(transport); final TMessage header = new TMessage(methodName, TMessageType.REPLY, seqId); outProto.writeMessageBegin(header); result.write(outProto); outProto.writeMessageEnd(); ctx.logBuilder().responseContent(reply, new ThriftReply(header, result)); final HttpData encoded = new ByteBufHttpData(buf, false); success = true; return encoded; } catch (TException e) { throw new Error(e); // Should never reach here. } finally { if (!success) { buf.release(); } } }
applicationException = new TApplicationException(throwable.getMessage()); message = new TMessage(rd.methodName, TMessageType.EXCEPTION, rd.id); } else { message = new TMessage(rd.methodName, TMessageType.REPLY, rd.id); protocol.getTransport().flush(); headerLength = bos.size(); switch (message.type) { case TMessageType.EXCEPTION: applicationException.write(protocol); break; case TMessageType.REPLY: protocol.getTransport().flush(); int oldIndex = messageLength = bos.size();
public void process(int seqid, TProtocol iprot, TProtocol oprot) throws TException { write_args args = new write_args(); try { args.read(iprot); } catch (TProtocolException e) { iprot.readMessageEnd(); TApplicationException x = new TApplicationException(TApplicationException.PROTOCOL_ERROR, e.getMessage()); oprot.writeMessageBegin(new TMessage("write", TMessageType.EXCEPTION, seqid)); x.write(oprot); oprot.writeMessageEnd(); oprot.getTransport().flush(); return; } iprot.readMessageEnd(); write_result result = new write_result(); result.success = iface_.write(args.stream, args.data); oprot.writeMessageBegin(new TMessage("write", TMessageType.REPLY, seqid)); result.write(oprot); oprot.writeMessageEnd(); oprot.getTransport().flush(); } }
public Future<Void> setAcceptNewStream(boolean enabled) { try { // TODO: size TMemoryBuffer __memoryTransport__ = new TMemoryBuffer(512); TProtocol __prot__ = this.protocolFactory.getProtocol(__memoryTransport__); __prot__.writeMessageBegin(new TMessage("setAcceptNewStream", TMessageType.CALL, 0)); setAcceptNewStream_args __args__ = new setAcceptNewStream_args(); __args__.setEnabled(enabled); __args__.write(__prot__); __prot__.writeMessageEnd(); byte[] __buffer__ = Arrays.copyOfRange(__memoryTransport__.getArray(), 0, __memoryTransport__.length()); ThriftClientRequest __request__ = new ThriftClientRequest(__buffer__, false); Future<byte[]> __done__ = this.service.apply(__request__); return __done__.flatMap(new Function<byte[], Future<Void>>() { public Future<Void> apply(byte[] __buffer__) { TMemoryInputTransport __memoryTransport__ = new TMemoryInputTransport(__buffer__); TProtocol __prot__ = ServiceToClient.this.protocolFactory.getProtocol(__memoryTransport__); try { (new Client(__prot__)).recv_setAcceptNewStream(); return Future.value(null); } catch (Exception e) { return Future.exception(e); } } }); } catch (TException e) { return Future.exception(e); } } }
public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("resourcePoolGetAll", org.apache.thrift.protocol.TMessageType.CALL, 0)); resourcePoolGetAll_args args = new resourcePoolGetAll_args(); args.write(prot); prot.writeMessageEnd(); }
public void send_handshakeWithClientInfo(ClientInfo clientInfo) throws TException { oprot_.writeMessageBegin(new TMessage("handshakeWithClientInfo", TMessageType.CALL, ++seqid_)); handshakeWithClientInfo_args args = new handshakeWithClientInfo_args(); args.setClientInfo(clientInfo); args.write(oprot_); oprot_.writeMessageEnd(); oprot_.getTransport().flush(); }
protected void encodeRequest(Channel channel, ChannelBuffer buffer, Request request) throws IOException { Invocation invocation = (Invocation) request.getData(); TProtocol protocol = newProtocol(channel.getUrl(), buffer); try { protocol.writeMessageBegin(new TMessage( invocation.getMethodName(), TMessageType.CALL, thriftSeq.getAndIncrement())); protocol.writeStructBegin(new TStruct(invocation.getMethodName() + "_args")); for (int i = 0; i < invocation.getParameterTypes().length; i++) { Class<?> type = invocation.getParameterTypes()[i]; } } catch (TException e) { throw new IOException(e.getMessage(), e); } }
applicationException = new TApplicationException(throwable.getMessage()); message = new TMessage(rd.methodName, TMessageType.EXCEPTION, rd.id); } else { message = new TMessage(rd.methodName, TMessageType.REPLY, rd.id); protocol.getTransport().flush(); headerLength = bos.size(); switch (message.type) { case TMessageType.EXCEPTION: applicationException.write(protocol); break; case TMessageType.REPLY: protocol.getTransport().flush(); int oldIndex = messageLength = bos.size();