Interface CancellationPoint
-
- All Superinterfaces:
java.lang.AutoCloseable
,CancelCheck
,Cancellable
- All Known Implementing Classes:
DefaultCancellationPoint
,DelegatingCancellationPoint
,DummyCancellationPoint
public interface CancellationPoint extends java.lang.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
DO_NOT_CLOSE, DUMMY
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description void
cancel()
Cancel current point;void
close()
Closes cancellation point;static CancellationPoint
forCancelCheck(java.lang.String description, CancelCheck check)
Wraps the non-cancellableCancelCheck
as a cancellableCancellationPoint
.java.lang.String
getCancellationMessage()
Returns null if the process has not been cancelled, otherwise the cancellation cause (if set).java.lang.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, java.util.concurrent.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 Detail
-
getProcessDescription
java.lang.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 java.lang.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 interfaceCancelCheck
- Returns:
- cancellation message used for cancel;
-
wait
void wait(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
Waits for specified timeout while the process acquired Cancellation point has been finished;- Parameters:
timeout
- - the time;unit
- - the unit;- Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
-
close
void close()
Closes cancellation point;- Specified by:
close
in interfacejava.lang.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(java.lang.String description, CancelCheck check)
Wraps the non-cancellableCancelCheck
as a cancellableCancellationPoint
. This is supposed to be used in those rare cases when a process can be cancelled externally (i.e. gets aCancelCheck
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 supportwaiting
.- Parameters:
description
- the process descriptioncheck
- the external cancellation check- Returns:
- the cancellation point which is cancelled either via its cancel method or when the external flag is raised.
-
-