Ether Framework
Unified API docs for Ether modules
Loading...
Searching...
No Matches
dev.rafex.ether.di.Closer Class Reference

Composite AutoCloseable that closes registered resources in LIFO order. More...

Inheritance diagram for dev.rafex.ether.di.Closer:
Collaboration diagram for dev.rafex.ether.di.Closer:

Public Member Functions

void close ()
 Closes all registered resources in LIFO order.
boolean isClosed ()
 Returns true if close() has already been called.

Detailed Description

Composite AutoCloseable that closes registered resources in LIFO order.

Resources are registered via register(AutoCloseable) and are closed in reverse registration order (last-in, first-out) when close() is called. If multiple resources throw during close, only the first exception is propagated; subsequent ones are attached as suppressed.

Calling close() more than once is a no-op after the first call.


var closer = new Closer();
var pool = closer.register(DataSourceFactory.create(config));
var cache = closer.register(new CacheManager());

try (closer) {
runApplication(pool, cache);
}
// cache closed first, then pool

Definition at line 54 of file Closer.java.

Member Function Documentation

◆ close()

void dev.rafex.ether.di.Closer.close ( )

Closes all registered resources in LIFO order.

Idempotent: subsequent calls after the first are no-ops.

Exceptions
RuntimeExceptionwrapping the first exception thrown during close, with any subsequent exceptions attached as suppressed

Definition at line 85 of file Closer.java.

◆ isClosed()

boolean dev.rafex.ether.di.Closer.isClosed ( )

Returns true if close() has already been called.

Returns
true after the first call to close()

Definition at line 121 of file Closer.java.


The documentation for this class was generated from the following file:
  • ether-di/ether-di/src/main/java/dev/rafex/ether/di/Closer.java