Class AttributeBeanStore
- java.lang.Object
-
- org.jboss.weld.contexts.beanstore.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 Summary
Constructors Constructor Description AttributeBeanStore(NamingScheme namingScheme, boolean attributeLazyFetchingEnabled)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
attach()
Attach the bean store, any updates from now on will be written through to the underlying store.void
clear()
Clears the store of contextual instancesboolean
contains(org.jboss.weld.serialization.spi.BeanIdentifier id)
Check if the store contains an instanceboolean
detach()
Detach the bean store, causing updates to longer be written through to the underlying store.void
fetchUninitializedAttributes()
Fetch all relevant attributes from the backing store and copy instances which are not present in the local bean store.<T> org.jboss.weld.context.api.ContextualInstance<T>
get(org.jboss.weld.serialization.spi.BeanIdentifier id)
Gets an instance of a contextual from the storeprotected abstract Object
getAttribute(String prefixedId)
Gets an attribute from the underlying storageprotected abstract Iterator<String>
getAttributeNames()
Gets an enumeration of the attribute names present in the underlying storage.protected abstract LockStore
getLockStore()
protected NamingScheme
getNamingScheme()
protected Collection<String>
getPrefixedAttributeNames()
Gets an enumeration of the attribute names present in the underlying storageboolean
isAttached()
Return true if the bean store is attachedboolean
isAttributeLazyFetchingEnabled()
protected boolean
isLocalBeanStoreSyncNeeded()
Iterator<org.jboss.weld.serialization.spi.BeanIdentifier>
iterator()
LockedBean
lock(org.jboss.weld.serialization.spi.BeanIdentifier id)
Gets a creation lock for the given bean id.<T> void
put(org.jboss.weld.serialization.spi.BeanIdentifier id, org.jboss.weld.context.api.ContextualInstance<T> instance)
Adds a bean instance to the storage<T> org.jboss.weld.context.api.ContextualInstance<T>
remove(org.jboss.weld.serialization.spi.BeanIdentifier id)
Removes a bean instance identified by the given id.protected abstract void
removeAttribute(String prefixedId)
Removes an attribute from the underlying storageprotected abstract void
setAttribute(String prefixedId, Object instance)
Sets an instance under a key in the underlying storage-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
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 interfaceBoundBeanStore
- 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 interfaceBoundBeanStore
- 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 interfaceBoundBeanStore
- 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
-
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
-
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.
-
clear
public void clear()
Description copied from interface:BeanStore
Clears the store of contextual instances
-
contains
public boolean contains(org.jboss.weld.serialization.spi.BeanIdentifier id)
Description copied from interface:BeanStore
Check if the store contains an instance
-
getNamingScheme
protected NamingScheme getNamingScheme()
-
iterator
public Iterator<org.jboss.weld.serialization.spi.BeanIdentifier> iterator()
-
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 setinstance
- 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.
-
getLockStore
protected abstract LockStore getLockStore()
-
isLocalBeanStoreSyncNeeded
protected boolean isLocalBeanStoreSyncNeeded()
- Returns:
true
if a bean store synchronization is required duringattach()
invocation,false
otherwise
-
isAttributeLazyFetchingEnabled
public boolean isAttributeLazyFetchingEnabled()
- Returns:
true
if attributes should be fetched lazily,false
otherwise
-
-