public final class Cleaner
extends java.lang.Object
implements java.lang.AutoCloseable
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 and Description |
|---|
Cleaner()
Creates a new cleaner with no (an empty) description.
|
Cleaner(java.lang.String description)
Creates a new cleaner.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(CleanAction<?> cleanAction)
Registers a new clean action with this context.
|
void |
close()
Performs all the clean operations that has been registered in this context in a reversed order
of the registration order.
|
java.lang.String |
getDescription()
Returns a description of this cleaner.
|
int |
getNumRegisteredActions()
Returns the number of the registered clean actions.
|
boolean |
isClosed()
Returns true if this cleaner is closed.
|
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.
|
public Cleaner()
public Cleaner(java.lang.String description)
description - a description of this context, which describes its origin
and is included in toString()public boolean isClosed()
public void add(CleanAction<?> cleanAction)
cleanAction - a clean action to register; must not be nulljava.lang.IllegalStateException - if it’s attempted to add a clean action to a closed contextpublic void close()
throws CloseFailuresException
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.
close in interface java.lang.AutoCloseableCloseFailuresException - if any clean action failed. The exception includes all
thrown exceptions as suppressedpublic java.lang.String getDescription()
public int getNumRegisteredActions()
public java.lang.String toString()
toString in class java.lang.ObjectCopyright © 2018 Exonum. All rights reserved.