Package com.complexible.common.cancellation

# Interface CancellationPoint

All Superinterfaces:
  `AutoCloseable`, `CancelCheck`, `Cancellable`

All Known Implementing Classes:
  `DefaultCancellationPoint`, `DelegatingCancellationPoint`, `DummyCancellationPoint`

public interface CancellationPoint extends AutoCloseable, CancelCheck, Cancellable
Interface for cancellation points; We create cancellation point in one place and have a contract that we don't dispose system or don't drop database while the point is active and actual;

- ## Field Summary

  ### Fields inherited from interface com.complexible.common.cancellation.CancelCheck

  `DUMMY`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `cancel()`
  Cancel current point;
  `void`
  `close()`
  Closes cancellation point;
  `static CancellationPoint`
  `forCancelCheck(String description, CancelCheck check)`
  Wraps the non-cancellable `CancelCheck` as a cancellable `CancellationPoint`.
  `String`
  `getCancellationMessage()`
  Returns null if the process has not been cancelled, otherwise the cancellation cause (if set).
  `String`
  `getProcessDescription()`
  Returns the description of the process that this cancellation point represents.
  `static CancellationPoint`
  `uncloseable(CancellationPoint cp)`
  Returns a cancellation point which can be checked but cannot be closed.
  `void`
  `wait(long timeout, TimeUnit unit)`
  Waits for specified timeout while the process acquired Cancellation point has been finished;

  ### Methods inherited from interface com.complexible.common.cancellation.CancelCheck

  `check, check, isCancelled, throwIfCancelled`

  ### Methods inherited from interface com.complexible.common.cancellation.Cancellable

  `cancel`

- ## Method Details

  - ### getProcessDescription

    String getProcessDescription()
    Returns the description of the process that this cancellation point represents.
    Returns:
      the process description.

  - ### cancel

    void cancel()
    Cancel current point;

  - ### getCancellationMessage

    @Nullable String getCancellationMessage()
    Description copied from interface: `CancelCheck`
    Returns null if the process has not been cancelled, otherwise the cancellation cause (if set).
    Specified by:
      `getCancellationMessage` in interface `CancelCheck`
    Returns:
      cancellation message used for cancel;

  - ### wait

    void wait(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
    Waits for specified timeout while the process acquired Cancellation point has been finished;
    Parameters:
      `timeout` - - the time;
      `unit` - - the unit;
    Throws:
      `InterruptedException`
      `ExecutionException`
      `TimeoutException`

  - ### close

    void close()
    Closes cancellation point;
    Specified by:
      `close` in interface `AutoCloseable`

  - ### uncloseable

    static CancellationPoint uncloseable(CancellationPoint cp)
    Returns a cancellation point which can be checked but cannot be closed. Useful for passing a cancellation point into processes which don't own it and are not supposed to close it.

  - ### forCancelCheck

    static CancellationPoint forCancelCheck(String description, CancelCheck check)
    Wraps the non-cancellable `CancelCheck` as a cancellable `CancellationPoint`. This is supposed to be used in those rare cases when a process can be cancelled externally (i.e. gets a `CancelCheck` from the outer code) but also spawns sub-processes which it can cancel itself. This method makes it easier to ensure that sub-processes get cancelled both from outside of the main process and from inside it. Note: the returned object does not support `waiting`.
    Parameters:
      `description` - the process description
      `check` - the external cancellation check
    Returns:
      the cancellation point which is cancelled either via its cancel method or when the external flag is raised.