Package de.bmiag.tapir.util.extensions
Class WaitExtensions
- java.lang.Object
-
- de.bmiag.tapir.util.extensions.WaitExtensions
-
@Component("tapirWaitExtensions") public class WaitExtensions extends java.lang.Object
Provides some convenience methods in order to wait for a certain condition.- Since:
- 2.0.0
- Author:
- Oliver Libutzki <[email protected]>
-
-
Constructor Summary
Constructors Constructor Description WaitExtensions()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected long
calculateWaitTime(long timeout)
Calculates the wait time between two attempts.boolean
waitForCondition(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends java.lang.Boolean> condition)
CallswaitForCondition(Function0, long)
with the configured implicit wait time.boolean
waitForCondition(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends java.lang.Boolean> condition, long timeout)
Waits for the condition becoming true.<T> T
waitForNoException(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable)
CallswaitForNoThrowableOfType(Class, Function0)
withException
as throwableType parameter.<T> T
waitForNoException(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable, long timeout)
CallswaitForNoThrowableOfType(Class, Function0, long)
withException
as throwableType parameter.<T> T
waitForNoThrowableOfType(java.lang.Class<? extends java.lang.Throwable> throwableType, org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable)
CallswaitForNoThrowableOfType(Class, Function0, long)
with the configured implicit wait time.<T> T
waitForNoThrowableOfType(java.lang.Class<? extends java.lang.Throwable> throwableType, org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable, long timeout)
Waits for the lambda expression throwing no longer anThrowable
which is assignable-compatible with the given throwableType.<T> T
waitForNotNull(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable)
CallswaitForNotNull(Function0, long)
with the configured implicit wait time.<T> T
waitForNotNull(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable, long timeout)
Waits for the lambda expression returning something else than null.
-
-
-
Method Detail
-
waitForCondition
public boolean waitForCondition(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends java.lang.Boolean> condition)
CallswaitForCondition(Function0, long)
with the configured implicit wait time. The condition is evaluated at least once.- Parameters:
condition
- The condition to wait for.- Returns:
- true if and only if the condition became true before the timeout.
- Since:
- 3.0.0
-
waitForNotNull
public <T> T waitForNotNull(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable)
CallswaitForNotNull(Function0, long)
with the configured implicit wait time. The executable is executed at least once.- Type Parameters:
T
- return type of the given executable- Parameters:
executable
- The lambda expression to wait for.- Returns:
- The result of the lambda expression once it returns something else than null before the timeout occurs. Otherwise null is returned.
- Since:
- 3.0.0
-
waitForNoException
public <T> T waitForNoException(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable)
CallswaitForNoThrowableOfType(Class, Function0)
withException
as throwableType parameter. The executable is executed at least once.- Type Parameters:
T
- return type of the given executable- Parameters:
executable
- The lambda expression to wait for.- Returns:
- The result of the lambda expression once it returns something. Otherwise the last thrown exception is thrown.
- Since:
- 2.0.0
-
waitForNoThrowableOfType
public <T> T waitForNoThrowableOfType(java.lang.Class<? extends java.lang.Throwable> throwableType, org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable)
CallswaitForNoThrowableOfType(Class, Function0, long)
with the configured implicit wait time. The executable is executed at least once.- Type Parameters:
T
- return type of the given executable- Parameters:
throwableType
- The throwable type (including subtypes) which should be handled.executable
- The lambda expression to wait for.- Returns:
- The result of the lambda expression once it returns something. Otherwise the last thrown exception is thrown.
- Since:
- 3.1.0
-
waitForCondition
public boolean waitForCondition(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends java.lang.Boolean> condition, long timeout)
Waits for the condition becoming true. The default implementation waits a quarter of the timeout between each attempt. The condition is evaluated at least once.- Parameters:
condition
- The condition to wait for.timeout
- The timeout in milliseconds after which the method returns false.- Returns:
- true if and only if the condition became true before the timeout.
- Since:
- 2.0.0
-
waitForNotNull
public <T> T waitForNotNull(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable, long timeout)
Waits for the lambda expression returning something else than null. The default implementation waits a quarter of the timeout between each attempt. The executable is executed at least once.- Type Parameters:
T
- return type of the given executable- Parameters:
executable
- The lambda expression to wait for.timeout
- The timeout in milliseconds after which the method returns null.- Returns:
- The result of the lambda expression once it returns something else than null before the timeout occurs. Otherwise null is returned.
- Since:
- 2.0.0
-
waitForNoException
public <T> T waitForNoException(org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable, long timeout)
CallswaitForNoThrowableOfType(Class, Function0, long)
withException
as throwableType parameter. The executable is executed at least once.- Type Parameters:
T
- return type of the given executable- Parameters:
executable
- The lambda expression to wait for.timeout
- The timeout in milliseconds after which the method returns null or throws the last exception.- Returns:
- The result of the lambda expression once it returns something. Otherwise the last thrown exception is thrown.
- Since:
- 2.0.0
-
waitForNoThrowableOfType
public <T> T waitForNoThrowableOfType(java.lang.Class<? extends java.lang.Throwable> throwableType, org.eclipse.xtext.xbase.lib.Functions.Function0<? extends T> executable, long timeout)
Waits for the lambda expression throwing no longer anThrowable
which is assignable-compatible with the given throwableType. The default implementation waits a quarter of the timeout between each attempt. The executable is executed at least once.- Type Parameters:
T
- return type of the given executable- Parameters:
throwableType
- The throwable type (including subtypes) which should be handled.executable
- The lambda expression to wait for.timeout
- The timeout in milliseconds after which the method returns null or throws the lastThrowable
.- Returns:
- The result of the lambda expression once it returns something. Otherwise the last thrown
Throwable
is thrown. - Since:
- 3.1.0
-
calculateWaitTime
protected long calculateWaitTime(long timeout)
Calculates the wait time between two attempts. This is a quarter of the timeout or at most 200 ms in the default implementation.- Parameters:
timeout
- The timeout in milliseconds.- Returns:
- The wait time in milliseconds.
-
-