ilog.mt
Class IlSynchronizationStrategy

java.lang.Object
  |
  +--ilog.mt.IlSynchronizationStrategy
Direct Known Subclasses:
IlSwingThreadSyncStrategy, IlSynchronizeOnLockStrategy

public abstract class IlSynchronizationStrategy
extends Object

Synchronization strategy base class. The name strategy refers to the strategy design pattern. Here, it enables concurrent access to shared resources using alternative synchronization schemes. Two standard implementations of this class are provided:

- IlSwingThreadSyncStrategy for Swing-based applications

- IlSynchronizeOnLockStrategy to synchronize on a mutex

This class also provides a default synchronization strategy. This default strategy can be changed by using the SetDefault function, or by using the ilog.mt.IlSynchronization.Strategy.Default system property. For example, to use IlSynchronizOnLockStrategy, launch your java application with the command: java -Dilog.mt.IlSynchronization.Strategy.Default=ilog.mt.IlSynchronizOnLockStrategy Aprogram

If no default property is set when GetDefault is first called, then the IlSwingThreadSyncStrategy class will be loaded and used as the default strategy.


Field Summary
protected static boolean _DefaultAlreadyInitialized
           
protected static IlSynchronizationStrategy _DefaultStrategy
          Excluded.  
static String DEFAULT_PROPERTY
           
 
Constructor Summary
IlSynchronizationStrategy()
           
 
Method Summary
static IlSynchronizationStrategy GetDefault()
          Gets the default strategy to use See the description of the class for more details
 boolean readLock(Runnable runnable, Object lock)
          Acquires a read lock for the current thread and calls run on the Runnable object passed.
static void SetDefault(IlSynchronizationStrategy defaultStrategy)
          Change the default strategy to use.
abstract  boolean synchronizeRun(Runnable runnable, Object locker)
          Synchronizes the current thread and calls run on the Runnable object passed.
 boolean writeLock(Runnable runnable, Object lock)
          Acquires a write lock for the current thread and calls run on the Runnable object passed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PROPERTY

public static final String DEFAULT_PROPERTY

_DefaultStrategy

protected static IlSynchronizationStrategy _DefaultStrategy
Excluded. 

_DefaultAlreadyInitialized

protected static boolean _DefaultAlreadyInitialized
Constructor Detail

IlSynchronizationStrategy

public IlSynchronizationStrategy()
Method Detail

SetDefault

public static void SetDefault(IlSynchronizationStrategy defaultStrategy)
Change the default strategy to use. The default locking behavior of an application can be changed just by just changing this default.
Parameters:
defaultStrategy - The new default strategy

GetDefault

public static IlSynchronizationStrategy GetDefault()
Gets the default strategy to use See the description of the class for more details
Returns:
the default strategy

synchronizeRun

public abstract boolean synchronizeRun(Runnable runnable,
                                       Object locker)
Synchronizes the current thread and calls run on the Runnable object passed. Depending on the implementation of the strategy, the synchronization may be global (such as in a Swing application) or may use the object passed as the lock parameter to synchronize on.
Parameters:
runnable - The Runnable object on which the run method will be called
lock - This object may be used as the object to synchronize on
Returns:
false if the operation fails for any reason.

readLock

public boolean readLock(Runnable runnable,
                        Object lock)
Acquires a read lock for the current thread and calls run on the Runnable object passed. Some implementations may not support read/write locks. For this reason, the default implementation will call the synchronizeRun method.
Parameters:
runnable - The Runnable object on which the run method will be called
lock - This object may be used as the object to synchronize on
Returns:
false if the operation fails for any reason.

writeLock

public boolean writeLock(Runnable runnable,
                         Object lock)
Acquires a write lock for the current thread and calls run on the Runnable object passed. Some implementations may not support read/write locks. For this reason, the default implementation will call the synchronizeRun method.
Parameters:
runnable - The Runnable object on which the run method will be called
lock - This object may be used as the object to synchronize on
Returns:
false if the operation fails for any reason.