RpcCallCache (Apache Hadoop Common 3.5.0 API)
Description: declaration: package: org.apache.hadoop.oncrpc, class: RpcCallCache

Package org.apache.hadoop.oncrpc

# Class RpcCallCache

java.lang.Object
org.apache.hadoop.oncrpc.RpcCallCache

public class RpcCallCache extends Object
This class is used for handling the duplicate non-idempotenty Rpc calls. A non-idempotent request is processed as follows:

- If the request is being processed for the first time, its state is in-progress in cache.
- If the request is retransimitted and is in-progress state, it is ignored.
- If the request is retransimitted and is completed, the previous response from the cache is sent back to the client.

A request is identified by the client ID (address of the client) and transaction ID (xid) from the Rpc call.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `RpcCallCache.CacheEntry`
  `static class`
  `RpcCallCache.ClientRequest`
  Call that is used to track a client in the `RpcCallCache`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RpcCallCache(String program, int maxEntries)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `callCompleted(InetAddress clientId, int xid, RpcResponse response)`
  Mark a request as completed and add corresponding response to the cache.
  `RpcCallCache.CacheEntry`
  `checkOrAddToCache(InetAddress clientId, int xid)`
  Check the cache for an entry.
  `String`
  `getProgram()`
  Return the program name.
  `Iterator<Map.Entry<RpcCallCache.ClientRequest,RpcCallCache.CacheEntry>>`
  `iterator()`
  Iterator to the cache entries.
  `int`
  `size()`
  Return number of cached entries.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### RpcCallCache

    public RpcCallCache(String program, int maxEntries)

- ## Method Details

  - ### getProgram

    public String getProgram()
    Return the program name.
    Returns:
      RPC program name

  - ### callCompleted

    public void callCompleted(InetAddress clientId, int xid, RpcResponse response)
    Mark a request as completed and add corresponding response to the cache.
    Parameters:
      `clientId` - client IP address
      `xid` - transaction id
      `response` - RPC response

  - ### checkOrAddToCache

    public RpcCallCache.CacheEntry checkOrAddToCache(InetAddress clientId, int xid)
    Check the cache for an entry. If it does not exist, add the request as in progress.
    Parameters:
      `clientId` - client IP address
      `xid` - transaction id
    Returns:
      cached entry

  - ### size

    public int size()
    Return number of cached entries.
    Returns:
      cache size

  - ### iterator

    @VisibleForTesting public Iterator<Map.Entry<RpcCallCache.ClientRequest,RpcCallCache.CacheEntry>> iterator()
    Iterator to the cache entries.
    Returns:
      iterator cache iterator