Package io.pravega.common.util
Class ReusableFutureLatch<T>
- java.lang.Object
-
- io.pravega.common.util.ReusableFutureLatch<T>
-
- Type Parameters:
T- The type of the futures that this class works with.
public class ReusableFutureLatch<T> extends java.lang.ObjectThis class is similar toReusableLatchbut that works withCompletableFutureso that blocking can be async and exceptions and results can be passed.
-
-
Constructor Summary
Constructors Constructor Description ReusableFutureLatch()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidregister(java.util.concurrent.CompletableFuture<T> toNotify)Supply a future to be notified whenrelease(Object)is called.voidregisterAndRunReleaser(java.lang.Runnable willCallRelease, java.util.concurrent.CompletableFuture<T> toNotify)If the latch is released, completes the provided future without invoking the provided runnable.voidrelease(T result)Complete all waiting futures, and all future calls to register be notified immediately.voidreleaseExceptionally(java.lang.Throwable e)Complete all waiting futures, and all future calls to register be notified immediately.voidreleaseExceptionallyAndReset(java.lang.Throwable e)Identical to calling#releaseExceptionally(Exception); #reset()except it is atomic.voidreset()Ifrelease(Object)orreleaseExceptionally(Throwable)has been called it resets the object into the unreleased state.java.lang.StringtoString()
-
-
-
Method Detail
-
register
public void register(java.util.concurrent.CompletableFuture<T> toNotify)
Supply a future to be notified whenrelease(Object)is called. If release has already been called, it will be completed immediately.- Parameters:
toNotify- The future that should be completed.
-
registerAndRunReleaser
public void registerAndRunReleaser(java.lang.Runnable willCallRelease, java.util.concurrent.CompletableFuture<T> toNotify)If the latch is released, completes the provided future without invoking the provided runnable. If the latch is not released it will add the provided future to the list to be notified and runs the provided runnable if there is not already one running. If there are multiple calls to this method, only the runnable of one will be invoked. If the runnable throws the exception will be thrown to the caller of this method, and future callers may have their runnable method invoked (Presuming that the latch is not released)- Parameters:
willCallRelease- A runnable that should result inrelease(Object)being called.toNotify- The future to notify once release is called.
-
release
public void release(T result)
Complete all waiting futures, and all future calls to register be notified immediately. If release is called twice consecutively the second value will be the one passed to future callers ofregister(CompletableFuture)- Parameters:
result- The result to pass to waiting futures.
-
releaseExceptionally
public void releaseExceptionally(java.lang.Throwable e)
Complete all waiting futures, and all future calls to register be notified immediately. If release is called twice consecutively the second value will be the one passed to future callers ofregister(CompletableFuture)- Parameters:
e- The exception to pass to waiting futures.
-
reset
public void reset()
Ifrelease(Object)orreleaseExceptionally(Throwable)has been called it resets the object into the unreleased state. If release has not been called this will have no effect.
-
releaseExceptionallyAndReset
public void releaseExceptionallyAndReset(java.lang.Throwable e)
Identical to calling#releaseExceptionally(Exception); #reset()except it is atomic.- Parameters:
e- The exception to fail all waiting futures with.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-