EDU.oswego.cs.dl.util.concurrent

Class SyncMap

public class SyncMap extends 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:

Field Summary
protected Mapc_
protected Syncrd_
protected SynchronizedLongsyncFailures_
protected Syncwr_
Constructor Summary
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, 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 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 voidafterRead(boolean wasInterrupted)
Clean up after a reader operation *
protected booleanbeforeRead()
Try to acquire sync before a reader operation; record failure *
voidclear()
booleancontainsKey(Object o)
booleancontainsValue(Object o)
SetentrySet()
booleanequals(Object o)
Objectget(Object key)
inthashCode()
booleanisEmpty()
SetkeySet()
Objectput(Object key, Object value)
voidputAll(Map coll)
SyncreaderSync()
Return the Sync object managing read-only operations
Objectremove(Object key)
intsize()
longsyncFailures()
Return the number of synchronization failures for read-only operations
Collectionvalues()
SyncwriterSync()
Return the Sync object managing mutative operations

Field Detail

c_

protected final Map c_

rd_

protected final Sync rd_

syncFailures_

protected final SynchronizedLong syncFailures_

wr_

protected final Sync wr_

Constructor Detail

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, 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 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 Detail

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