|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectch.javasoft.jbase.concurrent.ConcurrentTable<E>
public class ConcurrentTable<E>
The ConcurrentTable creates a thread-safe table for concurrent
use. Concurrent tables allow multiple concurrent readers, writing requires
exclusive table access. The access control is handled with a
read/write lock.
A read copy is created for every thread when the table is accessed for reading the first time. If it is accessed for writing, exclusive access to the main table is required. If the table is closed, only the read copy will be closed, unless the owner of the table (mostly the thread which created this instance) closes it. If the owner closes the table, every subsequent table access will cause an exception, also for read access to read copy tables. Multiple close calls do not cause an exception.
| Constructor Summary | |
|---|---|
ConcurrentTable(T table)
Creates a table owned by the current thread. |
|
ConcurrentTable(T table,
Thread owner)
Creates a table owned by the specified thread. |
|
| Method Summary | |
|---|---|
int |
add(E entity)
Adds a new entity to the table. |
void |
close(boolean erase)
Closes this table. |
void |
flush()
Flush ensures that all write operations are persisted. |
E |
get(int index)
Returns the entity at the given position. |
protected Table<E> |
getReadTable(boolean forceCreate)
|
protected ReadWriteLock |
getReadWriteLock()
Returns the read/write lock which controls access to read and write methods of this table |
protected boolean |
isOwner()
|
void |
remove(int index)
Removes the entity at the given position from the table. |
void |
removeAll()
Closes this table. |
void |
set(int index,
E entity)
Replaces the entity at the given position by the specified entity. |
int |
size()
Returns the size of the table, i.e. |
void |
swap(int indexA,
int indexB)
Swaps the two entities specified by their index. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ConcurrentTable(T table)
throws IOException
IOException
public ConcurrentTable(T table,
Thread owner)
throws IOException
IOException| Method Detail |
|---|
protected ReadWriteLock getReadWriteLock()
protected Table<E> getReadTable(boolean forceCreate)
throws IOException
IOExceptionprotected boolean isOwner()
public int add(E entity)
throws IOException
Tablesize-1 after adding
the new entity.
add in interface Table<E>IOException
public void close(boolean erase)
throws IOException
Tableflushed,
and underlying files are closed. Subsequent access to the table
is not allowed and causes exceptions. Multiple calls to this
close method do not cause any exceptions.
close in interface Table<E>IOException
public void flush()
throws IOException
Table
flush in interface Table<E>IOException
public E get(int index)
throws IOException
Table
get in interface Table<E>IOException
public void removeAll()
throws IOException
Tableflushed,
and underlying files are closed. Subsequent access to the table
is not allowed and causes exceptions. Multiple calls to this
close method do not cause any exceptions.
removeAll in interface Table<E>IOException
public void remove(int index)
throws IOException
Table
remove in interface Table<E>IOException
public void set(int index,
E entity)
throws IOException
Table
set in interface Table<E>IOException
public void swap(int indexA,
int indexB)
throws IOException
Table
swap in interface Table<E>IOException
public int size()
throws IOException
Table
size in interface Table<E>IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||