jade.util
Class SynchList

java.lang.Object
  extended by jade.util.RWLock
      extended by jade.util.SynchList

public class SynchList
extends RWLock

Implementation of a list of objects providing methods to synchronize threads acting on the list in such a way to prevent concurrent modifications (addition/remotion of elements) and concurrent scanning/modification. Concurrent scannings are allowed instead.

Author:
Giovanni Caire - TILab

Constructor Summary
SynchList()
          Default constructor.
 
Method Summary
protected  void onWriteEnd()
          This placeholder method is called every time a thread actually releases the protected resource with writing privileges (this means that, in case of multiple recursive unlocking by the same thread, this method is called only the last time).
protected  void onWriteStart()
          This placeholder method is called every time a thread actually acquires the protected resource with writing privileges (this means that, in case of multiple recursive locking by the same thread, this method is called only the first time).
 List startModifying()
          This method grants writing privileges to the calling thread and grants access to the protected list.
 List startScanning()
          This method grants reading privileges to the calling thread and grants access to the protected list.
 void stopModifying()
          This method must be called when a writer thread has finished modifying the list, so that the associated readers-writer lock can be relinquished.
 void stopScanning()
          This method must be called when a reader thread has finished accessing the list, so that the associated readers-writer lock can be relinquished.
 
Methods inherited from class jade.util.RWLock
readLock, readUnlock, writeLock, writeUnlock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SynchList

public SynchList()
Default constructor.

Method Detail

startModifying

public List startModifying()
This method grants writing privileges to the calling thread and grants access to the protected list.

Returns:
The inner, protected list.

stopModifying

public void stopModifying()
This method must be called when a writer thread has finished modifying the list, so that the associated readers-writer lock can be relinquished.


startScanning

public List startScanning()
This method grants reading privileges to the calling thread and grants access to the protected list.

Returns:
The inner, protected list.

stopScanning

public void stopScanning()
This method must be called when a reader thread has finished accessing the list, so that the associated readers-writer lock can be relinquished.


onWriteStart

protected void onWriteStart()
Description copied from class: RWLock
This placeholder method is called every time a thread actually acquires the protected resource with writing privileges (this means that, in case of multiple recursive locking by the same thread, this method is called only the first time). Subclasses can exploit this to transparently trigger a resource acquisition prolog.

Overrides:
onWriteStart in class RWLock

onWriteEnd

protected void onWriteEnd()
Description copied from class: RWLock
This placeholder method is called every time a thread actually releases the protected resource with writing privileges (this means that, in case of multiple recursive unlocking by the same thread, this method is called only the last time). Subclasses can exploit this to transparently trigger a resource release epilog.

Overrides:
onWriteEnd in class RWLock