Class GroupRequest<T>
- All Implemented Interfaces:
CompletionStage<RspList<T>>,Future<RspList<T>>
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 the execute() method and call receiveResponse() to do so.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.CompletableFuture
CompletableFuture.AsynchronousCompletionTaskNested classes/interfaces inherited from interface java.util.concurrent.Future
Future.State -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Lockprotected intprotected intCorrelates requests and responsesFields inherited from class org.jgroups.blocks.Request
corr, options, req_id, start_time -
Constructor Summary
ConstructorsConstructorDescriptionGroupRequest(RequestCorrelator corr, Collection<Address> targets, RequestOptions options) -
Method Summary
Modifier and TypeMethodDescriptiondoAndComplete(Callable<RspList<T>> supplier) get()booleanjoin()voidmemberUnreachable(Address mbr) voidreceiveResponse(Object response_value, Address sender, boolean is_exception) Callback (called by RequestCorrelator or Transport).protected booleanvoidsendRequest(Message msg) protected voidsendRequest(Message msg, Collection<Address> targetMembers) protected booleansetSuspected(Address mbr) voidsiteUnreachable(String site) toString()voidMarks all responses with an exception (unless a response was already marked as done)protected voidunreachable(Predicate<SiteAddress> pred) voidviewChange(View view, boolean handle_previous_subgroups) Any member of 'membership' that is not in the new view is flagged as SUSPECTED.waitForCompletion(long timeout, TimeUnit unit) Blocks until all responses have been received and returns result or throws exceptionMethods inherited from class org.jgroups.blocks.Request
cancel, corrDone, execute, requestId, requestId, setResponseFilterMethods 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, exceptionallyAsync, exceptionallyAsync, exceptionallyCompose, exceptionallyComposeAsync, exceptionallyComposeAsync, exceptionNow, failedFuture, failedStage, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, minimalCompletionStage, newIncompleteFuture, obtrudeException, obtrudeValue, orTimeout, resultNow, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, state, supplyAsync, supplyAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, whenComplete, whenCompleteAsync, whenCompleteAsync
-
Field Details
-
lock
-
rsps
Correlates requests and responses -
num_valid
protected int num_valid -
num_received
protected int num_received
-
-
Constructor Details
-
GroupRequest
- 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 reasonGroupRequestuses it instead of aTransportis 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 Details
-
sendRequest
- Specified by:
sendRequestin classRequest<RspList<T>>- Throws:
Exception
-
receiveResponse
Callback (called by RequestCorrelator or Transport). Adds a response to the response table. When all responses have been received,execute()returns.- Specified by:
receiveResponsein classRequest<RspList<T>>
-
siteUnreachable
- Specified by:
siteUnreachablein classRequest<RspList<T>>
-
memberUnreachable
- Specified by:
memberUnreachablein classRequest<RspList<T>>
-
unreachable
-
viewChange
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:
viewChangein classRequest<RspList<T>>
-
transportClosed
public void transportClosed()Marks all responses with an exception (unless a response was already marked as done)- Specified by:
transportClosedin classRequest<RspList<T>>
-
getResponsesComplete
public boolean getResponsesComplete() -
get
- Specified by:
getin interfaceFuture<T>- Overrides:
getin classCompletableFuture<RspList<T>>- Throws:
InterruptedExceptionExecutionException
-
get
public RspList<T> get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
getin interfaceFuture<T>- Overrides:
getin classCompletableFuture<RspList<T>>- Throws:
InterruptedExceptionExecutionExceptionTimeoutException
-
join
- Overrides:
joinin classCompletableFuture<RspList<T>>
-
getNow
- Overrides:
getNowin classCompletableFuture<RspList<T>>
-
waitForCompletion
Description copied from class:RequestBlocks until all responses have been received and returns result or throws exception- Specified by:
waitForCompletionin classRequest<RspList<T>>
-
waitForCompletion
- Specified by:
waitForCompletionin classRequest<RspList<T>>- Throws:
ExecutionExceptionInterruptedException
-
toString
-
setSuspected
-
doAndComplete
-
sendRequest
- Throws:
Exception
-
responsesComplete
protected boolean responsesComplete()
-