public final class AsyncCloseables
extends Object
AsyncCloseables.| Modifier and Type | Class and Description |
|---|---|
static interface |
AsyncCloseables.CloseableResource
A resource that can be converted to an
AsyncCloseable. |
public static Completable closeAsyncGracefully(AsyncCloseable closable, long timeout, TimeUnit timeoutUnit)
AsyncCloseable.closeAsyncGracefully() on the closable, applies a timeout, and if the
timeout fires forces a call to AsyncCloseable.closeAsync().closable - The AsyncCloseable to initiate AsyncCloseable.closeAsyncGracefully() on.timeout - The timeout duration to wait for AsyncCloseable.closeAsyncGracefully() to complete.timeoutUnit - The time unit applied to timeout.Completable that is notified once the close is complete.public static ListenableAsyncCloseable emptyAsyncCloseable()
ListenableAsyncCloseable that does nothing when
AsyncCloseable.closeAsync() apart from completing the
ListenableAsyncCloseable.onClose().ListenableAsyncCloseable.public static ListenableAsyncCloseable toListenableAsyncCloseable(AsyncCloseable asyncCloseable)
AsyncCloseable and creates a new ListenableAsyncCloseable.
This method owns the passed AsyncCloseable after this method returns and hence it should not be used by
the caller after this method returns.asyncCloseable - AsyncCloseable to convert to ListenableAsyncCloseable.ListenableAsyncCloseable.public static ListenableAsyncCloseable toListenableAsyncCloseable(AsyncCloseable asyncCloseable, Function<Completable,Completable> onCloseDecorator)
AsyncCloseable and creates a new ListenableAsyncCloseable.
This method owns the passed AsyncCloseable after this method returns and hence it should not be used by
the caller after this method returns.asyncCloseable - AsyncCloseable to convert to ListenableAsyncCloseable.onCloseDecorator - Function that can decorate the Completable returned from the returned
ListenableAsyncCloseable.onClose().ListenableAsyncCloseable.public static ListenableAsyncCloseable toAsyncCloseable(AsyncCloseables.CloseableResource closeableResource)
ListenableAsyncCloseable which uses the passed Supplier to get the implementation
of close.closeableResource - AsyncCloseables.CloseableResource that is to be wrapped into a ListenableAsyncCloseable.
AsyncCloseables.CloseableResource.doClose(boolean) will be called when the returned ListenableAsyncCloseable is
closed or
gracefully closed for the first time.ListenableAsyncCloseable.public static CompositeCloseable newCompositeCloseable()
CompositeCloseable.CompositeCloseable.