Class BeanStorage

java.lang.Object
org.omnifaces.cdi.BeanStorage
All Implemented Interfaces:
Serializable

public class BeanStorage extends Object implements Serializable
CDI bean storage. This class is theoretically reusable for multiple CDI scopes. It's currently however only used by the OmniFaces CDI view scope.
Since:
1.6
Author:
Radu Creanga <rdcrng@gmail.com>, Bauke Scholtz
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    BeanStorage(int initialCapacity)
    Construct a new CDI bean storage with the given initial capacity of the map holding all beans.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Registers that the current HTTP request has started using this bean storage, which will keep its beans alive until release().
    void
    Destroy all beans managed so far.
    void
    Registers that this bean storage has been evicted.
    <T> T
    Returns the bean associated with the given context, or null if there is none.
    <T> T
    getBean(Contextual<T> type, CreationalContext<T> context)
    Returns the bean associated with the given context, or if there is none, then create one with the given creational context.
    void
    Registers that the current HTTP request has finished using this bean storage.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BeanStorage

      public BeanStorage(int initialCapacity)
      Construct a new CDI bean storage with the given initial capacity of the map holding all beans.
      Parameters:
      initialCapacity - The initial capacity of the map holding all beans.
  • Method Details

    • getBean

      public <T> T getBean(Contextual<T> type, CreationalContext<T> context)
      Returns the bean associated with the given context, or if there is none, then create one with the given creational context.
      Type Parameters:
      T - The generic bean type.
      Parameters:
      type - The contextual type of the CDI managed bean.
      Returns:
      The bean associated with given context and creational context.
      Since:
      4.5
    • getBean

      public <T> T getBean(Contextual<T> type)
      Returns the bean associated with the given context, or null if there is none.
      Type Parameters:
      T - The generic bean type.
      Parameters:
      type - The contextual type of the CDI managed bean.
      Returns:
      The bean associated with the given context, or null if there is none.
    • acquire

      public boolean acquire()
      Registers that the current HTTP request has started using this bean storage, which will keep its beans alive until release().
      Returns:
      false when the beans have meanwhile been destroyed, in which case this bean storage must no longer be used.
      Since:
      3.14.22
    • release

      public void release()
      Registers that the current HTTP request has finished using this bean storage. When it was meanwhile evicted, and this was the last HTTP request using it, then its beans are destroyed.
      Since:
      3.14.22
    • evict

      public void evict()
      Registers that this bean storage has been evicted. Its beans are destroyed immediately when no HTTP request is currently using it, otherwise the last HTTP request finishing with it will destroy them.
      Since:
      3.14.22
    • destroyBeans

      public void destroyBeans()
      Destroy all beans managed so far. This is a no-op when they have already been destroyed.