use of com.alibaba.nacos.api.remote.RequestFuture in project nacos by alibaba.
the class GrpcConnection method requestFuture.
@Override
public RequestFuture requestFuture(Request request) throws NacosException {
Payload grpcRequest = GrpcUtils.convert(request);
final ListenableFuture<Payload> requestFuture = grpcFutureServiceStub.request(grpcRequest);
return new RequestFuture() {
@Override
public boolean isDone() {
return requestFuture.isDone();
}
@Override
public Response get() throws Exception {
Payload grpcResponse = requestFuture.get();
Response response = (Response) GrpcUtils.parse(grpcResponse);
if (response instanceof ErrorResponse) {
throw new NacosException(response.getErrorCode(), response.getMessage());
}
return response;
}
@Override
public Response get(long timeout) throws Exception {
Payload grpcResponse = requestFuture.get(timeout, TimeUnit.MILLISECONDS);
Response response = (Response) GrpcUtils.parse(grpcResponse);
if (response instanceof ErrorResponse) {
throw new NacosException(response.getErrorCode(), response.getMessage());
}
return response;
}
};
}
Aggregations