public final class Cleaner extends Object implements 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(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.
|
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.
|
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(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 nullIllegalStateException - 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 AutoCloseableCloseFailuresException - if any clean action failed. The exception includes all
thrown exceptions as suppressedpublic String getDescription()
public int getNumRegisteredActions()
Copyright © 2019 Exonum. All rights reserved.