Class AbstractContext<K>

    • Constructor Detail

      • AbstractContext

        public AbstractContext()
    • Method Detail

      • get

        public <T> T get​(javax.enterprise.context.spi.Contextual<T> contextual,
                         javax.enterprise.context.spi.CreationalContext<T> creationalContext)
        Specified by:
        get in interface javax.enterprise.context.spi.Context
      • get

        public <T> T get​(javax.enterprise.context.spi.Contextual<T> contextual)
        Specified by:
        get in interface javax.enterprise.context.spi.Context
      • destroy

        public void destroy​(javax.enterprise.context.spi.Contextual contextual)

        Destroy the existing contextual instance. If there is no existing instance, no action is taken.

        Specified by:
        destroy in interface AdvancedContext<K>
        Parameters:
        contextual - the contextual type
      • isActive

        public boolean isActive()
        Specified by:
        isActive in interface javax.enterprise.context.spi.Context
      • activate

        public void activate​(K key)
        Activates the current context using the given key within the context of the thread
        Specified by:
        activate in interface AdvancedContext<K>
        Parameters:
        key - the key to use to activate the context
      • deactivate

        public void deactivate​(K key)
        Deactivates the current context using the given key from the context of the thread
        Specified by:
        deactivate in interface AdvancedContext<K>
        Parameters:
        key - the key to use to deactivate the context
      • register

        public void register​(K key)
        Registers a new key to the context
        Specified by:
        register in interface AdvancedContext<K>
        Parameters:
        key - the key to register
      • unregister

        public void unregister​(K key)
        Unregisters a given key from the context
        Specified by:
        unregister in interface AdvancedContext<K>
        Parameters:
        key - the key to unregister
      • getId

        protected <T> String getId​(javax.enterprise.context.spi.Contextual<T> contextual)
        Gives an id for the given Contextual
        Parameters:
        contextual - the contextual object for which we want an id
      • isSharable

        protected abstract boolean isSharable()
        Indicates whether the objects of the context that can shared or not. sharable
        Returns:
        true if the components are sharable, false otherwise.
      • getLock

        protected abstract Lock getLock​(String id)
        In case the context is sharable, we will need a lock to synchronize the accesses
        Parameters:
        id - the id of the contextual for which we want a lock
        Returns:
        a lock corresponding to the given contextual within the current context
      • setStorage

        protected void setStorage​(CreationContextStorage storage)
        Sets the current storage
        Parameters:
        storage - the new current storage. Set it to null to remove the current storage
      • destroy

        protected void destroy()
        Destroys all the CreationContext that has been stored in the current storage
      • destroy

        protected void destroy​(CreationContextStorage storage)
        Destroys all the CreationContext that has been stored in the given storage
        Parameters:
        storage - the storage that we would like to cleanup
      • getInstance

        protected <T> T getInstance​(CreationContextStorage storage,
                                    String id)
        Gives the instance stored with the given Contextual id.
        Parameters:
        storage - the storage from which we will get the instance
        id - the id of the contextual for which we want the instance
        Returns:
        the corresponding instance if it exists, null otherwise
      • getFromCache

        protected <T> T getFromCache​(AbstractContext.ThreadLocalData data,
                                     String id)
        Gets the component from the cache if it has already been registered
        Parameters:
        data - the data corresponding to the current context
        id - the id of the component
        Returns:
        the corresponding component if is already in the cache
      • putInCache

        protected void putInCache​(AbstractContext.ThreadLocalData data,
                                  String id,
                                  Object o)
        Puts in the cache a given object instance corresponding to the given id
        Parameters:
        data - the data corresponding to the current context
        id - the id of the component
        o - the corresponding instance