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.ipc;
019
020import java.net.InetAddress;
021import java.util.Optional;
022import org.apache.hadoop.hbase.security.User;
023import org.apache.yetus.audience.InterfaceAudience;
024
025import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.VersionInfo;
026
027/**
028 * Interface of all necessary to carry out a RPC service invocation on the server. This interface
029 * focus on the information needed or obtained during the actual execution of the service method.
030 */
031@InterfaceAudience.Private
032public interface RpcCallContext {
033  /**
034   * Check if the caller who made this IPC call has disconnected. If called from outside the context
035   * of IPC, this does nothing.
036   * @return < 0 if the caller is still connected. The time in ms since the disconnection
037   *         otherwise
038   */
039  long disconnectSince();
040
041  /**
042   * If the client connected and specified a codec to use, then we will use this codec making
043   * cellblocks to return. If the client did not specify a codec, we assume it does not support
044   * cellblocks and will return all content protobuf'd (though it makes our serving slower). We need
045   * to ask this question per call because a server could be hosting both clients that support
046   * cellblocks while fielding requests from clients that do not.
047   * @return True if the client supports cellblocks, else return all content in pb
048   */
049  boolean isClientCellBlockSupported();
050
051  /**
052   * Returns the user credentials associated with the current RPC request or not present if no
053   * credentials were provided.
054   * @return A User
055   */
056  Optional<User> getRequestUser();
057
058  /** Returns Current request's user name or not present if none ongoing. */
059  default Optional<String> getRequestUserName() {
060    return getRequestUser().map(User::getShortName);
061  }
062
063  /** Returns Address of remote client in this call */
064  InetAddress getRemoteAddress();
065
066  /** Returns the client version info, or null if the information is not present */
067  VersionInfo getClientVersionInfo();
068
069  /**
070   * Sets a callback which has to be executed at the end of this RPC call. Such a callback is an
071   * optional one for any Rpc call. n
072   */
073  void setCallBack(RpcCallback callback);
074
075  boolean isRetryImmediatelySupported();
076
077  /**
078   * The size of response cells that have been accumulated so far. This along with the corresponding
079   * increment call is used to ensure that multi's or scans dont get too excessively large
080   */
081  long getResponseCellSize();
082
083  /**
084   * Add on the given amount to the retained cell size. This is not thread safe and not synchronized
085   * at all. If this is used by more than one thread then everything will break. Since this is
086   * called for every row synchronization would be too onerous.
087   */
088  void incrementResponseCellSize(long cellSize);
089
090  long getResponseBlockSize();
091
092  void incrementResponseBlockSize(long blockSize);
093
094  long getResponseExceptionSize();
095
096  void incrementResponseExceptionSize(long exceptionSize);
097}