com.sun.jdo.api.persistence.support
Class SynchronizationManager

java.lang.Object
  extended by com.sun.jdo.api.persistence.support.SynchronizationManager
All Implemented Interfaces:
Synchronization

public class SynchronizationManager
extends java.lang.Object
implements Synchronization

This class allows for multiple instances to be called at transaction completion, which JDO does not currently provide. JDO only provides for a single instance to be registered. This service exploits the JDO capability by registering an instance of SynchronizationManager with JDO and then calling each instance registered with itself.

Version:
1.0
Author:
Craig Russell

Field Summary
protected static int defaultCapacity
          The default capacity of the List of Synchronizations.
protected  java.util.List synchronizations
          The list of instances to synchronize.
 
Constructor Summary
  SynchronizationManager()
          Creates new SynchronizationManager instance with a default capacity of the List of Synchronization instances.
  SynchronizationManager(int initialCapacity)
          Creates new SynchronizationManager instance specifying the initial capacity of the list of Synchronization instances.
protected SynchronizationManager(PersistenceManager pm)
          Creates new SynchronizationManager instance and registers it with the persistence manager.
 
Method Summary
 void afterCompletion(int status)
          This method will be called during transaction completion.
 void beforeCompletion()
          This method will be called during transaction completion.
protected static SynchronizationManager getSynchronizationManager(PersistenceManager pm)
          Get the synchronization manager already registered with this persistence manager.
protected  void registerSynchronization(Synchronization instance)
          Register an instance with this synchronization manager.
static void registerSynchronization(Synchronization instance, PersistenceManager pm)
          Register a new Synchronization with the current transaction.
static void setDefaultCapacity(int capacity)
          Specify the default capacity of the list of Synchronizations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultCapacity

protected static int defaultCapacity
The default capacity of the List of Synchronizations.


synchronizations

protected final java.util.List synchronizations
The list of instances to synchronize. Duplicate registrations will result in the instance being called multiple times. Since we cannot depend on the caller implementing hashCode and equals, we cannot use a Set implementaion.

Constructor Detail

SynchronizationManager

public SynchronizationManager(int initialCapacity)
Creates new SynchronizationManager instance specifying the initial capacity of the list of Synchronization instances.

Parameters:
initialCapacity - the initial capacity of the List of Synchronization instances

SynchronizationManager

public SynchronizationManager()
Creates new SynchronizationManager instance with a default capacity of the List of Synchronization instances.


SynchronizationManager

protected SynchronizationManager(PersistenceManager pm)
Creates new SynchronizationManager instance and registers it with the persistence manager.

Parameters:
pm - the persistence manager managing this transaction
Method Detail

registerSynchronization

public static void registerSynchronization(Synchronization instance,
                                           PersistenceManager pm)
Register a new Synchronization with the current transaction.

Parameters:
instance - the instance to be registered
pm - the persistence manager which manages this transaction

setDefaultCapacity

public static void setDefaultCapacity(int capacity)
Specify the default capacity of the list of Synchronizations.

Parameters:
capacity - the default capacity of the List of Synchronizations

getSynchronizationManager

protected static SynchronizationManager getSynchronizationManager(PersistenceManager pm)
Get the synchronization manager already registered with this persistence manager. If the synchronization instance is not of the proper class, then replace it with a new instance of the synchronization manager, and register the previous synchronization with the newly created synchronization manager.

Parameters:
pm - the persistence manager
Returns:
the synchronization manager

beforeCompletion

public void beforeCompletion()
This method will be called during transaction completion. Resource access is allowed. This method in turn calls each registered instance beforeCompletion method.

Specified by:
beforeCompletion in interface Synchronization

afterCompletion

public void afterCompletion(int status)
This method will be called during transaction completion. No resource access is allowed. This method in turn calls each registered instance afterCompletion method. After this method completes, instances must register again in the new transaction, but the synchronization manager remains bound to the persistence manager transaction instance.

Specified by:
afterCompletion in interface Synchronization
Parameters:
status - the completion status of the transaction

registerSynchronization

protected void registerSynchronization(Synchronization instance)
Register an instance with this synchronization manager. Note that this is not thread-safe. If multiple threads call this method at the same time, the synchronizations List might become corrupt. The correct way to fix this is to ask the PersistenceManager for the Multithreaded flag and perform a synchronized add if the flag is true. We currently do not have the Multithreaded flag implemented.

Parameters:
instance - the instance to be registered


Copyright © 2012 GlassFish Community. All Rights Reserved.