Package com.exonum.binding.core.proxy
Class Cleaner
java.lang.Object
com.exonum.binding.core.proxy.Cleaner
- All Implemented Interfaces:
AutoCloseable
public final class Cleaner extends Object implements AutoCloseable
A context controlling lifecycle of native proxies. When a proxy of a native object is created,
it must register a cleaner of the native object in a context.
The context performs the cleaning actions in a reversed order of their registration
when it is closed. Once closed, the context must no longer be used
to register new clean actions.
The context might have a description of its origin so that it can be identified for a particular context.
All method arguments are non-null by default.
This class is not thread-safe.
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description voidadd(CleanAction<?> cleanAction)Registers a new clean action with this context.voidclose()Performs all the clean operations that has been registered in this context in a reversed order of the registration order.StringgetDescription()Returns a description of this cleaner.intgetNumRegisteredActions()Returns the number of the registered clean actions.booleanisClosed()Returns true if this cleaner is closed.StringtoString()Returns a string representation of this object, including its hash code so that this instance can be easily identified in the logs.
-
Constructor Details
-
Cleaner
public Cleaner()Creates a new cleaner with no (an empty) description. -
Cleaner
Creates a new cleaner.- Parameters:
description- a description of this context, which describes its origin and is included intoString()
-
-
Method Details
-
isClosed
public boolean isClosed()Returns true if this cleaner is closed. -
add
Registers a new clean action with this context. If the context is already closed, the clean action will be executed immediately.- Parameters:
cleanAction- a clean action to register; must not be null- Throws:
IllegalStateException- if it’s attempted to add a clean action to a closed context
-
close
Performs all the clean operations that has been registered in this context in a reversed order of the registration order.If any clean operation throws an exception in its
CleanAction.clean(), the context logs the exception and attempts to perform the remaining operations.The implementation is idempotent — subsequent invocations have no effect.
- Specified by:
closein interfaceAutoCloseable- Throws:
CloseFailuresException- if any clean action failed. The exception includes all thrown exceptions as suppressed
-
getDescription
Returns a description of this cleaner. May be empty. -
getNumRegisteredActions
public int getNumRegisteredActions()Returns the number of the registered clean actions. -
toString
Returns a string representation of this object, including its hash code so that this instance can be easily identified in the logs.
-