We're updating the issue view to help you get more done. 

Implement CDI/Spring bean releasing more cleanly

Description

Currently, CDI beans are held in a map, and released on shutdown.
This is not ideal, as some beans may only be used during bootstrap, so we could release them earlier.

One way to solve this would be to make BridgeBuilder and BeanResolver return a "releasable" BeanHolder, so that ContainedBeans from CDI/Spring (obtained through Hibernate ORM) can be properly released.
This would also allow users to properly release their own CDI beans, for instance those built using an Instance<MyBridge> and returned by a custom BridgeBuilder: users would be able to implement a BeanHolder that calls instance.destroy( bean ) upon release.

Also, the fact that most of or beans extend AutoCloseable makes CDI lifecycle a bit confusing: should users add a @PreDestory method? Should they simply add code to #close()? Both?

I would personally be in favor of removing the close() method from user-provided components. I would make the reflection-based bean provider return a CloseableBeanReference whenever a user bean implements AutoCloseable. This reference would just call close() when release() is called, wrapping the exception with a RuntimeException if necessary.

DECISION on the striked-through text above: let's just improve the Javadoc to 1) tell in which order the close() / @PreDestroy-annotated methods will be called and 2) remind users that their close() methods should work correctly even if called twice.

Environment

None

Status

Assignee

Yoann Rodière

Reporter

Yoann Rodière

Labels

None

Suitable for new contributors

None

Feedback Requested

None

Components

Fix versions

Priority

Major