Interface SynchronizerSupport
-
- All Known Subinterfaces:
Configuration
,FileBasedConfiguration
,HierarchicalConfiguration<T>
- All Known Implementing Classes:
AbstractConfiguration
,AbstractHierarchicalConfiguration
,AbstractYAMLBasedConfiguration
,AppletConfiguration
,BaseConfiguration
,BaseHierarchicalConfiguration
,CombinedConfiguration
,CompositeConfiguration
,DatabaseConfiguration
,DataConfiguration
,DynamicCombinedConfiguration
,EnvironmentConfiguration
,INIConfiguration
,JNDIConfiguration
,JSONConfiguration
,MapConfiguration
,PatternSubtreeConfigurationWrapper
,PropertiesConfiguration
,PropertyListConfiguration
,ServletConfiguration
,ServletContextConfiguration
,ServletFilterConfiguration
,ServletRequestConfiguration
,SubnodeConfiguration
,SubsetConfiguration
,SystemConfiguration
,XMLConfiguration
,XMLPropertiesConfiguration
,XMLPropertyListConfiguration
,YAMLConfiguration
public interface SynchronizerSupport
Definition of an interface for objects that can be associated with a
Synchronizer
.This interface defines methods for querying and setting the
Synchronizer
. In addition, it is possible to lock the object for a certain operation. This is useful if some complex operations are to be performed on theSynchronizerSupport
object in an atomic way.Note that the actual effect of these methods depends on the concrete
Synchronizer
implementation in use! If only a dummySynchronizer
is involved (which is appropriate if objects are only accessed by a single thread), locking an object does not really prohibit concurrent access.- Since:
- 2.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Synchronizer
getSynchronizer()
Returns theSynchronizer
used by this object.void
lock(LockMode mode)
Locks this object for the specified mode.void
setSynchronizer(Synchronizer sync)
Sets theSynchronizer
to be used by this object.void
unlock(LockMode mode)
Releases a lock of this object that was obtained using thelock(LockMode)
method.
-
-
-
Method Detail
-
getSynchronizer
Synchronizer getSynchronizer()
Returns theSynchronizer
used by this object. An implementation must not return null. If noSynchronizer
has been set so far, a meaningful defaultSynchronizer
has to be returned.- Returns:
- the
Synchronizer
used by this object
-
setSynchronizer
void setSynchronizer(Synchronizer sync)
Sets theSynchronizer
to be used by this object. Calling this method and setting an appropriateSynchronizer
determines whether this object can be accessed in a thread-safe way or not. The argument may be null; in this case an implementation should switch to a defaultSynchronizer
.- Parameters:
sync
- theSynchronizer
for this object
-
lock
void lock(LockMode mode)
Locks this object for the specified mode. This call may block until this object is released from other lock operations. When it returns the caller can access the object in a way compatible to the specifiedLockMode
. When done theunlock()
must be called with the sameLockMode
argument. In practice, a try-finally construct should be used as in the following example:SynchronizerSupport syncSupport = ...; syncSupport.lock(LockMode.READ); try { // read access to syncSupport } finally { syncSupport.unlock(LockMode.READ); }
Note: Always use this method for obtaining a lock rather than accessing the object'sSynchronizer
directly. An implementation may perform additional actions which are not executed when only interacting with theSynchronizer
.- Parameters:
mode
- theLockMode
-
unlock
void unlock(LockMode mode)
Releases a lock of this object that was obtained using thelock(LockMode)
method. This method must always be called pair-wise withlock()
. The argument must match to the one passed to the correspondinglock()
call; otherwise, the behavior of theSynchronizer
is unspecified.- Parameters:
mode
- theLockMode
-
-