Class ApplicationClose
operator close, when the program ends. It is the application's - "if you hold it,
you close it" - and an injected x as T! is only a borrow of it (CloseSteps).
It is built into the application's _decommission, which the program ALWAYS runs: on a normal return, on a
returned exit code and on an uncaught failure alike (the entry point's protected region). _decommission already
takes each registration out of the _Application registry in REVERSE registration order and drops it; for
a closeable one the close goes between the two, so the last registered closes first (the Contract 14 order). A
component registered once is one object however many places it is injected, so it is closed once.
The close is ResourceCloser's - shape B, Contract 3: each _close() in its own protected region, so
one that throws never stops the others; the FIRST EK9 Exception is rethrown from _decommission once every
component has been closed and dropped, later ones suppressed onto it; a Panic aborts the closes that remain.
Nothing is emitted for an application none of whose components is closeable (isCloseable(RegistrationData)).
Which type is closed through: the type the component is registered AS when that has a close (virtual, so the
runtime component's own override runs); otherwise the implementation, reached by a CAST (it is what was
constructed). A component registered with aspects is a generated proxy of the registered-as type - not an
instance of the implementation - so it is closed through the registered-as type when that has a close, otherwise
through the Closeable trait (the generated proxy implements it); either way the proxy forwards
close to the delegate, unadvised.
-
Field Summary
Fields inherited from class AbstractGenerator
constantCopyOnAccessLoader, instructionBuilder, MAX_MESSAGE_LENGTH, stackContext, symbolTypeOrException, synthesisedCallMetaData, typeNameOrException, variableNameForIR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleananyCloseable(List<RegistrationData> registrations) True when any of the registrations is closed at program end.voidcloseOwned(IRInstructionBuilder builder, String taken, RegistrationData registration, ResourceCloser.FirstFailure firstFailure, DebugInfo debugInfo) The close of one registered component that has been taken out of the registry intotaken, inside the registration's OWN scope (the caller'sIRInstructionBuilder.inNewScope(DebugInfo, Consumer)): that scope owns the component across the close and drops it at its exit, so it is released whether the close returns, records a failure or the region is left by a Panic (V-A: never live and unowned across a call).declare(ResourceCloser.FirstFailure firstFailure, DebugInfo debugInfo) static booleanisCloseable(RegistrationData registration) True when the application closes this registration at program end.The first-failure slot the closes record into, declared before the first close.rethrow(ResourceCloser.FirstFailure firstFailure, DebugInfo debugInfo) After every registration has been closed and dropped: rethrow the first close failure, if any.
-
Constructor Details
-
ApplicationClose
-
-
Method Details
-
isCloseable
True when the application closes this registration at program end. -
anyCloseable
True when any of the registrations is closed at program end. -
newFirstFailure
The first-failure slot the closes record into, declared before the first close. Make it where its owner scope is the current one. -
declare
-
closeOwned
public void closeOwned(IRInstructionBuilder builder, String taken, RegistrationData registration, ResourceCloser.FirstFailure firstFailure, DebugInfo debugInfo) The close of one registered component that has been taken out of the registry intotaken, inside the registration's OWN scope (the caller'sIRInstructionBuilder.inNewScope(DebugInfo, Consumer)): that scope owns the component across the close and drops it at its exit, so it is released whether the close returns, records a failure or the region is left by a Panic (V-A: never live and unowned across a call). The close is skipped if the component is absent (a registration that never ran), otherwiseCALL taken._close()runs in its own protected region. When it is reached through aCASTthe cast takes the count (V-D), so the cast result is what the scope owns and what is closed.- Parameters:
builder- the builder whose current scope owns the componenttaken- the variable holding the component the registry gave upregistration- the registration it came fromfirstFailure- the slot the first close failure is recorded indebugInfo- where the close is attributed
-
rethrow
After every registration has been closed and dropped: rethrow the first close failure, if any.
-