Class DelegatingCancellationPoint
- java.lang.Object
-
- com.complexible.common.cancellation.DelegatingCancellationPoint
-
- All Implemented Interfaces:
CancelCheck
,Cancellable
,CancellationPoint
,java.lang.AutoCloseable
public class DelegatingCancellationPoint extends java.lang.Object implements CancellationPoint
- Since:
- 7.4.2
- Author:
- Pavel Klinov
-
-
Field Summary
-
Fields inherited from interface com.complexible.common.cancellation.CancelCheck
DO_NOT_CLOSE, DUMMY
-
-
Constructor Summary
Constructors Constructor Description DelegatingCancellationPoint(CancellationPoint thePoint)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancel()
Cancel current point;void
cancel(java.lang.String theCause)
Cancels the execution of this computation.void
check()
Check if cancellation point is valid; It throws an exception in case if the cancellation point has been canceled.void
close()
Closes cancellation point;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.boolean
isCancelled()
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 class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.complexible.common.cancellation.CancelCheck
check, throwIfCancelled
-
-
-
-
Constructor Detail
-
DelegatingCancellationPoint
public DelegatingCancellationPoint(CancellationPoint thePoint)
-
-
Method Detail
-
getProcessDescription
public java.lang.String getProcessDescription()
Description copied from interface:CancellationPoint
Returns the description of the process that this cancellation point represents.- Specified by:
getProcessDescription
in interfaceCancellationPoint
- Returns:
- the process description.
-
check
public void check()
Description copied from interface:CancelCheck
Check if cancellation point is valid; It throws an exception in case if the cancellation point has been canceled.- Specified by:
check
in interfaceCancelCheck
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelled
in interfaceCancelCheck
- Returns:
- true if point has been cancelled, false otherwise;
-
cancel
public void cancel()
Description copied from interface:CancellationPoint
Cancel current point;- Specified by:
cancel
in interfaceCancellationPoint
-
cancel
public void cancel(java.lang.String theCause)
Description copied from interface:Cancellable
Cancels 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:
cancel
in interfaceCancellable
- Parameters:
theCause
- the cause of the cancellation ornull
if the cause is unknown
-
getCancellationMessage
public 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
- Specified by:
getCancellationMessage
in interfaceCancellationPoint
- Returns:
- cancellation message used for cancel;
-
wait
public void wait(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
Description copied from interface:CancellationPoint
Waits for specified timeout while the process acquired Cancellation point has been finished;- Specified by:
wait
in interfaceCancellationPoint
- Parameters:
timeout
- - the time;unit
- - the unit;- Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
-
close
public void close()
Description copied from interface:CancellationPoint
Closes cancellation point;- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceCancellationPoint
-
-