Package org.alfresco.repo.transaction
Class TransactionAwareSingleton<T>
- java.lang.Object
-
- org.alfresco.repo.transaction.TransactionListenerAdapter
-
- org.alfresco.repo.transaction.TransactionAwareSingleton<T>
-
- All Implemented Interfaces:
TransactionListener,org.alfresco.util.transaction.TransactionListener
public class TransactionAwareSingleton<T> extends TransactionListenerAdapter
A transactionally-safe storage class for singleton objects. Changes to the singleton are only visibly promoted when the transaction is committed.private static final TransactionAwareSingletonMY_SINGLETON = new TransactionAwareSingleton (); All modifications to the singleton via
get()andput(Object)are made in a transaction-local manner and promoted to the shared value in a thread-safe manner upon transacton completion. Transaction-local changes take precedence over the shared value.- Author:
- Derek Hulley
- See Also:
AlfrescoTransactionSupport
-
-
Constructor Summary
Constructors Constructor Description TransactionAwareSingleton()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterCommit()Promotes the storage value to the single value, if requiredTget()voidput(T value)Store the value in a transaction- and thread-safe manner.-
Methods inherited from class org.alfresco.repo.transaction.TransactionListenerAdapter
afterRollback, beforeCommit, beforeCompletion, flush
-
-
-
-
Method Detail
-
get
public T get()
- Returns:
- Returns the transaction- and thread-safe wrapped instance
-
put
public void put(T value)
Store the value in a transaction- and thread-safe manner. It will only be persisted at the end of the transaction but will be visible to the current transaction from this call onwards.- Parameters:
value- the value to store
-
afterCommit
public void afterCommit()
Promotes the storage value to the single value, if required- Specified by:
afterCommitin interfaceTransactionListener- Specified by:
afterCommitin interfaceorg.alfresco.util.transaction.TransactionListener- Overrides:
afterCommitin classTransactionListenerAdapter
-
-