@FunctionalInterface
public interface Timeout
Interface represents a "storable" timeout that you can create with required milliseconds value and then reuse it in different parts of your program.
This is a FunctionalInterface so it may be created with a simple lambda, like: () -> 5000
This code will create a 5 second timeout.
Other way to get an instance is to use create(long) method that will create new timeout
from the specified number of milliseconds.
Note for each simple operation there's also a 'dangerous' method that takes one of the "dangerous functional" interfaces and a string name that is required to make fail message more informative.
getMillis(),
sleep(),
await(LongConsumer),
await(BiConsumer),
awaitAndGet(LongFunction),
awaitAndGet(BiFunction),
awaitDangerous(DangerousConsumer, String),
awaitDangerous(DangerousBiConsumer, String),
awaitAndGetDangerous(DangerousFunction, String),
awaitAndGetDangerous(DangerousBiFunction, String)| Modifier and Type | Method and Description |
|---|---|
default void |
await(java.util.function.BiConsumer<java.lang.Long,java.util.concurrent.TimeUnit> operation)
Specified operation is called with the value received from the
getMillis()
and the time unit: TimeUnit.MILLISECONDS |
default void |
await(java.util.function.LongConsumer operation)
Specified operation is called with the value received from the
getMillis() |
default <T> T |
awaitAndGet(java.util.function.BiFunction<java.lang.Long,java.util.concurrent.TimeUnit,T> operation)
Specified function is applied to the value received from the
getMillis()
and time unit: TimeUnit.MILLISECONDS. |
default <T> T |
awaitAndGet(java.util.function.LongFunction<T> operation)
Specified function is applied to the value received from the
getMillis(). |
default <T> T |
awaitAndGetDangerous(DangerousBiFunction<java.lang.Long,java.util.concurrent.TimeUnit,T,?> operation,
java.lang.String name)
Specified dangerous function is applied to the value received from the
getMillis()
and time unit: TimeUnit.MILLISECONDS. |
default <T> T |
awaitAndGetDangerous(DangerousFunction<java.lang.Long,T,?> operation,
java.lang.String name)
Specified dangerous function is applied to the value received from the
getMillis(). |
default void |
awaitDangerous(DangerousBiConsumer<java.lang.Long,java.util.concurrent.TimeUnit,?> operation,
java.lang.String name)
Specified dangerous operation is called with the value received from the
getMillis()
and the time unit: TimeUnit.MILLISECONDS |
default void |
awaitDangerous(DangerousConsumer<java.lang.Long,?> operation,
java.lang.String name)
Specified dangerous operation is called with the value received from the
getMillis() |
static Timeout |
create(long millis)
New instance of the
Timeout is created with the specified milliseconds value. |
long |
getMillis() |
default boolean |
sleep()
Call
Thread.sleep(long) for the number of milliseconds returned from getMillis() |
static Timeout create(long millis)
Timeout is created with the specified milliseconds value.long getMillis()
default boolean sleep()
Thread.sleep(long) for the number of milliseconds returned from getMillis()true if no Exception was thrown during sleepdefault void await(java.util.function.LongConsumer operation)
getMillis()default void awaitDangerous(DangerousConsumer<java.lang.Long,?> operation, java.lang.String name)
Specified dangerous operation is called with the value received from the getMillis()
java.lang.IllegalStateException - thrown if calling of the specified operation has failed with exception.
Contains cause exception and message with the specified name.default void await(java.util.function.BiConsumer<java.lang.Long,java.util.concurrent.TimeUnit> operation)
getMillis()
and the time unit: TimeUnit.MILLISECONDSdefault void awaitDangerous(DangerousBiConsumer<java.lang.Long,java.util.concurrent.TimeUnit,?> operation, java.lang.String name)
Specified dangerous operation is called with the value received from the getMillis()
and the time unit: TimeUnit.MILLISECONDS
java.lang.IllegalStateException - thrown if calling of the specified operation has failed with exception.
Contains cause exception and message with the specified name.default <T> T awaitAndGet(java.util.function.LongFunction<T> operation)
getMillis().
Result of the function is returned.default <T> T awaitAndGetDangerous(DangerousFunction<java.lang.Long,T,?> operation, java.lang.String name)
Specified dangerous function is applied to the value received from the getMillis().
Result of the function is returned.
java.lang.IllegalStateException - thrown if calling of the specified operation has failed with exception.
Contains cause exception and message with the specified name.default <T> T awaitAndGet(java.util.function.BiFunction<java.lang.Long,java.util.concurrent.TimeUnit,T> operation)
getMillis()
and time unit: TimeUnit.MILLISECONDS. Result of the function is returned.default <T> T awaitAndGetDangerous(DangerousBiFunction<java.lang.Long,java.util.concurrent.TimeUnit,T,?> operation, java.lang.String name)
Specified dangerous function is applied to the value received from the getMillis()
and time unit: TimeUnit.MILLISECONDS. Result of the function is returned.
java.lang.IllegalStateException - thrown if calling of the specified operation has failed with exception.
Contains cause exception and message with the specified name.