001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.apache.hadoop.hbase.client;
020
021import org.apache.hadoop.hbase.TableName;
022import org.apache.yetus.audience.InterfaceAudience;
023import org.apache.hadoop.hbase.ipc.HBaseRpcController;
024
025/**
026 * Implementations make an rpc call against a RegionService via a protobuf Service.
027 * Implement #rpcCall(RpcController) and then call {@link #call(int)} to
028 * trigger the rpc. The {@link #call(int)} eventually invokes your
029 * #rpcCall(RpcController) meanwhile saving you having to write a bunch of
030 * boilerplate. The {@link #call(int)} implementation is from {@link RpcRetryingCaller} so rpcs are
031 * retried on fail.
032 *
033 * <p>TODO: this class is actually tied to one region, because most of the paths make use of
034 *       the regioninfo part of location when building requests. The only reason it works for
035 *       multi-region requests (e.g. batch) is that they happen to not use the region parts.
036 *       This could be done cleaner (e.g. having a generic parameter and 2 derived classes,
037 *       RegionCallable and actual RegionServerCallable with ServerName.
038 * @param <T> the class that the ServerCallable handles
039 */
040@InterfaceAudience.Private
041public abstract class NoncedRegionServerCallable<T> extends ClientServiceCallable<T> {
042  private final long nonce;
043
044  /**
045   * @param connection Connection to use.
046   * @param tableName Table name to which <code>row</code> belongs.
047   * @param row The row we want in <code>tableName</code>.
048   */
049  public NoncedRegionServerCallable(Connection connection, TableName tableName, byte [] row,
050      HBaseRpcController rpcController, int priority) {
051    super(connection, tableName, row, rpcController, priority);
052    this.nonce = getConnection().getNonceGenerator().newNonce();
053  }
054
055  long getNonceGroup() {
056    return getConnection().getNonceGenerator().getNonceGroup();
057  }
058
059  long getNonce() {
060    return this.nonce;
061  }
062}