public class Haltable<V> extends Object implements IHaltable<V>
Future
, this class is used in
contexts where the process to be halted does not map nicely into a
Callable
or Runnable
and hence can not be modeled using a
FutureTask
.
This class embeds certain knowledge about which exceptions may be observed
during normal termination of asynchronous processes using I/O, thread pools,
and IBlockingBuffer
s. See
isNormalTerminationCause(Throwable)
for a list of the
Throwable
causes which are treated as normal termination.
Constructor and Description |
---|
Haltable()
Designated constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
cancel(boolean mayInterruptIfRunning) |
V |
get() |
V |
get(long timeout,
TimeUnit unit) |
Throwable |
getAsThrownCause()
Return the first
cause regardless of whether it is
indicative of normal termination and null iff no cause has
been set. |
Throwable |
getCause()
Return the first
Throwable which caused this process to halt, but
only for abnormal termination. |
<T extends Throwable> |
halt(T cause)
Halt (exception thrown).
|
void |
halt(V v)
Halt (normal termination).
|
void |
halted()
Return unless processing has been halted.
|
boolean |
isCancelled() |
protected boolean |
isDeadlineTerminationCause(Throwable cause)
Note: There is a special exemption for
QueryTimeoutException . |
boolean |
isDone()
Return
true if the process is done. |
boolean |
isError()
Return
true if the process was halted by a Throwable
not included in the set of known normal termination causes. |
protected boolean |
isNormalTerminationCause(Throwable cause)
Return
true if the Throwable is a known normal
termination cause for the process. |
static boolean |
isTerminationByInterrupt(Throwable cause) |
public final void halt(V v)
public final <T extends Throwable> T halt(T cause)
public final void halted()
Note: External processes waiting on the Future
interface should
use isDone()
which does not have the semantics of asserting that
the process should still be running.
RuntimeException
- wrapping the firstCause
iff processing has been
halted.public final boolean cancel(boolean mayInterruptIfRunning)
public final V get() throws InterruptedException, ExecutionException
get
in interface Future<V>
InterruptedException
ExecutionException
public final V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
get
in interface Future<V>
InterruptedException
ExecutionException
TimeoutException
public final boolean isDone()
true
if the process is done.public final boolean isError()
true
if the process was halted by a Throwable
not included in the set of known normal termination causes.public boolean isCancelled()
isCancelled
in interface Future<V>
public final Throwable getAsThrownCause()
IHaltable
cause
regardless of whether it is
indicative of normal termination and null
iff no cause has
been set.getAsThrownCause
in interface IHaltable<V>
protected boolean isNormalTerminationCause(Throwable cause)
true
if the Throwable
is a known normal
termination cause for the process. The method inspects the stack trace,
examining both the outer and InnerCause
s. The following causes
are interpreted as normal termination:
InterruptedException
IAsynchronousIterator.close()
the iterator through which they are
consuming results from the process.CancellationException
Future
.ClosedByInterruptException
BufferClosedException
IBlockingBuffer
on which the process was writing was
asynchronously closed.RejectedExecutionException
cause
- The Throwable
.true
if the Throwable
indicates normal
termination.getCause()
protected boolean isDeadlineTerminationCause(Throwable cause)
QueryTimeoutException
.
This can not be interpreted as "normal" termination since we want the
exception to be thrown out and then turned into the corresponding openrdf
exception. However, we do not want to log a full stack trace for this
since it is, in fact, an exception termination mode for a query.public static boolean isTerminationByInterrupt(Throwable cause)
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.