Class AttributeBeanStore

  • All Implemented Interfaces:
    Iterable<org.jboss.weld.serialization.spi.BeanIdentifier>, BeanStore, BoundBeanStore
    Direct Known Subclasses:
    MapBeanStore

    public abstract class AttributeBeanStore
    extends Object
    implements BoundBeanStore

    A bound bean store backed by attributes. This bean store is "write-through" - if attached it will write any modifications to the backing store immediately. If detached modifications will not be written through. If the bean store is reattached, then any local modifications will be written to the underlying store.

    This construct is not thread safe.

    Author:
    Pete Muir, Nicklas Karlsson, David Allen
    • Constructor Detail

      • AttributeBeanStore

        public AttributeBeanStore​(NamingScheme namingScheme,
                                  boolean attributeLazyFetchingEnabled)
        Parameters:
        namingScheme -
        attributeLazyFetchingEnabled -
    • Method Detail

      • detach

        public boolean detach()
        Detach the bean store, causing updates to longer be written through to the underlying store.
        Specified by:
        detach in interface BoundBeanStore
        Returns:
        true if the bean store was detached, or false if the bean store is already detached
      • attach

        public boolean attach()

        Attach the bean store, any updates from now on will be written through to the underlying store.

        When the bean store is attached, the detached state is assumed to be authoritative if there are any conflicts.

        Specified by:
        attach in interface BoundBeanStore
        Returns:
        true if the bean store was attached, or false if the bean store is already attached
      • fetchUninitializedAttributes

        public void fetchUninitializedAttributes()
        Fetch all relevant attributes from the backing store and copy instances which are not present in the local bean store.
      • isAttached

        public boolean isAttached()
        Description copied from interface: BoundBeanStore
        Return true if the bean store is attached
        Specified by:
        isAttached in interface BoundBeanStore
        Returns:
        true if the bean store is attached or false if the bean store has been detached
      • get

        public <T> org.jboss.weld.context.api.ContextualInstance<T> get​(org.jboss.weld.serialization.spi.BeanIdentifier id)
        Description copied from interface: BeanStore
        Gets an instance of a contextual from the store
        Specified by:
        get in interface BeanStore
        Parameters:
        id - The id of the contextual to return
        Returns:
        The instance or null if not found
      • put

        public <T> void put​(org.jboss.weld.serialization.spi.BeanIdentifier id,
                            org.jboss.weld.context.api.ContextualInstance<T> instance)
        Description copied from interface: BeanStore
        Adds a bean instance to the storage
        Specified by:
        put in interface BeanStore
        instance - the contextual instance
      • remove

        public <T> org.jboss.weld.context.api.ContextualInstance<T> remove​(org.jboss.weld.serialization.spi.BeanIdentifier id)
        Description copied from interface: BeanStore
        Removes a bean instance identified by the given id.
        Specified by:
        remove in interface BeanStore
        Parameters:
        id - The bean id
        Returns:
        the removed bean instance of null if there was no bean instance before
      • clear

        public void clear()
        Description copied from interface: BeanStore
        Clears the store of contextual instances
        Specified by:
        clear in interface BeanStore
      • contains

        public boolean contains​(org.jboss.weld.serialization.spi.BeanIdentifier id)
        Description copied from interface: BeanStore
        Check if the store contains an instance
        Specified by:
        contains in interface BeanStore
        Parameters:
        id - the id of the instance to check for
        Returns:
        true if the instance is present, otherwise false
      • getNamingScheme

        protected NamingScheme getNamingScheme()
      • iterator

        public Iterator<org.jboss.weld.serialization.spi.BeanIdentifier> iterator()
        Specified by:
        iterator in interface BeanStore
        Specified by:
        iterator in interface Iterable<org.jboss.weld.serialization.spi.BeanIdentifier>
      • getAttribute

        protected abstract Object getAttribute​(String prefixedId)
        Gets an attribute from the underlying storage
        Parameters:
        prefixedId - The (prefixed) id of the attribute
        Returns:
        The data
      • removeAttribute

        protected abstract void removeAttribute​(String prefixedId)
        Removes an attribute from the underlying storage
        Parameters:
        prefixedId - The (prefixed) id of the attribute to remove
      • getAttributeNames

        protected abstract Iterator<String> getAttributeNames()
        Gets an enumeration of the attribute names present in the underlying storage. The collection must guarantee non-interference with other threads when iterating over it using iterator.
        Returns:
        The attribute names
      • getPrefixedAttributeNames

        protected Collection<String> getPrefixedAttributeNames()
        Gets an enumeration of the attribute names present in the underlying storage
        Returns:
        The attribute names
      • setAttribute

        protected abstract void setAttribute​(String prefixedId,
                                             Object instance)
        Sets an instance under a key in the underlying storage
        Parameters:
        prefixedId - The (prefixed) id of the attribute to set
        instance - The instance
      • lock

        public LockedBean lock​(org.jboss.weld.serialization.spi.BeanIdentifier id)
        Description copied from interface: BeanStore
        Gets a creation lock for the given bean id.
        Specified by:
        lock in interface BeanStore
        Parameters:
        id - The bean id
        Returns:
        A handle that must be used to unlock the bean
      • getLockStore

        protected abstract LockStore getLockStore()
      • isLocalBeanStoreSyncNeeded

        protected boolean isLocalBeanStoreSyncNeeded()
        Returns:
        true if a bean store synchronization is required during attach() invocation, false otherwise
      • isAttributeLazyFetchingEnabled

        public boolean isAttributeLazyFetchingEnabled()
        Returns:
        true if attributes should be fetched lazily, false otherwise