Package EDU.oswego.cs.dl.util.concurrent
Class SyncMap
- java.lang.Object
-
- EDU.oswego.cs.dl.util.concurrent.SyncMap
-
- All Implemented Interfaces:
java.util.Map
- Direct Known Subclasses:
SyncSortedMap
public class SyncMap extends java.lang.Object implements java.util.MapSyncMaps wrap Sync-based control around java.util.Maps. They operate in the same way as SyncCollection.Reader operations are
- size
- isEmpty
- get
- containsKey
- containsValue
- keySet
- entrySet
- values
- put
- putAll
- remove
- clear
- See Also:
SyncCollection
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Mapc_protected Syncrd_protected SynchronizedLongsyncFailures_protected Syncwr_
-
Constructor Summary
Constructors Constructor Description SyncMap(java.util.Map map, ReadWriteLock rwl)Create a new SyncMap protecting the given map, and using the given ReadWriteLock to control reader and writer methods.SyncMap(java.util.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(java.util.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidafterRead(boolean wasInterrupted)Clean up after a reader operationprotected booleanbeforeRead()Try to acquire sync before a reader operation; record failurevoidclear()booleancontainsKey(java.lang.Object o)booleancontainsValue(java.lang.Object o)java.util.SetentrySet()booleanequals(java.lang.Object o)java.lang.Objectget(java.lang.Object key)inthashCode()booleanisEmpty()java.util.SetkeySet()java.lang.Objectput(java.lang.Object key, java.lang.Object value)voidputAll(java.util.Map coll)SyncreaderSync()Return the Sync object managing read-only operationsjava.lang.Objectremove(java.lang.Object key)intsize()longsyncFailures()Return the number of synchronization failures for read-only operationsjava.util.Collectionvalues()SyncwriterSync()Return the Sync object managing mutative operations
-
-
-
Field Detail
-
c_
protected final java.util.Map c_
-
rd_
protected final Sync rd_
-
wr_
protected final Sync wr_
-
syncFailures_
protected final SynchronizedLong syncFailures_
-
-
Constructor Detail
-
SyncMap
public SyncMap(java.util.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(java.util.Map map, ReadWriteLock rwl)Create a new SyncMap protecting the given map, and using the given ReadWriteLock to control reader and writer methods.
-
-
Method Detail
-
readerSync
public Sync readerSync()
Return the Sync object managing read-only operations
-
writerSync
public Sync writerSync()
Return the Sync object managing mutative operations
-
syncFailures
public long syncFailures()
Return the number of synchronization failures for read-only operations
-
beforeRead
protected boolean beforeRead()
Try to acquire sync before a reader operation; record failure
-
afterRead
protected void afterRead(boolean wasInterrupted)
Clean up after a reader operation
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfacejava.util.Map- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Specified by:
equalsin interfacejava.util.Map- Overrides:
equalsin classjava.lang.Object
-
size
public int size()
- Specified by:
sizein interfacejava.util.Map
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Map
-
containsKey
public boolean containsKey(java.lang.Object o)
- Specified by:
containsKeyin interfacejava.util.Map
-
containsValue
public boolean containsValue(java.lang.Object o)
- Specified by:
containsValuein interfacejava.util.Map
-
get
public java.lang.Object get(java.lang.Object key)
- Specified by:
getin interfacejava.util.Map
-
put
public java.lang.Object put(java.lang.Object key, java.lang.Object value)- Specified by:
putin interfacejava.util.Map
-
remove
public java.lang.Object remove(java.lang.Object key)
- Specified by:
removein interfacejava.util.Map
-
putAll
public void putAll(java.util.Map coll)
- Specified by:
putAllin interfacejava.util.Map
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Map
-
keySet
public java.util.Set keySet()
- Specified by:
keySetin interfacejava.util.Map
-
entrySet
public java.util.Set entrySet()
- Specified by:
entrySetin interfacejava.util.Map
-
values
public java.util.Collection values()
- Specified by:
valuesin interfacejava.util.Map
-
-