001/*
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019
020package org.apache.hadoop.hbase.ipc;
021
022import org.apache.yetus.audience.InterfaceAudience;
023import org.apache.yetus.audience.InterfaceStability;
024
025import java.io.IOException;
026
027import org.apache.hadoop.hbase.CellScanner;
028import org.apache.hadoop.hbase.HBaseInterfaceAudience;
029import org.apache.hbase.thirdparty.com.google.protobuf.BlockingService;
030import org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.MethodDescriptor;
031import org.apache.hbase.thirdparty.com.google.protobuf.Message;
032import org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.RequestHeader;
033
034/**
035 * Interface of all necessary to carry out a RPC method invocation on the server.
036 */
037@InterfaceAudience.LimitedPrivate({HBaseInterfaceAudience.COPROC, HBaseInterfaceAudience.PHOENIX})
038@InterfaceStability.Evolving
039public interface RpcCall extends RpcCallContext {
040
041  /**
042   * @return The service of this call.
043   */
044  BlockingService getService();
045
046  /**
047   * @return The service method.
048   */
049  MethodDescriptor getMethod();
050
051  /**
052   * @return The call parameter message.
053   */
054  Message getParam();
055
056  /**
057   * @return The CellScanner that can carry input and result payload.
058   */
059  CellScanner getCellScanner();
060
061  /**
062   * @return The timestamp when the call is constructed.
063   */
064  long getReceiveTime();
065
066  /**
067   * @return The time when the call starts to be executed.
068   */
069  long getStartTime();
070
071  /**
072   * Set the time when the call starts to be executed.
073   */
074  void setStartTime(long startTime);
075
076  /**
077   * @return The timeout of this call.
078   */
079  int getTimeout();
080
081  /**
082   * @return The Priority of this call.
083   */
084  int getPriority();
085
086  /**
087   * Return the deadline of this call. If we can not complete this call in time,
088   * we can throw a TimeoutIOException and RPCServer will drop it.
089   * @return The system timestamp of deadline.
090   */
091  long getDeadline();
092
093  /**
094   * Used to calculate the request call queue size.
095   * If the total request call size exceeds a limit, the call will be rejected.
096   * @return The raw size of this call.
097   */
098  long getSize();
099
100  /**
101   * @return The request header of this call.
102   */
103  RequestHeader getHeader();
104
105  /**
106   * @return Port of remote address in this call
107   */
108  int getRemotePort();
109
110  /**
111   * Set the response resulting from this RPC call.
112   * @param param The result message as response.
113   * @param cells The CellScanner that possibly carries the payload.
114   * @param errorThrowable The error Throwable resulting from the call.
115   * @param error Extra error message.
116   */
117  void setResponse(Message param, CellScanner cells, Throwable errorThrowable, String error);
118
119  /**
120   * Send the response of this RPC call.
121   * Implementation provides the underlying facility (connection, etc) to send.
122   * @throws IOException
123   */
124  void sendResponseIfReady() throws IOException;
125
126  /**
127   * Do the necessary cleanup after the call if needed.
128   */
129  void cleanup();
130
131  /**
132   * @return A short string format of this call without possibly lengthy params
133   */
134  String toShortString();
135}