Class RequestRepository

java.lang.Object
org.infinispan.remoting.transport.impl.RequestRepository
All Implemented Interfaces:
Lifecycle

public class RequestRepository extends Object implements Lifecycle
Registry of in-flight remote command requests.

Tracks all pending Request instances, dispatches inbound responses to the corresponding request, and cancels outstanding requests when the cache manager stops.

Thread-safety: All methods are safe for concurrent use.

Since:
9.0
Author:
Dan Berindei
  • Constructor Details

  • Method Details

    • singleRequest

      public <T> Request<Address,T> singleRequest(Address target, ResponseCollector<Address,T> collector, long timeout, TimeUnit unit)
      Creates a request targeting and expecting a response from a single cluster member.

      If the repository has been stopped, the returned request is immediately cancelled.

      Type Parameters:
      T - the result type produced by the collector
      Parameters:
      target - the address of the single expected respondent
      collector - gathers the response and produces the final result
      timeout - timeout duration; if positive and a timeout executor is available, the request is cancelled with a TimeoutException on expiry
      unit - time unit for timeout
      Returns:
      a completable request that completes when the collector produces a result
    • multiRequest

      public <T> Request<Address,T> multiRequest(Collection<Address> targets, Address excluded, ResponseCollector<Address,T> collector, long timeout, TimeUnit unit)
      Creates a request expecting responses from multiple cluster members.

      If all targets are excluded or absent, the returned request may already be complete. If the repository has been stopped, the returned request is immediately cancelled.

      Type Parameters:
      T - the result type produced by the collector
      Parameters:
      targets - the addresses of the expected respondents
      excluded - address to exclude from the target set (typically the local node), or null
      collector - gathers responses and produces the final result
      timeout - timeout duration; if positive and a timeout executor is available, the request is cancelled with a TimeoutException on expiry
      unit - time unit for timeout
      Returns:
      a completable request that completes when the collector produces a result
    • singleSiteRequest

      public <T> Request<String,T> singleSiteRequest(String site, ResponseCollector<String,T> collector, long timeout, TimeUnit unit)
      Creates a request expecting a response from a single remote site (cross-site replication).

      If the repository has been stopped, the returned request is immediately cancelled.

      Type Parameters:
      T - the result type produced by the collector
      Parameters:
      site - the name of the target site
      collector - gathers the response and produces the final result
      timeout - timeout duration; if positive and a timeout executor is available, the request is cancelled with a TimeoutException on expiry
      unit - time unit for timeout
      Returns:
      a completable request that completes when the collector produces a result
    • staggeredRequest

      public <T> StaggeredRequest<T> staggeredRequest(Collection<Address> targets, Address excluded, ResponseCollector<Address,T> collector, StaggeredRequest.StaggeredSender sender, long timeout, TimeUnit unit)
      Creates a request that sends the command to targets one at a time, advancing to the next target on each response or stagger-timeout.

      Unlike the other factory methods, the returned request manages its own timeout scheduling and message dispatch. If the repository has been stopped, the request is immediately cancelled.

      Type Parameters:
      T - the result type produced by the collector
      Parameters:
      targets - the candidate respondents, tried in order
      excluded - address to exclude (typically the local node), or null
      collector - gathers responses and produces the final result
      sender - the callback responsible for sending the request
      timeout - overall timeout for the entire staggered sequence
      unit - time unit for timeout
      Returns:
      the staggered request; the caller is responsible for initiating the first send
    • addRequest

      protected void addRequest(Request<?,?> request)
    • addResponse

      public final void addResponse(long requestId, Object sender, Response response)
      Dispatches an inbound response to the request that originated it.

      If no request with the given id exists (already completed or unknown), the response is silently ignored.

      Parameters:
      requestId - the request identifier carried by the response message
      sender - the origin of the response (an Address or site name)
      response - the response payload
    • removeRequest

      public void removeRequest(long requestId)
      Removes a request from the registry.

      Typically called by the request itself upon completion, cancellation, or timeout.

      Parameters:
      requestId - the identifier of the request to remove
    • forEach

      public void forEach(Consumer<Request<?,?>> consumer)
      Applies the given action to every in-flight request.
      Parameters:
      consumer - the action to apply
    • start

      public void start()
      Description copied from interface: Lifecycle
      Invoked on component start
      Specified by:
      start in interface Lifecycle
    • stop

      public void stop()
      Marks the repository as stopped so that newly created requests are immediately cancelled.

      Does not cancel already-registered requests; the caller is responsible for draining those separately via forEach(Consumer).

      Specified by:
      stop in interface Lifecycle