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
DUMMY
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description voidcancel()Cancel current point;voidclose()Closes cancellation point;static CancellationPointforCancelCheck(java.lang.String description, CancelCheck check)Wraps the non-cancellableCancelCheckas a cancellableCancellationPoint.java.lang.StringgetCancellationMessage()Returns null if the process has not been cancelled, otherwise the cancellation cause (if set).java.lang.StringgetProcessDescription()Returns the description of the process that this cancellation point represents.static CancellationPointuncloseable(CancellationPoint cp)Returns a cancellation point which can be checked but cannot be closed.voidwait(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:CancelCheckReturns null if the process has not been cancelled, otherwise the cancellation cause (if set).- Specified by:
getCancellationMessagein 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.TimeoutExceptionWaits for specified timeout while the process acquired Cancellation point has been finished;- Parameters:
timeout- - the time;unit- - the unit;- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionjava.util.concurrent.TimeoutException
-
close
void close()
Closes cancellation point;- Specified by:
closein 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-cancellableCancelCheckas a cancellableCancellationPoint. This is supposed to be used in those rare cases when a process can be cancelled externally (i.e. gets aCancelCheckfrom 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.
-
-