Package EDU.oswego.cs.dl.util.concurrent
Class SyncMap
- java.lang.Object
-
- EDU.oswego.cs.dl.util.concurrent.SyncMap
-
- All Implemented Interfaces:
Map
- Direct Known Subclasses:
SyncSortedMap
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
- size
- isEmpty
- get
- containsKey
- containsValue
- keySet
- entrySet
- values
- put
- putAll
- remove
- clear
- See Also:
SyncCollection
-
-
Field Summary
Fields Modifier and Type Field Description protected Mapc_protected Syncrd_protected SynchronizedLongsyncFailures_protected Syncwr_
-
Constructor Summary
Constructors Constructor Description 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
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(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 operationsObjectremove(Object key)intsize()longsyncFailures()Return the number of synchronization failures for read-only operationsCollectionvalues()SyncwriterSync()Return the Sync object managing mutative operations-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Field Detail
-
c_
protected final Map c_
-
rd_
protected final Sync rd_
-
wr_
protected final Sync wr_
-
syncFailures_
protected final SynchronizedLong syncFailures_
-
-
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.
-
-
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()
-
equals
public boolean equals(Object o)
-
containsKey
public boolean containsKey(Object o)
- Specified by:
containsKeyin interfaceMap
-
containsValue
public boolean containsValue(Object o)
- Specified by:
containsValuein interfaceMap
-
values
public Collection values()
-
-