Class DefaultCancellationPoint
- java.lang.Object
-
- com.complexible.common.cancellation.DefaultCancellationPoint
-
- All Implemented Interfaces:
CancelCheck,Cancellable,CancellationPoint,java.lang.AutoCloseable
public final class DefaultCancellationPoint extends java.lang.Object implements CancellationPoint
-
-
Field Summary
-
Fields inherited from interface com.complexible.common.cancellation.CancelCheck
DUMMY
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()Cancel current point;voidcancel(java.lang.String theCause)Cancels the execution of this computation.voidcheck()Check if cancellation point is valid; It throws an exception in case if the cancellation point has been canceled.voidclose()Closes cancellation point;java.lang.StringgetCancellationMessage()Returns null if the process has not been cancelled, otherwise the cancellation cause (if set).java.lang.StringgetDatabaseName()java.lang.StringgetProcessDescription()Returns the description of the process that this cancellation point represents.booleanisCancelled()java.lang.StringtoString()voidwait(long timeout, java.util.concurrent.TimeUnit unit)Waits for specified timeout while the process acquired Cancellation point has been finished;static java.util.function.Supplier<CancellationPoint>wrap(CancellationPoint theCancellationPoint)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.complexible.common.cancellation.CancelCheck
check, throwIfCancelled
-
-
-
-
Method Detail
-
getCancellationMessage
@Nullable public 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- Specified by:
getCancellationMessagein interfaceCancellationPoint- Returns:
- cancellation message used for cancel;
-
getProcessDescription
public java.lang.String getProcessDescription()
Description copied from interface:CancellationPointReturns the description of the process that this cancellation point represents.- Specified by:
getProcessDescriptionin interfaceCancellationPoint- Returns:
- the process description.
-
wrap
public static java.util.function.Supplier<CancellationPoint> wrap(CancellationPoint theCancellationPoint)
-
check
public void check()
Description copied from interface:CancelCheckCheck if cancellation point is valid; It throws an exception in case if the cancellation point has been canceled.- Specified by:
checkin interfaceCancelCheck
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelledin interfaceCancelCheck- Returns:
- true if point has been cancelled, false otherwise;
-
cancel
public void cancel()
Description copied from interface:CancellationPointCancel current point;- Specified by:
cancelin interfaceCancellationPoint
-
cancel
public void cancel(java.lang.String theCause)
Description copied from interface:CancellableCancels the execution of this computation. It is up to the implementation to decide how to implement the cancellation process. If the underlying implementation is based on the iterator model, callingIterator.next()orIterator.hasNext()after this function is called will result in an exception being thrown. Some implementations might have a different strategy but the expectation for every implementation is to finish computation in a reasonable time. So implementations that always return few results without much computation might ignore cancel calls completely. If a computation is composed of other computations then cancel call will be typically propagated to the child computations since there could be significant amount of work performed by them before the parent computation returns a single value. This function is typically called from a different thread the thread that iterates over the results of this computation so implementations should consider this.- Specified by:
cancelin interfaceCancellable- Parameters:
theCause- the cause of the cancellation ornullif the cause is unknown
-
wait
public void wait(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutExceptionDescription copied from interface:CancellationPointWaits for specified timeout while the process acquired Cancellation point has been finished;- Specified by:
waitin interfaceCancellationPoint- Parameters:
timeout- - the time;unit- - the unit;- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionjava.util.concurrent.TimeoutException
-
close
public void close()
Description copied from interface:CancellationPointCloses cancellation point;- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceCancellationPoint
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getDatabaseName
public java.lang.String getDatabaseName()
-
-