EDU.oswego.cs.dl.util.concurrent

Class SyncMap

Implemented Interfaces:
Map
Known Direct Subclasses:
SyncSortedMap

public class SyncMap
extends java.lang.Object
implements Map

SyncMaps wrap Sync-based control around java.util.Maps. They operate in the same way as SyncCollection.

Reader operations are

Writer operations are:

[ Introduction to this package. ]

See Also:
SyncCollection

Field Summary

protected Map
c_
protected Sync
rd_
protected SynchronizedLong
syncFailures_
protected Sync
wr_

Constructor Summary

SyncMap(Map map, ReadWriteLock rwl)
Create a new SyncMap protecting the given map, and using the given ReadWriteLock to control reader and writer methods.
SyncMap(Map map, Sync sync)
Create a new SyncMap protecting the given map, and using the given sync to control both reader and writer methods.
SyncMap(Map map, Sync readLock, Sync writeLock)
Create a new SyncMap protecting the given map, and using the given pair of locks to control reader and writer methods.

Method Summary

protected void
afterRead(boolean wasInterrupted)
Clean up after a reader operation *
protected boolean
beforeRead()
Try to acquire sync before a reader operation; record failure *
void
clear()
boolean
containsKey(Object o)
boolean
containsValue(Object o)
Set
entrySet()
boolean
equals(Object o)
Object
get(Object key)
int
hashCode()
boolean
isEmpty()
Set
keySet()
Object
put(Object key, Object value)
void
putAll(Map coll)
Sync
readerSync()
Return the Sync object managing read-only operations
Object
remove(Object key)
int
size()
long
syncFailures()
Return the number of synchronization failures for read-only operations
Collection
values()
Sync
writerSync()
Return the Sync object managing mutative operations

Field Details

c_

protected final Map c_

rd_

protected final Sync rd_

syncFailures_

protected final SynchronizedLong syncFailures_

wr_

protected final Sync wr_

Constructor Details

SyncMap

public SyncMap(Map map,
               ReadWriteLock rwl)
Create a new SyncMap protecting the given map, and using the given ReadWriteLock to control reader and writer methods.

SyncMap

public SyncMap(Map map,
               Sync sync)
Create a new SyncMap protecting the given map, and using the given sync to control both reader and writer methods. Common, reasonable choices for the sync argument include Mutex, ReentrantLock, and Semaphores initialized to 1.

SyncMap

public SyncMap(Map map,
               Sync readLock,
               Sync writeLock)
Create a new SyncMap protecting the given map, and using the given pair of locks to control reader and writer methods.

Method Details

afterRead

protected void afterRead(boolean wasInterrupted)
Clean up after a reader operation *

beforeRead

protected boolean beforeRead()
Try to acquire sync before a reader operation; record failure *

clear

public void clear()

containsKey

public boolean containsKey(Object o)

containsValue

public boolean containsValue(Object o)

entrySet

public Set entrySet()

equals

public boolean equals(Object o)

get

public Object get(Object key)

hashCode

public int hashCode()

isEmpty

public boolean isEmpty()

keySet

public Set keySet()

put

public Object put(Object key,
                  Object value)

putAll

public void putAll(Map coll)

readerSync

public Sync readerSync()
Return the Sync object managing read-only operations

remove

public Object remove(Object key)

size

public int size()

syncFailures

public long syncFailures()
Return the number of synchronization failures for read-only operations

values

public Collection values()

writerSync

public Sync writerSync()
Return the Sync object managing mutative operations