public final class OneTimeToggle extends Object implements TargetState
AtomicBoolean which
can only be toggled once. There is no way to "untoggle" it.
Successive attempts to toggle it with now() will have no effect,
but it is possible to enforce a fail-fast toggle only once policy using
nowOrIfAlreadyThenThrow(Supplier) which will throw an exception
if the toggle happens several times.TargetStateTargetState.TaskControlIMMEDIATELY, NEVER| Constructor and Description |
|---|
OneTimeToggle() |
| Modifier and Type | Method and Description |
|---|---|
void |
now()
Toggle it! This will make
yet() return true. |
<E extends Throwable> |
nowOrIfAlreadyThenThrow(Supplier<E> exceptionSupplier)
Toggle it, or throw exception if the toggle has already been done, for instance
by another thread.
|
boolean |
yet()
Tell if the target state has been reached yet.
|
public void now()
yet() return true.public <E extends Throwable> void nowOrIfAlreadyThenThrow(Supplier<E> exceptionSupplier) throws E extends Throwable
E - the exception type that this method may throw.exceptionSupplier - supply exception to throw if it was already toggled.E extends Throwablepublic boolean yet()
TargetStatetrue, it will never return false again.yet in interface TargetStatetrue when the target state has been reached,
false otherwise.Copyright © 2019 Digipost. All rights reserved.