Package org.jgroups.protocols.pbcast
Class ViewHandler<R>
- java.lang.Object
-
- org.jgroups.protocols.pbcast.ViewHandler<R>
-
- Type Parameters:
R- the type of the request
public class ViewHandler<R> extends java.lang.ObjectResponsible 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.AtomicIntegercountprotected GMSgmsprotected BoundedList<java.lang.String>historyprotected java.util.concurrent.locks.Locklockprotected booleanprocessingprotected java.util.concurrent.locks.Conditionprocessing_doneprotected java.util.function.BiPredicate<R,R>req_matcherprotected java.util.function.Consumer<java.util.Collection<R>>req_processorprotected java.util.Collection<R>requestsprotected java.util.concurrent.atomic.AtomicBooleansuspended
-
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.StringdumpHistory()java.lang.StringdumpQueue()protected Loglog()protected voidprocess(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>>
Tprocessing(boolean flag)To be used by testing only!protected voidremoveAndProcess(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)voidresume()protected booleansetProcessing(boolean flag)intsize()voidsuspend()Clears the queue and discards new requests from now onbooleansuspended()java.lang.StringtoString()voidwaitUntilComplete()Blocks the caller until the current set of requests being processed have been completed.voidwaitUntilComplete(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
-
-
-
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
-
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 GMSreq_processor- A request processor which processes a list of requestsreq_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)
-
add
public ViewHandler<R> add(R req)
-
add
public ViewHandler<R> add(R... reqs)
-
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:
toStringin classjava.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!
-
-