标签:
protobuf在windows环境下的安装
option java_package = "com.theta.hbase.coprocessor.protos";option java_outer_classname = "CountProtos";option java_generic_services = true;option java_generate_equals_and_hash = true;option optimize_for = SPEED;/*具体的消息*每个message域对应一个内部类,该内部类还包含一个Builder内部类*域内字段会生成对应的 setter和getter方法*使用Builder内部类来对字段赋值**/message CountRequest {required string startKey = 1;required string endKey = 2;}message CountResponse {required int64 count = 1 [default = 0];}/*提供服务的类*该类没有Builder内部类*/service CountService {rpc count(CountRequest)returns (CountResponse);}
HbaseEndpoint的实现
2、client端使用HTable实例的 coprocessorService 方法发送Rpc请求,得到response结果例子:public long count(HTableInterface ht, String startKey, String endKey)throws Throwable {final CountProtos.CountRequest request = CountProtos.CountRequest. newBuilder().setStartKey(startKey).setEndKey(endKey).build();Map< byte[], Long> results = ht.coprocessorService(CountProtos.CountService. class, null , null,new Batch.Call<CountProtos.CountService, Long>() {public Long call(CountProtos.CountService counter)throws IOException {ServerRpcController controller = new ServerRpcController();BlockingRpcCallback<CountProtos.CountResponse> rpcCallback = newBlockingRpcCallback<CountProtos.CountResponse>();counter.count(controller, request, rpcCallback);CountProtos.CountResponse response = rpcCallback.get();if (controller.failedOnException()) {throw controller.getFailedOn();}return (response != null && response.getCount() != 0) ?response.getCount() : 0;}});System. out.println(results.values());return results.size();}
标签:
原文地址:http://www.cnblogs.com/hankedang/p/5586356.html