Package com.exonum.binding.proxy
Class Cleaner
- java.lang.Object
 - 
- com.exonum.binding.proxy.Cleaner
 
 
- 
- All Implemented Interfaces:
 java.lang.AutoCloseable
public final class Cleaner extends java.lang.Object implements java.lang.AutoCloseableA 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.
 
- 
- 
Method Summary
All Methods Instance Methods Concrete Methods 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.java.lang.StringgetDescription()Returns a description of this cleaner.intgetNumRegisteredActions()Returns the number of the registered clean actions.booleanisClosed()Returns true if this cleaner is closed.java.lang.StringtoString()Returns a string representation of this object, including its hash code so that this instance can be easily identified in the logs. 
 - 
 
- 
- 
Constructor Detail
- 
Cleaner
public Cleaner()
Creates a new cleaner with no (an empty) description. 
- 
Cleaner
public Cleaner(java.lang.String description)
Creates a new cleaner.- Parameters:
 description- a description of this context, which describes its origin and is included intoString()
 
 - 
 
- 
Method Detail
- 
isClosed
public boolean isClosed()
Returns true if this cleaner is closed. 
- 
add
public void add(CleanAction<?> cleanAction)
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:
 java.lang.IllegalStateException- if it’s attempted to add a clean action to a closed context
 
- 
close
public void close() throws CloseFailuresExceptionPerforms 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 interfacejava.lang.AutoCloseable- Throws:
 CloseFailuresException- if any clean action failed. The exception includes all thrown exceptions as suppressed
 
- 
getDescription
public java.lang.String getDescription()
Returns a description of this cleaner. May be empty. 
- 
getNumRegisteredActions
public int getNumRegisteredActions()
Returns the number of the registered clean actions. 
- 
toString
public java.lang.String toString()
Returns a string representation of this object, including its hash code so that this instance can be easily identified in the logs.- Overrides:
 toStringin classjava.lang.Object
 
 - 
 
 -