Class NodeResponseTracker

java.lang.Object
org.elasticsearch.action.support.NodeResponseTracker

public class NodeResponseTracker extends Object
This class tracks the intermediate responses that will be used to create aggregated cluster response to a request. It also gives the possibility to discard the intermediate results when asked, for example when the initial request is cancelled, in order to release the resources.
  • Constructor Details

    • NodeResponseTracker

      public NodeResponseTracker(int size)
    • NodeResponseTracker

      public NodeResponseTracker(Collection<Object> array)
  • Method Details

    • discardIntermediateResponses

      public void discardIntermediateResponses(Exception cause)
      This method discards the results collected so far to free up the resources.
      Parameters:
      cause - the discarding, this will be communicated if they try to access the discarded results
    • responsesDiscarded

      public boolean responsesDiscarded()
    • trackResponseAndCheckIfLast

      public boolean trackResponseAndCheckIfLast(int nodeIndex, Object response)
      This method stores a new node response if the intermediate responses haven't been discarded yet. If the responses are not discarded the method asserts that this is the first response encountered from this node to protect from miscounting the responses in case of a double invocation. If the responses have been discarded we accept this risk for simplicity.
      Parameters:
      nodeIndex - , the index that represents a single node of the cluster
      response - , a response can be either a NodeResponse or an error
      Returns:
      true if all the nodes' responses have been received, else false
    • getResponse

      public Object getResponse(int nodeIndex) throws NodeResponseTracker.DiscardedResponsesException
      Returns the tracked response or null if the response hasn't been received yet for a specific index that represents a node of the cluster.
      Throws:
      NodeResponseTracker.DiscardedResponsesException - if the responses have been discarded
    • getExpectedResponseCount

      public int getExpectedResponseCount()