Class AbstractUnsafeCodeDecorator<T>
java.lang.Object
com.atlassian.bamboo.plugin.decorator.AbstractUnsafeCodeDecorator<T>
- Type Parameters:
T
- type of unsafe entity
- Direct Known Subclasses:
QuickFilterRuleTypeUnsafeCodeDecorator
Abstract class for decorating unsafe entities (e.g. classes from plugins).
This class is intended to help implementing classes wrap methods from the underlying entity and react on unexpected exceptions by logging them instead of rethrowing.
This class exposes some utility methods to wrap execution of actual methods with BambooPluginUtils.callUnsafeCode(BambooPluginUtils.Callable)
.
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractUnsafeCodeDecorator
(T entity) Creates a new instance of the decorator for the entity. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
executeUnsafeCode
(@NotNull String methodName, @NotNull Runnable unsafeRunnable) Helper method to execute unsafe code and log exception if any occurs.protected <V> V
executeUnsafeCode
(@NotNull String methodName, @NotNull Callable<V> unsafeCallable) Helper method to execute unsafe code and log exception if any occurs.protected <V> V
executeUnsafeCode
(@NotNull String methodName, @NotNull Callable<V> unsafeCallable, @NotNull Supplier<V> defaultValueSupplier) Helper method to execute unsafe code and log exception if any occurs.protected <V> V
executeUnsafeCode
(@NotNull String methodName, @NotNull Callable<V> unsafeCallable, V defaultValue) Helper method to execute unsafe code and log exception if any occurs.Wrapped entity.
-
Constructor Details
-
AbstractUnsafeCodeDecorator
Creates a new instance of the decorator for the entity.- Parameters:
entity
- entity to decorate
-
-
Method Details
-
getEntity
Wrapped entity. -
executeUnsafeCode
@Nullable protected <V> V executeUnsafeCode(@NotNull @NotNull String methodName, @NotNull @NotNull Callable<V> unsafeCallable) Helper method to execute unsafe code and log exception if any occurs.- Type Parameters:
V
- result type- Parameters:
methodName
- name of the executed methodunsafeCallable
- callable which will execute the unsafe method- Returns:
- result of execution or null, if unexpected exception occurs
-
executeUnsafeCode
@NotNull protected <V> V executeUnsafeCode(@NotNull @NotNull String methodName, @NotNull @NotNull Callable<V> unsafeCallable, @NotNull V defaultValue) Helper method to execute unsafe code and log exception if any occurs.- Type Parameters:
V
- result type- Parameters:
methodName
- name of the executed methodunsafeCallable
- callable which will execute the unsafe methoddefaultValue
- default value to return if unexpected exception occurs- Returns:
- result of execution or default value, if unexpected exception occurs
-
executeUnsafeCode
@NotNull protected <V> V executeUnsafeCode(@NotNull @NotNull String methodName, @NotNull @NotNull Callable<V> unsafeCallable, @NotNull @NotNull Supplier<V> defaultValueSupplier) Helper method to execute unsafe code and log exception if any occurs.- Type Parameters:
V
- result type- Parameters:
methodName
- name of the executed methodunsafeCallable
- callable which will execute the unsafe methoddefaultValueSupplier
- supplier of default value to return if unexpected exception occurs- Returns:
- result of execution or default value (lazily calculated), if unexpected exception occurs
-
executeUnsafeCode
protected void executeUnsafeCode(@NotNull @NotNull String methodName, @NotNull @NotNull Runnable unsafeRunnable) Helper method to execute unsafe code and log exception if any occurs.- Parameters:
methodName
- name of the executed methodunsafeRunnable
- runnable which will execute the unsafe method
-