|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap
wt.cache.DirtyMap
Manages thread-local modifications to a backing "global" map.
The following methods make thread-local modifications that are not committed to the global map until the current transaction commits:
putLater(Object, Object, Object)
putAllLater(Map, Object)
removeLater(Object)
removeAllLater(Collection)
clearLater()
Map
modify the backing
map directly.
The query operations in this Map all check for thread-local modifications before going to the backing map. The key, entry, and values views of this map also check for thread-local modifications.
addListener
and removeListener
allow
DirtyMapListener
s to receive notifications of
puts and removes.
Supported API: false
Extendable: false
Nested Class Summary | |
(package private) class |
DirtyMap.DirtyEntryIterator
Iterates over the thread-local and global mappinsg |
static interface |
DirtyMap.DirtyMapListener
Notified by putLater, putAllLater, removeLater, and removeAllLater when changes to mappings are commited to the shared cache. |
static class |
DirtyMap.DirtyMapListenerAdapter
Convenience base class for listener implementations. |
(package private) class |
DirtyMap.EntrySet
|
(package private) class |
DirtyMap.KeySet
|
(package private) class |
DirtyMap.Values
|
Nested classes inherited from class java.util.AbstractMap |
|
Nested classes inherited from class java.util.Map |
Map.Entry |
Field Summary | |
protected Object |
contextKey
Key used to look up the thread-local cache in the method context |
protected Map |
data
Backing store of mappings |
private static DirtyMap.DirtyMapListener[] |
EMPTY_LISTENERS
|
private Set |
entrySet
|
private Set |
keySet
|
private DirtyMap.DirtyMapListener[] |
listeners
|
protected static Object |
REMOVED
Used as thev value in the dirty map to indicate a thread-local remove. |
private Collection |
values
|
Constructor Summary | |
DirtyMap(Map data)
Constructs a cache with a private context key |
|
DirtyMap(Map data,
Object context_key)
Constructs a cache with the given context key |
Method Summary | |
void |
addListener(DirtyMap.DirtyMapListener listener)
|
void |
clear()
Clears all mappings from the global cache. |
protected Object |
clearDirty(Object key)
Removes the given mapping from the thread-local cache |
void |
clearLater()
Removes all the current mappings from the global cache. |
boolean |
containsKey(Object key)
Determine if the given key exists in the thread-local cache; if there is no thread-local mapping, check the global cache. |
boolean |
containsValue(Object value)
Determine if the given value exists in the thread-local cache; if there is no thread-local mapping, check the global cache. |
Set |
entrySet()
Returns a Set view of the thread-local and global Entry objects in this cache. |
boolean |
equals(Object o)
|
Object |
get(Object key)
Get the mapping for the given key from the thread-local cache; if there is no thread-local mapping, check the global cache. |
protected Map |
getDirtyMap()
Gets the current thread's dirty map. |
int |
hashCode()
|
protected boolean |
isTransactionActive()
Determines if we are in a transaction |
Set |
keySet()
Returns a Set view of the thread-local and global keys in this cache. |
private void |
notifyPut(Object key,
Object value,
Object placeholder)
|
private void |
notifyPutAll(Map mappings,
Object placeholder)
|
private void |
notifyRemove(Object key)
|
private void |
notifyRemoveAll(Collection keys)
|
Object |
put(Object key,
Object value)
Puts the given mapping in the global cache. |
void |
putAllLater(Map mappings,
Object placeholder)
Puts all the mappings in the given map into the cache, following the same semantics as putLater(Object,Object,Object). |
protected Object |
putDirty(Object key,
Object dirty)
Puts the given mapping in the thread-local cache |
void |
putLater(Object key,
Object value,
Object placeholder)
Keeps change in thread-local cache until the current transaction commits. |
Object |
remove(Object key)
Remove the mapping for the given key from the global cache. |
void |
removeAll(Collection keys)
Convenience method that removes all the mappings for the keys in the given collection |
void |
removeAllLater(Collection keys)
Removes all the keys in the given set, following the semantics of removeLater(Object) |
protected Object |
removeDirty(Object key)
Records the removal of the given mapping in the thread-local cache. |
void |
removeLater(Object key)
Overridden to keep change in thread-local cache until the current transaction commits |
void |
removeListener(DirtyMap.DirtyMapListener listener)
|
int |
size()
Returns the size of the global cache, minus any thread-local removals. |
String |
toString()
|
Collection |
values()
Returns a Collection view of the thread-local and global values in this cache. |
Methods inherited from class java.util.AbstractMap |
clone, isEmpty, putAll |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
private static final DirtyMap.DirtyMapListener[] EMPTY_LISTENERS
protected final Object contextKey
protected static final Object REMOVED
protected final Map data
private volatile Set keySet
private volatile Set entrySet
private volatile Collection values
private volatile DirtyMap.DirtyMapListener[] listeners
Constructor Detail |
public DirtyMap(Map data)
data
- public DirtyMap(Map data, Object context_key)
data
- context_key
- Method Detail |
public int size()
public boolean containsKey(Object key)
key
-
public boolean containsValue(Object value)
value
-
public Object get(Object key)
key
-
public Object put(Object key, Object value)
putLater
key
- value
-
public Object remove(Object key)
removeLater
key
-
public void clear()
clearLater()
public Set keySet()
ConcurrentModificationException
s. Removals from this set's
iterator are not thread-local.
public Set entrySet()
ConcurrentModificationException
s. Removals from this set's
iterator are not thread-local.
public Collection values()
ConcurrentModificationException
s. Removals from this
collection's iterator are not thread-local.
public boolean equals(Object o)
public int hashCode()
public String toString()
protected Map getDirtyMap()
public void removeAll(Collection keys)
keys
- The keys to remove mappings forprotected Object putDirty(Object key, Object dirty)
key
-
protected Object removeDirty(Object key)
key
-
protected Object clearDirty(Object key)
key
-
public void putLater(Object key, Object value, Object placeholder) throws WTException
placeholder
is non-null, then only modifies the cache if
the key still maps to the local placeholder. This allows for the detection
of concurrent modification of the key by another thread.
Warning: This method must be called from within an active transaction
key
- value
- placeholder
-
WTException
public void putAllLater(Map mappings, Object placeholder) throws WTException
mappings
- The mappings that should be added to the cacheplaceholder
- The placeholder to use
WTException
public void removeLater(Object key) throws WTException
Warning: This method must be called from within an active transaction
key
-
WTException
public void removeAllLater(Collection keys) throws WTException
keys
-
WTException
public void clearLater() throws WTException
WTException
protected boolean isTransactionActive()
public void addListener(DirtyMap.DirtyMapListener listener)
public void removeListener(DirtyMap.DirtyMapListener listener)
private void notifyPut(Object key, Object value, Object placeholder)
private void notifyRemove(Object key)
private void notifyPutAll(Map mappings, Object placeholder)
private void notifyRemoveAll(Collection keys)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |