Search in sources :

Example 1 with InvokeContext

use of com.alipay.sofa.jraft.rpc.InvokeContext in project sofa-jraft by sofastack.

the class DefaultRheaKVRpcService method internalCallAsyncWithRpc.

private <V> void internalCallAsyncWithRpc(final Endpoint endpoint, final BaseRequest request, final FailoverClosure<V> closure) {
    final InvokeContext invokeCtx = new InvokeContext();
    invokeCtx.put(BoltRpcClient.BOLT_CTX, ExtSerializerSupports.getInvokeContext());
    final InvokeCallback invokeCallback = new InvokeCallback() {

        @Override
        public void complete(final Object result, final Throwable err) {
            if (err == null) {
                final BaseResponse<?> response = (BaseResponse<?>) result;
                if (response.isSuccess()) {
                    closure.setData(response.getValue());
                    closure.run(Status.OK());
                } else {
                    closure.setError(response.getError());
                    closure.run(new Status(-1, "RPC failed with address: %s, response: %s", endpoint, response));
                }
            } else {
                closure.failure(err);
            }
        }

        @Override
        public Executor executor() {
            return rpcCallbackExecutor;
        }
    };
    try {
        this.rpcClient.invokeAsync(endpoint, request, invokeCtx, invokeCallback, this.rpcTimeoutMillis);
    } catch (final Throwable t) {
        closure.failure(t);
    }
}
Also used : Status(com.alipay.sofa.jraft.Status) BaseResponse(com.alipay.sofa.jraft.rhea.cmd.store.BaseResponse) InvokeContext(com.alipay.sofa.jraft.rpc.InvokeContext) InvokeCallback(com.alipay.sofa.jraft.rpc.InvokeCallback)

Example 2 with InvokeContext

use of com.alipay.sofa.jraft.rpc.InvokeContext in project sofa-jraft by sofastack.

the class DefaultRaftClientService method getFile.

@Override
public Future<Message> getFile(final Endpoint endpoint, final GetFileRequest request, final int timeoutMs, final RpcResponseClosure<GetFileResponse> done) {
    // open checksum
    final InvokeContext ctx = new InvokeContext();
    ctx.put(InvokeContext.CRC_SWITCH, true);
    return invokeWithDone(endpoint, request, ctx, done, timeoutMs);
}
Also used : InvokeContext(com.alipay.sofa.jraft.rpc.InvokeContext)

Example 3 with InvokeContext

use of com.alipay.sofa.jraft.rpc.InvokeContext in project sofa-jraft by sofastack.

the class DefaultPlacementDriverRpcService method internalCallPdWithRpc.

private <V> void internalCallPdWithRpc(final Endpoint endpoint, final BaseRequest request, final FailoverClosure<V> closure) {
    final InvokeContext invokeCtx = new InvokeContext();
    invokeCtx.put(BoltRpcClient.BOLT_CTX, ExtSerializerSupports.getInvokeContext());
    final InvokeCallback invokeCallback = new InvokeCallback() {

        @Override
        public void complete(final Object result, final Throwable err) {
            if (err == null) {
                final BaseResponse<?> response = (BaseResponse<?>) result;
                if (response.isSuccess()) {
                    closure.setData(response.getValue());
                    closure.run(Status.OK());
                } else {
                    closure.setError(response.getError());
                    closure.run(new Status(-1, "RPC failed with address: %s, response: %s", endpoint, response));
                }
            } else {
                closure.failure(err);
            }
        }

        @Override
        public Executor executor() {
            return rpcCallbackExecutor;
        }
    };
    try {
        this.rpcClient.invokeAsync(endpoint, request, invokeCtx, invokeCallback, this.rpcTimeoutMillis);
    } catch (final Throwable t) {
        closure.failure(t);
    }
}
Also used : Status(com.alipay.sofa.jraft.Status) BaseResponse(com.alipay.sofa.jraft.rhea.cmd.pd.BaseResponse) InvokeContext(com.alipay.sofa.jraft.rpc.InvokeContext) InvokeCallback(com.alipay.sofa.jraft.rpc.InvokeCallback)

Aggregations

InvokeContext (com.alipay.sofa.jraft.rpc.InvokeContext)3 Status (com.alipay.sofa.jraft.Status)2 InvokeCallback (com.alipay.sofa.jraft.rpc.InvokeCallback)2 BaseResponse (com.alipay.sofa.jraft.rhea.cmd.pd.BaseResponse)1 BaseResponse (com.alipay.sofa.jraft.rhea.cmd.store.BaseResponse)1