Class ProgressObservers


  • @Beta
    @PublicAPI
    public final class ProgressObservers
    extends Object
    Utility functions for the creation of ProgressObservers.

    Please note that this class is marked with @Beta annotation, so it can be subject of incompatible changes or removal in any of the later releases.

    • Method Detail

      • createStrictNullObserver

        public static SubProgressObserver createStrictNullObserver()
        Returns a SubProgressObserver which ignores observed data.

        API contract is still enforced, eg. IllegalStateException is thrown on API contract breaches from the observed code.

        Returns:
        A ProgressObserver with no query functionality.
      • createNullObserver

        @Deprecated
        public static SubProgressObserver createNullObserver​(String taskName)
        Deprecated.
        Returns a SubProgressObserver which ignores observed data.

        API contract is still enforced, eg. IllegalStateException is thrown on API contract breaches from the observed code.

        Parameters:
        taskName - Name of observed subtask
        Returns:
        A ProgressObserver with no query functionality.
      • noCanceller

        public static CancelObserver noCanceller()
        Returns a cancel observer which wont cancel execution.
        Returns:
        A canceller which wont cancel
      • timeoutCanceller

        public static CancelObserver timeoutCanceller​(long timeoutInSeconds)
        Returns a cancel observer which cancels after a specified timeout. This method returns a naive observer which checks System.currentTimeMillis() upon every invocation of its CancelObserver.isCancelled() method.
        Parameters:
        timeoutInSeconds - Timeout in seconds. Use 0 for no timeout.
        Returns:
        Canceller which cancel after a specified amount of time or a noCanceller() when 0 timeout is specified
      • anyCancelled

        public static CancelObserver anyCancelled​(CancelObserver... cancelObservers)
        Returns a cancel observer which cancels when any of the specified observer is cancelled.
        Parameters:
        cancelObservers - Observers to watch. Note that null is accepted
        Returns:
        Canceller which cancel when any of the passed non-null observers cancelled
      • orTimeout

        public static CancelObserver orTimeout​(CancelObserver cancelObserver,
                                               long timeoutInSeconds)
        Returns a cancel observer which cancels when a passed observer is cancelled or a timeout occurred.
        Parameters:
        cancelObserver - Base observer, can be null
        timeoutInSeconds - Timeout in seconds; use 0 for no timeout
        Returns:
        Canceller
      • createNoCancelObserver

        @Deprecated
        public static CancelObserver createNoCancelObserver()
        Deprecated.
        Returns a cancel observer which wont cancel execution.
        Returns:
        A Canceller which wont cancel
      • nullProgressObserver

        public static SubProgressObserver nullProgressObserver()
        Returns a forgiving observer which wont enforce API contracts.
        Returns:
        A SubProgressObserver which wont enforce API contracts and wont cancel
      • nullProgressObserver

        public static SubProgressObserver nullProgressObserver​(CancelObserver canceller)
        Returns a forgiving cancellable observer which wont enforce API contracts.

        Note that current implementation polls cancelling upon method calls. If an observed code expects cancelling only through listener callbacks and wont call other methods (progress update) cancel event wont be generated.

        Parameters:
        canceller - Underlying canceller polled at every operation
        Returns:
        A SubProgressObserver which wont enforce API contracts and propagates cancellinkg