Package com.yahoo.concurrent
Class EventBarrier
java.lang.Object
com.yahoo.concurrent.EventBarrier
Reference implementation of the 'Incremental Minimal Event Barrier'
algorithm. An event in this context is defined to be something that
happens during a time interval. An event barrier is a time interval
for which events may start before or end after, but not both. The
problem solved by the algorithm is to determine the minimal event
barrier starting at a given time. In other words; wait for the
currently active events to complete. The most natural use of this
algorithm would be to make a thread wait for events happening in
other threads to complete.
- Author:
- Haavard Pettersen, Simon Thoresen Hult
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Declares the interface required to wait for the detection of a minimal event barrier. -
Constructor Summary
ConstructorDescriptionAt creation there are no active events and no pending barriers. -
Method Summary
Modifier and TypeMethodDescriptionvoid
completeEvent
(int token) Signal the completion of an event.boolean
startBarrier
(EventBarrier.BarrierWaiter handler) Initiate the detection of the minimal event barrier starting now.int
Signal the start of an event.
-
Constructor Details
-
EventBarrier
public EventBarrier()At creation there are no active events and no pending barriers.
-
-
Method Details
-
startEvent
public int startEvent()Signal the start of an event. The value returned from this method must later be passed to the completeEvent method when signaling the completion of the event.- Returns:
- Opaque token identifying the started event.
-
completeEvent
public void completeEvent(int token) Signal the completion of an event. The value passed to this method must be the same as the return value previously obtained from the startEvent method. This method will signal the completion of all pending barriers that were completed by the completion of this event.- Parameters:
token
- Opaque token identifying the completed event.
-
startBarrier
Initiate the detection of the minimal event barrier starting now. If this method returns false it means that no events were currently active and the minimal event barrier was infinitely small. If this method returns false the handler will not be notified of the completion of the barrier. If this method returns true it means that the started barrier is pending and that the handler passed to this method will be notified of its completion at a later time.- Parameters:
handler
- Handler notified of the completion of the barrier.- Returns:
- True if a barrier was started, false if no events were active.
-