Package org.openhab.core.common
Interface SafeCallerBuilder<T>
- Type Parameters:
T
-
@NonNullByDefault
public interface SafeCallerBuilder<@NonNull T>
Builder to create a safe-call wrapper for another object.
- Author:
- Simon Kaufmann - Initial contribution
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Creates a dynamic proxy with the according properties which guards the caller from hanging implementations in the target object.onException
(Consumer<Throwable> exceptionHandler) Specifies a callback in case of execution errors.Specifies a callback in case of timeouts.Denotes that the calls should be executed asynchronously, i.e.withIdentifier
(Object identifier) Specifies the identifier for the context in which only one thread may be occupied at the same time.withTimeout
(long timeout) Sets the timeout
-
Method Details
-
build
T build()Creates a dynamic proxy with the according properties which guards the caller from hanging implementations in the target object.- Returns:
- the dynamic proxy wrapping the target object
-
withTimeout
Sets the timeout- Parameters:
timeout
- the timeout in milliseconds.- Returns:
- the SafeCallerBuilder itself
-
withIdentifier
Specifies the identifier for the context in which only one thread may be occupied at the same time.- Parameters:
identifier
- the identifier much must have a proper hashcode()/equals() implementation in order to distinguish different contexts.- Returns:
- the SafeCallerBuilder itself
-
onException
Specifies a callback in case of execution errors.- Parameters:
exceptionHandler
-- Returns:
- the SafeCallerBuilder itself
-
onTimeout
Specifies a callback in case of timeouts.- Parameters:
timeoutHandler
-- Returns:
- the SafeCallerBuilder itself
-
withAsync
SafeCallerBuilder<T> withAsync()Denotes that the calls should be executed asynchronously, i.e. that they should return immediately and not even block until they reached the timeout.By default, calls will be executed synchronously (i.e. blocking) until the timeout is reached.
- Returns:
- the SafeCallerBuilder itself
-