org.alfresco.repo.transaction
Class TransactionAwareSingleton

java.lang.Object
  extended by org.alfresco.repo.transaction.TransactionListenerAdapter
      extended by org.alfresco.repo.transaction.TransactionAwareSingleton
All Implemented Interfaces:
TransactionListener

public class TransactionAwareSingleton
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 TransactionAwareSingleton MY_SINGLETON = new TransactionAwareSingleton();

All modifications to the singleton via TransactionAwareSingleton.get() and #put(T) 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.

See Also:
AlfrescoTransactionSupport

Constructor Summary
TransactionAwareSingleton()
           
 
Method Summary
 void afterCommit()
          Promotes the storage value to the single value, if required
 java.lang.Object get()
           
 void put(java.lang.Object value)
          Store the value in a transaction- and thread-safe manner.
 
Methods inherited from class org.alfresco.repo.transaction.TransactionListenerAdapter
afterRollback, beforeCommit, beforeCompletion, flush
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransactionAwareSingleton

public TransactionAwareSingleton()
Method Detail

get

public java.lang.Object get()
Returns:
Returns the transaction- and thread-safe wrapped instance

put

public void put(java.lang.Object 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:
afterCommit in interface TransactionListener
Overrides:
afterCommit in class TransactionListenerAdapter


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.