Class MultiBinaryLongMap.PrimaryBinaryLongMap.DelegatingPrimaryBinaryLongMap
- java.lang.Object
-
- com.tangosol.util.MultiBinaryLongMap.AbstractDelegateBinaryLongMap
-
- com.tangosol.util.MultiBinaryLongMap.PrimaryBinaryLongMap.DelegatingPrimaryBinaryLongMap
-
- All Implemented Interfaces:
BinaryLongMap
- Enclosing class:
- MultiBinaryLongMap.PrimaryBinaryLongMap
protected class MultiBinaryLongMap.PrimaryBinaryLongMap.DelegatingPrimaryBinaryLongMap extends MultiBinaryLongMap.AbstractDelegateBinaryLongMap
An extension to the DelegatingBinaryLongMap for the "primary" or "owning" BinaryLongMap that is responsible for adding and removing keys.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.tangosol.util.MultiBinaryLongMap.AbstractDelegateBinaryLongMap
MultiBinaryLongMap.AbstractDelegateBinaryLongMap.DelegateEntryVisitor
-
Nested classes/interfaces inherited from interface com.tangosol.util.BinaryLongMap
BinaryLongMap.Entry, BinaryLongMap.EntryVisitor, BinaryLongMap.SimpleMapImpl
-
-
Field Summary
Fields Modifier and Type Field Description protected Lock
f_lockSThis
The shared lock that protects the logical contents of the primary BinaryLongMap.protected Lock
f_lockXMaster
The (exclusive) lock that protects the data-structures for the MultiBinaryLongMap.protected Lock
f_lockXThis
The exclusive lock that protects the logical contents of the primary BinaryLongMap.-
Fields inherited from class com.tangosol.util.MultiBinaryLongMap.AbstractDelegateBinaryLongMap
f_blm, f_store, m_iIndex
-
-
Constructor Summary
Constructors Constructor Description DelegatingPrimaryBinaryLongMap(BinaryLongMap blmKeyTree, MultiBinaryLongMap.LongStorage store, ReentrantReadWriteLock rwLockMaster)
Construct a DelegatingPrimaryBinaryLongMap.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addValue(Binary binKey, long lValueNew)
Add the specified key to the BinaryLongMap, and associate the specified value with it in the primary BLM.protected void
checkCompaction()
Check to see whether or not the LongStorage slots should be compacted.void
clear()
Initialize the map to an empty state.protected boolean
doPut(Binary binKey, long lValue, boolean fOnlyIfAbsent)
Helper method forput(com.tangosol.util.Binary, long)
andputIfAbsent(com.tangosol.util.Binary, long)
operations.long
get(Binary binKey)
Find the specified key in the map and return the value associated with it.void
internKeys(Object o)
Internal opaque method: De-duplicate keys.Iterator<Binary>
keys()
Obtain an iterator of the keys stored in the map.Iterator<Binary>
keys(Predicate<BinaryLongMap.Entry> predicate)
Obtain an iterator of the keys stored in the map whose correspondingEntry
matches the passedPredicate<Entry>
.void
put(Binary binKey, long lValue)
Blindly store the passed value for the specified key, adding the key if it is not already in the map, or replacing the current value if the key is in the map.boolean
putIfAbsent(Binary binKey, long lValue)
Store the passed value for the specified key, only if the key does not currently exist in the map.void
remove(Binary binKey)
Blindly remove the specified Binary key from the map.boolean
remove(Binary binKey, long lValue)
Remove the specified Binary key from the map iff it exists in the map and is associated with the specified value.protected boolean
removeValue(Binary binKey, long lValue)
Remove the specified key from the BinaryLongMap, optionally performing the operation only if the value currently associated with the key matches the passed "old" value.boolean
replace(Binary binKey, long lValueOld, long lValueNew)
Store the passed "new" value for the specified key, only if the current value associated with the specified key is the same as the specified "old" value.int
size()
Determine the size of the map.void
visit(Binary binKey, BinaryLongMap.EntryVisitor visitor)
Apply the specified visitor to the entry associated with the specified key, if the entry exists or may be added.void
visitAll(BinaryLongMap.EntryVisitor visitor)
Apply the specified visitor to all entries in the BinaryLongMap.-
Methods inherited from class com.tangosol.util.MultiBinaryLongMap.AbstractDelegateBinaryLongMap
getIndex, getSlot, setIndex, updateValue
-
-
-
-
Field Detail
-
f_lockXMaster
protected final Lock f_lockXMaster
The (exclusive) lock that protects the data-structures for the MultiBinaryLongMap.
-
f_lockSThis
protected final Lock f_lockSThis
The shared lock that protects the logical contents of the primary BinaryLongMap.
-
f_lockXThis
protected final Lock f_lockXThis
The exclusive lock that protects the logical contents of the primary BinaryLongMap.
-
-
Constructor Detail
-
DelegatingPrimaryBinaryLongMap
public DelegatingPrimaryBinaryLongMap(BinaryLongMap blmKeyTree, MultiBinaryLongMap.LongStorage store, ReentrantReadWriteLock rwLockMaster)
Construct a DelegatingPrimaryBinaryLongMap.- Parameters:
blmKeyTree
- the BinaryLongMap that holds the keys for this mapstore
- the LongStorage that holds the values for this maprwLockMaster
- the "master" ReentrantReadWriteLock protecting the underlying MLBM BRT and LongStorage structures
-
-
Method Detail
-
get
public long get(Binary binKey)
Find the specified key in the map and return the value associated with it.- Specified by:
get
in interfaceBinaryLongMap
- Overrides:
get
in classMultiBinaryLongMap.AbstractDelegateBinaryLongMap
- Parameters:
binKey
- a Binary key- Returns:
- the value associated with the specified key, or 0L if the specified key is not in the map
-
put
public void put(Binary binKey, long lValue)
Blindly store the passed value for the specified key, adding the key if it is not already in the map, or replacing the current value if the key is in the map.Note that associating the value zero with a key is analogous to removing the key.
- Parameters:
binKey
- the Binary key to add or updatelValue
- the value to associate with the key
-
remove
public void remove(Binary binKey)
Blindly remove the specified Binary key from the map.- Parameters:
binKey
- a Binary key
-
remove
public boolean remove(Binary binKey, long lValue)
Remove the specified Binary key from the map iff it exists in the map and is associated with the specified value.Note that removing an association whose value is zero has no effect.
- Parameters:
binKey
- a Binary keylValue
- the value that the key must have in order to be removed- Returns:
- true iff the map contained the key, it was associated with the specified value, and has now been removed
-
putIfAbsent
public boolean putIfAbsent(Binary binKey, long lValue)
Store the passed value for the specified key, only if the key does not currently exist in the map.Note that associating the value zero with a key using this method will have no effect, since were that key already present, there would be no change, and were it not present, the value zero is analogous to removing the key, which again is no change (since it is not present).
- Parameters:
binKey
- a Binary keylValue
- the new value to associate with the passed key- Returns:
- true iff the key was not present in the map, and now it is present in the map associated with the passed value
-
replace
public boolean replace(Binary binKey, long lValueOld, long lValueNew)
Store the passed "new" value for the specified key, only if the current value associated with the specified key is the same as the specified "old" value.Note that replacing the value of zero is analogous to
putIfAbsent
, and associating the value zero with a key using this method is the same asremove
passing the old value to match.- Parameters:
binKey
- a Binary keylValueOld
- the assumed old value to replacelValueNew
- the new value to associate with the passed key- Returns:
- true iff the key was associated with the passed "old" value, and now it is associated with the passed "new" value
-
clear
public void clear()
Initialize the map to an empty state.
-
size
public int size()
Determine the size of the map.- Returns:
- the number of unique keys stored in the map
-
keys
public Iterator<Binary> keys()
Obtain an iterator of the keys stored in the map.- Specified by:
keys
in interfaceBinaryLongMap
- Overrides:
keys
in classMultiBinaryLongMap.AbstractDelegateBinaryLongMap
- Returns:
- an Iterator of Binary keys
-
keys
public Iterator<Binary> keys(Predicate<BinaryLongMap.Entry> predicate)
Obtain an iterator of the keys stored in the map whose correspondingEntry
matches the passedPredicate<Entry>
.The entry passed to the predicate should be treated as read-only, and any attempt to modify the entry may have undefined behavior and/or throw an Exception. Modifications to entries should instead be performed using an
BinaryLongMap.EntryVisitor
via theBinaryLongMap.visit(com.tangosol.util.Binary, com.tangosol.util.BinaryLongMap.EntryVisitor)
orBinaryLongMap.visitAll(com.tangosol.util.BinaryLongMap.EntryVisitor)
methods.- Specified by:
keys
in interfaceBinaryLongMap
- Overrides:
keys
in classMultiBinaryLongMap.AbstractDelegateBinaryLongMap
- Parameters:
predicate
- a Predicate<Entry> to apply to each Entry- Returns:
- an Iterator of Binary keys
-
visit
public void visit(Binary binKey, BinaryLongMap.EntryVisitor visitor)
Apply the specified visitor to the entry associated with the specified key, if the entry exists or may be added. The visited entry may or may not logically exist in the BinaryLongMap (e.g. it may be associated with a value of 0L) but is guaranteed to be safe to be added or removed (viaBinaryLongMap.Entry.setValue(long)
).- Specified by:
visit
in interfaceBinaryLongMap
- Overrides:
visit
in classMultiBinaryLongMap.AbstractDelegateBinaryLongMap
- Parameters:
binKey
- the key to visitvisitor
- the visitor to apply
-
visitAll
public void visitAll(BinaryLongMap.EntryVisitor visitor)
Apply the specified visitor to all entries in the BinaryLongMap.- Specified by:
visitAll
in interfaceBinaryLongMap
- Overrides:
visitAll
in classMultiBinaryLongMap.AbstractDelegateBinaryLongMap
- Parameters:
visitor
- the visitor to apply
-
internKeys
public void internKeys(Object o)
Internal opaque method: De-duplicate keys.- Specified by:
internKeys
in interfaceBinaryLongMap
- Overrides:
internKeys
in classMultiBinaryLongMap.AbstractDelegateBinaryLongMap
- Parameters:
o
- some implementation-specific object
-
doPut
protected boolean doPut(Binary binKey, long lValue, boolean fOnlyIfAbsent)
Helper method forput(com.tangosol.util.Binary, long)
andputIfAbsent(com.tangosol.util.Binary, long)
operations.- Parameters:
binKey
- the key to add to the maplValue
- the value to be associatedfOnlyIfAbsent
- true iff the key/value should be associated only if the key was previously absent- Returns:
- true iff the contents of the binary long map were changed
-
addValue
protected void addValue(Binary binKey, long lValueNew)
Add the specified key to the BinaryLongMap, and associate the specified value with it in the primary BLM.The caller is responsible for holding the exclusive lock protecting the key tree and LongStorage.
- Parameters:
binKey
- the key to add to the BinaryLongMaplValueNew
- the new value to associate with the key
-
removeValue
protected boolean removeValue(Binary binKey, long lValue)
Remove the specified key from the BinaryLongMap, optionally performing the operation only if the value currently associated with the key matches the passed "old" value.The caller is responsible for holding the exclusive lock protecting the key tree and LongStorage.
- Parameters:
binKey
- the keylValue
- the value that is assumed to be currently associated with the key, or 0 if the key should be removed unconditionally- Returns:
- true iff the operation affected a change to the BinaryLongMap
-
checkCompaction
protected void checkCompaction()
Check to see whether or not the LongStorage slots should be compacted.The caller is responsible for holding the exclusive lock protecting the key tree and LongStorage.
-
-