ilog.mt
Class IlSynchronizationStrategy

java.lang.Object
  extended by 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:

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.

Since:
JTGO 3.0

Field Summary
static String DEFAULT_PROPERTY
          System property name: ilog.mt.IlSynchronization.Strategy.Default The property value specifies the synchronization strategy class.
 
Constructor Summary
IlSynchronizationStrategy()
           
 
Method Summary
static IlSynchronizationStrategy GetDefault()
          Gets the default strategy to use.
 boolean isInTargetThread()
          Returns true if currently executing in the target thread of this strategy.
 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
System property name: ilog.mt.IlSynchronization.Strategy.Default

The property value specifies the synchronization strategy class. An instance of this class is created and used as the default one, if a synchronization strategy is not specified in the application deployment descriptor.

See Also:
Constant Field Values
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 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
locker - 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.

isInTargetThread

public boolean isInTargetThread()
Returns true if currently executing in the target thread of this strategy. Returns false if not in the target thread, or if this strategy has no target thread.



Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.   . All Rights Reserved.