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;
022
023import org.apache.yetus.audience.InterfaceAudience;
024import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.VersionInfo;
025import org.apache.hadoop.hbase.security.User;
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.
035   * If called from outside the context of IPC, this does nothing.
036   * @return < 0 if the caller is still connected. The time in ms
037   *  since the disconnection 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).
045   * We need to ask this question per call because a server could be hosting both clients that
046   * support 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  /**
059   * @return Current request's user name or not present if none ongoing.
060   */
061  default Optional<String> getRequestUserName() {
062    return getRequestUser().map(User::getShortName);
063  }
064
065  /**
066   * @return Address of remote client in this call
067   */
068  InetAddress getRemoteAddress();
069
070  /**
071   * @return the client version info, or null if the information is not present
072   */
073  VersionInfo getClientVersionInfo();
074
075  /**
076   * Sets a callback which has to be executed at the end of this RPC call. Such a callback is an
077   * optional one for any Rpc call.
078   *
079   * @param callback
080   */
081  void setCallBack(RpcCallback callback);
082
083  boolean isRetryImmediatelySupported();
084
085  /**
086   * The size of response cells that have been accumulated so far.
087   * This along with the corresponding increment call is used to ensure that multi's or
088   * scans dont get too excessively large
089   */
090  long getResponseCellSize();
091
092  /**
093   * Add on the given amount to the retained cell size.
094   *
095   * This is not thread safe and not synchronized at all. If this is used by more than one thread
096   * then everything will break. Since this is called for every row synchronization would be too
097   * onerous.
098   */
099  void incrementResponseCellSize(long cellSize);
100
101  long getResponseBlockSize();
102
103  void incrementResponseBlockSize(long blockSize);
104
105  long getResponseExceptionSize();
106  void incrementResponseExceptionSize(long exceptionSize);
107}