Observer协处理器通常在一个特定的事件(诸如GetPut)之前或之后发生,相当于RDBMS中的触发器。Endpoint协处理器则类似于RDBMS中的存储过程,因为它可以让你在RegionServer上对数据执行自定义计算,而不是在客户端上执行计算。

本文是以上两者的简单实例,使用的环境:环境 jdk1.8 hadoop2.6.5 hbase1.2.4。

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

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

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

2> 编译上面的proto文件
使用protoc程序进行编译,linux下或者windows均可,protoc程序可以直接从github下载:https://github.com/google/protobuf/releases,也可以自己编译生成,参见protobuf的编译安装

注意,编译的版本要与hadoop以及hbase使用的版本相同,或者略高,但最好不要过高,hadoop2.6.5 hbase1.2.4使用的都是protobuf2.5.0的版本,写此篇文章时的最新版为3.1.0

(高版本必须指定syntax,例如proto3的syntax在第一行非空白非注释行,必须写:syntax = “proto3″,字段规则移除了 “required”,并把 “optional” 改名为 “singular”,移除了 default 选项。可搜索Protobuf 的 proto3 与 proto2 的区别进行了解。)下载的话选择带win或linux的版本,这是编译好的版本。有很多带具体语言的版本,是一些具体某种语言的发行版源码包。为了与hbase以及hadoop统一起来,此处用的是protoc-2.5.0-win32.zip。

解压文件:

hbase协处理器编码实例

使用windows命令行进入上面的目录,执行以下命令即可:

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

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

protoc sum.proto --java_out=./

结果都一样,生成的代码参见折叠部分,有很多,因为上面文件中指定java_outer_classname = “Sum”,所以会生成Sum类,将这个类引入到项目中,注意项目的包名称与上面文件中指定(option java_package = “com.endpoint.test”)的名称要一致。

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

 package com.endpoint.test;

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

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

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

     private static final SumRequest defaultInstance;<br/>
     public static SumRequest getDefaultInstance() {<br/>
       return defaultInstance;<br/>
     }

     public SumRequest getDefaultInstanceForType() {<br/>
       return defaultInstance;<br/>
     }

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

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

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

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

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

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

     private void initFields() {<br/>
       family_ = "";<br/>
       column_ = "";<br/>
     }<br/>
     private byte memoizedIsInitialized = -1;<br/>
     public final boolean isInitialized() {<br/>
       byte isInitialized = memoizedIsInitialized;<br/>
       if (isInitialized != -1) return isInitialized == 1;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

       public Builder clear() {<br/>
         super.clear();<br/>
         family_ = "";<br/>
         bitField0_ = (bitField0_ & ~0x00000001);<br/>
         column_ = "";<br/>
         bitField0_ = (bitField0_ & ~0x00000002);<br/>
         return this;<br/>
       }

       public Builder clone() {<br/>
         return create().mergeFrom(buildPartial());<br/>
       }

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

       public com.endpoint.test.Sum.SumRequest getDefaultInstanceForType() {<br/>
         return com.endpoint.test.Sum.SumRequest.getDefaultInstance();<br/>
       }

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

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

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

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

       public final boolean isInitialized() {<br/>
         if (!hasFamily()) {

           return false;<br/>
         }<br/>
         if (!hasColumn()) {

           return false;<br/>
         }<br/>
         return true;<br/>
       }

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

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

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

       // @@protoc_insertion_point(builder_scope:SumRequest)<br/>
     }

     static {<br/>
       defaultInstance = new SumRequest(true);<br/>
       defaultInstance.initFields();<br/>
     }

     // @@protoc_insertion_point(class_scope:SumRequest)<br/>
   }

   public interface SumResponseOrBuilder<br/>
       extends com.google.protobuf.MessageOrBuilder {

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

     private static final SumResponse defaultInstance;<br/>
     public static SumResponse getDefaultInstance() {<br/>
       return defaultInstance;<br/>
     }

     public SumResponse getDefaultInstanceForType() {<br/>
       return defaultInstance;<br/>
     }

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

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

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

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

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

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

       if (!hasSum()) {<br/>
         memoizedIsInitialized = 0;<br/>
         return false;<br/>
       }<br/>
       memoizedIsInitialized = 1;<br/>
       return true;<br/>
     }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

       public Builder clone() {<br/>
         return create().mergeFrom(buildPartial());<br/>
       }

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

       public com.endpoint.test.Sum.SumResponse getDefaultInstanceForType() {<br/>
         return com.endpoint.test.Sum.SumResponse.getDefaultInstance();<br/>
       }

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

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

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

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

       public final boolean isInitialized() {<br/>
         if (!hasSum()) {

           return false;<br/>
         }<br/>
         return true;<br/>
       }

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

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

       // @@protoc_insertion_point(builder_scope:SumResponse)<br/>
     }

     static {<br/>
       defaultInstance = new SumResponse(true);<br/>
       defaultInstance.initFields();<br/>
     }

     // @@protoc_insertion_point(class_scope:SumResponse)<br/>
   }

   /**<br/>
    * Protobuf service {@code SumService}<br/>
    */<br/>
   public static abstract class SumService<br/>
       implements com.google.protobuf.Service {<br/>
     protected SumService() {}

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

     }

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

       };<br/>
     }

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

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

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

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

       };<br/>
     }

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

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

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

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

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

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

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

       private final com.google.protobuf.RpcChannel channel;

       public com.google.protobuf.RpcChannel getChannel() {<br/>
         return channel;<br/>
       }

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

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

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

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

       private final com.google.protobuf.BlockingRpcChannel channel;

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

     }

     // @@protoc_insertion_point(class_scope:SumService)<br/>
   }

   private static com.google.protobuf.Descriptors.Descriptor<br/>
     internal_static_SumRequest_descriptor;<br/>
   private static<br/>
     com.google.protobuf.GeneratedMessage.FieldAccessorTable<br/>
       internal_static_SumRequest_fieldAccessorTable;<br/>
   private static com.google.protobuf.Descriptors.Descriptor<br/>
     internal_static_SumResponse_descriptor;<br/>
   private static<br/>
     com.google.protobuf.GeneratedMessage.FieldAccessorTable<br/>
       internal_static_SumResponse_fieldAccessorTable;

   public static com.google.protobuf.Descriptors.FileDescriptor<br/>
       getDescriptor() {<br/>
     return descriptor;<br/>
   }<br/>
   private static com.google.protobuf.Descriptors.FileDescriptor<br/>
       descriptor;<br/>
   static {<br/>
     java.lang.String[] descriptorData = {<br/>
       "\n\rsumcode.proto\",\n\nSumRequest\022\016\n\006family\030" +<br/>
       "\001 \002(\t\022\016\n\006column\030\002 \002(\t\"\035\n\013SumResponse\022\016\n\003" +<br/>
       "sum\030\001 \002(\003:\001021\n\nSumService\022#\n\006getSum\022\013.S" +<br/>
       "umRequest\032\014.SumResponseB \n\021com.endpoint." +<br/>
       "testB\003SumH\001\210\001\001\240\001\001"<br/>
     };<br/>
     com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =<br/>
       new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {<br/>
         public com.google.protobuf.ExtensionRegistry assignDescriptors(<br/>
             com.google.protobuf.Descriptors.FileDescriptor root) {<br/>
           descriptor = root;<br/>
           internal_static_SumRequest_descriptor =<br/>
             getDescriptor().getMessageTypes().get(0);<br/>
           internal_static_SumRequest_fieldAccessorTable = new<br/>
             com.google.protobuf.GeneratedMessage.FieldAccessorTable(<br/>
               internal_static_SumRequest_descriptor,<br/>
               new java.lang.String[] { "Family", "Column", });<br/>
           internal_static_SumResponse_descriptor =<br/>
             getDescriptor().getMessageTypes().get(1);<br/>
           internal_static_SumResponse_fieldAccessorTable = new<br/>
             com.google.protobuf.GeneratedMessage.FieldAccessorTable(<br/>
               internal_static_SumResponse_descriptor,<br/>
               new java.lang.String[] { "Sum", });<br/>
           return null;<br/>
         }<br/>
       };<br/>
     com.google.protobuf.Descriptors.FileDescriptor<br/>
       .internalBuildGeneratedFileFrom(descriptorData,<br/>
         new com.google.protobuf.Descriptors.FileDescriptor[] {<br/>
         }, assigner);<br/>
   }

   // @@protoc_insertion_point(outer_class_scope)<br/>
 }

2> 编写服务器端的代码

 package com.endpoint.test;

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

 public class SumEndPoint extends SumService implements Coprocessor,CoprocessorService{

     private RegionCoprocessorEnvironment env;   // 定义环境<br/>
     @Override<br/>
     public Service getService() {

         return this;<br/>
     }

     @Override<br/>
     public void start(CoprocessorEnvironment env) throws IOException {<br/>
          if (env instanceof RegionCoprocessorEnvironment) {<br/>
                 this.env = (RegionCoprocessorEnvironment)env;<br/>
             } else {<br/>
                 throw new CoprocessorException("no load region");<br/>
             }  

     }

     @Override<br/>
     public void stop(CoprocessorEnvironment env) throws IOException {

     }

     @Override<br/>
     public void getSum(RpcController controller, SumRequest request, RpcCallback<SumResponse> done) {

         // 设置扫描对象<br/>
         Scan scan = new Scan();<br/>
         scan.addFamily(Bytes.toBytes(request.getFamily()));<br/>
         scan.addColumn(Bytes.toBytes(request.getFamily()), Bytes.toBytes(request.getColumn()));  

         // 定义变量<br/>
         SumResponse response = null;<br/>
         InternalScanner scanner = null;  

         // 扫描每个region,取值后求和<br/>
         try {<br/>
             scanner = env.getRegion().getScanner(scan);<br/>
             List<Cell> results = new ArrayList<Cell>();<br/>
             boolean hasMore = false;<br/>
             Long sum = 0L;<br/>
             do {<br/>
                 hasMore = scanner.next(results);<br/>
                 for (Cell cell : results) {<br/>
                     sum += Long.parseLong(new String(CellUtil.cloneValue(cell)));<br/>
                 }<br/>
                 results.clear();<br/>
             } while (hasMore);<br/>
             // 设置返回结果<br/>
             response = SumResponse.newBuilder().setSum(sum).build();<br/>
         } catch (IOException e) {<br/>
             ResponseConverter.setControllerException(controller, e);<br/>
         } finally {<br/>
             if (scanner != null) {<br/>
                 try {<br/>
                     scanner.close();<br/>
                 } catch (IOException e) {<br/>
                     //e.printStackTrace();<br/>
                 }<br/>
             }<br/>
         }<br/>
         // 将rpc结果返回给客户端<br/>
         done.run(response);  

     }

 }

3> 客户端测试代码

 package com.endpoint.test;

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

 public class TestClient {

     public static void main(String[] args) throws Exception {

             // 配置HBse<br/>
             Configuration conf = HBaseConfiguration.create();<br/>
             conf.set("hbase.zookeeper.quorum", "master,data1,data2");<br/>
             conf.set("hbase.zookeeper.property.clientPort", "2181");<br/>
             conf.setLong("hbase.rpc.timeout", 600000);<br/>
             System.setProperty("hadoop.home.dir", "C:/hadoopfiles/hadoop-common-2.2.0-bin-master");

             // 建立一个数据库的连接<br/>
             Connection conn = ConnectionFactory.createConnection(conf);<br/>
             // 获取表<br/>
             HTable table = (HTable) conn.getTable(TableName.valueOf("etable"));  

             long sum = 0L;                

             // 设置请求对象<br/>
             final SumRequest request = SumRequest.newBuilder().setFamily("cf").setColumn("value").build();  

             try {<br/>
                 // 获得返回值<br/>
                 Map<byte[], Long> result = table.coprocessorService(SumService.class, null, null,<br/>
                         new Batch.Call<SumService, Long>() {  

                             @Override<br/>
                             public Long call(SumService service) throws IOException {<br/>
                                 BlockingRpcCallback<SumResponse> rpcCallback = new BlockingRpcCallback<SumResponse>();<br/>
                                 service.getSum(null, request, rpcCallback);<br/>
                                 SumResponse response = (SumResponse) rpcCallback.get();<br/>
                                 return response.hasSum() ? response.getSum() : 0L;<br/>
                             }<br/>
                 });<br/>
                 // 将返回值进行迭代相加<br/>
                 for (Long v : result.values()) {<br/>
                     sum += v;<br/>
                 }<br/>
                 // 结果输出<br/>
                 System.out.println("sum: " + sum);                        

             } catch (ServiceException e) {<br/>
                 e.printStackTrace();<br/>
             }catch (Throwable e) {<br/>
                 e.printStackTrace();<br/>
             }<br/>
             table.close();<br/>
             conn.close();  

     }

 }

System.setProperty(“hadoop.home.dir”, “C:/hadoopfiles/hadoop-common-2.2.0-bin-master”); 这句代码是防错误用的,不具有实际意义,在hadoop-common-2.2.0-bin-master下建立bin目录放一个winutils.exe文件即可,否则会出现提示“Could not locate executable null\bin\winutils.exe in the Hadoop binaries”

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

4> 使用Endpoint协处理器

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

chown hadoop:hadoop datacode.jar<br/>
chmod g+w  datacode.jar 

先改一下权限,之后

hadoop fs -copyFromLocal sumtest.jar /input/

下面是要使用协处理器的hbase表

hbase协处理器编码实例

要将协处理器加载到这个表上

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

此外,值得注意的一点,在集群中,最好在hbase-site.xml中设置以下属性

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

设置为false目的在于提高容错性,如果这个属性没有设置为false,则在上传的jar包存在错误的情况下,会导致表不能enable或disable,从而导致集群中的这张表无法使用,甚至会影响到其他表。

hbase协处理器编码实例

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

hbase协处理器编码实例

 2、Observer实例
这个是一个二级索引实例,即假定在initialtable表中的数据格式是这样的

row1    E   151<br/>
row2    Y   158

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

Y    158

1> 编写服务端代码

 package com.observer.test;

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

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

             table.put(indexPut);<br/>
         }  

         table.close();<br/>
     }

 }

2> 编写客户段代码

 package com.observer.test;

 import java.io.IOException;

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

 public class DataClient {

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

     }

 }

3> 创建需要的表

hbase协处理器编码实例

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

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

之后,将协处理器加载到初始表中

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

5> 执行客户端代码,显示结果