Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArC: document InstanceHandle.close() behavior #43623

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/src/main/asciidoc/cdi-reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,28 @@

<1> The argument is the bindings source class.

=== `Instance.Handle.close()` Behavior

Per the CDI specification, the `Instance.Handle.close()` method always delegates to `destroy()`.
In ArC, this is only true in the <<strict_mode>>.

In the default mode, the `close()` method only delegates to `destroy()` when the bean is `@Dependent` (or when the instance handle does not represent a CDI contextual object).
When the instance handle represents a bean of any other scope, the `close()` method does nothing; the bean is left as is and will be destroyed whenever its context is destroyed.

This is to make the following code behave as one would naively expect:

Check warning on line 1342 in docs/src/main/asciidoc/cdi-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'. Raw Output: {"message": "[Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'.", "location": {"path": "docs/src/main/asciidoc/cdi-reference.adoc", "range": {"start": {"line": 1342, "column": 43}}}, "severity": "INFO"}

[source,java]
----
Instance<T> instance = ...;
try (Instance.Handle<T> handle : instance.getHandle()) {
T value = handle.get();
... use value ...
}
----

The `@Dependent` beans are destroyed immediately, while other beans are not destroyed at all.
This is important when multiple beans of different scopes might be returned by the `Instance`.

[[reactive_pitfalls]]
== Pitfalls with Reactive Programming

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ default InjectableBean<T> getBean() {
/**
* Delegates to {@link #destroy()} if the handle does not represent a CDI contextual instance or if it represents a
* {@link Dependent} CDI contextual instance.
* <p>
* Note that in the strict compatibility mode, this method delegates to {@link #destroy()} always,
* for compatibility with the CDI specification.
*/
@Override
default void close() {
// https:/quarkusio/quarkus/issues/33665
if (Arc.container().strictCompatibility()) {
destroy();
return;
Expand Down
Loading