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 */
018package org.apache.hadoop.hbase.client;
019
020import org.apache.hadoop.hbase.TableName;
021import org.apache.hadoop.hbase.ipc.HBaseRpcController;
022import org.apache.yetus.audience.InterfaceAudience;
023
024/**
025 * Implementations make an rpc call against a RegionService via a protobuf Service. Implement
026 * #rpcCall(RpcController) and then call {@link #call(int)} to trigger the rpc. The
027 * {@link #call(int)} eventually invokes your #rpcCall(RpcController) meanwhile saving you having to
028 * write a bunch of boilerplate. The {@link #call(int)} implementation is from
029 * {@link RpcRetryingCaller} so rpcs are retried on fail.
030 * <p>
031 * TODO: this class is actually tied to one region, because most of the paths make use of the
032 * regioninfo part of location when building requests. The only reason it works for multi-region
033 * requests (e.g. batch) is that they happen to not use the region parts. This could be done cleaner
034 * (e.g. having a generic parameter and 2 derived classes, RegionCallable and actual
035 * RegionServerCallable with ServerName.
036 * @param <T> the class that the ServerCallable handles
037 */
038@InterfaceAudience.Private
039public abstract class NoncedRegionServerCallable<T> extends ClientServiceCallable<T> {
040  private final long nonce;
041
042  /**
043   * @param connection Connection to use.
044   * @param tableName  Table name to which <code>row</code> belongs.
045   * @param row        The row we want in <code>tableName</code>.
046   */
047  public NoncedRegionServerCallable(Connection connection, TableName tableName, byte[] row,
048    HBaseRpcController rpcController, int priority) {
049    super(connection, tableName, row, rpcController, priority);
050    this.nonce = getConnection().getNonceGenerator().newNonce();
051  }
052
053  long getNonceGroup() {
054    return getConnection().getNonceGenerator().getNonceGroup();
055  }
056
057  long getNonce() {
058    return this.nonce;
059  }
060}