Package com.franz.util
Class Closer
java.lang.Object
com.franz.util.Closer
- All Implemented Interfaces:
AutoCloseable
Use this class to collect objects that should be closed at a later time.
Subclasses can override handleCloseException()
to decide what should
happen with exceptions thrown during close. The default behavior is to
log a warning and ignore the exception.
- Since:
- AG v4.3.3
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes all resources registered withcloseLater(AutoCloseable)
.<CloseableType extends AutoCloseable>
CloseableTypeclose
(CloseableType o) Close an object immediately, will not be closed "later".void
close
(Collection<? extends AutoCloseable> objects) Close given objects immediately, will not be closed "later".<Obj extends AutoCloseable>
ObjcloseLater
(Obj o) Add a resource to be closed withclose()
.boolean
Remove object from collection so close will not be called later.toString()
-
Constructor Details
-
Closer
public Closer()
-
-
Method Details
-
closeLater
Add a resource to be closed withclose()
.Resources will be closed in reverse registration order.
- Type Parameters:
Obj
- The type of objects to be closed by this Closer- Parameters:
o
- Object to note for later closing- Returns:
- Obj always returns o
-
remove
Remove object from collection so close will not be called later.- Parameters:
o
- Object to be removed from this Closer- Returns:
- boolean Returns true if o was removed, else false
- See Also:
-
close
public void close()Closes all resources registered withcloseLater(AutoCloseable)
.- Specified by:
close
in interfaceAutoCloseable
-
close
Close given objects immediately, will not be closed "later".- Parameters:
objects
- The collection of objects to close
-
toString
-
close
Close an object immediately, will not be closed "later".If the object is registered on the list of resources to be closed later by this Closer, it will be removed from that list.
- Type Parameters:
CloseableType
- The type of objects that can be closed by this Closer- Parameters:
o
- The object being closed- Returns:
- Obj o is always returned.
-