ch.javasoft.jbase.concurrent
Interface Stateful

All Known Subinterfaces:
RandomAccessPersister
All Known Implementing Classes:
BufferedRandomAccessPersister, FixedWidthTable, RandomAccessFilePersistor, VariableWidthTable

public interface Stateful

A Stateful object uses member variables to store state information during method calls. Thus, concurrently invoking the object's method is not possible, synchronization or locking is necessary. A stateful object is similar to a cloneable object, only that creating a copy here is for reading only, and a read/write lock is available (the write lock is held when copying).

If synchronization implemented with a read/write lock, a copy of the state is needed for read concurrent readers. Such a read copy of the state can be created by calling createReadCopy(ReadWriteLock).


Method Summary
 Object createReadCopy(ReadWriteLock lock)
          Returns a read copy of this stateful object.
 

Method Detail

createReadCopy

Object createReadCopy(ReadWriteLock lock)
                      throws IOException
Returns a read copy of this stateful object. The returned read copy contains its own state compared to another read copy instance, i.e. read copies can be used by different threads without causing conflicts considering the state of the stateful object.

The submitted read/write lock can be used later on e.g. for lazy opening of additional files. When this method is invoked, the write lock of the submitted read/write lock is held.

Parameters:
lock - A read/write lock, the write lock is held. The lock, however, might also be used for other functionality of the returned read copy, for instance, if the read copy has to be put in sync with the main object.
Returns:
a new read copy instance, with copied state compared to other read copy instances
Throws:
IOException