Class ViewHandler<R>

  • Type Parameters:
    R - the type of the request

    public class ViewHandler<R>
    extends java.lang.Object
    Responsible for dispatching JOIN/LEAVE/MERGE requests to the GMS protocol. Bundles multiple concurrent requests into a request list
    Since:
    4.0.5
    Author:
    Bela Ban
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.concurrent.atomic.AtomicInteger count  
      protected GMS gms  
      protected BoundedList<java.lang.String> history  
      protected java.util.concurrent.locks.Lock lock  
      protected boolean processing  
      protected java.util.concurrent.locks.Condition processing_done  
      protected java.util.function.BiPredicate<R,​R> req_matcher  
      protected java.util.function.Consumer<java.util.Collection<R>> req_processor  
      protected java.util.Collection<R> requests  
      protected java.util.concurrent.atomic.AtomicBoolean suspended  
    • Constructor Summary

      Constructors 
      Constructor Description
      ViewHandler​(GMS gms, java.util.function.Consumer<java.util.Collection<R>> req_processor, java.util.function.BiPredicate<R,​R> req_matcher)
      Constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean _add​(java.util.Collection<R> reqs)  
      protected boolean _add​(R req)  
      protected boolean _add​(R... reqs)  
      ViewHandler<R> add​(java.util.Collection<R> reqs)  
      ViewHandler<R> add​(R req)  
      ViewHandler<R> add​(R... reqs)  
      java.lang.String dumpHistory()  
      java.lang.String dumpQueue()  
      protected Log log()  
      protected void process​(java.util.Collection<R> requests)
      We're guaranteed that only one thread will be called with this method at any time
      <T extends ViewHandler<R>>
      T
      processing​(boolean flag)
      To be used by testing only!
      protected void removeAndProcess​(java.util.Collection<R> requests)
      Removes requests as long as they match - breaks at the first non-matching request or when requests is empty This method must catch all exceptions; or else process() might return without setting processing to true again!
      java.util.function.BiPredicate<R,​R> reqMatcher()  
      ViewHandler<R> reqMatcher​(java.util.function.BiPredicate<R,​R> m)  
      java.util.function.Consumer<java.util.Collection<R>> reqProcessor()  
      ViewHandler<R> reqProcessor​(java.util.function.Consumer<java.util.Collection<R>> p)  
      void resume()  
      protected boolean setProcessing​(boolean flag)  
      int size()  
      void suspend()
      Clears the queue and discards new requests from now on
      boolean suspended()  
      java.lang.String toString()  
      void waitUntilComplete()
      Blocks the caller until the current set of requests being processed have been completed.
      void waitUntilComplete​(long timeout)
      Blocks the caller until the current set of requests being processed have been completed, or the timeout elapsed.
      Returns immediately if no requests are currently being processed
      • Methods inherited from class java.lang.Object

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

      • requests

        protected final java.util.Collection<R> requests
      • lock

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

        protected final java.util.concurrent.atomic.AtomicInteger count
      • suspended

        protected final java.util.concurrent.atomic.AtomicBoolean suspended
      • processing

        protected boolean processing
      • processing_done

        protected final java.util.concurrent.locks.Condition processing_done
      • gms

        protected final GMS gms
      • req_processor

        protected java.util.function.Consumer<java.util.Collection<R>> req_processor
      • req_matcher

        protected java.util.function.BiPredicate<R,​R> req_matcher
      • history

        protected final BoundedList<java.lang.String> history
    • Constructor Detail

      • ViewHandler

        public ViewHandler​(GMS gms,
                           java.util.function.Consumer<java.util.Collection<R>> req_processor,
                           java.util.function.BiPredicate<R,​R> req_matcher)
        Constructor
        Parameters:
        gms - The ref to GMS
        req_processor - A request processor which processes a list of requests
        req_matcher - The matcher which determines whether any given 2 requests can be processed together
    • Method Detail

      • suspended

        public boolean suspended()
      • size

        public int size()
      • reqProcessor

        public ViewHandler<R> reqProcessor​(java.util.function.Consumer<java.util.Collection<R>> p)
      • reqProcessor

        public java.util.function.Consumer<java.util.Collection<R>> reqProcessor()
      • reqMatcher

        public ViewHandler<R> reqMatcher​(java.util.function.BiPredicate<R,​R> m)
      • reqMatcher

        public java.util.function.BiPredicate<R,​R> reqMatcher()
      • add

        public ViewHandler<R> add​(java.util.Collection<R> reqs)
      • suspend

        public void suspend()
        Clears the queue and discards new requests from now on
      • resume

        public void resume()
      • waitUntilComplete

        public void waitUntilComplete()
        Blocks the caller until the current set of requests being processed have been completed. Returns immediately if no requests are currently being processed
      • waitUntilComplete

        public void waitUntilComplete​(long timeout)
        Blocks the caller until the current set of requests being processed have been completed, or the timeout elapsed.
        Returns immediately if no requests are currently being processed
        Parameters:
        timeout - Max time to wait in milliseconds
      • processing

        public <T extends ViewHandler<R>> T processing​(boolean flag)
        To be used by testing only!
      • dumpQueue

        public java.lang.String dumpQueue()
      • dumpHistory

        public java.lang.String dumpHistory()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • log

        protected Log log()
      • setProcessing

        protected boolean setProcessing​(boolean flag)
      • _add

        protected boolean _add​(R req)
      • _add

        protected boolean _add​(R... reqs)
      • _add

        protected boolean _add​(java.util.Collection<R> reqs)
      • process

        protected void process​(java.util.Collection<R> requests)
        We're guaranteed that only one thread will be called with this method at any time
      • removeAndProcess

        protected void removeAndProcess​(java.util.Collection<R> requests)
        Removes requests as long as they match - breaks at the first non-matching request or when requests is empty This method must catch all exceptions; or else process() might return without setting processing to true again!