Class AbstractUnsafeCodeDecorator<T>

  • Type Parameters:
    T - type of unsafe entity
    Direct Known Subclasses:
    QuickFilterRuleTypeUnsafeCodeDecorator

    public class AbstractUnsafeCodeDecorator<T>
    extends Object

    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 Detail

      • AbstractUnsafeCodeDecorator

        protected AbstractUnsafeCodeDecorator​(@NotNull
                                              T entity)
        Creates a new instance of the decorator for the entity.
        Parameters:
        entity - entity to decorate
    • Method Detail

      • getEntity

        @NotNull
        public T 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 method
        unsafeCallable - 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 method
        unsafeCallable - callable which will execute the unsafe method
        defaultValue - 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 method
        unsafeCallable - callable which will execute the unsafe method
        defaultValueSupplier - 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 method
        unsafeRunnable - runnable which will execute the unsafe method