List of usage examples for org.apache.thrift.protocol TMessageType ONEWAY
byte ONEWAY
To view the source code for org.apache.thrift.protocol TMessageType ONEWAY.
Click Source Link
From source file:com.facebook.swift.service.ThriftServiceProcessor.java
License:Apache License
@Override @SuppressWarnings("PMD.EmptyCatchBlock") public ListenableFuture<Boolean> process(final TProtocol in, TProtocol out, RequestContext requestContext) throws TException { String methodName = null;//from ww w . ja v a 2 s .co m int sequenceId = 0; try { final SettableFuture<Boolean> resultFuture = SettableFuture.create(); TMessage message = in.readMessageBegin(); methodName = message.name; sequenceId = message.seqid; // lookup method ThriftMethodProcessor method = methods.get(methodName); if (method == null) { TProtocolUtil.skip(in, TType.STRUCT); createAndWriteApplicationException(out, requestContext, methodName, sequenceId, UNKNOWN_METHOD, "Invalid method name: '" + methodName + "'", null); return Futures.immediateFuture(true); } switch (message.type) { case TMessageType.CALL: case TMessageType.ONEWAY: // Ideally we'd check the message type here to make the presence/absence of // the "oneway" keyword annotating the method matches the message type. // Unfortunately most clients send both one-way and two-way messages as CALL // message type instead of using ONEWAY message type, and servers ignore the // difference. break; default: TProtocolUtil.skip(in, TType.STRUCT); createAndWriteApplicationException(out, requestContext, methodName, sequenceId, INVALID_MESSAGE_TYPE, "Received invalid message type " + message.type + " from client", null); return Futures.immediateFuture(true); } // invoke method final ContextChain context = new ContextChain(eventHandlers, method.getQualifiedName(), requestContext); ListenableFuture<Boolean> processResult = method.process(in, out, sequenceId, context); Futures.addCallback(processResult, new FutureCallback<Boolean>() { @Override public void onSuccess(Boolean result) { context.done(); resultFuture.set(result); } @Override public void onFailure(Throwable t) { LOG.error(t, "Failed to process method [" + method.getName() + "] of service [" + method.getServiceName() + "]"); context.done(); resultFuture.setException(t); } }); return resultFuture; } catch (TApplicationException e) { // If TApplicationException was thrown send it to the client. // This could happen if for example, some of event handlers method threw an exception. writeApplicationException(out, requestContext, methodName, sequenceId, e); return Futures.immediateFuture(true); } catch (Exception e) { return Futures.immediateFailedFuture(e); } }
From source file:com.linecorp.armeria.client.thrift.ThriftInvocation.java
License:Apache License
boolean isOneway() { return TMessageType.ONEWAY == tMessage.type; }
From source file:com.linecorp.armeria.client.thrift.ThriftMethod.java
License:Apache License
byte methodType() { return oneWay ? TMessageType.ONEWAY : TMessageType.CALL; }
From source file:com.linecorp.armeria.client.thrift.ThriftOverHttpClientTest.java
License:Apache License
@Test(timeout = 10000) public void testMessageLogsForOneWay() throws Exception { OnewayHelloService.Iface client = Clients.newClient(clientFactory(), getURI(Handlers.HELLO), Handlers.ONEWAYHELLO.iface(), clientOptions); recordMessageLogs = true;//from w w w. j a v a 2 s . c o m client.hello("trustin"); final RequestLog log = requestLogs.take(); assertThat(log.requestEnvelope()).isInstanceOf(HttpHeaders.class); assertThat(log.requestContent()).isInstanceOf(RpcRequest.class); assertThat(log.rawRequestContent()).isInstanceOf(ThriftCall.class); final RpcRequest request = (RpcRequest) log.requestContent(); assertThat(request.serviceType()).isEqualTo(OnewayHelloService.Iface.class); assertThat(request.method()).isEqualTo("hello"); assertThat(request.params()).containsExactly("trustin"); final ThriftCall rawRequest = (ThriftCall) log.rawRequestContent(); assertThat(rawRequest.header().type).isEqualTo(TMessageType.ONEWAY); assertThat(rawRequest.header().name).isEqualTo("hello"); assertThat(rawRequest.args()).isInstanceOf(OnewayHelloService.hello_args.class); assertThat(((OnewayHelloService.hello_args) rawRequest.args()).getName()).isEqualTo("trustin"); assertThat(log.responseEnvelope()).isInstanceOf(HttpHeaders.class); assertThat(log.responseContent()).isInstanceOf(RpcResponse.class); assertThat(log.rawResponseContent()).isNull(); final RpcResponse response = (RpcResponse) log.responseContent(); assertThat(response.get()).isNull(); }
From source file:com.linecorp.armeria.common.thrift.ApacheThriftCall.java
License:Apache License
/** * Creates a new instance that contains a Thrift {@link TMessageType#CALL} or {@link TMessageType#ONEWAY} * message./*w ww . ja v a2 s . c om*/ */ public ApacheThriftCall(TMessage header, TBase<?, ?> args) { super(header); if (header.type != TMessageType.CALL && header.type != TMessageType.ONEWAY) { throw new IllegalArgumentException( "header.type: " + typeStr(header.type) + " (expected: CALL or ONEWAY)"); } this.args = requireNonNull(args, "args"); }
From source file:com.linecorp.armeria.common.thrift.ApacheThriftMessage.java
License:Apache License
static String typeStr(byte type) { switch (type) { case TMessageType.CALL: return "CALL"; case TMessageType.ONEWAY: return "ONEWAY"; case TMessageType.REPLY: return "REPLY"; case TMessageType.EXCEPTION: return "EXCEPTION"; default:/* www. j a v a 2 s .c o m*/ return "UNKNOWN(" + (type & 0xFF) + ')'; } }
From source file:com.linecorp.armeria.common.thrift.text.TTextProtocolTest.java
License:Apache License
@Test public void rpcCall_oneWay() throws Exception { String request = "{\n" + " \"method\" : \"doDebug\",\n" + " \"type\" : \"ONEWAY\",\n" + " \"seqid\" : 1,\n" + " \"args\" : {\n" + " \"methodArg1\" : \"foo1\",\n" + " \"methodArg2\" : 200,\n" + " \"details\" : {\n" + " \"detailsArg1\" : \"foo2\",\n" + " \"detailsArg2\" : 100\n" + " }\n" + " }\n" + '}'; TTextProtocol prot = new TTextProtocol( new TIOStreamTransport(new ByteArrayInputStream(request.getBytes()))); TMessage header = prot.readMessageBegin(); doDebug_args args = new RpcDebugService.Processor.doDebug().getEmptyArgsInstance(); args.read(prot);/*from w w w . ja va 2s . c om*/ prot.readMessageEnd(); assertEquals("doDebug", header.name); assertEquals(TMessageType.ONEWAY, header.type); assertEquals(1, header.seqid); assertEquals("foo1", args.getMethodArg1()); assertEquals(200, args.getMethodArg2()); assertEquals("foo2", args.getDetails().getDetailsArg1()); assertEquals(100, args.getDetails().getDetailsArg2()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); prot = new TTextProtocol(new TIOStreamTransport(outputStream)); prot.writeMessageBegin(header); args.write(prot); prot.writeMessageEnd(); assertJsonEquals(request, new String(outputStream.toByteArray(), StandardCharsets.UTF_8)); }
From source file:com.linecorp.armeria.common.thrift.ThriftCall.java
License:Apache License
/** * Creates a new instance that contains a Thrift {@link TMessageType#CALL} or {@link TMessageType#ONEWAY} * message.//w w w. jav a2 s .c o m */ public ThriftCall(TMessage header, TBase<?, ?> args) { super(header); if (header.type != TMessageType.CALL && header.type != TMessageType.ONEWAY) { throw new IllegalArgumentException( "header.type: " + typeStr(header.type) + " (expected: CALL or ONEWAY)"); } this.args = requireNonNull(args, "args"); }
From source file:com.linecorp.armeria.internal.thrift.ThriftFunction.java
License:Apache License
/** * Returns the type of this function.//from w w w .j a v a 2 s . c om * * @return {@link TMessageType#CALL} or {@link TMessageType#ONEWAY} */ public byte messageType() { return isOneWay() ? TMessageType.ONEWAY : TMessageType.CALL; }
From source file:com.linecorp.armeria.server.logging.structured.StructuredLogJsonFormatTest.java
License:Apache License
@Test public void testSerializingOnewayFunctionCall() throws IOException { ApacheThriftStructuredLog log = buildLog( new ThriftCall(new TMessage(THRIFT_METHOD_NAME, TMessageType.ONEWAY, 0), new hello_args().setName("kawamuray")), null);/* w w w . j a v a 2s .c om*/ String actualJson = customObjectMapper.writeValueAsString(log); final String expectedJson = "{" + " \"timestampMillis\": 12345," + " \"responseTimeNanos\": 6789," + " \"requestSize\": 128," + " \"responseSize\": 512," + " \"thriftServiceName\": \"com.linecorp.armeria.service.test.thrift.main.HelloService\"," + " \"thriftMethodName\": \"hello\"," + " \"thriftCall\": {" + " \"header\": {" + " \"name\": \"hello\"," + " \"type\": 4," + " \"seqid\": 0" + " }," + " \"args\": {" + " \"name\": \"kawamuray\"" + " }" + " }," + " \"thriftReply\": null" + "}"; assertThatJson(actualJson).isEqualTo(expectedJson); }