Search in sources :

Example 1 with BaseResponse

use of io.dingodb.store.row.cmd.pd.BaseResponse in project dingo by dingodb.

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(io.dingodb.raft.Status) BaseResponse(io.dingodb.store.row.cmd.pd.BaseResponse) InvokeContext(io.dingodb.raft.rpc.InvokeContext) InvokeCallback(io.dingodb.raft.rpc.InvokeCallback)

Example 2 with BaseResponse

use of io.dingodb.store.row.cmd.pd.BaseResponse in project dingo by dingodb.

the class StoreHeartbeatSender method callAsyncWithRpc.

private <V> void callAsyncWithRpc(final Endpoint endpoint, final BaseRequest request, final HeartbeatClosure<V> closure) {
    final io.dingodb.raft.rpc.InvokeContext invokeCtx = new io.dingodb.raft.rpc.InvokeContext();
    invokeCtx.put(BoltRpcClient.BOLT_CTX, ExtSerializerSupports.getInvokeContext());
    final InvokeCallback invokeCallback = new InvokeCallback() {

        @SuppressWarnings("unchecked")
        @Override
        public void complete(final Object result, final Throwable err) {
            if (err == null) {
                final BaseResponse<?> response = (BaseResponse<?>) result;
                if (response.isSuccess()) {
                    closure.setResult((V) 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.run(new Status(-1, err.getMessage()));
            }
        }

        @Override
        public Executor executor() {
            return heartbeatRpcCallbackExecutor;
        }
    };
    try {
        this.rpcClient.invokeAsync(endpoint, request, invokeCtx, invokeCallback, this.heartbeatRpcTimeoutMillis);
    } catch (final Throwable t) {
        closure.run(new Status(-1, t.getMessage()));
    }
}
Also used : Status(io.dingodb.raft.Status) BaseResponse(io.dingodb.store.row.cmd.pd.BaseResponse) InvokeCallback(io.dingodb.raft.rpc.InvokeCallback)

Example 3 with BaseResponse

use of io.dingodb.store.row.cmd.pd.BaseResponse in project dingo by dingodb.

the class StoreHeartbeatSender method callAsyncWithRpc.

private <V> void callAsyncWithRpc(final Endpoint endpoint, final BaseRequest request, final HeartbeatClosure<V> closure) {
    final io.dingodb.raft.rpc.InvokeContext invokeCtx = new io.dingodb.raft.rpc.InvokeContext();
    invokeCtx.put(BoltRpcClient.BOLT_CTX, ExtSerializerSupports.getInvokeContext());
    final InvokeCallback invokeCallback = new InvokeCallback() {

        @SuppressWarnings("unchecked")
        @Override
        public void complete(final Object result, final Throwable err) {
            if (err == null) {
                final BaseResponse<?> response = (BaseResponse<?>) result;
                if (response.isSuccess()) {
                    closure.setResult((V) 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.run(new Status(-1, err.getMessage()));
            }
        }

        @Override
        public Executor executor() {
            return heartbeatRpcCallbackExecutor;
        }
    };
    try {
        this.rpcClient.invokeAsync(endpoint, request, invokeCtx, invokeCallback, this.heartbeatRpcTimeoutMillis);
    } catch (final Throwable t) {
        closure.run(new Status(-1, t.getMessage()));
    }
}
Also used : Status(io.dingodb.raft.Status) BaseResponse(io.dingodb.store.row.cmd.pd.BaseResponse) InvokeCallback(io.dingodb.raft.rpc.InvokeCallback)

Aggregations

Status (io.dingodb.raft.Status)3 InvokeCallback (io.dingodb.raft.rpc.InvokeCallback)3 BaseResponse (io.dingodb.store.row.cmd.pd.BaseResponse)3 InvokeContext (io.dingodb.raft.rpc.InvokeContext)1