Class RequestRepository
- All Implemented Interfaces:
Lifecycle
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 Summary
ConstructorsConstructorDescriptionRequestRepository(JGroupsMetricsManager metricsManager, ScheduledExecutorService timeoutExecutor, TimeService timeService) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddRequest(Request<?, ?> request) final voidaddResponse(long requestId, Object sender, Response response) Dispatches an inbound response to the request that originated it.voidApplies the given action to every in-flight request.multiRequest(Collection<Address> targets, Address excluded, ResponseCollector<Address, T> collector, long timeout, TimeUnit unit) Creates a request expecting responses from multiple cluster members.voidremoveRequest(long requestId) Removes a request from the registry.singleRequest(Address target, ResponseCollector<Address, T> collector, long timeout, TimeUnit unit) Creates a request targeting and expecting a response from a single cluster member.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).<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.voidstart()Invoked on component startvoidstop()Marks the repository as stopped so that newly created requests are immediately cancelled.
-
Constructor Details
-
RequestRepository
public RequestRepository(JGroupsMetricsManager metricsManager, ScheduledExecutorService timeoutExecutor, TimeService timeService)
-
-
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 respondentcollector- gathers the response and produces the final resulttimeout- timeout duration; if positive and a timeout executor is available, the request is cancelled with aTimeoutExceptionon expiryunit- time unit fortimeout- 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 respondentsexcluded- address to exclude from the target set (typically the local node), ornullcollector- gathers responses and produces the final resulttimeout- timeout duration; if positive and a timeout executor is available, the request is cancelled with aTimeoutExceptionon expiryunit- time unit fortimeout- 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 sitecollector- gathers the response and produces the final resulttimeout- timeout duration; if positive and a timeout executor is available, the request is cancelled with aTimeoutExceptionon expiryunit- time unit fortimeout- 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 orderexcluded- address to exclude (typically the local node), ornullcollector- gathers responses and produces the final resultsender- the callback responsible for sending the requesttimeout- overall timeout for the entire staggered sequenceunit- time unit fortimeout- Returns:
- the staggered request; the caller is responsible for initiating the first send
-
addRequest
-
addResponse
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 messagesender- the origin of the response (anAddressor 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
-
start
-
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).
-