public final class AsyncCloseableSupport extends Object implements ListenableAsyncCloseable
AsyncCloseable or ListenableAsyncCloseable.| Modifier and Type | Method and Description |
|---|---|
void |
close()
Releases any underlying resources held by this object synchronously.
|
CompletableFuture<?> |
closeAsync()
Releases any underlying resources held by this object asynchronously.
|
static AsyncCloseableSupport |
closed()
Returns the
AsyncCloseableSupport which has been closed already. |
boolean |
isClosed()
Returns whether
AsyncCloseable.close() or AsyncCloseable.closeAsync() operation has been completed. |
boolean |
isClosing()
Returns whether
AsyncCloseable.close() or AsyncCloseable.closeAsync() has been called. |
static AsyncCloseableSupport |
of()
|
static AsyncCloseableSupport |
of(Consumer<CompletableFuture<?>> closeAction)
|
CompletableFuture<?> |
whenClosed()
Returns the
CompletableFuture which is completed after the AsyncCloseable.close() or
AsyncCloseable.closeAsync() operation is completed. |
public static AsyncCloseableSupport of()
AsyncCloseableSupport that will be completed immediately on close() or
closeAsync(). This method is useful when you don't have any resources to release.
> public class MyClass implements ListenableAsyncCloseable {
> final AsyncCloseableSupport closeable = AsyncCloseableSupport.of();
>
> public void doSomething() {
> if (closeable.isClosing()) {
> throw new IllegalStateException("Closed already");
> }
> ...
> }
>
> @Override
> public boolean isClosing() { return closeable.isClosing(); }
>
> @Override
> public CompletableFuture<?> whenClosed() { return closeable.whenClosed(); }
>
> @Override
> public CompletableFuture<?> closeAsync() { return closeable.closeAsync(); }
>
> @Override
> public void close() { closeable.close(); }
> }
public static AsyncCloseableSupport of(Consumer<CompletableFuture<?>> closeAction)
AsyncCloseableSupport which calls the specified Consumer on
close() or closeAsync().
> class MyClass implements ListenableAsyncCloseable {
> final AsyncCloseableSupport closeable = AsyncCloseableSupport.of(f -> {
> // Release resources here.
> ...
> f.complete(null);
> });
>
> @Override
> public boolean isClosing() { return closeable.isClosing(); }
>
> @Override
> public CompletableFuture<?> whenClosed() { return closeable.whenClosed(); }
>
> @Override
> public CompletableFuture<?> closeAsync() { return closeable.closeAsync(); }
>
> @Override
> public void close() { closeable.close(); }
> }
closeAction - the Consumer which performs the task that release the resources and
completes the given CompletableFuture.public static AsyncCloseableSupport closed()
AsyncCloseableSupport which has been closed already.public boolean isClosing()
ListenableAsyncCloseableAsyncCloseable.close() or AsyncCloseable.closeAsync() has been called.isClosing in interface ListenableAsyncCloseableListenableAsyncCloseable.isClosed()public boolean isClosed()
ListenableAsyncCloseableAsyncCloseable.close() or AsyncCloseable.closeAsync() operation has been completed.isClosed in interface ListenableAsyncCloseableListenableAsyncCloseable.isClosing()public CompletableFuture<?> closeAsync()
AsyncCloseablecloseAsync in interface AsyncCloseableCompletableFuture which is completed after the resources are releasedpublic void close()
AsyncCloseableclose in interface AsyncCloseableclose in interface AutoCloseablepublic CompletableFuture<?> whenClosed()
ListenableAsyncCloseableCompletableFuture which is completed after the AsyncCloseable.close() or
AsyncCloseable.closeAsync() operation is completed.whenClosed in interface ListenableAsyncCloseableCopyright © 2020 LeanCloud. All rights reserved.