Add javadoc

This commit is contained in:
Nex 2018-09-14 10:15:36 +08:00
parent 201a59964f
commit 511c53c3d1
3 changed files with 124 additions and 6 deletions

View File

@ -19,6 +19,20 @@ sourceCompatibility = 1.8
def grpc_java_version = '1.14.0'
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
javadoc {
source = sourceSets.main.allJava
classpath = configurations.compile
options {
encoding 'UTF-8'
charSet 'UTF-8'
title "BDChain Java SDK API"
}
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.6.0"

View File

@ -15,6 +15,14 @@ import java.util.logging.Logger;
// import bdchain.api.grpc.AccountingChainGrpc.AccountingChainStub;
/**
* 记账链客户端
*
* <p>如有更灵活的需求可直接使用{@link bdchain.api.grpc.AccountingChainGrpc}
*
* @see <a href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#api-1">记账链API</a>
* @author nex
*/
public class AccountingChainClient {
private static final Logger logger = Logger.getLogger(AccountingChainClient.class.getName());
@ -22,26 +30,32 @@ public class AccountingChainClient {
private final ManagedChannel channel;
private final AccountingChainFutureStub futureStub;
private final AccountingChainBlockingStub blockingStub;
// private final AccountingChainStub asyncStub;
// private final AccountingChainStub asyncStub;
/** Construct client for accessing AccountingChain server at {@code host:port}. */
/** 构造客户端来访问{@code host:port}的记账链服务。 */
public AccountingChainClient(String host, int port) {
this(ManagedChannelBuilder.forAddress(host, port).usePlaintext());
}
/** Construct client for accessing AccountingChain server using the existing channel. */
/** 用已有的{@link io.grpc.Channel}对象构造客户端来访问记账链服务。 */
public AccountingChainClient(ManagedChannelBuilder<?> channelBuilder) {
channel = channelBuilder.build();
AccountingChainGrpc.newFutureStub(channel);
futureStub = AccountingChainGrpc.newFutureStub(channel);
blockingStub = AccountingChainGrpc.newBlockingStub(channel);
// asyncStub = AccountingChainGrpc.newStub(channel);
// asyncStub = AccountingChainGrpc.newStub(channel);
}
/** 关闭客户端的网络连接。 */
public void shutdown() throws InterruptedException {
channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
}
/**
* <a
* href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#blocknumber">返回最新区块的区块号</a>
* 非阻塞
*/
public ListenableFuture<BlockNumberResponse> blockNumber(String ledger) {
info("*** blockNumber: ledger={0}", ledger);
@ -56,6 +70,11 @@ public class AccountingChainClient {
}
}
/**
* <a
* href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#blocknumber">返回最新区块的区块号</a>
* 阻塞
*/
public BlockNumberResponse blockNumberSync(String ledger) {
info("*** blockNumberSync: ledger={0}", ledger);
@ -70,6 +89,11 @@ public class AccountingChainClient {
}
}
/**
* <a
* href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#getblockbynumber">返回区块号所指定区块的信息</a>
* 非阻塞
*/
public ListenableFuture<Block> getBlockByNumber(
String ledger, long number, boolean fullTransaction) {
@ -92,6 +116,11 @@ public class AccountingChainClient {
}
}
/**
* <a
* href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#getblockbynumber">返回区块号所指定区块的信息</a>
* 阻塞
*/
public Block getBlockByNumberSync(String ledger, long number, boolean fullTransaction) {
info(
@ -113,6 +142,11 @@ public class AccountingChainClient {
}
}
/**
* <a
* href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#getblockbyhash">返回哈希所指定区块的信息</a>
* 非阻塞
*/
public ListenableFuture<Block> getBlockByHash(
String ledger, String hash, boolean fullTransaction) {
@ -135,6 +169,11 @@ public class AccountingChainClient {
}
}
/**
* <a
* href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#getblockbyhash">返回哈希所指定区块的信息</a>
* 阻塞
*/
public Block getBlockByHashSync(String ledger, String hash, boolean fullTransaction) {
info(
@ -156,6 +195,11 @@ public class AccountingChainClient {
}
}
/**
* <a
* href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#gettransactionbyhash">返回哈希所指定事务的信息</a>
* 非阻塞
*/
public ListenableFuture<Transaction> getTransactionByHash(String ledger, String hash) {
info("*** getTransactionByHash: ledger={0} hash={1}", ledger, hash);
@ -174,6 +218,11 @@ public class AccountingChainClient {
}
}
/**
* <a
* href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#gettransactionbyhash">返回哈希所指定事务的信息</a>
* 阻塞
*/
public Transaction getTransactionByHashSync(String ledger, String hash) {
info("*** getTransactionByHashSync: ledger={0} hash={1}", ledger, hash);
@ -192,6 +241,11 @@ public class AccountingChainClient {
}
}
/**
* <a
* href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#gettransactionbyblocknum">返回区块号与事务index所指定事务的信息</a>
* 非阻塞
*/
public ListenableFuture<Transaction> getTransactionByBlockNumberAndIndex(
String ledger, long block_number, int index) {
@ -214,6 +268,11 @@ public class AccountingChainClient {
}
}
/**
* <a
* href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#gettransactionbyblocknum">返回区块号与事务index所指定事务的信息</a>
* 阻塞
*/
public Transaction getTransactionByBlockNumberAndIndexSync(
String ledger, long block_number, int index) {
@ -236,6 +295,11 @@ public class AccountingChainClient {
}
}
/**
* <a
* href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#gettransactionbyblockhas">返回区块的哈希与事务的index所指定事务的信息</a>
* 非阻塞
*/
public ListenableFuture<Transaction> getTransactionByBlockHashAndIndex(
String ledger, String block_hash, int index) {
@ -258,6 +322,11 @@ public class AccountingChainClient {
}
}
/**
* <a
* href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#gettransactionbyblockhas">返回区块的哈希与事务的index所指定事务的信息</a>
* 阻塞
*/
public Transaction getTransactionByBlockHashAndIndexSync(
String ledger, String block_hash, int index) {

View File

@ -16,6 +16,14 @@ import java.util.logging.Logger;
// import bdchain.api.grpc.TransactionLedgerGrpc.TransactionLedgerStub;
/**
* 事务账本客户端
*
* <p>如有更灵活的需求可直接使用{@link bdchain.api.grpc.TransactionLedgerGrpc}
*
* @see <a href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#api">事务账本API</a>
* @author nex
*/
public class TransactionLedgerClient {
private static final Logger logger = Logger.getLogger(TransactionLedgerClient.class.getName());
@ -25,12 +33,12 @@ public class TransactionLedgerClient {
private final TransactionLedgerBlockingStub blockingStub;
// private final TransactionLedgerStub asyncStub;
/** Construct client for accessing TransactionLedger server at {@code host:port}. */
/** 构造客户端来访问{@code host:port}的事务账本服务。 */
public TransactionLedgerClient(String host, int port) {
this(ManagedChannelBuilder.forAddress(host, port).usePlaintext());
}
/** Construct client for accessing TransactionLedger server using the existing channel. */
/** 用已有的{@link io.grpc.Channel}对象构造客户端来访问事务账本服务。 */
public TransactionLedgerClient(ManagedChannelBuilder<?> channelBuilder) {
channel = channelBuilder.build();
futureStub = TransactionLedgerGrpc.newFutureStub(channel);
@ -38,10 +46,15 @@ public class TransactionLedgerClient {
// asyncStub = TransactionLedgerGrpc.newStub(channel);
}
/** 关闭客户端的网络连接。 */
public void shutdown() throws InterruptedException {
channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
}
/**
* <a href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#createledger">创建账本</a>
* 非阻塞
*/
public ListenableFuture<CreateLedgerResponse> createLedger(String name) {
info("*** createLedger: name={0}", name);
@ -56,6 +69,10 @@ public class TransactionLedgerClient {
}
}
/**
* <a href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#createledger">创建账本</a>
* 阻塞
*/
public CreateLedgerResponse createLedgerSync(String name) {
info("*** createLedgerSync: name={0}", name);
@ -70,6 +87,10 @@ public class TransactionLedgerClient {
}
}
/**
* <a href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#getledgers">返回账本列表</a>
* 非阻塞
*/
public ListenableFuture<GetLedgersResponse> getLedgers() {
info("*** getLedgers");
@ -82,6 +103,10 @@ public class TransactionLedgerClient {
}
}
/**
* <a href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#getledgers">返回账本列表</a>
* 阻塞
*/
public GetLedgersResponse getLedgersSync() {
info("*** getLedgersSync");
@ -94,6 +119,11 @@ public class TransactionLedgerClient {
}
}
/**
* <a
* href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#sendtransaction">发送新事务</a>
* 非阻塞
*/
public ListenableFuture<SendTransactionResponse> sendTransaction(
String ledger, TransactionType type, String from, String to, byte[] data) {
@ -120,6 +150,11 @@ public class TransactionLedgerClient {
}
}
/**
* <a
* href="https://phabricator.internetapi.cn/w/public/bdchain/grpc-api/#sendtransaction">发送新事务</a>
* 阻塞
*/
public SendTransactionResponse sendTransactionSync(
String ledger, TransactionType type, String from, String to, byte[] data) {