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.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 java.util.Map
c_
protected Sync
rd_
protected SynchronizedLong
syncFailures_
protected Sync
wr_
-
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 void
afterRead(boolean wasInterrupted)
Clean up after a reader operationprotected boolean
beforeRead()
Try to acquire sync before a reader operation; record failurevoid
clear()
boolean
containsKey(java.lang.Object o)
boolean
containsValue(java.lang.Object o)
java.util.Set
entrySet()
boolean
equals(java.lang.Object o)
java.lang.Object
get(java.lang.Object key)
int
hashCode()
boolean
isEmpty()
java.util.Set
keySet()
java.lang.Object
put(java.lang.Object key, java.lang.Object value)
void
putAll(java.util.Map coll)
Sync
readerSync()
Return the Sync object managing read-only operationsjava.lang.Object
remove(java.lang.Object key)
int
size()
long
syncFailures()
Return the number of synchronization failures for read-only operationsjava.util.Collection
values()
Sync
writerSync()
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:
hashCode
in interfacejava.util.Map
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Specified by:
equals
in interfacejava.util.Map
- Overrides:
equals
in classjava.lang.Object
-
size
public int size()
- Specified by:
size
in interfacejava.util.Map
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfacejava.util.Map
-
containsKey
public boolean containsKey(java.lang.Object o)
- Specified by:
containsKey
in interfacejava.util.Map
-
containsValue
public boolean containsValue(java.lang.Object o)
- Specified by:
containsValue
in interfacejava.util.Map
-
get
public java.lang.Object get(java.lang.Object key)
- Specified by:
get
in interfacejava.util.Map
-
put
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
- Specified by:
put
in interfacejava.util.Map
-
remove
public java.lang.Object remove(java.lang.Object key)
- Specified by:
remove
in interfacejava.util.Map
-
putAll
public void putAll(java.util.Map coll)
- Specified by:
putAll
in interfacejava.util.Map
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Map
-
keySet
public java.util.Set keySet()
- Specified by:
keySet
in interfacejava.util.Map
-
entrySet
public java.util.Set entrySet()
- Specified by:
entrySet
in interfacejava.util.Map
-
values
public java.util.Collection values()
- Specified by:
values
in interfacejava.util.Map
-
-