T
- type of the result.public abstract class AsyncSnapshotCallable<T> extends Object implements Callable<T>
callInternal()
is invoked in the asynchronous part. All resources created by this methods should
be released by the end of the method. If the created resources are Closeable
objects and can block in calls
(e.g. in/output streams), they should be registered with the snapshot's CloseableRegistry
so that the can
be closed and unblocked on cancellation. After callInternal()
ended, logAsyncSnapshotComplete(long)
is called. In that method, implementations can emit log statements about the duration. At the very end, this class
calls cleanupProvidedResources()
. The implementation of this method should release all provided resources
that have been passed into the snapshot from the synchronous part of the snapshot.Modifier and Type | Class and Description |
---|---|
class |
AsyncSnapshotCallable.AsyncSnapshotTask
FutureTask that wraps a AsyncSnapshotCallable and connects it with cancellation and closing. |
Modifier | Constructor and Description |
---|---|
protected |
AsyncSnapshotCallable() |
Modifier and Type | Method and Description |
---|---|
T |
call() |
protected abstract T |
callInternal()
This method implements the (async) snapshot logic.
|
protected void |
cancel() |
protected abstract void |
cleanupProvidedResources()
This method implements the cleanup of resources that have been passed in (from the sync part).
|
protected void |
logAsyncSnapshotComplete(long startTime)
This method is invoked after completion of the snapshot and can be overridden to output a logging about the
duration of the async part.
|
protected void |
registerCloseableForCancellation(Closeable toRegister)
Registers the
Closeable with the snapshot's CloseableRegistry , so that it will be closed on
cancel() and becomes unblocked. |
AsyncSnapshotCallable.AsyncSnapshotTask |
toAsyncSnapshotFutureTask(CloseableRegistry taskRegistry)
Creates a future task from this and registers it with the given
CloseableRegistry . |
protected boolean |
unregisterCloseableFromCancellation(Closeable toUnregister)
Unregisters the given argument from the snapshot's
CloseableRegistry and returns true iff
the argument was registered before the call. |
@VisibleForTesting protected void cancel()
public AsyncSnapshotCallable.AsyncSnapshotTask toAsyncSnapshotFutureTask(@Nonnull CloseableRegistry taskRegistry) throws IOException
CloseableRegistry
. The task is
unregistered again in FutureTask.done()
.IOException
protected abstract T callInternal() throws Exception
Exception
protected abstract void cleanupProvidedResources()
callInternal()
.protected void logAsyncSnapshotComplete(long startTime)
protected void registerCloseableForCancellation(@Nullable Closeable toRegister) throws IOException
Closeable
with the snapshot's CloseableRegistry
, so that it will be closed on
cancel()
and becomes unblocked. If the registry is already closed, the arguments is closed and an
IOException
is emitted.IOException
protected boolean unregisterCloseableFromCancellation(@Nullable Closeable toUnregister)
CloseableRegistry
and returns true
iff
the argument was registered before the call.Copyright © 2014–2020 The Apache Software Foundation. All rights reserved.