Example usage for org.apache.thrift ProcessFunction getResult

List of usage examples for org.apache.thrift ProcessFunction getResult

Introduction

In this page you can find the example usage for org.apache.thrift ProcessFunction getResult.

Prototype

public abstract TBase getResult(I iface, T args) throws TException;

Source Link

Usage

From source file:com.linecorp.armeria.server.thrift.ThriftCallService.java

License:Apache License

private static void invokeSynchronously(ServiceRequestContext ctx, Object impl, ThriftFunction func,
        TBase<TBase<?, ?>, TFieldIdEnum> args, DefaultRpcResponse reply) {

    final ProcessFunction<Object, TBase<TBase<?, ?>, TFieldIdEnum>> f = func.syncFunc();
    ctx.blockingTaskExecutor().execute(() -> {
        if (reply.isDone()) {
            // Closed already most likely due to timeout.
            return;
        }/* w w  w  . j  a  v a  2  s  . c om*/

        try {
            @SuppressWarnings("unchecked")
            TBase<TBase<?, ?>, TFieldIdEnum> result = f.getResult(impl, args);
            if (func.isOneWay()) {
                reply.complete(null);
            } else {
                reply.complete(func.getResult(result));
            }
        } catch (Throwable t) {
            reply.completeExceptionally(t);
        }
    });
}

From source file:com.linecorp.armeria.server.thrift.ThriftServiceInvocationHandler.java

License:Apache License

private void invokeSynchronously(ThriftServiceInvocationContext ctx, Executor blockingTaskExecutor,
        Promise<Object> promise) {

    final ThriftFunction func = ctx.func;
    final ProcessFunction<Object, TBase<TBase<?, ?>, TFieldIdEnum>> f = func.syncFunc();
    try {//from   w w w. java2s  .  c  om
        blockingTaskExecutor.execute(() -> {
            if (promise.isDone()) {
                ctx.logger().warn("Promise is done already; not invoking: {}", promise);
                return;
            }

            ServiceInvocationContext.setCurrent(ctx);
            try {
                @SuppressWarnings("unchecked")
                TBase<TBase<?, ?>, TFieldIdEnum> result = f.getResult(service, ctx.args);
                if (func.isOneway()) {
                    result = null;
                }

                safeSetSuccess(ctx, promise, result);
            } catch (Throwable t) {
                safeSetFailure(ctx, promise, t);
            } finally {
                ServiceInvocationContext.removeCurrent();
            }
        });
    } catch (Throwable t) {
        promise.setFailure(t);
    }
}