Uploaded image for project: 'Hibernate Search'
  1. HSEARCH-3170

Implement CDI/Spring bean releasing more cleanly


    • Type: Task
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.0.0.Alpha2
    • Component/s: engine
    • Labels:


      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.


          Issue links



              • Assignee:
                yrodiere Yoann Rodière
                yrodiere Yoann Rodière
              • Votes:
                0 Vote for this issue
                1 Start watching this issue


                • Created: