Class GroupRequest<T>
- java.lang.Object
-
- java.util.concurrent.CompletableFuture<T>
-
- org.jgroups.blocks.Request<RspList<T>>
-
- org.jgroups.blocks.GroupRequest<T>
-
- All Implemented Interfaces:
java.util.concurrent.CompletionStage<RspList<T>>
,java.util.concurrent.Future<RspList<T>>
public class GroupRequest<T> extends Request<RspList<T>>
Sends a message to all members of the group and waits for all responses (or timeout). Returns a boolean value (success or failure). Results (if any) can be retrieved when done.The supported transport to send requests is currently either a RequestCorrelator or a generic Transport. One of them has to be given in the constructor. It will then be used to send a request. When a message is received by either one, the receiveResponse() of this class has to be called (this class does not actively receive requests/responses itself). Also, when a view change or suspicion is received, the methods viewChange() or suspect() of this class have to be called.
When started, an array of responses, correlating to the membership, is created. Each response is added to the corresponding field in the array. When all fields have been set, the algorithm terminates. This algorithm can optionally use a suspicion service (failure detector) to detect (and exclude from the membership) fauly members. If no suspicion service is available, timeouts can be used instead (see
execute()
). When done, a list of suspected members can be retrieved.Because a channel might deliver requests, and responses to different requests, the
GroupRequest
class cannot itself receive and process requests/responses from the channel. A mechanism outside this class has to do this; it has to determine what the responses are for the message sent by theexecute()
method and callreceiveResponse()
to do so.- Author:
- Bela Ban
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.locks.Lock
lock
protected int
num_received
protected int
num_valid
protected RspList<T>
rsps
Correlates requests and responses-
Fields inherited from class org.jgroups.blocks.Request
corr, options, req_id, start_time
-
-
Constructor Summary
Constructors Constructor Description GroupRequest(RequestCorrelator corr, java.util.Collection<Address> targets, RequestOptions options)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected RspList<T>
doAndComplete(java.util.concurrent.Callable<RspList<T>> supplier)
RspList<T>
get()
RspList<T>
get(long timeout, java.util.concurrent.TimeUnit unit)
RspList<T>
getNow(RspList<T> valueIfAbsent)
boolean
getResponsesComplete()
RspList<T>
join()
void
receiveResponse(java.lang.Object response_value, Address sender, boolean is_exception)
Callback (called by RequestCorrelator or Transport).protected boolean
responsesComplete()
void
sendRequest(Buffer data)
protected void
sendRequest(Buffer data, java.util.Collection<Address> targetMembers)
protected boolean
setSuspected(Address mbr)
void
siteUnreachable(java.lang.String site)
java.lang.String
toString()
void
transportClosed()
Marks all responses with an exception (unless a response was already marked as done)void
viewChange(View view, boolean handle_previous_subgroups)
Any member of 'membership' that is not in the new view is flagged as SUSPECTED.RspList<T>
waitForCompletion()
RspList<T>
waitForCompletion(long timeout, java.util.concurrent.TimeUnit unit)
Blocks until all responses have been received and returns result or throws exception-
Methods inherited from class org.jgroups.blocks.Request
cancel, corrDone, execute, requestId, requestId, setResponseFilter
-
Methods inherited from class java.util.concurrent.CompletableFuture
acceptEither, acceptEitherAsync, acceptEitherAsync, allOf, anyOf, applyToEither, applyToEitherAsync, applyToEitherAsync, complete, completeAsync, completeAsync, completedFuture, completedStage, completeExceptionally, completeOnTimeout, copy, defaultExecutor, delayedExecutor, delayedExecutor, exceptionally, failedFuture, failedStage, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, minimalCompletionStage, newIncompleteFuture, obtrudeException, obtrudeValue, orTimeout, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, supplyAsync, supplyAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, whenComplete, whenCompleteAsync, whenCompleteAsync
-
-
-
-
Constructor Detail
-
GroupRequest
public GroupRequest(RequestCorrelator corr, java.util.Collection<Address> targets, RequestOptions options)
- Parameters:
corr
- The request correlator to be used. A request correlator sends requests tagged with a unique ID and notifies the sender when matching responses are received. The reasonGroupRequest
uses it instead of aTransport
is that multiple requests/responses might be sent/received concurrentlytargets
- The targets, which are supposed to receive the message. Any receiver not in this set will discard the message. Targets are always a subset of the current membershipoptions
- The request options to be used for this call
-
-
Method Detail
-
sendRequest
public void sendRequest(Buffer data) throws java.lang.Exception
- Specified by:
sendRequest
in classRequest<RspList<T>>
- Throws:
java.lang.Exception
-
receiveResponse
public void receiveResponse(java.lang.Object response_value, Address sender, boolean is_exception)
Callback (called by RequestCorrelator or Transport). Adds a response to the response table. When all responses have been received,execute()
returns.- Specified by:
receiveResponse
in classRequest<RspList<T>>
-
siteUnreachable
public void siteUnreachable(java.lang.String site)
- Specified by:
siteUnreachable
in classRequest<RspList<T>>
-
viewChange
public void viewChange(View view, boolean handle_previous_subgroups)
Any member of 'membership' that is not in the new view is flagged as SUSPECTED. Any member in the new view that is not in the membership (ie, the set of responses expected for the current RPC) will not be added to it. If we did this we might run into the following problem:- Membership is {A,B}
- A sends a synchronous group RPC (which sleeps for 60 secs in the invocation handler)
- C joins while A waits for responses from A and B
- If this would generate a new view {A,B,C} and if this expanded the response set to {A,B,C}, A would wait forever on C's response because C never received the request in the first place, therefore won't send a response.
- Specified by:
viewChange
in classRequest<RspList<T>>
-
transportClosed
public void transportClosed()
Marks all responses with an exception (unless a response was already marked as done)- Specified by:
transportClosed
in classRequest<RspList<T>>
-
getResponsesComplete
public boolean getResponsesComplete()
-
get
public RspList<T> get() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
-
get
public RspList<T> get(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
-
waitForCompletion
public RspList<T> waitForCompletion(long timeout, java.util.concurrent.TimeUnit unit)
Description copied from class:Request
Blocks until all responses have been received and returns result or throws exception- Specified by:
waitForCompletion
in classRequest<RspList<T>>
-
waitForCompletion
public RspList<T> waitForCompletion() throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
- Specified by:
waitForCompletion
in classRequest<RspList<T>>
- Throws:
java.util.concurrent.ExecutionException
java.lang.InterruptedException
-
setSuspected
protected boolean setSuspected(Address mbr)
-
doAndComplete
protected RspList<T> doAndComplete(java.util.concurrent.Callable<RspList<T>> supplier)
-
sendRequest
protected void sendRequest(Buffer data, java.util.Collection<Address> targetMembers) throws java.lang.Exception
- Throws:
java.lang.Exception
-
responsesComplete
protected boolean responsesComplete()
-
-