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.io.IOException; 021import java.net.InetAddress; 022 023import org.apache.hadoop.hbase.CellScanner; 024import org.apache.hadoop.hbase.io.ByteBuffAllocator; 025import org.apache.hadoop.hbase.ipc.RpcServer.CallCleanup; 026import org.apache.yetus.audience.InterfaceAudience; 027import org.apache.hbase.thirdparty.com.google.protobuf.BlockingService; 028import org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.MethodDescriptor; 029import org.apache.hbase.thirdparty.com.google.protobuf.Message; 030import org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.RequestHeader; 031 032/** 033 * Datastructure that holds all necessary to a method invocation and then afterward, carries the 034 * result. 035 */ 036@InterfaceAudience.Private 037class SimpleServerCall extends ServerCall<SimpleServerRpcConnection> { 038 039 final SimpleRpcServerResponder responder; 040 041 @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "NP_NULL_ON_SOME_PATH", 042 justification = "Can't figure why this complaint is happening... see below") 043 SimpleServerCall(int id, final BlockingService service, final MethodDescriptor md, 044 RequestHeader header, Message param, CellScanner cellScanner, 045 SimpleServerRpcConnection connection, long size, final InetAddress remoteAddress, 046 long receiveTime, int timeout, ByteBuffAllocator bbAllocator, 047 CellBlockBuilder cellBlockBuilder, CallCleanup reqCleanup, 048 SimpleRpcServerResponder responder) { 049 super(id, service, md, header, param, cellScanner, connection, size, remoteAddress, receiveTime, 050 timeout, bbAllocator, cellBlockBuilder, reqCleanup); 051 this.responder = responder; 052 } 053 054 /** 055 * Call is done. Execution happened and we returned results to client. It is now safe to cleanup. 056 */ 057 @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "IS2_INCONSISTENT_SYNC", 058 justification = "Presume the lock on processing request held by caller is protection enough") 059 @Override 060 public void done() { 061 super.done(); 062 this.getConnection().decRpcCount(); // Say that we're done with this call. 063 } 064 065 @Override 066 public synchronized void sendResponseIfReady() throws IOException { 067 // set param null to reduce memory pressure 068 this.param = null; 069 this.responder.doRespond(getConnection(), this); 070 } 071 072 SimpleServerRpcConnection getConnection() { 073 return this.connection; 074 } 075}