菜单

HBase协助管理理器编码实例

2019年6月1日 - UNIXSolaris

Observer协助管理理器常常在2个一定的事件(诸如GetPut)在此以前或以往产生,也正是猎豹CS6DBMS中的触发器。Endpoint协助管理理器则接近于讴歌RDXDBMS中的存储进度,因为它能够令你在RegionServer上对数码施行自定义总结,而不是在客户端上实行总结。

Observer协助管理理器日常在2个一定的事件(诸如GetPut)在此之前或现在爆发,约等于奥德赛DBMS中的触发器。Endpoint协助管理理器则周围于冠道DBMS中的存款和储蓄进程,因为它可以令你在RegionServer上对数码实施自定义总结,而不是在客户端上进行总括。

正文是上述两个的简短实例,使用的条件:情况 jdk一.八
Hadoop2.6.5
hbase1.2.4。

正文是上述两个的粗略实例,使用的情况:情况 jdk一.捌 hadoop二.陆.伍hbase一.二.4。

1、Endpoint实例 
1>
编写适用于protobuf的proto文件,如下,尽量不要带注释,因为编写翻译时恐怕出现乱码

1、Endpoint实例 
一>
编写适用于protobuf的proto文件,如下,尽量不要带注释,因为编写翻译时恐怕现身乱码

option java_package = "com.endpoint.test";
option java_outer_classname = "Sum";
option java_generic_services = true;
option java_generate_equals_and_hash = true;
option optimize_for = SPEED;

message SumRequest {
    required string family = 1;    
    required string column = 2;    
}
message SumResponse {
    required int64 sum = 1 [default = 0];
}
service SumService {
    rpc getSum(SumRequest)
        returns (SumResponse);
}
option java_package = "com.endpoint.test";
option java_outer_classname = "Sum";
option java_generic_services = true;
option java_generate_equals_and_hash = true;
option optimize_for = SPEED;

message SumRequest {
    required string family = 1;    
    required string column = 2;    
}
message SumResponse {
    required int64 sum = 1 [default = 0];
}
service SumService {
    rpc getSum(SumRequest)
        returns (SumResponse);
}

 贰> 编译上边的proto文件
动用protoc程序开始展览编写翻译,linux下或许windows均可,protoc程序能够平昔从github下载:https://github.com/google/protobuf/releases,也可以自己编译生成,参见
CentOS
七下protobuf的源码编译安装

http://www.linuxidc.com/Linux/2016-12/138716.htm

 二> 编写翻译上边的proto文件
动用protoc程序开展编写翻译,linux下只怕windows均可,protoc程序能够直接从github下载:https://github.com/google/protobuf/releases,也能够团结编写翻译生成,参见protobuf的编写翻译安装

在意,编写翻译的本子要与hadoop以及hbase使用的本子同样,或许略高,但不过不用过高,hadoop二.陆.5hbase1.2.肆应用的都是protobuf二.伍.0的版本,写此篇作品时的最新版为3.一.0

留神,编写翻译的本子要与hadoop以及hbase使用的版本同样,或然略高,但最棒不用过高,hadoop二.陆.5hbase一.二.四应用的都以protobuf二.伍.0的版本,写此篇文章时的流行版为叁.1.0

(高版本必须内定syntax,例如proto3的syntax在首先行非空白非注释行,必须写:syntax
= “proto三”,字段规则移除了 “required”,并把 “optional” 改名为“singular”,移除了 default 选项。可找出Protobuf 的 proto三 与 proto2的分别张开打探。)下载的话选用带win或linux的本子,那是编写翻译好的版本。有数不清带具体语言的本子,是局部有血有肉某种语言的批发版源码包。,为了与hbase以及hadoop统一同来,此处用的是protoc-2.伍.0-win3二.zip。

(高版本必须钦点syntax,比方proto三的syntax在首先行非空白非注释行,必须写:syntax
= “proto叁”,字段规则移除了 “required”,并把 “optional” 改名称为“singular”,移除了 default 选项。可找寻Protobuf 的 proto3 与 proto二的差别进行问询。)下载的话选取带win或linux的本子,这是编译好的版本。有数不尽带具身体语言言的版本,是部分现实某种语言的批发版源码包。为了与hbase以及hadoop统一齐来,此处用的是protoc-贰.五.0-win32.zip。

解压文件:

解压文件:

 图片 1

 图片 2

 使用windows命令行进入上面的目录,施行以下命令就能够:

 使用windows命令行进入上边的目录,施行以下命令就能够:

protoc.exe sum1.proto --java_out=./
protoc.exe sum1.proto --java_out=./

高版本有编写翻译好的适用于linux下的protoc程序文件,低版本没有。在linux下实践以下命令:

高版本有编写翻译好的适用于linux下的protoc程序文件,低版本未有。在linux下进行以下命令:

protoc sum.proto --java_out=./
protoc sum.proto --java_out=./

 结果都无差异,生成的代码参见折叠部分,有成都百货上千,因为上边文件中钦定java_outer_classname = “Sum”,所以会生成Sum类,将这几个类引进到品种中,注意项指标包名称与地点文件中钦点(option java_package =
“com.endpoint.test”)的称呼要1律。

 结果都一律,生成的代码参见折叠部分,有无数,因为上边文件中钦赐java_outer_classname = “Sum”,所以会生成Sum类,将那一个类引进到品种中,注意项目标包名称与地方文件中钦点(option java_package =
“com.endpoint.test”)的名称要一律。

// Generated by the protocol buffer compiler.  DO NOT EDIT!
// source: sumcode.proto

图片 3图片 4

package com.endpoint.test;

   1 // Generated by the protocol buffer compiler.  DO NOT EDIT!
   2 // source: sumcode.proto
   3 
   4 package com.endpoint.test;
   5 
   6 public final class Sum {
   7   private Sum() {}
   8   public static void registerAllExtensions(
   9       com.google.protobuf.ExtensionRegistry registry) {
  10   }
  11   public interface SumRequestOrBuilder
  12       extends com.google.protobuf.MessageOrBuilder {
  13 
  14     // required string family = 1;
  15     /**
  16      * <code>required string family = 1;</code>
  17      */
  18     boolean hasFamily();
  19     /**
  20      * <code>required string family = 1;</code>
  21      */
  22     java.lang.String getFamily();
  23     /**
  24      * <code>required string family = 1;</code>
  25      */
  26     com.google.protobuf.ByteString
  27         getFamilyBytes();
  28 
  29     // required string column = 2;
  30     /**
  31      * <code>required string column = 2;</code>
  32      */
  33     boolean hasColumn();
  34     /**
  35      * <code>required string column = 2;</code>
  36      */
  37     java.lang.String getColumn();
  38     /**
  39      * <code>required string column = 2;</code>
  40      */
  41     com.google.protobuf.ByteString
  42         getColumnBytes();
  43   }
  44   /**
  45    * Protobuf type {@code SumRequest}
  46    */
  47   public static final class SumRequest extends
  48       com.google.protobuf.GeneratedMessage
  49       implements SumRequestOrBuilder {
  50     // Use SumRequest.newBuilder() to construct.
  51     private SumRequest(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
  52       super(builder);
  53       this.unknownFields = builder.getUnknownFields();
  54     }
  55     private SumRequest(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }
  56 
  57     private static final SumRequest defaultInstance;
  58     public static SumRequest getDefaultInstance() {
  59       return defaultInstance;
  60     }
  61 
  62     public SumRequest getDefaultInstanceForType() {
  63       return defaultInstance;
  64     }
  65 
  66     private final com.google.protobuf.UnknownFieldSet unknownFields;
  67     @java.lang.Override
  68     public final com.google.protobuf.UnknownFieldSet
  69         getUnknownFields() {
  70       return this.unknownFields;
  71     }
  72     private SumRequest(
  73         com.google.protobuf.CodedInputStream input,
  74         com.google.protobuf.ExtensionRegistryLite extensionRegistry)
  75         throws com.google.protobuf.InvalidProtocolBufferException {
  76       initFields();
  77       int mutable_bitField0_ = 0;
  78       com.google.protobuf.UnknownFieldSet.Builder unknownFields =
  79           com.google.protobuf.UnknownFieldSet.newBuilder();
  80       try {
  81         boolean done = false;
  82         while (!done) {
  83           int tag = input.readTag();
  84           switch (tag) {
  85             case 0:
  86               done = true;
  87               break;
  88             default: {
  89               if (!parseUnknownField(input, unknownFields,
  90                                      extensionRegistry, tag)) {
  91                 done = true;
  92               }
  93               break;
  94             }
  95             case 10: {
  96               bitField0_ |= 0x00000001;
  97               family_ = input.readBytes();
  98               break;
  99             }
 100             case 18: {
 101               bitField0_ |= 0x00000002;
 102               column_ = input.readBytes();
 103               break;
 104             }
 105           }
 106         }
 107       } catch (com.google.protobuf.InvalidProtocolBufferException e) {
 108         throw e.setUnfinishedMessage(this);
 109       } catch (java.io.IOException e) {
 110         throw new com.google.protobuf.InvalidProtocolBufferException(
 111             e.getMessage()).setUnfinishedMessage(this);
 112       } finally {
 113         this.unknownFields = unknownFields.build();
 114         makeExtensionsImmutable();
 115       }
 116     }
 117     public static final com.google.protobuf.Descriptors.Descriptor
 118         getDescriptor() {
 119       return com.endpoint.test.Sum.internal_static_SumRequest_descriptor;
 120     }
 121 
 122     protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
 123         internalGetFieldAccessorTable() {
 124       return com.endpoint.test.Sum.internal_static_SumRequest_fieldAccessorTable
 125           .ensureFieldAccessorsInitialized(
 126               com.endpoint.test.Sum.SumRequest.class, com.endpoint.test.Sum.SumRequest.Builder.class);
 127     }
 128 
 129     public static com.google.protobuf.Parser<SumRequest> PARSER =
 130         new com.google.protobuf.AbstractParser<SumRequest>() {
 131       public SumRequest parsePartialFrom(
 132           com.google.protobuf.CodedInputStream input,
 133           com.google.protobuf.ExtensionRegistryLite extensionRegistry)
 134           throws com.google.protobuf.InvalidProtocolBufferException {
 135         return new SumRequest(input, extensionRegistry);
 136       }
 137     };
 138 
 139     @java.lang.Override
 140     public com.google.protobuf.Parser<SumRequest> getParserForType() {
 141       return PARSER;
 142     }
 143 
 144     private int bitField0_;
 145     // required string family = 1;
 146     public static final int FAMILY_FIELD_NUMBER = 1;
 147     private java.lang.Object family_;
 148     /**
 149      * <code>required string family = 1;</code>
 150      */
 151     public boolean hasFamily() {
 152       return ((bitField0_ & 0x00000001) == 0x00000001);
 153     }
 154     /**
 155      * <code>required string family = 1;</code>
 156      */
 157     public java.lang.String getFamily() {
 158       java.lang.Object ref = family_;
 159       if (ref instanceof java.lang.String) {
 160         return (java.lang.String) ref;
 161       } else {
 162         com.google.protobuf.ByteString bs = 
 163             (com.google.protobuf.ByteString) ref;
 164         java.lang.String s = bs.toStringUtf8();
 165         if (bs.isValidUtf8()) {
 166           family_ = s;
 167         }
 168         return s;
 169       }
 170     }
 171     /**
 172      * <code>required string family = 1;</code>
 173      */
 174     public com.google.protobuf.ByteString
 175         getFamilyBytes() {
 176       java.lang.Object ref = family_;
 177       if (ref instanceof java.lang.String) {
 178         com.google.protobuf.ByteString b = 
 179             com.google.protobuf.ByteString.copyFromUtf8(
 180                 (java.lang.String) ref);
 181         family_ = b;
 182         return b;
 183       } else {
 184         return (com.google.protobuf.ByteString) ref;
 185       }
 186     }
 187 
 188     // required string column = 2;
 189     public static final int COLUMN_FIELD_NUMBER = 2;
 190     private java.lang.Object column_;
 191     /**
 192      * <code>required string column = 2;</code>
 193      */
 194     public boolean hasColumn() {
 195       return ((bitField0_ & 0x00000002) == 0x00000002);
 196     }
 197     /**
 198      * <code>required string column = 2;</code>
 199      */
 200     public java.lang.String getColumn() {
 201       java.lang.Object ref = column_;
 202       if (ref instanceof java.lang.String) {
 203         return (java.lang.String) ref;
 204       } else {
 205         com.google.protobuf.ByteString bs = 
 206             (com.google.protobuf.ByteString) ref;
 207         java.lang.String s = bs.toStringUtf8();
 208         if (bs.isValidUtf8()) {
 209           column_ = s;
 210         }
 211         return s;
 212       }
 213     }
 214     /**
 215      * <code>required string column = 2;</code>
 216      */
 217     public com.google.protobuf.ByteString
 218         getColumnBytes() {
 219       java.lang.Object ref = column_;
 220       if (ref instanceof java.lang.String) {
 221         com.google.protobuf.ByteString b = 
 222             com.google.protobuf.ByteString.copyFromUtf8(
 223                 (java.lang.String) ref);
 224         column_ = b;
 225         return b;
 226       } else {
 227         return (com.google.protobuf.ByteString) ref;
 228       }
 229     }
 230 
 231     private void initFields() {
 232       family_ = "";
 233       column_ = "";
 234     }
 235     private byte memoizedIsInitialized = -1;
 236     public final boolean isInitialized() {
 237       byte isInitialized = memoizedIsInitialized;
 238       if (isInitialized != -1) return isInitialized == 1;
 239 
 240       if (!hasFamily()) {
 241         memoizedIsInitialized = 0;
 242         return false;
 243       }
 244       if (!hasColumn()) {
 245         memoizedIsInitialized = 0;
 246         return false;
 247       }
 248       memoizedIsInitialized = 1;
 249       return true;
 250     }
 251 
 252     public void writeTo(com.google.protobuf.CodedOutputStream output)
 253                         throws java.io.IOException {
 254       getSerializedSize();
 255       if (((bitField0_ & 0x00000001) == 0x00000001)) {
 256         output.writeBytes(1, getFamilyBytes());
 257       }
 258       if (((bitField0_ & 0x00000002) == 0x00000002)) {
 259         output.writeBytes(2, getColumnBytes());
 260       }
 261       getUnknownFields().writeTo(output);
 262     }
 263 
 264     private int memoizedSerializedSize = -1;
 265     public int getSerializedSize() {
 266       int size = memoizedSerializedSize;
 267       if (size != -1) return size;
 268 
 269       size = 0;
 270       if (((bitField0_ & 0x00000001) == 0x00000001)) {
 271         size += com.google.protobuf.CodedOutputStream
 272           .computeBytesSize(1, getFamilyBytes());
 273       }
 274       if (((bitField0_ & 0x00000002) == 0x00000002)) {
 275         size += com.google.protobuf.CodedOutputStream
 276           .computeBytesSize(2, getColumnBytes());
 277       }
 278       size += getUnknownFields().getSerializedSize();
 279       memoizedSerializedSize = size;
 280       return size;
 281     }
 282 
 283     private static final long serialVersionUID = 0L;
 284     @java.lang.Override
 285     protected java.lang.Object writeReplace()
 286         throws java.io.ObjectStreamException {
 287       return super.writeReplace();
 288     }
 289 
 290     @java.lang.Override
 291     public boolean equals(final java.lang.Object obj) {
 292       if (obj == this) {
 293        return true;
 294       }
 295       if (!(obj instanceof com.endpoint.test.Sum.SumRequest)) {
 296         return super.equals(obj);
 297       }
 298       com.endpoint.test.Sum.SumRequest other = (com.endpoint.test.Sum.SumRequest) obj;
 299 
 300       boolean result = true;
 301       result = result && (hasFamily() == other.hasFamily());
 302       if (hasFamily()) {
 303         result = result && getFamily()
 304             .equals(other.getFamily());
 305       }
 306       result = result && (hasColumn() == other.hasColumn());
 307       if (hasColumn()) {
 308         result = result && getColumn()
 309             .equals(other.getColumn());
 310       }
 311       result = result &&
 312           getUnknownFields().equals(other.getUnknownFields());
 313       return result;
 314     }
 315 
 316     private int memoizedHashCode = 0;
 317     @java.lang.Override
 318     public int hashCode() {
 319       if (memoizedHashCode != 0) {
 320         return memoizedHashCode;
 321       }
 322       int hash = 41;
 323       hash = (19 * hash) + getDescriptorForType().hashCode();
 324       if (hasFamily()) {
 325         hash = (37 * hash) + FAMILY_FIELD_NUMBER;
 326         hash = (53 * hash) + getFamily().hashCode();
 327       }
 328       if (hasColumn()) {
 329         hash = (37 * hash) + COLUMN_FIELD_NUMBER;
 330         hash = (53 * hash) + getColumn().hashCode();
 331       }
 332       hash = (29 * hash) + getUnknownFields().hashCode();
 333       memoizedHashCode = hash;
 334       return hash;
 335     }
 336 
 337     public static com.endpoint.test.Sum.SumRequest parseFrom(
 338         com.google.protobuf.ByteString data)
 339         throws com.google.protobuf.InvalidProtocolBufferException {
 340       return PARSER.parseFrom(data);
 341     }
 342     public static com.endpoint.test.Sum.SumRequest parseFrom(
 343         com.google.protobuf.ByteString data,
 344         com.google.protobuf.ExtensionRegistryLite extensionRegistry)
 345         throws com.google.protobuf.InvalidProtocolBufferException {
 346       return PARSER.parseFrom(data, extensionRegistry);
 347     }
 348     public static com.endpoint.test.Sum.SumRequest parseFrom(byte[] data)
 349         throws com.google.protobuf.InvalidProtocolBufferException {
 350       return PARSER.parseFrom(data);
 351     }
 352     public static com.endpoint.test.Sum.SumRequest parseFrom(
 353         byte[] data,
 354         com.google.protobuf.ExtensionRegistryLite extensionRegistry)
 355         throws com.google.protobuf.InvalidProtocolBufferException {
 356       return PARSER.parseFrom(data, extensionRegistry);
 357     }
 358     public static com.endpoint.test.Sum.SumRequest parseFrom(java.io.InputStream input)
 359         throws java.io.IOException {
 360       return PARSER.parseFrom(input);
 361     }
 362     public static com.endpoint.test.Sum.SumRequest parseFrom(
 363         java.io.InputStream input,
 364         com.google.protobuf.ExtensionRegistryLite extensionRegistry)
 365         throws java.io.IOException {
 366       return PARSER.parseFrom(input, extensionRegistry);
 367     }
 368     public static com.endpoint.test.Sum.SumRequest parseDelimitedFrom(java.io.InputStream input)
 369         throws java.io.IOException {
 370       return PARSER.parseDelimitedFrom(input);
 371     }
 372     public static com.endpoint.test.Sum.SumRequest parseDelimitedFrom(
 373         java.io.InputStream input,
 374         com.google.protobuf.ExtensionRegistryLite extensionRegistry)
 375         throws java.io.IOException {
 376       return PARSER.parseDelimitedFrom(input, extensionRegistry);
 377     }
 378     public static com.endpoint.test.Sum.SumRequest parseFrom(
 379         com.google.protobuf.CodedInputStream input)
 380         throws java.io.IOException {
 381       return PARSER.parseFrom(input);
 382     }
 383     public static com.endpoint.test.Sum.SumRequest parseFrom(
 384         com.google.protobuf.CodedInputStream input,
 385         com.google.protobuf.ExtensionRegistryLite extensionRegistry)
 386         throws java.io.IOException {
 387       return PARSER.parseFrom(input, extensionRegistry);
 388     }
 389 
 390     public static Builder newBuilder() { return Builder.create(); }
 391     public Builder newBuilderForType() { return newBuilder(); }
 392     public static Builder newBuilder(com.endpoint.test.Sum.SumRequest prototype) {
 393       return newBuilder().mergeFrom(prototype);
 394     }
 395     public Builder toBuilder() { return newBuilder(this); }
 396 
 397     @java.lang.Override
 398     protected Builder newBuilderForType(
 399         com.google.protobuf.GeneratedMessage.BuilderParent parent) {
 400       Builder builder = new Builder(parent);
 401       return builder;
 402     }
 403     /**
 404      * Protobuf type {@code SumRequest}
 405      */
 406     public static final class Builder extends
 407         com.google.protobuf.GeneratedMessage.Builder<Builder>
 408        implements com.endpoint.test.Sum.SumRequestOrBuilder {
 409       public static final com.google.protobuf.Descriptors.Descriptor
 410           getDescriptor() {
 411         return com.endpoint.test.Sum.internal_static_SumRequest_descriptor;
 412       }
 413 
 414       protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
 415           internalGetFieldAccessorTable() {
 416         return com.endpoint.test.Sum.internal_static_SumRequest_fieldAccessorTable
 417             .ensureFieldAccessorsInitialized(
 418                 com.endpoint.test.Sum.SumRequest.class, com.endpoint.test.Sum.SumRequest.Builder.class);
 419       }
 420 
 421       // Construct using com.endpoint.test.Sum.SumRequest.newBuilder()
 422       private Builder() {
 423         maybeForceBuilderInitialization();
 424       }
 425 
 426       private Builder(
 427           com.google.protobuf.GeneratedMessage.BuilderParent parent) {
 428         super(parent);
 429         maybeForceBuilderInitialization();
 430       }
 431       private void maybeForceBuilderInitialization() {
 432         if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
 433         }
 434       }
 435       private static Builder create() {
 436         return new Builder();
 437       }
 438 
 439       public Builder clear() {
 440         super.clear();
 441         family_ = "";
 442         bitField0_ = (bitField0_ & ~0x00000001);
 443         column_ = "";
 444         bitField0_ = (bitField0_ & ~0x00000002);
 445         return this;
 446       }
 447 
 448       public Builder clone() {
 449         return create().mergeFrom(buildPartial());
 450       }
 451 
 452       public com.google.protobuf.Descriptors.Descriptor
 453           getDescriptorForType() {
 454         return com.endpoint.test.Sum.internal_static_SumRequest_descriptor;
 455       }
 456 
 457       public com.endpoint.test.Sum.SumRequest getDefaultInstanceForType() {
 458         return com.endpoint.test.Sum.SumRequest.getDefaultInstance();
 459       }
 460 
 461       public com.endpoint.test.Sum.SumRequest build() {
 462         com.endpoint.test.Sum.SumRequest result = buildPartial();
 463         if (!result.isInitialized()) {
 464           throw newUninitializedMessageException(result);
 465         }
 466         return result;
 467       }
 468 
 469       public com.endpoint.test.Sum.SumRequest buildPartial() {
 470         com.endpoint.test.Sum.SumRequest result = new com.endpoint.test.Sum.SumRequest(this);
 471         int from_bitField0_ = bitField0_;
 472         int to_bitField0_ = 0;
 473         if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
 474           to_bitField0_ |= 0x00000001;
 475         }
 476         result.family_ = family_;
 477         if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
 478           to_bitField0_ |= 0x00000002;
 479         }
 480         result.column_ = column_;
 481         result.bitField0_ = to_bitField0_;
 482         onBuilt();
 483         return result;
 484       }
 485 
 486       public Builder mergeFrom(com.google.protobuf.Message other) {
 487         if (other instanceof com.endpoint.test.Sum.SumRequest) {
 488           return mergeFrom((com.endpoint.test.Sum.SumRequest)other);
 489         } else {
 490           super.mergeFrom(other);
 491           return this;
 492         }
 493       }
 494 
 495       public Builder mergeFrom(com.endpoint.test.Sum.SumRequest other) {
 496         if (other == com.endpoint.test.Sum.SumRequest.getDefaultInstance()) return this;
 497         if (other.hasFamily()) {
 498           bitField0_ |= 0x00000001;
 499           family_ = other.family_;
 500           onChanged();
 501         }
 502         if (other.hasColumn()) {
 503           bitField0_ |= 0x00000002;
 504           column_ = other.column_;
 505           onChanged();
 506         }
 507         this.mergeUnknownFields(other.getUnknownFields());
 508         return this;
 509       }
 510 
 511       public final boolean isInitialized() {
 512         if (!hasFamily()) {
 513           
 514           return false;
 515         }
 516         if (!hasColumn()) {
 517           
 518           return false;
 519         }
 520         return true;
 521       }
 522 
 523       public Builder mergeFrom(
 524           com.google.protobuf.CodedInputStream input,
 525           com.google.protobuf.ExtensionRegistryLite extensionRegistry)
 526           throws java.io.IOException {
 527         com.endpoint.test.Sum.SumRequest parsedMessage = null;
 528         try {
 529           parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
 530         } catch (com.google.protobuf.InvalidProtocolBufferException e) {
 531           parsedMessage = (com.endpoint.test.Sum.SumRequest) e.getUnfinishedMessage();
 532           throw e;
 533         } finally {
 534           if (parsedMessage != null) {
 535             mergeFrom(parsedMessage);
 536           }
 537         }
 538         return this;
 539       }
 540       private int bitField0_;
 541 
 542       // required string family = 1;
 543       private java.lang.Object family_ = "";
 544       /**
 545        * <code>required string family = 1;</code>
 546        */
 547       public boolean hasFamily() {
 548         return ((bitField0_ & 0x00000001) == 0x00000001);
 549       }
 550       /**
 551        * <code>required string family = 1;</code>
 552        */
 553       public java.lang.String getFamily() {
 554         java.lang.Object ref = family_;
 555         if (!(ref instanceof java.lang.String)) {
 556           java.lang.String s = ((com.google.protobuf.ByteString) ref)
 557               .toStringUtf8();
 558           family_ = s;
 559           return s;
 560         } else {
 561           return (java.lang.String) ref;
 562         }
 563       }
 564       /**
 565        * <code>required string family = 1;</code>
 566        */
 567       public com.google.protobuf.ByteString
 568           getFamilyBytes() {
 569         java.lang.Object ref = family_;
 570         if (ref instanceof String) {
 571           com.google.protobuf.ByteString b = 
 572               com.google.protobuf.ByteString.copyFromUtf8(
 573                   (java.lang.String) ref);
 574           family_ = b;
 575           return b;
 576         } else {
 577           return (com.google.protobuf.ByteString) ref;
 578         }
 579       }
 580       /**
 581        * <code>required string family = 1;</code>
 582        */
 583       public Builder setFamily(
 584           java.lang.String value) {
 585         if (value == null) {
 586     throw new NullPointerException();
 587   }
 588   bitField0_ |= 0x00000001;
 589         family_ = value;
 590         onChanged();
 591         return this;
 592       }
 593       /**
 594        * <code>required string family = 1;</code>
 595        */
 596       public Builder clearFamily() {
 597         bitField0_ = (bitField0_ & ~0x00000001);
 598         family_ = getDefaultInstance().getFamily();
 599         onChanged();
 600         return this;
 601       }
 602       /**
 603        * <code>required string family = 1;</code>
 604        */
 605       public Builder setFamilyBytes(
 606           com.google.protobuf.ByteString value) {
 607         if (value == null) {
 608     throw new NullPointerException();
 609   }
 610   bitField0_ |= 0x00000001;
 611         family_ = value;
 612         onChanged();
 613         return this;
 614       }
 615 
 616       // required string column = 2;
 617       private java.lang.Object column_ = "";
 618       /**
 619        * <code>required string column = 2;</code>
 620        */
 621       public boolean hasColumn() {
 622         return ((bitField0_ & 0x00000002) == 0x00000002);
 623       }
 624       /**
 625        * <code>required string column = 2;</code>
 626        */
 627       public java.lang.String getColumn() {
 628         java.lang.Object ref = column_;
 629         if (!(ref instanceof java.lang.String)) {
 630           java.lang.String s = ((com.google.protobuf.ByteString) ref)
 631               .toStringUtf8();
 632           column_ = s;
 633           return s;
 634         } else {
 635           return (java.lang.String) ref;
 636         }
 637       }
 638       /**
 639        * <code>required string column = 2;</code>
 640        */
 641       public com.google.protobuf.ByteString
 642           getColumnBytes() {
 643         java.lang.Object ref = column_;
 644         if (ref instanceof String) {
 645           com.google.protobuf.ByteString b = 
 646               com.google.protobuf.ByteString.copyFromUtf8(
 647                   (java.lang.String) ref);
 648           column_ = b;
 649           return b;
 650         } else {
 651           return (com.google.protobuf.ByteString) ref;
 652         }
 653       }
 654       /**
 655        * <code>required string column = 2;</code>
 656        */
 657       public Builder setColumn(
 658           java.lang.String value) {
 659         if (value == null) {
 660     throw new NullPointerException();
 661   }
 662   bitField0_ |= 0x00000002;
 663         column_ = value;
 664         onChanged();
 665         return this;
 666       }
 667       /**
 668        * <code>required string column = 2;</code>
 669        */
 670       public Builder clearColumn() {
 671         bitField0_ = (bitField0_ & ~0x00000002);
 672         column_ = getDefaultInstance().getColumn();
 673         onChanged();
 674         return this;
 675       }
 676       /**
 677        * <code>required string column = 2;</code>
 678        */
 679       public Builder setColumnBytes(
 680           com.google.protobuf.ByteString value) {
 681         if (value == null) {
 682     throw new NullPointerException();
 683   }
 684   bitField0_ |= 0x00000002;
 685         column_ = value;
 686         onChanged();
 687         return this;
 688       }
 689 
 690       // @@protoc_insertion_point(builder_scope:SumRequest)
 691     }
 692 
 693     static {
 694       defaultInstance = new SumRequest(true);
 695       defaultInstance.initFields();
 696     }
 697 
 698     // @@protoc_insertion_point(class_scope:SumRequest)
 699   }
 700 
 701   public interface SumResponseOrBuilder
 702       extends com.google.protobuf.MessageOrBuilder {
 703 
 704     // required int64 sum = 1 [default = 0];
 705     /**
 706      * <code>required int64 sum = 1 [default = 0];</code>
 707      */
 708     boolean hasSum();
 709     /**
 710      * <code>required int64 sum = 1 [default = 0];</code>
 711      */
 712     long getSum();
 713   }
 714   /**
 715    * Protobuf type {@code SumResponse}
 716    */
 717   public static final class SumResponse extends
 718       com.google.protobuf.GeneratedMessage
 719       implements SumResponseOrBuilder {
 720     // Use SumResponse.newBuilder() to construct.
 721     private SumResponse(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
 722       super(builder);
 723       this.unknownFields = builder.getUnknownFields();
 724     }
 725     private SumResponse(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }
 726 
 727     private static final SumResponse defaultInstance;
 728     public static SumResponse getDefaultInstance() {
 729       return defaultInstance;
 730     }
 731 
 732     public SumResponse getDefaultInstanceForType() {
 733       return defaultInstance;
 734     }
 735 
 736     private final com.google.protobuf.UnknownFieldSet unknownFields;
 737     @java.lang.Override
 738     public final com.google.protobuf.UnknownFieldSet
 739         getUnknownFields() {
 740       return this.unknownFields;
 741     }
 742     private SumResponse(
 743         com.google.protobuf.CodedInputStream input,
 744         com.google.protobuf.ExtensionRegistryLite extensionRegistry)
 745         throws com.google.protobuf.InvalidProtocolBufferException {
 746       initFields();
 747       int mutable_bitField0_ = 0;
 748       com.google.protobuf.UnknownFieldSet.Builder unknownFields =
 749           com.google.protobuf.UnknownFieldSet.newBuilder();
 750       try {
 751         boolean done = false;
 752         while (!done) {
 753           int tag = input.readTag();
 754           switch (tag) {
 755             case 0:
 756               done = true;
 757               break;
 758             default: {
 759               if (!parseUnknownField(input, unknownFields,
 760                                      extensionRegistry, tag)) {
 761                 done = true;
 762               }
 763               break;
 764             }
 765             case 8: {
 766               bitField0_ |= 0x00000001;
 767               sum_ = input.readInt64();
 768               break;
 769             }
 770           }
 771         }
 772       } catch (com.google.protobuf.InvalidProtocolBufferException e) {
 773         throw e.setUnfinishedMessage(this);
 774       } catch (java.io.IOException e) {
 775         throw new com.google.protobuf.InvalidProtocolBufferException(
 776             e.getMessage()).setUnfinishedMessage(this);
 777       } finally {
 778         this.unknownFields = unknownFields.build();
 779         makeExtensionsImmutable();
 780       }
 781     }
 782     public static final com.google.protobuf.Descriptors.Descriptor
 783         getDescriptor() {
 784       return com.endpoint.test.Sum.internal_static_SumResponse_descriptor;
 785     }
 786 
 787     protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
 788         internalGetFieldAccessorTable() {
 789       return com.endpoint.test.Sum.internal_static_SumResponse_fieldAccessorTable
 790           .ensureFieldAccessorsInitialized(
 791               com.endpoint.test.Sum.SumResponse.class, com.endpoint.test.Sum.SumResponse.Builder.class);
 792     }
 793 
 794     public static com.google.protobuf.Parser<SumResponse> PARSER =
 795         new com.google.protobuf.AbstractParser<SumResponse>() {
 796       public SumResponse parsePartialFrom(
 797           com.google.protobuf.CodedInputStream input,
 798           com.google.protobuf.ExtensionRegistryLite extensionRegistry)
 799           throws com.google.protobuf.InvalidProtocolBufferException {
 800         return new SumResponse(input, extensionRegistry);
 801       }
 802     };
 803 
 804     @java.lang.Override
 805     public com.google.protobuf.Parser<SumResponse> getParserForType() {
 806       return PARSER;
 807     }
 808 
 809     private int bitField0_;
 810     // required int64 sum = 1 [default = 0];
 811     public static final int SUM_FIELD_NUMBER = 1;
 812     private long sum_;
 813     /**
 814      * <code>required int64 sum = 1 [default = 0];</code>
 815      */
 816     public boolean hasSum() {
 817       return ((bitField0_ & 0x00000001) == 0x00000001);
 818     }
 819     /**
 820      * <code>required int64 sum = 1 [default = 0];</code>
 821      */
 822     public long getSum() {
 823       return sum_;
 824     }
 825 
 826     private void initFields() {
 827       sum_ = 0L;
 828     }
 829     private byte memoizedIsInitialized = -1;
 830     public final boolean isInitialized() {
 831       byte isInitialized = memoizedIsInitialized;
 832       if (isInitialized != -1) return isInitialized == 1;
 833 
 834       if (!hasSum()) {
 835         memoizedIsInitialized = 0;
 836         return false;
 837       }
 838       memoizedIsInitialized = 1;
 839       return true;
 840     }
 841 
 842     public void writeTo(com.google.protobuf.CodedOutputStream output)
 843                         throws java.io.IOException {
 844       getSerializedSize();
 845       if (((bitField0_ & 0x00000001) == 0x00000001)) {
 846         output.writeInt64(1, sum_);
 847       }
 848       getUnknownFields().writeTo(output);
 849     }
 850 
 851     private int memoizedSerializedSize = -1;
 852     public int getSerializedSize() {
 853       int size = memoizedSerializedSize;
 854       if (size != -1) return size;
 855 
 856       size = 0;
 857       if (((bitField0_ & 0x00000001) == 0x00000001)) {
 858         size += com.google.protobuf.CodedOutputStream
 859           .computeInt64Size(1, sum_);
 860       }
 861       size += getUnknownFields().getSerializedSize();
 862       memoizedSerializedSize = size;
 863       return size;
 864     }
 865 
 866     private static final long serialVersionUID = 0L;
 867     @java.lang.Override
 868     protected java.lang.Object writeReplace()
 869         throws java.io.ObjectStreamException {
 870       return super.writeReplace();
 871     }
 872 
 873     @java.lang.Override
 874     public boolean equals(final java.lang.Object obj) {
 875       if (obj == this) {
 876        return true;
 877       }
 878       if (!(obj instanceof com.endpoint.test.Sum.SumResponse)) {
 879         return super.equals(obj);
 880       }
 881       com.endpoint.test.Sum.SumResponse other = (com.endpoint.test.Sum.SumResponse) obj;
 882 
 883       boolean result = true;
 884       result = result && (hasSum() == other.hasSum());
 885       if (hasSum()) {
 886         result = result && (getSum()
 887             == other.getSum());
 888       }
 889       result = result &&
 890           getUnknownFields().equals(other.getUnknownFields());
 891       return result;
 892     }
 893 
 894     private int memoizedHashCode = 0;
 895     @java.lang.Override
 896     public int hashCode() {
 897       if (memoizedHashCode != 0) {
 898         return memoizedHashCode;
 899       }
 900       int hash = 41;
 901       hash = (19 * hash) + getDescriptorForType().hashCode();
 902       if (hasSum()) {
 903         hash = (37 * hash) + SUM_FIELD_NUMBER;
 904         hash = (53 * hash) + hashLong(getSum());
 905       }
 906       hash = (29 * hash) + getUnknownFields().hashCode();
 907       memoizedHashCode = hash;
 908       return hash;
 909     }
 910 
 911     public static com.endpoint.test.Sum.SumResponse parseFrom(
 912         com.google.protobuf.ByteString data)
 913         throws com.google.protobuf.InvalidProtocolBufferException {
 914       return PARSER.parseFrom(data);
 915     }
 916     public static com.endpoint.test.Sum.SumResponse parseFrom(
 917         com.google.protobuf.ByteString data,
 918         com.google.protobuf.ExtensionRegistryLite extensionRegistry)
 919         throws com.google.protobuf.InvalidProtocolBufferException {
 920       return PARSER.parseFrom(data, extensionRegistry);
 921     }
 922     public static com.endpoint.test.Sum.SumResponse parseFrom(byte[] data)
 923         throws com.google.protobuf.InvalidProtocolBufferException {
 924       return PARSER.parseFrom(data);
 925     }
 926     public static com.endpoint.test.Sum.SumResponse parseFrom(
 927         byte[] data,
 928         com.google.protobuf.ExtensionRegistryLite extensionRegistry)
 929         throws com.google.protobuf.InvalidProtocolBufferException {
 930       return PARSER.parseFrom(data, extensionRegistry);
 931     }
 932     public static com.endpoint.test.Sum.SumResponse parseFrom(java.io.InputStream input)
 933         throws java.io.IOException {
 934       return PARSER.parseFrom(input);
 935     }
 936     public static com.endpoint.test.Sum.SumResponse parseFrom(
 937         java.io.InputStream input,
 938         com.google.protobuf.ExtensionRegistryLite extensionRegistry)
 939         throws java.io.IOException {
 940       return PARSER.parseFrom(input, extensionRegistry);
 941     }
 942     public static com.endpoint.test.Sum.SumResponse parseDelimitedFrom(java.io.InputStream input)
 943         throws java.io.IOException {
 944       return PARSER.parseDelimitedFrom(input);
 945     }
 946     public static com.endpoint.test.Sum.SumResponse parseDelimitedFrom(
 947         java.io.InputStream input,
 948         com.google.protobuf.ExtensionRegistryLite extensionRegistry)
 949         throws java.io.IOException {
 950       return PARSER.parseDelimitedFrom(input, extensionRegistry);
 951     }
 952     public static com.endpoint.test.Sum.SumResponse parseFrom(
 953         com.google.protobuf.CodedInputStream input)
 954         throws java.io.IOException {
 955       return PARSER.parseFrom(input);
 956     }
 957     public static com.endpoint.test.Sum.SumResponse parseFrom(
 958         com.google.protobuf.CodedInputStream input,
 959         com.google.protobuf.ExtensionRegistryLite extensionRegistry)
 960         throws java.io.IOException {
 961       return PARSER.parseFrom(input, extensionRegistry);
 962     }
 963 
 964     public static Builder newBuilder() { return Builder.create(); }
 965     public Builder newBuilderForType() { return newBuilder(); }
 966     public static Builder newBuilder(com.endpoint.test.Sum.SumResponse prototype) {
 967       return newBuilder().mergeFrom(prototype);
 968     }
 969     public Builder toBuilder() { return newBuilder(this); }
 970 
 971     @java.lang.Override
 972     protected Builder newBuilderForType(
 973         com.google.protobuf.GeneratedMessage.BuilderParent parent) {
 974       Builder builder = new Builder(parent);
 975       return builder;
 976     }
 977     /**
 978      * Protobuf type {@code SumResponse}
 979      */
 980     public static final class Builder extends
 981         com.google.protobuf.GeneratedMessage.Builder<Builder>
 982        implements com.endpoint.test.Sum.SumResponseOrBuilder {
 983       public static final com.google.protobuf.Descriptors.Descriptor
 984           getDescriptor() {
 985         return com.endpoint.test.Sum.internal_static_SumResponse_descriptor;
 986       }
 987 
 988       protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
 989           internalGetFieldAccessorTable() {
 990         return com.endpoint.test.Sum.internal_static_SumResponse_fieldAccessorTable
 991             .ensureFieldAccessorsInitialized(
 992                 com.endpoint.test.Sum.SumResponse.class, com.endpoint.test.Sum.SumResponse.Builder.class);
 993       }
 994 
 995       // Construct using com.endpoint.test.Sum.SumResponse.newBuilder()
 996       private Builder() {
 997         maybeForceBuilderInitialization();
 998       }
 999 
1000       private Builder(
1001           com.google.protobuf.GeneratedMessage.BuilderParent parent) {
1002         super(parent);
1003         maybeForceBuilderInitialization();
1004       }
1005       private void maybeForceBuilderInitialization() {
1006         if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
1007         }
1008       }
1009       private static Builder create() {
1010         return new Builder();
1011       }
1012 
1013       public Builder clear() {
1014         super.clear();
1015         sum_ = 0L;
1016         bitField0_ = (bitField0_ & ~0x00000001);
1017         return this;
1018       }
1019 
1020       public Builder clone() {
1021         return create().mergeFrom(buildPartial());
1022       }
1023 
1024       public com.google.protobuf.Descriptors.Descriptor
1025           getDescriptorForType() {
1026         return com.endpoint.test.Sum.internal_static_SumResponse_descriptor;
1027       }
1028 
1029       public com.endpoint.test.Sum.SumResponse getDefaultInstanceForType() {
1030         return com.endpoint.test.Sum.SumResponse.getDefaultInstance();
1031       }
1032 
1033       public com.endpoint.test.Sum.SumResponse build() {
1034         com.endpoint.test.Sum.SumResponse result = buildPartial();
1035         if (!result.isInitialized()) {
1036           throw newUninitializedMessageException(result);
1037         }
1038         return result;
1039       }
1040 
1041       public com.endpoint.test.Sum.SumResponse buildPartial() {
1042         com.endpoint.test.Sum.SumResponse result = new com.endpoint.test.Sum.SumResponse(this);
1043         int from_bitField0_ = bitField0_;
1044         int to_bitField0_ = 0;
1045         if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
1046           to_bitField0_ |= 0x00000001;
1047         }
1048         result.sum_ = sum_;
1049         result.bitField0_ = to_bitField0_;
1050         onBuilt();
1051         return result;
1052       }
1053 
1054       public Builder mergeFrom(com.google.protobuf.Message other) {
1055         if (other instanceof com.endpoint.test.Sum.SumResponse) {
1056           return mergeFrom((com.endpoint.test.Sum.SumResponse)other);
1057         } else {
1058           super.mergeFrom(other);
1059           return this;
1060         }
1061       }
1062 
1063       public Builder mergeFrom(com.endpoint.test.Sum.SumResponse other) {
1064         if (other == com.endpoint.test.Sum.SumResponse.getDefaultInstance()) return this;
1065         if (other.hasSum()) {
1066           setSum(other.getSum());
1067         }
1068         this.mergeUnknownFields(other.getUnknownFields());
1069         return this;
1070       }
1071 
1072       public final boolean isInitialized() {
1073         if (!hasSum()) {
1074           
1075           return false;
1076         }
1077         return true;
1078       }
1079 
1080       public Builder mergeFrom(
1081           com.google.protobuf.CodedInputStream input,
1082           com.google.protobuf.ExtensionRegistryLite extensionRegistry)
1083           throws java.io.IOException {
1084         com.endpoint.test.Sum.SumResponse parsedMessage = null;
1085         try {
1086           parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
1087         } catch (com.google.protobuf.InvalidProtocolBufferException e) {
1088           parsedMessage = (com.endpoint.test.Sum.SumResponse) e.getUnfinishedMessage();
1089           throw e;
1090         } finally {
1091           if (parsedMessage != null) {
1092             mergeFrom(parsedMessage);
1093           }
1094         }
1095         return this;
1096       }
1097       private int bitField0_;
1098 
1099       // required int64 sum = 1 [default = 0];
1100       private long sum_ ;
1101       /**
1102        * <code>required int64 sum = 1 [default = 0];</code>
1103        */
1104       public boolean hasSum() {
1105         return ((bitField0_ & 0x00000001) == 0x00000001);
1106       }
1107       /**
1108        * <code>required int64 sum = 1 [default = 0];</code>
1109        */
1110       public long getSum() {
1111         return sum_;
1112       }
1113       /**
1114        * <code>required int64 sum = 1 [default = 0];</code>
1115        */
1116       public Builder setSum(long value) {
1117         bitField0_ |= 0x00000001;
1118         sum_ = value;
1119         onChanged();
1120         return this;
1121       }
1122       /**
1123        * <code>required int64 sum = 1 [default = 0];</code>
1124        */
1125       public Builder clearSum() {
1126         bitField0_ = (bitField0_ & ~0x00000001);
1127         sum_ = 0L;
1128         onChanged();
1129         return this;
1130       }
1131 
1132       // @@protoc_insertion_point(builder_scope:SumResponse)
1133     }
1134 
1135     static {
1136       defaultInstance = new SumResponse(true);
1137       defaultInstance.initFields();
1138     }
1139 
1140     // @@protoc_insertion_point(class_scope:SumResponse)
1141   }
1142 
1143   /**
1144    * Protobuf service {@code SumService}
1145    */
1146   public static abstract class SumService
1147       implements com.google.protobuf.Service {
1148     protected SumService() {}
1149 
1150     public interface Interface {
1151       /**
1152        * <code>rpc getSum(.SumRequest) returns (.SumResponse);</code>
1153        */
1154       public abstract void getSum(
1155           com.google.protobuf.RpcController controller,
1156           com.endpoint.test.Sum.SumRequest request,
1157           com.google.protobuf.RpcCallback<com.endpoint.test.Sum.SumResponse> done);
1158 
1159     }
1160 
1161     public static com.google.protobuf.Service newReflectiveService(
1162         final Interface impl) {
1163       return new SumService() {
1164         @java.lang.Override
1165         public  void getSum(
1166             com.google.protobuf.RpcController controller,
1167             com.endpoint.test.Sum.SumRequest request,
1168             com.google.protobuf.RpcCallback<com.endpoint.test.Sum.SumResponse> done) {
1169           impl.getSum(controller, request, done);
1170         }
1171 
1172       };
1173     }
1174 
1175     public static com.google.protobuf.BlockingService
1176         newReflectiveBlockingService(final BlockingInterface impl) {
1177       return new com.google.protobuf.BlockingService() {
1178         public final com.google.protobuf.Descriptors.ServiceDescriptor
1179             getDescriptorForType() {
1180           return getDescriptor();
1181         }
1182 
1183         public final com.google.protobuf.Message callBlockingMethod(
1184             com.google.protobuf.Descriptors.MethodDescriptor method,
1185             com.google.protobuf.RpcController controller,
1186             com.google.protobuf.Message request)
1187             throws com.google.protobuf.ServiceException {
1188           if (method.getService() != getDescriptor()) {
1189             throw new java.lang.IllegalArgumentException(
1190               "Service.callBlockingMethod() given method descriptor for " +
1191               "wrong service type.");
1192           }
1193           switch(method.getIndex()) {
1194             case 0:
1195               return impl.getSum(controller, (com.endpoint.test.Sum.SumRequest)request);
1196             default:
1197               throw new java.lang.AssertionError("Can't get here.");
1198           }
1199         }
1200 
1201         public final com.google.protobuf.Message
1202             getRequestPrototype(
1203             com.google.protobuf.Descriptors.MethodDescriptor method) {
1204           if (method.getService() != getDescriptor()) {
1205             throw new java.lang.IllegalArgumentException(
1206               "Service.getRequestPrototype() given method " +
1207               "descriptor for wrong service type.");
1208           }
1209           switch(method.getIndex()) {
1210             case 0:
1211               return com.endpoint.test.Sum.SumRequest.getDefaultInstance();
1212             default:
1213               throw new java.lang.AssertionError("Can't get here.");
1214           }
1215         }
1216 
1217         public final com.google.protobuf.Message
1218             getResponsePrototype(
1219             com.google.protobuf.Descriptors.MethodDescriptor method) {
1220           if (method.getService() != getDescriptor()) {
1221             throw new java.lang.IllegalArgumentException(
1222               "Service.getResponsePrototype() given method " +
1223               "descriptor for wrong service type.");
1224           }
1225           switch(method.getIndex()) {
1226             case 0:
1227               return com.endpoint.test.Sum.SumResponse.getDefaultInstance();
1228             default:
1229               throw new java.lang.AssertionError("Can't get here.");
1230           }
1231         }
1232 
1233       };
1234     }
1235 
1236     /**
1237      * <code>rpc getSum(.SumRequest) returns (.SumResponse);</code>
1238      */
1239     public abstract void getSum(
1240         com.google.protobuf.RpcController controller,
1241         com.endpoint.test.Sum.SumRequest request,
1242         com.google.protobuf.RpcCallback<com.endpoint.test.Sum.SumResponse> done);
1243 
1244     public static final
1245         com.google.protobuf.Descriptors.ServiceDescriptor
1246         getDescriptor() {
1247       return com.endpoint.test.Sum.getDescriptor().getServices().get(0);
1248     }
1249     public final com.google.protobuf.Descriptors.ServiceDescriptor
1250         getDescriptorForType() {
1251       return getDescriptor();
1252     }
1253 
1254     public final void callMethod(
1255         com.google.protobuf.Descriptors.MethodDescriptor method,
1256         com.google.protobuf.RpcController controller,
1257         com.google.protobuf.Message request,
1258         com.google.protobuf.RpcCallback<
1259           com.google.protobuf.Message> done) {
1260       if (method.getService() != getDescriptor()) {
1261         throw new java.lang.IllegalArgumentException(
1262           "Service.callMethod() given method descriptor for wrong " +
1263           "service type.");
1264       }
1265       switch(method.getIndex()) {
1266         case 0:
1267           this.getSum(controller, (com.endpoint.test.Sum.SumRequest)request,
1268             com.google.protobuf.RpcUtil.<com.endpoint.test.Sum.SumResponse>specializeCallback(
1269               done));
1270           return;
1271         default:
1272           throw new java.lang.AssertionError("Can't get here.");
1273       }
1274     }
1275 
1276     public final com.google.protobuf.Message
1277         getRequestPrototype(
1278         com.google.protobuf.Descriptors.MethodDescriptor method) {
1279       if (method.getService() != getDescriptor()) {
1280         throw new java.lang.IllegalArgumentException(
1281           "Service.getRequestPrototype() given method " +
1282           "descriptor for wrong service type.");
1283       }
1284       switch(method.getIndex()) {
1285         case 0:
1286           return com.endpoint.test.Sum.SumRequest.getDefaultInstance();
1287         default:
1288           throw new java.lang.AssertionError("Can't get here.");
1289       }
1290     }
1291 
1292     public final com.google.protobuf.Message
1293         getResponsePrototype(
1294         com.google.protobuf.Descriptors.MethodDescriptor method) {
1295       if (method.getService() != getDescriptor()) {
1296         throw new java.lang.IllegalArgumentException(
1297           "Service.getResponsePrototype() given method " +
1298           "descriptor for wrong service type.");
1299       }
1300       switch(method.getIndex()) {
1301         case 0:
1302           return com.endpoint.test.Sum.SumResponse.getDefaultInstance();
1303         default:
1304           throw new java.lang.AssertionError("Can't get here.");
1305       }
1306     }
1307 
1308     public static Stub newStub(
1309         com.google.protobuf.RpcChannel channel) {
1310       return new Stub(channel);
1311     }
1312 
1313     public static final class Stub extends com.endpoint.test.Sum.SumService implements Interface {
1314       private Stub(com.google.protobuf.RpcChannel channel) {
1315         this.channel = channel;
1316       }
1317 
1318       private final com.google.protobuf.RpcChannel channel;
1319 
1320       public com.google.protobuf.RpcChannel getChannel() {
1321         return channel;
1322       }
1323 
1324       public  void getSum(
1325           com.google.protobuf.RpcController controller,
1326           com.endpoint.test.Sum.SumRequest request,
1327           com.google.protobuf.RpcCallback<com.endpoint.test.Sum.SumResponse> done) {
1328         channel.callMethod(
1329           getDescriptor().getMethods().get(0),
1330           controller,
1331           request,
1332           com.endpoint.test.Sum.SumResponse.getDefaultInstance(),
1333           com.google.protobuf.RpcUtil.generalizeCallback(
1334             done,
1335             com.endpoint.test.Sum.SumResponse.class,
1336             com.endpoint.test.Sum.SumResponse.getDefaultInstance()));
1337       }
1338     }
1339 
1340     public static BlockingInterface newBlockingStub(
1341         com.google.protobuf.BlockingRpcChannel channel) {
1342       return new BlockingStub(channel);
1343     }
1344 
1345     public interface BlockingInterface {
1346       public com.endpoint.test.Sum.SumResponse getSum(
1347           com.google.protobuf.RpcController controller,
1348           com.endpoint.test.Sum.SumRequest request)
1349           throws com.google.protobuf.ServiceException;
1350     }
1351 
1352     private static final class BlockingStub implements BlockingInterface {
1353       private BlockingStub(com.google.protobuf.BlockingRpcChannel channel) {
1354         this.channel = channel;
1355       }
1356 
1357       private final com.google.protobuf.BlockingRpcChannel channel;
1358 
1359       public com.endpoint.test.Sum.SumResponse getSum(
1360           com.google.protobuf.RpcController controller,
1361           com.endpoint.test.Sum.SumRequest request)
1362           throws com.google.protobuf.ServiceException {
1363         return (com.endpoint.test.Sum.SumResponse) channel.callBlockingMethod(
1364           getDescriptor().getMethods().get(0),
1365           controller,
1366           request,
1367           com.endpoint.test.Sum.SumResponse.getDefaultInstance());
1368       }
1369 
1370     }
1371 
1372     // @@protoc_insertion_point(class_scope:SumService)
1373   }
1374 
1375   private static com.google.protobuf.Descriptors.Descriptor
1376     internal_static_SumRequest_descriptor;
1377   private static
1378     com.google.protobuf.GeneratedMessage.FieldAccessorTable
1379       internal_static_SumRequest_fieldAccessorTable;
1380   private static com.google.protobuf.Descriptors.Descriptor
1381     internal_static_SumResponse_descriptor;
1382   private static
1383     com.google.protobuf.GeneratedMessage.FieldAccessorTable
1384       internal_static_SumResponse_fieldAccessorTable;
1385 
1386   public static com.google.protobuf.Descriptors.FileDescriptor
1387       getDescriptor() {
1388     return descriptor;
1389   }
1390   private static com.google.protobuf.Descriptors.FileDescriptor
1391       descriptor;
1392   static {
1393     java.lang.String[] descriptorData = {
1394       "\n\rsumcode.proto\",\n\nSumRequest\022\016\n\006family\030" +
1395       "\001 \002(\t\022\016\n\006column\030\002 \002(\t\"\035\n\013SumResponse\022\016\n\003" +
1396       "sum\030\001 \002(\003:\001021\n\nSumService\022#\n\006getSum\022\013.S" +
1397       "umRequest\032\014.SumResponseB \n\021com.endpoint." +
1398       "testB\003SumH\001\210\001\001\240\001\001"
1399     };
1400     com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
1401       new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
1402         public com.google.protobuf.ExtensionRegistry assignDescriptors(
1403             com.google.protobuf.Descriptors.FileDescriptor root) {
1404           descriptor = root;
1405           internal_static_SumRequest_descriptor =
1406             getDescriptor().getMessageTypes().get(0);
1407           internal_static_SumRequest_fieldAccessorTable = new
1408             com.google.protobuf.GeneratedMessage.FieldAccessorTable(
1409               internal_static_SumRequest_descriptor,
1410               new java.lang.String[] { "Family", "Column", });
1411           internal_static_SumResponse_descriptor =
1412             getDescriptor().getMessageTypes().get(1);
1413           internal_static_SumResponse_fieldAccessorTable = new
1414             com.google.protobuf.GeneratedMessage.FieldAccessorTable(
1415               internal_static_SumResponse_descriptor,
1416               new java.lang.String[] { "Sum", });
1417           return null;
1418         }
1419       };
1420     com.google.protobuf.Descriptors.FileDescriptor
1421       .internalBuildGeneratedFileFrom(descriptorData,
1422         new com.google.protobuf.Descriptors.FileDescriptor[] {
1423         }, assigner);
1424   }
1425 
1426   // @@protoc_insertion_point(outer_class_scope)
1427 }

public final class Sum {
  private Sum() {}
  public static void registerAllExtensions(
      com.google.protobuf.ExtensionRegistry registry) {
  }
  public interface SumRequestOrBuilder
      extends com.google.protobuf.MessageOrBuilder {

View Code

    // required string family = 1;
    /**
    * <code>required string family = 1;</code>
    */
    boolean hasFamily();
    /**
    * <code>required string family = 1;</code>
    */
    java.lang.String getFamily();
    /**
    * <code>required string family = 1;</code>
    */
    com.google.protobuf.ByteString
        getFamilyBytes();

 贰> 编写服务器端的代码

    // required string column = 2;
    /**
    * <code>required string column = 2;</code>
    */
    boolean hasColumn();
    /**
    * <code>required string column = 2;</code>
    */
    java.lang.String getColumn();
    /**
    * <code>required string column = 2;</code>
    */
    com.google.protobuf.ByteString
        getColumnBytes();
  }
  /**
  * Protobuf type %7B@code SumRequest}
  */
  public static final class SumRequest extends
      com.google.protobuf.GeneratedMessage
      implements SumRequestOrBuilder {
    // Use SumRequest.newBuilder() to construct.
    private
SumRequest(com.google.protobuf.GeneratedMessage.Builder<?>
builder) {
      super(builder);
      this.unknownFields = builder.getUnknownFields();
    }
    private SumRequest(boolean noInit) { this.unknownFields =
com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }

 1 package com.endpoint.test;
 2 
 3 import java.io.IOException;
 4 import java.util.ArrayList;
 5 import java.util.List;
 6 import org.apache.hadoop.hbase.Cell;
 7 import org.apache.hadoop.hbase.CellUtil;
 8 import org.apache.hadoop.hbase.Coprocessor;
 9 import org.apache.hadoop.hbase.CoprocessorEnvironment;
10 import org.apache.hadoop.hbase.client.Scan;
11 import org.apache.hadoop.hbase.coprocessor.CoprocessorException;
12 import org.apache.hadoop.hbase.coprocessor.CoprocessorService;
13 import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
14 import org.apache.hadoop.hbase.protobuf.ResponseConverter;
15 import org.apache.hadoop.hbase.regionserver.InternalScanner;
16 import org.apache.hadoop.hbase.util.Bytes;
17 import com.endpoint.test.Sum.SumRequest;
18 import com.endpoint.test.Sum.SumResponse;
19 import com.endpoint.test.Sum.SumService;
20 import com.google.protobuf.RpcCallback;
21 import com.google.protobuf.RpcController;
22 import com.google.protobuf.Service;
23 
24 public class SumEndPoint extends SumService implements Coprocessor,CoprocessorService{
25 
26     private RegionCoprocessorEnvironment env;   // 定义环境  
27     @Override
28     public Service getService() {
29         
30         return this;
31     }
32 
33     @Override
34     public void start(CoprocessorEnvironment env) throws IOException {
35          if (env instanceof RegionCoprocessorEnvironment) {  
36                 this.env = (RegionCoprocessorEnvironment)env;  
37             } else {  
38                 throw new CoprocessorException("no load region");  
39             }  
40         
41     }
42 
43     @Override
44     public void stop(CoprocessorEnvironment env) throws IOException {
45                 
46     }
47 
48     @Override
49     public void getSum(RpcController controller, SumRequest request, RpcCallback<SumResponse> done) {
50         
51         // 设置扫描对象  
52         Scan scan = new Scan();  
53         scan.addFamily(Bytes.toBytes(request.getFamily()));  
54         scan.addColumn(Bytes.toBytes(request.getFamily()), Bytes.toBytes(request.getColumn()));  
55         
56         // 定义变量  
57         SumResponse response = null;  
58         InternalScanner scanner = null;  
59         
60         // 扫描每个region,取值后求和  
61         try {  
62             scanner = env.getRegion().getScanner(scan);  
63             List<Cell> results = new ArrayList<Cell>();  
64             boolean hasMore = false;  
65             Long sum = 0L;  
66             do {  
67                 hasMore = scanner.next(results);  
68                 for (Cell cell : results) {  
69                     sum += Long.parseLong(new String(CellUtil.cloneValue(cell)));  
70                 }  
71                 results.clear();  
72             } while (hasMore);  
73             // 设置返回结果  
74             response = SumResponse.newBuilder().setSum(sum).build();  
75         } catch (IOException e) {  
76             ResponseConverter.setControllerException(controller, e);  
77         } finally {  
78             if (scanner != null) {  
79                 try {  
80                     scanner.close();  
81                 } catch (IOException e) {  
82                     //e.printStackTrace();  
83                 }  
84             }  
85         }  
86         // 将rpc结果返回给客户端  
87         done.run(response);  
88         
89     }
90 
91 }

    private static final SumRequest defaultInstance;
    public static SumRequest getDefaultInstance() {
      return defaultInstance;
    }

 3> 客户端测试代码

    public SumRequest getDefaultInstanceForType() {
      return defaultInstance;
    }

 1 package com.endpoint.test;
 2 
 3 import java.io.IOException;
 4 import java.util.Map;
 5 import org.apache.hadoop.conf.Configuration;
 6 import org.apache.hadoop.hbase.HBaseConfiguration;
 7 import org.apache.hadoop.hbase.TableName;
 8 import org.apache.hadoop.hbase.client.Connection;
 9 import org.apache.hadoop.hbase.client.ConnectionFactory;
10 import org.apache.hadoop.hbase.client.HTable;
11 import org.apache.hadoop.hbase.client.coprocessor.Batch;
12 import org.apache.hadoop.hbase.ipc.BlockingRpcCallback;
13 import com.endpoint.test.Sum.SumRequest;
14 import com.endpoint.test.Sum.SumResponse;
15 import com.endpoint.test.Sum.SumService;
16 import com.google.protobuf.ServiceException;
17 
18 public class TestClient {
19 
20     public static void main(String[] args) throws Exception {
21           
22             // 配置HBse  
23             Configuration conf = HBaseConfiguration.create();  
24             conf.set("hbase.zookeeper.quorum", "master,data1,data2");  
25             conf.set("hbase.zookeeper.property.clientPort", "2181");  
26             conf.setLong("hbase.rpc.timeout", 600000);
27             System.setProperty("hadoop.home.dir", "C:/hadoopfiles/hadoop-common-2.2.0-bin-master");
28 
29             // 建立一个数据库的连接  
30             Connection conn = ConnectionFactory.createConnection(conf);  
31             // 获取表  
32             HTable table = (HTable) conn.getTable(TableName.valueOf("etable"));  
33             
34             long sum = 0L;                
35             
36             // 设置请求对象  
37             final SumRequest request = SumRequest.newBuilder().setFamily("cf").setColumn("value").build();  
38             
39             try {
40                 // 获得返回值  
41                 Map<byte[], Long> result = table.coprocessorService(SumService.class, null, null,   
42                         new Batch.Call<SumService, Long>() {  
43           
44                             @Override  
45                             public Long call(SumService service) throws IOException {  
46                                 BlockingRpcCallback<SumResponse> rpcCallback = new BlockingRpcCallback<SumResponse>();  
47                                 service.getSum(null, request, rpcCallback);  
48                                 SumResponse response = (SumResponse) rpcCallback.get();  
49                                 return response.hasSum() ? response.getSum() : 0L;
50                             }  
51                 });  
52                 // 将返回值进行迭代相加  
53                 for (Long v : result.values()) {  
54                     sum += v;  
55                 }  
56                 // 结果输出  
57                 System.out.println("sum: " + sum);                        
58                 
59             } catch (ServiceException e) {
60                 e.printStackTrace(); 
61             }catch (Throwable e) {
62                 e.printStackTrace(); 
63             }
64             table.close();  
65             conn.close();  
66 
67     }
68 
69 }

    private final com.google.protobuf.UnknownFieldSet unknownFields;
    @java.lang.Override
    public final com.google.protobuf.UnknownFieldSet
        getUnknownFields() {
      return this.unknownFields;
    }
    private SumRequest(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      initFields();
      int mutable_bitField0_ = 0;
      com.google.protobuf.UnknownFieldSet.Builder unknownFields =
          com.google.protobuf.UnknownFieldSet.newBuilder();
      try {
        boolean done = false;
        while (!done) {
          int tag = input.readTag();
          switch (tag) {
            case 0:
              done = true;
              break;
            default: {
              if (!parseUnknownField(input, unknownFields,
                                    extensionRegistry, tag)) {
                done = true;
              }
              break;
            }
            case 10: {
              bitField0_ |= 0x00000001;
              family_ = input.readBytes();
              break;
            }
            case 18: {
              bitField0_ |= 0x00000002;
              column_ = input.readBytes();
              break;
            }
          }
        }
      } catch (com.google.protobuf.InvalidProtocolBufferException e) {
        throw e.setUnfinishedMessage(this);
      } catch (java.io.IOException e) {
        throw new com.google.protobuf.InvalidProtocolBufferException(
            e.getMessage()).setUnfinishedMessage(this);
      } finally {
        this.unknownFields = unknownFields.build();
        makeExtensionsImmutable();
      }
    }
    public static final com.google.protobuf.Descriptors.Descriptor
        getDescriptor() {
      return
com.endpoint.test.Sum.internal_static_SumRequest_descriptor;
    }

System.setProperty(“hadoop.home.dir”,
“C:/hadoopfiles/hadoop-common-二.2.0-bin-master”);
那句代码是防错误用的,不富有实际意义,在hadoop-common-2.二.0-bin-master下创建bin目录放3个winutils.exe文件就能够,不然会晤世提醒“Could
not locate executable null\bin\winutils.exe in the Hadoop binaries”

    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
        internalGetFieldAccessorTable() {
      return
com.endpoint.test.Sum.internal_static_SumRequest_fieldAccessorTable
          .ensureFieldAccessorsInitialized(
              com.endpoint.test.Sum.SumRequest.class,
com.endpoint.test.Sum.SumRequest.Builder.class);
    }

别的,须要在windows下设置一下hosts文件,因为conf.set(“hbase.zookeeper.quorum”,
“master,data壹,data二”);

    public static com.google.protobuf.Parser<SumRequest> PARSER

        new com.google.protobuf.AbstractParser<SumRequest>() {
      public SumRequest parsePartialFrom(
          com.google.protobuf.CodedInputStream input,
          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
          throws com.google.protobuf.InvalidProtocolBufferException {
        return new SumRequest(input, extensionRegistry);
      }
    };

    @java.lang.Override
    public com.google.protobuf.Parser<SumRequest>
getParserForType() {
      return PARSER;
    }

    private int bitField0_;
    // required string family = 1;
    public static final int FAMILY_FIELD_NUMBER = 1;
    private java.lang.Object family_;
    /**
    * <code>required string family = 1;</code>
    */
    public boolean hasFamily() {
      return ((bitField0_ & 0x00000001) == 0x00000001);
    }
    /**
    * <code>required string family = 1;</code>
    */
    public java.lang.String getFamily() {
      java.lang.Object ref = family_;
      if (ref instanceof java.lang.String) {
        return (java.lang.String) ref;
      } else {
        com.google.protobuf.ByteString bs =
            (com.google.protobuf.ByteString) ref;
        java.lang.String s = bs.toStringUtf8();
        if (bs.isValidUtf8()) {
          family_ = s;
        }
        return s;
      }
    }
    /**
    * <code>required string family = 1;</code>
    */
    public com.google.protobuf.ByteString
        getFamilyBytes() {
      java.lang.Object ref = family_;
      if (ref instanceof java.lang.String) {
        com.google.protobuf.ByteString b =
            com.google.protobuf.ByteString.copyFromUtf8(
                (java.lang.String) ref);
        family_ = b;
        return b;
      } else {
        return (com.google.protobuf.ByteString) ref;
      }
    }

    // required string column = 2;
    public static final int COLUMN_FIELD_NUMBER = 2;
    private java.lang.Object column_;
    /**
    * <code>required string column = 2;</code>
    */
    public boolean hasColumn() {
      return ((bitField0_ & 0x00000002) == 0x00000002);
    }
    /**
    * <code>required string column = 2;</code>
    */
    public java.lang.String getColumn() {
      java.lang.Object ref = column_;
      if (ref instanceof java.lang.String) {
        return (java.lang.String) ref;
      } else {
        com.google.protobuf.ByteString bs =
            (com.google.protobuf.ByteString) ref;
        java.lang.String s = bs.toStringUtf8();
        if (bs.isValidUtf8()) {
          column_ = s;
        }
        return s;
      }
    }
    /**
    * <code>required string column = 2;</code>
    */
    public com.google.protobuf.ByteString
        getColumnBytes() {
      java.lang.Object ref = column_;
      if (ref instanceof java.lang.String) {
        com.google.protobuf.ByteString b =
            com.google.protobuf.ByteString.copyFromUtf8(
                (java.lang.String) ref);
        column_ = b;
        return b;
      } else {
        return (com.google.protobuf.ByteString) ref;
      }
    }

    private void initFields() {
      family_ = “”;
      column_ = “”;
    }
    private byte memoizedIsInitialized = -1;
    public final boolean isInitialized() {
      byte isInitialized = memoizedIsInitialized;
      if (isInitialized != -1) return isInitialized == 1;

      if (!hasFamily()) {
        memoizedIsInitialized = 0;
        return false;
      }
      if (!hasColumn()) {
        memoizedIsInitialized = 0;
        return false;
      }
      memoizedIsInitialized = 1;
      return true;
    }

    public void writeTo(com.google.protobuf.CodedOutputStream output)
                        throws java.io.IOException {
      getSerializedSize();
      if (((bitField0_ & 0x00000001) == 0x00000001)) {
        output.writeBytes(1, getFamilyBytes());
      }
      if (((bitField0_ & 0x00000002) == 0x00000002)) {
        output.writeBytes(2, getColumnBytes());
      }
      getUnknownFields().writeTo(output);
    }

    private int memoizedSerializedSize = -1;
    public int getSerializedSize() {
      int size = memoizedSerializedSize;
      if (size != -1) return size;

      size = 0;
      if (((bitField0_ & 0x00000001) == 0x00000001)) {
        size += com.google.protobuf.CodedOutputStream
          .computeBytesSize(1, getFamilyBytes());
      }
      if (((bitField0_ & 0x00000002) == 0x00000002)) {
        size += com.google.protobuf.CodedOutputStream
          .computeBytesSize(2, getColumnBytes());
      }
      size += getUnknownFields().getSerializedSize();
      memoizedSerializedSize = size;
      return size;
    }

    private static final long serialVersionUID = 0L;
    @java.lang.Override
    protected java.lang.Object writeReplace()
        throws java.io.ObjectStreamException {
      return super.writeReplace();
    }

    @java.lang.Override
    public boolean equals(final java.lang.Object obj) {
      if (obj == this) {
      return true;
      }
      if (!(obj instanceof com.endpoint.test.Sum.SumRequest)) {
        return super.equals(obj);
      }
      com.endpoint.test.Sum.SumRequest other =
(com.endpoint.test.Sum.SumRequest) obj;

      boolean result = true;
      result = result && (hasFamily() == other.hasFamily());
      if (hasFamily()) {
        result = result && getFamily()
            .equals(other.getFamily());
      }
      result = result && (hasColumn() == other.hasColumn());
      if (hasColumn()) {
        result = result && getColumn()
            .equals(other.getColumn());
      }
      result = result &&
          getUnknownFields().equals(other.getUnknownFields());
      return result;
    }

    private int memoizedHashCode = 0;
    @java.lang.Override
    public int hashCode() {
      if (memoizedHashCode != 0) {
        return memoizedHashCode;
      }
      int hash = 41;
      hash = (19 * hash) + getDescriptorForType().hashCode();
      if (hasFamily()) {
        hash = (37 * hash) + FAMILY_FIELD_NUMBER;
        hash = (53 * hash) + getFamily().hashCode();
      }
      if (hasColumn()) {
        hash = (37 * hash) + COLUMN_FIELD_NUMBER;
        hash = (53 * hash) + getColumn().hashCode();
      }
      hash = (29 * hash) + getUnknownFields().hashCode();
      memoizedHashCode = hash;
      return hash;
    }

    public static com.endpoint.test.Sum.SumRequest parseFrom(
        com.google.protobuf.ByteString data)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return PARSER.parseFrom(data);
    }
    public static com.endpoint.test.Sum.SumRequest parseFrom(
        com.google.protobuf.ByteString data,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return PARSER.parseFrom(data, extensionRegistry);
    }
    public static com.endpoint.test.Sum.SumRequest parseFrom(byte[]
data)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return PARSER.parseFrom(data);
    }
    public static com.endpoint.test.Sum.SumRequest parseFrom(
        byte[] data,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return PARSER.parseFrom(data, extensionRegistry);
    }
    public static com.endpoint.test.Sum.SumRequest
parseFrom(java.io.InputStream input)
        throws java.io.IOException {
      return PARSER.parseFrom(input);
    }
    public static com.endpoint.test.Sum.SumRequest parseFrom(
        java.io.InputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws java.io.IOException {
      return PARSER.parseFrom(input, extensionRegistry);
    }
    public static com.endpoint.test.Sum.SumRequest
parseDelimitedFrom(java.io.InputStream input)
        throws java.io.IOException {
      return PARSER.parseDelimitedFrom(input);
    }
    public static com.endpoint.test.Sum.SumRequest parseDelimitedFrom(
        java.io.InputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws java.io.IOException {
      return PARSER.parseDelimitedFrom(input, extensionRegistry);
    }
    public static com.endpoint.test.Sum.SumRequest parseFrom(
        com.google.protobuf.CodedInputStream input)
        throws java.io.IOException {
      return PARSER.parseFrom(input);
    }
    public static com.endpoint.test.Sum.SumRequest parseFrom(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws java.io.IOException {
      return PARSER.parseFrom(input, extensionRegistry);
    }

    public static Builder newBuilder() { return Builder.create(); }
    public Builder newBuilderForType() { return newBuilder(); }
    public static Builder newBuilder(com.endpoint.test.Sum.SumRequest
prototype) {
      return newBuilder().mergeFrom(prototype);
    }
    public Builder toBuilder() { return newBuilder(this); }

    @java.lang.Override
    protected Builder newBuilderForType(
        com.google.protobuf.GeneratedMessage.BuilderParent parent) {
      Builder builder = new Builder(parent);
      return builder;
    }
    /**
    * Protobuf type %7B@code SumRequest}
    */
    public static final class Builder extends
        com.google.protobuf.GeneratedMessage.Builder<Builder>
      implements com.endpoint.test.Sum.SumRequestOrBuilder {
      public static final com.google.protobuf.Descriptors.Descriptor
          getDescriptor() {
        return
com.endpoint.test.Sum.internal_static_SumRequest_descriptor;
      }

      protected
com.google.protobuf.GeneratedMessage.FieldAccessorTable
          internalGetFieldAccessorTable() {
        return
com.endpoint.test.Sum.internal_static_SumRequest_fieldAccessorTable
            .ensureFieldAccessorsInitialized(
                com.endpoint.test.Sum.SumRequest.class,
com.endpoint.test.Sum.SumRequest.Builder.class);
      }

      // Construct using com.endpoint.test.Sum.SumRequest.newBuilder()
      private Builder() {
        maybeForceBuilderInitialization();
      }

      private Builder(
          com.google.protobuf.GeneratedMessage.BuilderParent parent) {
        super(parent);
        maybeForceBuilderInitialization();
      }
      private void maybeForceBuilderInitialization() {
        if
(com.google.protobuf.GeneratedMessage.alwaySUSEFieldBuilders)
{
        }
      }
      private static Builder create() {
        return new Builder();
      }

      public Builder clear() {
        super.clear();
        family_ = “”;
        bitField0_ = (bitField0_ & ~0x00000001);
        column_ = “”;
        bitField0_ = (bitField0_ & ~0x00000002);
        return this;
      }

      public Builder clone() {
        return create().mergeFrom(buildPartial());
      }

      public com.google.protobuf.Descriptors.Descriptor
          getDescriptorForType() {
        return
com.endpoint.test.Sum.internal_static_SumRequest_descriptor;
      }

      public com.endpoint.test.Sum.SumRequest
getDefaultInstanceForType() {
        return com.endpoint.test.Sum.SumRequest.getDefaultInstance();
      }

      public com.endpoint.test.Sum.SumRequest build() {
        com.endpoint.test.Sum.SumRequest result = buildPartial();
        if (!result.isInitialized()) {
          throw newUninitializedMessageException(result);
        }
        return result;
      }

      public com.endpoint.test.Sum.SumRequest buildPartial() {
        com.endpoint.test.Sum.SumRequest result = new
com.endpoint.test.Sum.SumRequest(this);
        int from_bitField0_ = bitField0_;
        int to_bitField0_ = 0;
        if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
          to_bitField0_ |= 0x00000001;
        }
        result.family_ = family_;
        if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
          to_bitField0_ |= 0x00000002;
        }
        result.column_ = column_;
        result.bitField0_ = to_bitField0_;
        onBuilt();
        return result;
      }

      public Builder mergeFrom(com.google.protobuf.Message other) {
        if (other instanceof com.endpoint.test.Sum.SumRequest) {
          return mergeFrom((com.endpoint.test.Sum.SumRequest)other);
        } else {
          super.mergeFrom(other);
          return this;
        }
      }

      public Builder mergeFrom(com.endpoint.test.Sum.SumRequest other)
{
        if (other ==
com.endpoint.test.Sum.SumRequest.getDefaultInstance()) return this;
        if (other.hasFamily()) {
          bitField0_ |= 0x00000001;
          family_ = other.family_;
          onChanged();
        }
        if (other.hasColumn()) {
          bitField0_ |= 0x00000002;
          column_ = other.column_;
          onChanged();
        }
        this.mergeUnknownFields(other.getUnknownFields());
        return this;
      }

      public final boolean isInitialized() {
        if (!hasFamily()) {
         
          return false;
        }
        if (!hasColumn()) {
         
          return false;
        }
        return true;
      }

      public Builder mergeFrom(
          com.google.protobuf.CodedInputStream input,
          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
          throws java.io.IOException {
        com.endpoint.test.Sum.SumRequest parsedMessage = null;
        try {
          parsedMessage = PARSER.parsePartialFrom(input,
extensionRegistry);
        } catch (com.google.protobuf.InvalidProtocolBufferException e)
{
          parsedMessage = (com.endpoint.test.Sum.SumRequest)
e.getUnfinishedMessage();
          throw e;
        } finally {
          if (parsedMessage != null) {
            mergeFrom(parsedMessage);
          }
        }
        return this;
      }
      private int bitField0_;

      // required string family = 1;
      private java.lang.Object family_ = “”;
      /**
      * <code>required string family = 1;</code>
      */
      public boolean hasFamily() {
        return ((bitField0_ & 0x00000001) == 0x00000001);
      }
      /**
      * <code>required string family = 1;</code>
      */
      public java.lang.String getFamily() {
        java.lang.Object ref = family_;
        if (!(ref instanceof java.lang.String)) {
          java.lang.String s = ((com.google.protobuf.ByteString) ref)
              .toStringUtf8();
          family_ = s;
          return s;
        } else {
          return (java.lang.String) ref;
        }
      }
      /**
      * <code>required string family = 1;</code>
      */
      public com.google.protobuf.ByteString
          getFamilyBytes() {
        java.lang.Object ref = family_;
        if (ref instanceof String) {
          com.google.protobuf.ByteString b =
              com.google.protobuf.ByteString.copyFromUtf8(
                  (java.lang.String) ref);
          family_ = b;
          return b;
        } else {
          return (com.google.protobuf.ByteString) ref;
        }
      }
      /**
      * <code>required string family = 1;</code>
      */
      public Builder setFamily(
          java.lang.String value) {
        if (value == null) {
    throw new NullPointerException();
  }
  bitField0_ |= 0x00000001;
        family_ = value;
        onChanged();
        return this;
      }
      /**
      * <code>required string family = 1;</code>
      */
      public Builder clearFamily() {
        bitField0_ = (bitField0_ & ~0x00000001);
        family_ = getDefaultInstance().getFamily();
        onChanged();
        return this;
      }
      /**
      * <code>required string family = 1;</code>
      */
      public Builder setFamilyBytes(
          com.google.protobuf.ByteString value) {
        if (value == null) {
    throw new NullPointerException();
  }
  bitField0_ |= 0x00000001;
        family_ = value;
        onChanged();
        return this;
      }

      // required string column = 2;
      private java.lang.Object column_ = “”;
      /**
      * <code>required string column = 2;</code>
      */
      public boolean hasColumn() {
        return ((bitField0_ & 0x00000002) == 0x00000002);
      }
      /**
      * <code>required string column = 2;</code>
      */
      public java.lang.String getColumn() {
        java.lang.Object ref = column_;
        if (!(ref instanceof java.lang.String)) {
          java.lang.String s = ((com.google.protobuf.ByteString) ref)
              .toStringUtf8();
          column_ = s;
          return s;
        } else {
          return (java.lang.String) ref;
        }
      }
      /**
      * <code>required string column = 2;</code>
      */
      public com.google.protobuf.ByteString
          getColumnBytes() {
        java.lang.Object ref = column_;
        if (ref instanceof String) {
          com.google.protobuf.ByteString b =
              com.google.protobuf.ByteString.copyFromUtf8(
                  (java.lang.String) ref);
          column_ = b;
          return b;
        } else {
          return (com.google.protobuf.ByteString) ref;
        }
      }
      /**
      * <code>required string column = 2;</code>
      */
      public Builder setColumn(
          java.lang.String value) {
        if (value == null) {
    throw new NullPointerException();
  }
  bitField0_ |= 0x00000002;
        column_ = value;
        onChanged();
        return this;
      }
      /**
      * <code>required string column = 2;</code>
      */
      public Builder clearColumn() {
        bitField0_ = (bitField0_ & ~0x00000002);
        column_ = getDefaultInstance().getColumn();
        onChanged();
        return this;
      }
      /**
      * <code>required string column = 2;</code>
      */
      public Builder setColumnBytes(
          com.google.protobuf.ByteString value) {
        if (value == null) {
    throw new NullPointerException();
  }
  bitField0_ |= 0x00000002;
        column_ = value;
        onChanged();
        return this;
      }

      // @@protoc_insertion_point(builder_scope:SumRequest)
    }

    static {
      defaultInstance = new SumRequest(true);
      defaultInstance.initFields();
    }

    // @@protoc_insertion_point(class_scope:SumRequest)
  }

  public interface SumResponseOrBuilder
      extends com.google.protobuf.MessageOrBuilder {

    // required int64 sum = 1 [default = 0];
    /**
    * <code>required int64 sum = 1 [default =
0];</code>
    */
    boolean hasSum();
    /**
    * <code>required int64 sum = 1 [default =
0];</code>
    */
    long getSum();
  }
  /**
  * Protobuf type %7B@code SumResponse}
  */
  public static final class SumResponse extends
      com.google.protobuf.GeneratedMessage
      implements SumResponseOrBuilder {
    // Use SumResponse.newBuilder() to construct.
    private
SumResponse(com.google.protobuf.GeneratedMessage.Builder<?>
builder) {
      super(builder);
      this.unknownFields = builder.getUnknownFields();
    }
    private SumResponse(boolean noInit) { this.unknownFields =
com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }

    private static final SumResponse defaultInstance;
    public static SumResponse getDefaultInstance() {
      return defaultInstance;
    }

    public SumResponse getDefaultInstanceForType() {
      return defaultInstance;
    }

    private final com.google.protobuf.UnknownFieldSet unknownFields;
    @java.lang.Override
    public final com.google.protobuf.UnknownFieldSet
        getUnknownFields() {
      return this.unknownFields;
    }
    private SumResponse(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      initFields();
      int mutable_bitField0_ = 0;
      com.google.protobuf.UnknownFieldSet.Builder unknownFields =
          com.google.protobuf.UnknownFieldSet.newBuilder();
      try {
        boolean done = false;
        while (!done) {
          int tag = input.readTag();
          switch (tag) {
            case 0:
              done = true;
              break;
            default: {
              if (!parseUnknownField(input, unknownFields,
                                    extensionRegistry, tag)) {
                done = true;
              }
              break;
            }
            case 8: {
              bitField0_ |= 0x00000001;
              sum_ = input.readInt64();
              break;
            }
          }
        }
      } catch (com.google.protobuf.InvalidProtocolBufferException e) {
        throw e.setUnfinishedMessage(this);
      } catch (java.io.IOException e) {
        throw new com.google.protobuf.InvalidProtocolBufferException(
            e.getMessage()).setUnfinishedMessage(this);
      } finally {
        this.unknownFields = unknownFields.build();
        makeExtensionsImmutable();
      }
    }
    public static final com.google.protobuf.Descriptors.Descriptor
        getDescriptor() {
      return
com.endpoint.test.Sum.internal_static_SumResponse_descriptor;
    }

    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
        internalGetFieldAccessorTable() {
      return
com.endpoint.test.Sum.internal_static_SumResponse_fieldAccessorTable
          .ensureFieldAccessorsInitialized(
              com.endpoint.test.Sum.SumResponse.class,
com.endpoint.test.Sum.SumResponse.Builder.class);
    }

4> 使用Endpoint协助管理理器

    public static com.google.protobuf.Parser<SumResponse> PARSER

        new com.google.protobuf.AbstractParser<SumResponse>() {
      public SumResponse parsePartialFrom(
          com.google.protobuf.CodedInputStream input,
          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
          throws com.google.protobuf.InvalidProtocolBufferException {
        return new SumResponse(input, extensionRegistry);
      }
    };

    @java.lang.Override
    public com.google.protobuf.Parser<SumResponse>
getParserForType() {
      return PARSER;
    }

    private int bitField0_;
    // required int64 sum = 1 [default = 0];
    public static final int SUM_FIELD_NUMBER = 1;
    private long sum_;
    /**
    * <code>required int64 sum = 1 [default =
0];</code>
    */
    public boolean hasSum() {
      return ((bitField0_ & 0x00000001) == 0x00000001);
    }
    /**
    * <code>required int64 sum = 1 [default =
0];</code>
    */
    public long getSum() {
      return sum_;
    }

    private void initFields() {
      sum_ = 0L;
    }
    private byte memoizedIsInitialized = -1;
    public final boolean isInitialized() {
      byte isInitialized = memoizedIsInitialized;
      if (isInitialized != -1) return isInitialized == 1;

      if (!hasSum()) {
        memoizedIsInitialized = 0;
        return false;
      }
      memoizedIsInitialized = 1;
      return true;
    }

    public void writeTo(com.google.protobuf.CodedOutputStream output)
                        throws java.io.IOException {
      getSerializedSize();
      if (((bitField0_ & 0x00000001) == 0x00000001)) {
        output.writeInt64(1, sum_);
      }
      getUnknownFields().writeTo(output);
    }

    private int memoizedSerializedSize = -1;
    public int getSerializedSize() {
      int size = memoizedSerializedSize;
      if (size != -1) return size;

      size = 0;
      if (((bitField0_ & 0x00000001) == 0x00000001)) {
        size += com.google.protobuf.CodedOutputStream
          .computeInt64Size(1, sum_);
      }
      size += getUnknownFields().getSerializedSize();
      memoizedSerializedSize = size;
      return size;
    }

    private static final long serialVersionUID = 0L;
    @java.lang.Override
    protected java.lang.Object writeReplace()
        throws java.io.ObjectStreamException {
      return super.writeReplace();
    }

    @java.lang.Override
    public boolean equals(final java.lang.Object obj) {
      if (obj == this) {
      return true;
      }
      if (!(obj instanceof com.endpoint.test.Sum.SumResponse)) {
        return super.equals(obj);
      }
      com.endpoint.test.Sum.SumResponse other =
(com.endpoint.test.Sum.SumResponse) obj;

      boolean result = true;
      result = result && (hasSum() == other.hasSum());
      if (hasSum()) {
        result = result && (getSum()
            == other.getSum());
      }
      result = result &&
          getUnknownFields().equals(other.getUnknownFields());
      return result;
    }

    private int memoizedHashCode = 0;
    @java.lang.Override
    public int hashCode() {
      if (memoizedHashCode != 0) {
        return memoizedHashCode;
      }
      int hash = 41;
      hash = (19 * hash) + getDescriptorForType().hashCode();
      if (hasSum()) {
        hash = (37 * hash) + SUM_FIELD_NUMBER;
        hash = (53 * hash) + hashLong(getSum());
      }
      hash = (29 * hash) + getUnknownFields().hashCode();
      memoizedHashCode = hash;
      return hash;
    }

    public static com.endpoint.test.Sum.SumResponse parseFrom(
        com.google.protobuf.ByteString data)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return PARSER.parseFrom(data);
    }
    public static com.endpoint.test.Sum.SumResponse parseFrom(
        com.google.protobuf.ByteString data,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return PARSER.parseFrom(data, extensionRegistry);
    }
    public static com.endpoint.test.Sum.SumResponse parseFrom(byte[]
data)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return PARSER.parseFrom(data);
    }
    public static com.endpoint.test.Sum.SumResponse parseFrom(
        byte[] data,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return PARSER.parseFrom(data, extensionRegistry);
    }
    public static com.endpoint.test.Sum.SumResponse
parseFrom(java.io.InputStream input)
        throws java.io.IOException {
      return PARSER.parseFrom(input);
    }
    public static com.endpoint.test.Sum.SumResponse parseFrom(
        java.io.InputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws java.io.IOException {
      return PARSER.parseFrom(input, extensionRegistry);
    }
    public static com.endpoint.test.Sum.SumResponse
parseDelimitedFrom(java.io.InputStream input)
        throws java.io.IOException {
      return PARSER.parseDelimitedFrom(input);
    }
    public static com.endpoint.test.Sum.SumResponse
parseDelimitedFrom(
        java.io.InputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws java.io.IOException {
      return PARSER.parseDelimitedFrom(input, extensionRegistry);
    }
    public static com.endpoint.test.Sum.SumResponse parseFrom(
        com.google.protobuf.CodedInputStream input)
        throws java.io.IOException {
      return PARSER.parseFrom(input);
    }
    public static com.endpoint.test.Sum.SumResponse parseFrom(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws java.io.IOException {
      return PARSER.parseFrom(input, extensionRegistry);
    }

    public static Builder newBuilder() { return Builder.create(); }
    public Builder newBuilderForType() { return newBuilder(); }
    public static Builder newBuilder(com.endpoint.test.Sum.SumResponse
prototype) {
      return newBuilder().mergeFrom(prototype);
    }
    public Builder toBuilder() { return newBuilder(this); }

    @java.lang.Override
    protected Builder newBuilderForType(
        com.google.protobuf.GeneratedMessage.BuilderParent parent) {
      Builder builder = new Builder(parent);
      return builder;
    }
    /**
    * Protobuf type %7B@code SumResponse}
    */
    public static final class Builder extends
        com.google.protobuf.GeneratedMessage.Builder<Builder>
      implements com.endpoint.test.Sum.SumResponseOrBuilder {
      public static final com.google.protobuf.Descriptors.Descriptor
          getDescriptor() {
        return
com.endpoint.test.Sum.internal_static_SumResponse_descriptor;
      }

      protected
com.google.protobuf.GeneratedMessage.FieldAccessorTable
          internalGetFieldAccessorTable() {
        return
com.endpoint.test.Sum.internal_static_SumResponse_fieldAccessorTable
            .ensureFieldAccessorsInitialized(
                com.endpoint.test.Sum.SumResponse.class,
com.endpoint.test.Sum.SumResponse.Builder.class);
      }

      // Construct using
com.endpoint.test.Sum.SumResponse.newBuilder()
      private Builder() {
        maybeForceBuilderInitialization();
      }

      private Builder(
          com.google.protobuf.GeneratedMessage.BuilderParent parent) {
        super(parent);
        maybeForceBuilderInitialization();
      }
      private void maybeForceBuilderInitialization() {
        if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders)
{
        }
      }
      private static Builder create() {
        return new Builder();
      }

      public Builder clear() {
        super.clear();
        sum_ = 0L;
        bitField0_ = (bitField0_ & ~0x00000001);
        return this;
      }

      public Builder clone() {
        return create().mergeFrom(buildPartial());
      }

      public com.google.protobuf.Descriptors.Descriptor
          getDescriptorForType() {
        return
com.endpoint.test.Sum.internal_static_SumResponse_descriptor;
      }

      public com.endpoint.test.Sum.SumResponse
getDefaultInstanceForType() {
        return com.endpoint.test.Sum.SumResponse.getDefaultInstance();
      }

      public com.endpoint.test.Sum.SumResponse build() {
        com.endpoint.test.Sum.SumResponse result = buildPartial();
        if (!result.isInitialized()) {
          throw newUninitializedMessageException(result);
        }
        return result;
      }

      public com.endpoint.test.Sum.SumResponse buildPartial() {
        com.endpoint.test.Sum.SumResponse result = new
com.endpoint.test.Sum.SumResponse(this);
        int from_bitField0_ = bitField0_;
        int to_bitField0_ = 0;
        if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
          to_bitField0_ |= 0x00000001;
        }
        result.sum_ = sum_;
        result.bitField0_ = to_bitField0_;
        onBuilt();
        return result;
      }

      public Builder mergeFrom(com.google.protobuf.Message other) {
        if (other instanceof com.endpoint.test.Sum.SumResponse) {
          return mergeFrom((com.endpoint.test.Sum.SumResponse)other);
        } else {
          super.mergeFrom(other);
          return this;
        }
      }

      public Builder mergeFrom(com.endpoint.test.Sum.SumResponse other)
{
        if (other ==
com.endpoint.test.Sum.SumResponse.getDefaultInstance()) return this;
        if (other.hasSum()) {
          setSum(other.getSum());
        }
        this.mergeUnknownFields(other.getUnknownFields());
        return this;
      }

      public final boolean isInitialized() {
        if (!hasSum()) {
         
          return false;
        }
        return true;
      }

      public Builder mergeFrom(
          com.google.protobuf.CodedInputStream input,
          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
          throws java.io.IOException {
        com.endpoint.test.Sum.SumResponse parsedMessage = null;
        try {
          parsedMessage = PARSER.parsePartialFrom(input,
extensionRegistry);
        } catch (com.google.protobuf.InvalidProtocolBufferException e)
{
          parsedMessage = (com.endpoint.test.Sum.SumResponse)
e.getUnfinishedMessage();
          throw e;
        } finally {
          if (parsedMessage != null) {
            mergeFrom(parsedMessage);
          }
        }
        return this;
      }
      private int bitField0_;

      // required int64 sum = 1 [default = 0];
      private long sum_ ;
      /**
      * <code>required int64 sum = 1 [default =
0];</code>
      */
      public boolean hasSum() {
        return ((bitField0_ & 0x00000001) == 0x00000001);
      }
      /**
      * <code>required int64 sum = 1 [default =
0];</code>
      */
      public long getSum() {
        return sum_;
      }
      /**
      * <code>required int64 sum = 1 [default =
0];</code>
      */
      public Builder setSum(long value) {
        bitField0_ |= 0x00000001;
        sum_ = value;
        onChanged();
        return this;
      }
      /**
      * <code>required int64 sum = 1 [default =
0];</code>
      */
      public Builder clearSum() {
        bitField0_ = (bitField0_ & ~0x00000001);
        sum_ = 0L;
        onChanged();
        return this;
      }

      // @@protoc_insertion_point(builder_scope:SumResponse)
    }

    static {
      defaultInstance = new SumResponse(true);
      defaultInstance.initFields();
    }

    // @@protoc_insertion_point(class_scope:SumResponse)
  }

  /**
  * Protobuf service %7B@code SumService}
  */
  public static abstract class SumService
      implements com.google.protobuf.Service {
    protected SumService() {}

    public interface Interface {
      /**
      * <code>rpc getSum(.SumRequest) returns
(.SumResponse);</code>
      */
      public abstract void getSum(
          com.google.protobuf.RpcController controller,
          com.endpoint.test.Sum.SumRequest request,
         
com.google.protobuf.RpcCallback<com.endpoint.test.Sum.SumResponse>
done);

    }

    public static com.google.protobuf.Service newReflectiveService(
        final Interface impl) {
      return new SumService() {
        @java.lang.Override
        public  void getSum(
            com.google.protobuf.RpcController controller,
            com.endpoint.test.Sum.SumRequest request,
           
com.google.protobuf.RpcCallback<com.endpoint.test.Sum.SumResponse>
done) {
          impl.getSum(controller, request, done);
        }

      };
    }

    public static com.google.protobuf.BlockingService
        newReflectiveBlockingService(final BlockingInterface impl) {
      return new com.google.protobuf.BlockingService() {
        public final com.google.protobuf.Descriptors.ServiceDescriptor
            getDescriptorForType() {
          return getDescriptor();
        }

        public final com.google.protobuf.Message callBlockingMethod(
            com.google.protobuf.Descriptors.MethodDescriptor method,
            com.google.protobuf.RpcController controller,
            com.google.protobuf.Message request)
            throws com.google.protobuf.ServiceException {
          if (method.getService() != getDescriptor()) {
            throw new java.lang.IllegalArgumentException(
              “Service.callBlockingMethod() given method descriptor for
” +
              “wrong service type.”);
          }
          switch(method.getIndex()) {
            case 0:
              return impl.getSum(controller,
(com.endpoint.test.Sum.SumRequest)request);
            default:
              throw new java.lang.AssertionError(“Can’t get here.”);
          }
        }

        public final com.google.protobuf.Message
            getRequestPrototype(
            com.google.protobuf.Descriptors.MethodDescriptor method) {
          if (method.getService() != getDescriptor()) {
            throw new java.lang.IllegalArgumentException(
              “Service.getRequestPrototype() given method ” +
              “descriptor for wrong service type.”);
          }
          switch(method.getIndex()) {
            case 0:
              return
com.endpoint.test.Sum.SumRequest.getDefaultInstance();
            default:
              throw new java.lang.AssertionError(“Can’t get here.”);
          }
        }

        public final com.google.protobuf.Message
            getResponsePrototype(
            com.google.protobuf.Descriptors.MethodDescriptor method) {
          if (method.getService() != getDescriptor()) {
            throw new java.lang.IllegalArgumentException(
              “Service.getResponsePrototype() given method ” +
              “descriptor for wrong service type.”);
          }
          switch(method.getIndex()) {
            case 0:
              return
com.endpoint.test.Sum.SumResponse.getDefaultInstance();
            default:
              throw new java.lang.AssertionError(“Can’t get here.”);
          }
        }

      };
    }

    /**
    * <code>rpc getSum(.SumRequest) returns
(.SumResponse);</code>
    */
    public abstract void getSum(
        com.google.protobuf.RpcController controller,
        com.endpoint.test.Sum.SumRequest request,
       
com.google.protobuf.RpcCallback<com.endpoint.test.Sum.SumResponse>
done);

    public static final
        com.google.protobuf.Descriptors.ServiceDescriptor
        getDescriptor() {
      return
com.endpoint.test.Sum.getDescriptor().getServices().get(0);
    }
    public final com.google.protobuf.Descriptors.ServiceDescriptor
        getDescriptorForType() {
      return getDescriptor();
    }

    public final void callMethod(
        com.google.protobuf.Descriptors.MethodDescriptor method,
        com.google.protobuf.RpcController controller,
        com.google.protobuf.Message request,
        com.google.protobuf.RpcCallback<
          com.google.protobuf.Message> done) {
      if (method.getService() != getDescriptor()) {
        throw new java.lang.IllegalArgumentException(
          “Service.callMethod() given method descriptor for wrong ” +
          “service type.”);
      }
      switch(method.getIndex()) {
        case 0:
          this.getSum(controller,
(com.endpoint.test.Sum.SumRequest)request,
           
com.google.protobuf.RpcUtil.<com.endpoint.test.Sum.SumResponse>specializeCallback(
              done));
          return;
        default:
          throw new java.lang.AssertionError(“Can’t get here.”);
      }
    }

    public final com.google.protobuf.Message
        getRequestPrototype(
        com.google.protobuf.Descriptors.MethodDescriptor method) {
      if (method.getService() != getDescriptor()) {
        throw new java.lang.IllegalArgumentException(
          “Service.getRequestPrototype() given method ” +
          “descriptor for wrong service type.”);
      }
      switch(method.getIndex()) {
        case 0:
          return
com.endpoint.test.Sum.SumRequest.getDefaultInstance();
        default:
          throw new java.lang.AssertionError(“Can’t get here.”);
      }
    }

    public final com.google.protobuf.Message
        getResponsePrototype(
        com.google.protobuf.Descriptors.MethodDescriptor method) {
      if (method.getService() != getDescriptor()) {
        throw new java.lang.IllegalArgumentException(
          “Service.getResponsePrototype() given method ” +
          “descriptor for wrong service type.”);
      }
      switch(method.getIndex()) {
        case 0:
          return
com.endpoint.test.Sum.SumResponse.getDefaultInstance();
        default:
          throw new java.lang.AssertionError(“Can’t get here.”);
      }
    }

    public static Stub newStub(
        com.google.protobuf.RpcChannel channel) {
      return new Stub(channel);
    }

    public static final class Stub extends
com.endpoint.test.Sum.SumService implements Interface {
      private Stub(com.google.protobuf.RpcChannel channel) {
        this.channel = channel;
      }

      private final com.google.protobuf.RpcChannel channel;

      public com.google.protobuf.RpcChannel getChannel() {
        return channel;
      }

      public  void getSum(
          com.google.protobuf.RpcController controller,
          com.endpoint.test.Sum.SumRequest request,
         
com.google.protobuf.RpcCallback<com.endpoint.test.Sum.SumResponse>
done) {
        channel.callMethod(
          getDescriptor().getMethods().get(0),
          controller,
          request,
          com.endpoint.test.Sum.SumResponse.getDefaultInstance(),
          com.google.protobuf.RpcUtil.generalizeCallback(
            done,
            com.endpoint.test.Sum.SumResponse.class,
            com.endpoint.test.Sum.SumResponse.getDefaultInstance()));
      }
    }

    public static BlockingInterface newBlockingStub(
        com.google.protobuf.BlockingRpcChannel channel) {
      return new BlockingStub(channel);
    }

    public interface BlockingInterface {
      public com.endpoint.test.Sum.SumResponse getSum(
          com.google.protobuf.RpcController controller,
          com.endpoint.test.Sum.SumRequest request)
          throws com.google.protobuf.ServiceException;
    }

    private static final class BlockingStub implements BlockingInterface
{
      private BlockingStub(com.google.protobuf.BlockingRpcChannel
channel) {
        this.channel = channel;
      }

      private final com.google.protobuf.BlockingRpcChannel channel;

      public com.endpoint.test.Sum.SumResponse getSum(
          com.google.protobuf.RpcController controller,
          com.endpoint.test.Sum.SumRequest request)
          throws com.google.protobuf.ServiceException {
        return (com.endpoint.test.Sum.SumResponse)
channel.callBlockingMethod(
          getDescriptor().getMethods().get(0),
          controller,
          request,
          com.endpoint.test.Sum.SumResponse.getDefaultInstance());
      }

    }

    // @@protoc_insertion_point(class_scope:SumService)
  }

  private static com.google.protobuf.Descriptors.Descriptor
    internal_static_SumRequest_descriptor;
  private static
    com.google.protobuf.GeneratedMessage.FieldAccessorTable
      internal_static_SumRequest_fieldAccessorTable;
  private static com.google.protobuf.Descriptors.Descriptor
    internal_static_SumResponse_descriptor;
  private static
    com.google.protobuf.GeneratedMessage.FieldAccessorTable
      internal_static_SumResponse_fieldAccessorTable;

  public static com.google.protobuf.Descriptors.FileDescriptor
      getDescriptor() {
    return descriptor;
  }
  private static com.google.protobuf.Descriptors.FileDescriptor
      descriptor;
  static {
    java.lang.String[] descriptorData = {
     
“\n\rsumcode.proto\”,\n\nSumRequest\022\016\n\006family\030″

  // @@protoc_insertion_point(outer_class_scope)
}

2> 编写服务器端的代码

package com.endpoint.test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.Coprocessor;
import org.apache.hadoop.hbase.CoprocessorEnvironment;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.coprocessor.CoprocessorException;
import org.apache.hadoop.hbase.coprocessor.CoprocessorService;
import
org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
import org.apache.hadoop.hbase.protobuf.ResponseConverter;
import org.apache.hadoop.hbase.regionserver.InternalScanner;
import org.apache.hadoop.hbase.util.Bytes;
import com.endpoint.test.Sum.SumRequest;
import com.endpoint.test.Sum.SumResponse;
import com.endpoint.test.Sum.SumService;
import com.google.protobuf.RpcCallback;
import com.google.protobuf.RpcController;
import com.google.protobuf.Service;

public class SumEndPoint extends SumService implements
Coprocessor,CoprocessorService{

    private RegionCoprocessorEnvironment env;  // 定义意况 
    @Override
    public Service getService() {
       
        return this;
    }

    @Override
    public void start(CoprocessorEnvironment env) throws IOException {
        if (env instanceof RegionCoprocessorEnvironment) { 
                this.env = (RegionCoprocessorEnvironment)env; 
            } else { 
                throw new CoprocessorException(“no load region”); 
            } 
       
    }

    @Override
    public void stop(CoprocessorEnvironment env) throws IOException {
               
    }

    @Override
    public void getSum(RpcController controller, SumRequest request,
RpcCallback<SumResponse> done) {
       
        // 设置扫描对象 
        Scan scan = new Scan(); 
        scan.addFamily(Bytes.toBytes(request.getFamily())); 
        scan.addColumn(Bytes.toBytes(request.getFamily()),
Bytes.toBytes(request.getColumn())); 
       
        // 定义变量 
        SumResponse response = null; 
        InternalScanner scanner = null; 
       
        // 扫描每一个region,取值后求和 
        try { 
            scanner = env.getRegion().getScanner(scan); 
            List<Cell> results = new ArrayList<Cell>(); 
            boolean hasMore = false; 
            Long sum = 0L; 
            do { 
                hasMore = scanner.next(results); 
                for (Cell cell : results) { 
                    sum += Long.parseLong(new
String(CellUtil.cloneValue(cell))); 
                } 
                results.clear(); 
            } while (hasMore); 
            // 设置再次回到结果 
            response = SumResponse.newBuilder().setSum(sum).build(); 
        } catch (IOException e) { 
            ResponseConverter.setControllerException(controller, e); 
        } finally { 
            if (scanner != null) { 
                try { 
                    scanner.close(); 
                } catch (IOException e) { 
                    //e.printStackTrace(); 
                } 
            } 
        } 
        // 将rpc结果回到给客户端 
        done.run(response); 
       
    }

}

3> 客户端测试代码

package com.endpoint.test;

import java.io.IOException;
import java.util.Map;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.coprocessor.Batch;
import org.apache.hadoop.hbase.ipc.BlockingRpcCallback;
import com.endpoint.test.Sum.SumRequest;
import com.endpoint.test.Sum.SumResponse;
import com.endpoint.test.Sum.SumService;
import com.google.protobuf.ServiceException;

public class TestClient {

    public static void main(String[] args) throws Exception {
         
            // 配置HBse 
            Configuration conf = HBaseConfiguration.create(); 
            conf.set(“hbase.zookeeper.quorum”, “master,data1,data2”); 
            conf.set(“hbase.zookeeper.property.clientPort”, “2181”); 
            conf.setLong(“hbase.rpc.timeout”, 600000);
            System.setProperty(“hadoop.home.dir”,
“C:/hadoopfiles/hadoop-common-2.2.0-bin-master”);

            // 组建3个数据库的连接 
            Connection conn =
ConnectionFactory.createConnection(conf); 
            // 获取表 
            HTable table = (HTable)
conn.getTable(TableName.valueOf(“etable”)); 
           
            long sum = 0L;               
           
            // 设置请求对象 
            final SumRequest request =
SumRequest.newBuilder().setFamily(“cf”).setColumn(“value”).build(); 
           
            try {
                // 拿到再次来到值 
                Map<byte[], Long> result =
table.coprocessorService(SumService.class, null, null, 
                        new Batch.Call<SumService, Long>() { 
         
                            @Override 
                            public Long call(SumService service) throws
IOException { 
                                BlockingRpcCallback<SumResponse>
rpcCallback = new BlockingRpcCallback<SumResponse>(); 
                                service.getSum(null, request,
rpcCallback); 
                                SumResponse response = (SumResponse)
rpcCallback.get(); 
                                return response.hasSum() ?
response.getSum() : 0L;
                            } 
                }); 
                // 将再次来到值举行迭代相加 
                for (Long v : result.values()) { 
                    sum += v; 
                } 
                // 结果输出 
                System.out.println(“sum: ” + sum);                     
 
               
            } catch (ServiceException e) {
                e.printStackTrace();
            }catch (Throwable e) {
                e.printStackTrace();
            }
            table.close(); 
            conn.close(); 

    }

}

System.setProperty(“hadoop.home.dir”,
“C:/hadoopfiles/hadoop-common-二.二.0-bin-master”);
那句代码是防错误用的,不具备实际意义,在hadoop-common-贰.二.0-bin-master下建设构造bin目录放2个winutils.exe文件就能够,不然会冒出提示“Could
not locate executable null\bin\winutils.exe in the Hadoop binaries”

别的,须要在windows下设置一下hosts文件,因为conf.set(“hbase.zookeeper.quorum”,
“master,data1,data2”);

四> 使用Endpoint协助管理理器

将上边的Sum类文件与用于服务端的SumEndPoint 类文件打包上传到服务器

chown hadoop:hadoop datacode.jar 
chmod g+w  datacode.jar 

先改一下放权力力,之后

hadoop fs -copyFromLocal sumtest.jar /input/

 上边是要利用协助管理理器的hbase表

图片 5

 要将协助管理理器加载到这么些表上

disable 'etable'
# 包名.类名|权重 com.endpoint.test.SumEndPoint|100
alter'etable',METHOD =>'table_att','coprocessor' =>'/input/sumcode.jar|com.endpoint.test.SumEndPoint|100'
enable 'etable'

包名.类名|权重 com.endpoint.test.SumEndPoint|100

# 这样也是可以的,但是在集群变换主节点的情况下,不是很好
# alter'etable',METHOD =>'table_att','coprocessor' =>'hdfs://192.168.1.215:9000/input/sumcode.jar|com.endpoint.test.SumEndPoint|100'

除此以外,值得注意的一些,在集群中,最佳在hbase-site.xml中安装以下属性

<property>  
        <name>hbase.coprocessor.abortonerror</name>  
        <value>false</value>  
</property> 

设置为false目的在于抓实容错性,假诺这特性格未有安装为false,则在上传的jar包存在不当的事态下,会促成表不能够enable或disable,从而致使集群中的那张表没办法运用,乃至会潜移默化到任何表。

 图片 6

 在windows中的客户端运转客户端的代码,结果如下:

图片 7

 2、Observer实例
以此是贰个二级索引实例,即如若在initialtable表中的数据格式是这么的

row1    E   151
row2    Y   158

在向initialtable表中写入数据时,自动将以下数据写入indextable表作为二级索引,indextable第一列成为indextable的键

Y    158

 一> 编写服务端代码

package com.observer.test;

import java.io.IOException;
import java.util.List;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Durability;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver;
import org.apache.hadoop.hbase.coprocessor.ObserverContext;
import
org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
import org.apache.hadoop.hbase.util.Bytes;

public class TestObserver extends BaseRegionObserver {
    @Override
    public void
postPut(ObserverContext<RegionCoprocessorEnvironment> e, Put put,
WALEdit edit, Durability durability)
            throws IOException {
        // indextable作为二级索引表 
        HTableInterface table =
e.getEnvironment().getTable(TableName.valueOf(“indextable”)); 
        // 获取值 
        List<Cell> cellList1 = put.get(Bytes.toBytes(“cf”),
Bytes.toBytes(“name”)); 
        List<Cell> cellList2 = put.get(Bytes.toBytes(“cf”),
Bytes.toBytes(“value”)); 
        // 写入数据
        for (Cell cell1 : cellList1) { 
            // 原表的列cf:name的值作为indextable的rowkey,加多行 
            Put indexPut = new Put(CellUtil.cloneValue(cell1)); 
            for (Cell cell2 : cellList2) { 
                // 原表的列cf:value的值作为indextable表中列cf:value的值

                indexPut.add(Bytes.toBytes(“cf”),
Bytes.toBytes(“value”), CellUtil.cloneValue(cell2)); 
            } 
         
            table.put(indexPut); 
        } 
       
        table.close(); 
    }

}

2> 编写客户段代码

package com.observer.test;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;

public class DataClient {

    public static void main(String[] args) throws IOException {
        //配置
        Configuration conf = HBaseConfiguration.create(); 
        conf.set(“hbase.zookeeper.quorum”, “master,data1,data2”); 
        conf.set(“hbase.zookeeper.property.clientPort”, “2181”); 
        //连接 
        Connection conn = ConnectionFactory.createConnection(conf);     
 
        HTable table = (HTable)
conn.getTable(TableName.valueOf(“initialtable”)); 
        // 写入数据 
        Put put = new Put(Bytes.toBytes(“row01”)); 
        put.addColumn(Bytes.toBytes(“cf”), Bytes.toBytes(“name”),
Bytes.toBytes(“E”)); 
        put.addColumn(Bytes.toBytes(“cf”), Bytes.toBytes(“value”),
Bytes.toBytes(“151”)); 
        table.put(put); 
        // 关闭财富 
        table.close(); 
        conn.close(); 

    }

}

 叁> 创立必要的表

 图片 8

 四> 加载协管理器
将服务端代码打包上传集群服务器的hdfs上

chown hadoop:hadoop datacode.jar 
chmod g+w  datacode.jar 
hadoop dfs -put datacode.jar /input/

从此,将协助管理理器加载到伊始表中

disable 'initialtable'
alter'initialtable',METHOD =>'table_att','coprocessor' =>'/input/datacode.jar|com.observer.test.TestObserver|100'
enable 'initialtable'

伍> 推行客户端代码,展现结果

 图片 9

Hadoop+HBase搭建云存款和储蓄总括 PDF
http://www.linuxidc.com/Linux/2013-05/83844.htm

Ubuntu Server 1四.0四 下
Hbase数据库安装 
http://www.linuxidc.com/Linux/2016-05/131499.htm

HBase 结点之间时间不平等导致regionserver运营退步
http://www.linuxidc.com/Linux/2013-06/86655.htm

CentOS 陆.三下HBase伪遍及式平台搭建 
http://www.linuxidc.com/Linux/2016-11/136830.htm

Hadoop集群安装&HBase实验情状搭建
http://www.linuxidc.com/Linux/2013-04/83560.htm

听说Hadoop集群的HBase集群的铺排
http://www.linuxidc.com/Linux/2013-03/80815.htm

Hadoop安装配置笔记之-HBase完全遍布形式安装
http://www.linuxidc.com/Linux/2012-12/76947.htm

CentOS 6.四下HBase集群安装
http://www.linuxidc.com/Linux/2016-11/137303.htm

HBase
的事无巨细介绍
请点这里
HBase
的下载地址
请点这里

本文永恒更新链接地址http://www.linuxidc.com/Linux/2016-12/138718.htm

图片 10

将上面包车型大巴Sum类文件与用于服务端的SumEndPoint 类文件打包上传到服务器

chown hadoop:hadoop datacode.jar 
chmod g+w  datacode.jar 

先改一下放权力力,之后

hadoop fs -copyFromLocal sumtest.jar /input/

 下边是要接纳协助处理理器的hbase表

图片 11

 要将协助管理理器加载到那个表上

disable 'etable'
# 包名.类名|权重 com.endpoint.test.SumEndPoint|100
alter'etable',METHOD =>'table_att','coprocessor' =>'/input/sumcode.jar|com.endpoint.test.SumEndPoint|100'
enable 'etable'

包名.类名|权重 com.endpoint.test.SumEndPoint|100

# 这样也是可以的,但是在集群变换主节点的情况下,不是很好
# alter'etable',METHOD =>'table_att','coprocessor' =>'hdfs://192.168.1.215:9000/input/sumcode.jar|com.endpoint.test.SumEndPoint|100'

别的,值得注意的某个,在集群中,最佳在hbase-site.xml中设置以下属性

<property>  
        <name>hbase.coprocessor.abortonerror</name>  
        <value>false</value>  
</property> 

设置为false意在抓牢容错性,假诺那几个天性未有设置为false,则在上传的jar包存在不当的情事下,会导致表不可能enable或disable,从而造成集群中的那张表无法利用,以致会影响到其它表。

 图片 12

 在windows中的客户端运营客户端的代码,结果如下:

图片 13

 2、Observer实例
其一是二个二级索引实例,即假诺在initialtable表中的数据格式是那般的

row1    E   151
row2    Y   158

在向initialtable表中写入数据时,自动将以下数据写入indextable表作为二级索引,indextable第三列成为indextable的键

Y    158

 1> 编写服务端代码

 1 package com.observer.test;
 2 
 3 import java.io.IOException;
 4 import java.util.List;
 5 import org.apache.hadoop.hbase.Cell;
 6 import org.apache.hadoop.hbase.CellUtil;
 7 import org.apache.hadoop.hbase.TableName;
 8 import org.apache.hadoop.hbase.client.Durability;
 9 import org.apache.hadoop.hbase.client.HTableInterface;
10 import org.apache.hadoop.hbase.client.Put;
11 import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver;
12 import org.apache.hadoop.hbase.coprocessor.ObserverContext;
13 import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
14 import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
15 import org.apache.hadoop.hbase.util.Bytes;
16 
17 public class TestObserver extends BaseRegionObserver {
18     @Override
19     public void postPut(ObserverContext<RegionCoprocessorEnvironment> e, Put put, WALEdit edit, Durability durability)
20             throws IOException {
21         // indextable作为二级索引表  
22         HTableInterface table = e.getEnvironment().getTable(TableName.valueOf("indextable"));  
23         // 获取值  
24         List<Cell> cellList1 = put.get(Bytes.toBytes("cf"), Bytes.toBytes("name"));  
25         List<Cell> cellList2 = put.get(Bytes.toBytes("cf"), Bytes.toBytes("value"));  
26         // 写入数据
27         for (Cell cell1 : cellList1) {  
28             // 原表的列cf:name的值作为indextable的rowkey,添加行  
29             Put indexPut = new Put(CellUtil.cloneValue(cell1));  
30             for (Cell cell2 : cellList2) {  
31                 // 原表的列cf:value的值作为indextable表中列cf:value的值 。
32                 indexPut.add(Bytes.toBytes("cf"), Bytes.toBytes("value"), CellUtil.cloneValue(cell2));  
33             }  
34           
35             table.put(indexPut);  
36         }  
37         
38         table.close();  
39     }
40 
41 }

 2> 编写客户段代码

 1 package com.observer.test;
 2 
 3 import java.io.IOException;
 4 
 5 import org.apache.hadoop.conf.Configuration;
 6 import org.apache.hadoop.hbase.HBaseConfiguration;
 7 import org.apache.hadoop.hbase.TableName;
 8 import org.apache.hadoop.hbase.client.Connection;
 9 import org.apache.hadoop.hbase.client.ConnectionFactory;
10 import org.apache.hadoop.hbase.client.HTable;
11 import org.apache.hadoop.hbase.client.Put;
12 import org.apache.hadoop.hbase.util.Bytes;
13 
14 public class DataClient {
15 
16     public static void main(String[] args) throws IOException {
17         //配置 
18         Configuration conf = HBaseConfiguration.create();  
19         conf.set("hbase.zookeeper.quorum", "master,data1,data2");  
20         conf.set("hbase.zookeeper.property.clientPort", "2181");  
21         //连接  
22         Connection conn = ConnectionFactory.createConnection(conf);        
23         HTable table = (HTable) conn.getTable(TableName.valueOf("initialtable"));  
24         // 写入数据  
25         Put put = new Put(Bytes.toBytes("row01"));  
26         put.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("name"), Bytes.toBytes("E"));  
27         put.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("value"), Bytes.toBytes("151"));  
28         table.put(put);  
29         // 关闭资源  
30         table.close();  
31         conn.close();  
32 
33     }
34 
35 }

 三> 创建须求的表

 图片 14

 4> 加载协助管理理器
将服务端代码打包上传集群服务器的hdfs上

chown hadoop:hadoop datacode.jar 
chmod g+w  datacode.jar 
hadoop dfs -put datacode.jar /input/

此后,将协助管理理器加载到初阶表中

disable 'initialtable'
alter'initialtable',METHOD =>'table_att','coprocessor' =>'/input/datacode.jar|com.observer.test.TestObserver|100'
enable 'initialtable'

5> 实行客户端代码,展现结果

 图片 15

 

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图