Update clients according to API updates

This commit is contained in:
Nex 2018-10-11 16:38:44 +08:00
parent 8bbe9ae173
commit ae0fcaf505
2 changed files with 71 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import bdchain.api.grpc.AccountingChainGrpc.AccountingChainBlockingStub;
import bdchain.api.grpc.AccountingChainGrpc.AccountingChainFutureStub;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.protobuf.ByteString;
import com.google.protobuf.Empty;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.StatusRuntimeException;
@ -30,7 +31,7 @@ public class AccountingChainClient {
private final ManagedChannel channel;
private final AccountingChainFutureStub futureStub;
private final AccountingChainBlockingStub blockingStub;
// private final AccountingChainStub asyncStub;
// private final AccountingChainStub asyncStub;
/** 构造客户端来访问{@code host:port}的记账链服务。 */
public AccountingChainClient(String host, int port) {
@ -43,7 +44,7 @@ public class AccountingChainClient {
AccountingChainGrpc.newFutureStub(channel);
futureStub = AccountingChainGrpc.newFutureStub(channel);
blockingStub = AccountingChainGrpc.newBlockingStub(channel);
// asyncStub = AccountingChainGrpc.newStub(channel);
// asyncStub = AccountingChainGrpc.newStub(channel);
}
/** 关闭客户端的网络连接。 */
@ -51,6 +52,40 @@ public class AccountingChainClient {
channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
}
/**
* <a
* href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#clientversion-1">查询节点客户端版本</a>
* 非阻塞
*/
public ListenableFuture<ClientVersionResponse> clientVersion() {
info("*** clientVersion");
try {
return futureStub.clientVersion(Empty.getDefaultInstance());
} catch (StatusRuntimeException e) {
warning("RPC failed: {0}", e.getStatus());
return null;
}
}
/**
* <a
* href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#clientversion-1">查询节点客户端版本</a>
* 阻塞
*/
public ClientVersionResponse clientVersionSync() {
info("*** clientVersionSync");
try {
return blockingStub.clientVersion(Empty.getDefaultInstance());
} catch (StatusRuntimeException e) {
warning("RPC failed: {0}", e.getStatus());
return null;
}
}
/**
* <a
* href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#blocknumber">返回最新区块的区块号</a>

View File

@ -51,6 +51,40 @@ public class TransactionLedgerClient {
channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
}
/**
* <a
* href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#clientversion">查询节点客户端版本</a>
* 非阻塞
*/
public ListenableFuture<ClientVersionResponse> clientVersion() {
info("*** clientVersion");
try {
return futureStub.clientVersion(Empty.getDefaultInstance());
} catch (StatusRuntimeException e) {
warning("RPC failed: {0}", e.getStatus());
return null;
}
}
/**
* <a
* href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#clientversion">查询节点客户端版本</a>
* 阻塞
*/
public ClientVersionResponse clientVersionSync() {
info("*** clientVersionSync");
try {
return blockingStub.clientVersion(Empty.getDefaultInstance());
} catch (StatusRuntimeException e) {
warning("RPC failed: {0}", e.getStatus());
return null;
}
}
/**
* <a href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#createledger">创建账本</a>
* 非阻塞