Class 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 the execute() method and call receiveResponse() to do so.

    Author:
    Bela Ban
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.concurrent.CompletableFuture

        java.util.concurrent.CompletableFuture.AsynchronousCompletionTask
    • 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 memberUnreachable​(Address mbr)  
      void receiveResponse​(java.lang.Object response_value, Address sender, boolean is_exception)
      Callback (called by RequestCorrelator or Transport).
      protected boolean responsesComplete()  
      void sendRequest​(Message msg)  
      protected void sendRequest​(Message msg, 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)
      protected void unreachable​(java.util.function.Predicate<SiteAddress> pred)  
      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 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • lock

        protected final java.util.concurrent.locks.Lock lock
      • rsps

        protected final RspList<T> rsps
        Correlates requests and responses
      • num_valid

        protected int num_valid
      • num_received

        protected int num_received
    • 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 reason GroupRequest uses it instead of a Transport is that multiple requests/responses might be sent/received concurrently
        targets - 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 membership
        options - The request options to be used for this call
    • Method Detail

      • sendRequest

        public void sendRequest​(Message msg)
                         throws java.lang.Exception
        Specified by:
        sendRequest in class Request<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 class Request<RspList<T>>
      • unreachable

        protected void unreachable​(java.util.function.Predicate<SiteAddress> pred)
      • 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 class Request<RspList<T>>
      • transportClosed

        public void transportClosed()
        Marks all responses with an exception (unless a response was already marked as done)
        Specified by:
        transportClosed in class Request<RspList<T>>
      • getResponsesComplete

        public boolean getResponsesComplete()
      • get

        public RspList<T> get()
                       throws java.lang.InterruptedException,
                              java.util.concurrent.ExecutionException
        Specified by:
        get in interface java.util.concurrent.Future<T>
        Overrides:
        get in class java.util.concurrent.CompletableFuture<RspList<T>>
        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
        Specified by:
        get in interface java.util.concurrent.Future<T>
        Overrides:
        get in class java.util.concurrent.CompletableFuture<RspList<T>>
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
        java.util.concurrent.TimeoutException
      • join

        public RspList<T> join()
        Overrides:
        join in class java.util.concurrent.CompletableFuture<RspList<T>>
      • getNow

        public RspList<T> getNow​(RspList<T> valueIfAbsent)
        Overrides:
        getNow in class java.util.concurrent.CompletableFuture<RspList<T>>
      • 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 class Request<RspList<T>>
      • waitForCompletion

        public RspList<T> waitForCompletion()
                                     throws java.util.concurrent.ExecutionException,
                                            java.lang.InterruptedException
        Specified by:
        waitForCompletion in class Request<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​(Message msg,
                                   java.util.Collection<Address> targetMembers)
                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • responsesComplete

        protected boolean responsesComplete()