Interface CompositeTerminable
- All Superinterfaces:
AutoCloseable,Terminable,TerminableConsumer
- All Known Implementing Classes:
AbstractCompositeTerminable,AbstractWeakCompositeTerminable
Represents a
Terminable made up of several other Terminables.
The close() method closes in LIFO (Last-In-First-Out) order.
Terminables can be reused. The instance is effectively cleared on each invocation of
close().
-
Field Summary
Fields inherited from interface dev.demeng.pluginbase.terminable.Terminable
EMPTY -
Method Summary
Modifier and TypeMethodDescriptiondefault <T extends AutoCloseable>
Tbind(T terminable) Binds with the given terminable.voidcleanup()Removes instances which have already been terminated.voidclose()Closes this composite terminable.default voidCloses this resource, and prints the exception if one is thrown.default @Nullable CompositeClosingExceptionSilently closes this resource, and returns the exception if one is thrown.static @NotNull CompositeTerminablecreate()Creates a new standaloneCompositeTerminable.static @NotNull CompositeTerminableCreates a new standaloneCompositeTerminable, which wraps contained terminables inWeakReferences.with(AutoCloseable autoCloseable) Binds anAutoCloseablewith this composite closable.default CompositeTerminablewithAll(AutoCloseable... autoCloseables) Binds all givenAutoCloseablewith this composite closable.default CompositeTerminablewithAll(Iterable<? extends AutoCloseable> autoCloseables) Binds all givenAutoCloseablewith this composite closable.Methods inherited from interface dev.demeng.pluginbase.terminable.Terminable
bindWith, isClosedMethods inherited from interface dev.demeng.pluginbase.terminable.TerminableConsumer
bindModule
-
Method Details
-
create
Creates a new standaloneCompositeTerminable.- Returns:
- a new
CompositeTerminable
-
createWeak
Creates a new standaloneCompositeTerminable, which wraps contained terminables inWeakReferences.- Returns:
- a new
CompositeTerminable
-
close
Closes this composite terminable.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceTerminable- Throws:
CompositeClosingException- if any of the sub-terminables throw an exception on close
-
closeSilently
Description copied from interface:TerminableSilently closes this resource, and returns the exception if one is thrown.- Specified by:
closeSilentlyin interfaceTerminable- Returns:
- the exception is one is thrown
-
closeAndReportException
default void closeAndReportException()Description copied from interface:TerminableCloses this resource, and prints the exception if one is thrown.- Specified by:
closeAndReportExceptionin interfaceTerminable
-
with
Binds anAutoCloseablewith this composite closable.Note that implementations do not keep track of duplicate contained terminables. If a single
AutoCloseableis added twice, it will beclosedtwice.- Parameters:
autoCloseable- the closable to bind- Returns:
- this (for chaining)
- Throws:
NullPointerException- if the closable is null
-
withAll
Binds all givenAutoCloseablewith this composite closable.Note that implementations do not keep track of duplicate contained terminables. If a single
AutoCloseableis added twice, it will beclosedtwice.Ignores null values.
- Parameters:
autoCloseables- the closables to bind- Returns:
- this (for chaining)
-
withAll
Binds all givenAutoCloseablewith this composite closable.Note that implementations do not keep track of duplicate contained terminables. If a single
AutoCloseableis added twice, it will beclosedtwice.Ignores null values.
- Parameters:
autoCloseables- the closables to bind- Returns:
- this (for chaining)
-
bind
Description copied from interface:TerminableConsumerBinds with the given terminable.- Specified by:
bindin interfaceTerminableConsumer- Type Parameters:
T- the terminable type- Parameters:
terminable- the terminable to bind with- Returns:
- the same terminable
-
cleanup
void cleanup()Removes instances which have already been terminated.
-