Class MultiBinaryLongMap.PrimaryBinaryLongMap
- All Implemented Interfaces:
BinaryLongMap,MultiBinaryLongMap.BinaryLongMapListener,EventListener
- Enclosing class:
MultiBinaryLongMap
The implementation dynamically switches between a "compressed" form which uses the real key-tree to store the primary BLM's logical contents, and a "delegating" multi-form which uses the LongStorage to associate multiple long values (split over multiple delegating BinaryLongMap instances) with each key.
Note: the reference to the "wrapped" underlying BLM can change dynamically
as the containing MultiBinaryLongMap grows or shrinks in size. The
MultiBinaryLongMap.PrimaryBinaryLongMap.ValidatingLock provides a memory-barrier for this field,
which is not otherwise declared "volatile".
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classThe CompressedPrimaryBinaryLongMap is a trivial "Safe" wrapper around the main key-tree, which associates keys to their single (primary) long value.protected classAn extension to the DelegatingBinaryLongMap for the "primary" or "owning" BinaryLongMap that is responsible for adding and removing keys.protected classMarker Exception thrown to indicate that the underlying BinaryLongMap implementation has concurrently changed and the operation needs to be resubmitted by the PrimaryBinaryLongMap.protected classValidatingLock is a Lock implementation specialized for the PrimaryBinaryLongMap that validates after every lock acquisition that the underlying BinaryLongMap implementation did not change.Nested classes/interfaces inherited from class com.tangosol.util.MultiBinaryLongMap.WrapperBinaryLongMap
MultiBinaryLongMap.WrapperBinaryLongMap.WrapperIteratorNested classes/interfaces inherited from interface com.tangosol.util.BinaryLongMap
BinaryLongMap.Entry, BinaryLongMap.EntryVisitor, BinaryLongMap.SimpleMapImpl -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ListenersThe listeners to notify of changes to the BinaryLongMap.The "compressed" PBLM implementation.protected final BinaryLongMapThe "full" or "multi-aware" PBLM implementation.protected final ReentrantReadWriteLockThe "master" read-write lock for the MultiBinaryLongMap.Fields inherited from class com.tangosol.util.MultiBinaryLongMap.WrapperBinaryLongMap
m_blm -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd the specified listener to the collection of listeners that this DelegatingPrimaryBinaryLongMap dispatches notifications to.voidclear()Initialize the map to an empty state.protected voidDeflate the underlying representation of the PrimaryBinaryLongMap to use the main key-tree to associate a single long value with each key (logically represented by this PrimaryBinaryLongMap).longFind the specified key in the map and return the value associated with it.protected voidInflate the underlying representation of the PrimaryBinaryLongMap to use the LongStorage to support multiple delegating BinaryLongMap instances.voidinternKeys(Object o) Internal opaque method: De-duplicate keys.voidA notification that the primary map has added a new Binary/long key/value mapping; this implicitly creates a new key/value mapping in each delegating map, with the value being 0L.voidkeyRemoving(Binary binKey) A notification that the primary map is removing a Binary/long key/value mapping; this implies that the existing key/value mapping for the same Binary key in each delegating map is also being removed.keys()Obtain an iterator of the keys stored in the map.keys(Predicate<BinaryLongMap.Entry> predicate) Obtain an iterator of the keys stored in the map whose correspondingEntrymatches the passedPredicate<Entry>.voidA notification that the primary map has been cleared; this implies that all of the existing key/value mappings in each delegating map have also been removed.voidA notification that the primary map is about to be cleared; this implies that all of the existing key/value mappings in each delegating map are about to be removed, but that no per-mapping events will be generated in response to those removals.voidBlindly 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.booleanputIfAbsent(Binary binKey, long lValue) Store the passed value for the specified key, only if the key does not currently exist in the map.voidBlindly remove the specified Binary key from the map.booleanRemove the specified Binary key from the map iff it exists in the map and is associated with the specified value.voidRemove the specified listener from the collection of listeners that this DelegatingPrimaryBinaryLongMap dispatches notifications to.booleanStore 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.intsize()Determine the size of the map.voidvisit(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.voidvisitAll(BinaryLongMap.EntryVisitor visitor) Apply the specified visitor to all entries in the BinaryLongMap.Methods inherited from class com.tangosol.util.MultiBinaryLongMap.WrapperBinaryLongMap
getMap, setMap
-
Field Details
-
f_rwLockMaster
The "master" read-write lock for the MultiBinaryLongMap. -
f_pblmCompressed
protected final MultiBinaryLongMap.PrimaryBinaryLongMap.CompressedPrimaryBinaryLongMap f_pblmCompressedThe "compressed" PBLM implementation. -
f_pblmMulti
The "full" or "multi-aware" PBLM implementation. -
f_listeners
The listeners to notify of changes to the BinaryLongMap.
-
-
Constructor Details
-
PrimaryBinaryLongMap
public PrimaryBinaryLongMap()Construct a PrimaryBinaryLongMap.
-
-
Method Details
-
inflateRep
protected void inflateRep()Inflate the underlying representation of the PrimaryBinaryLongMap to use the LongStorage to support multiple delegating BinaryLongMap instances.Note: it is the caller's responsibility to hold the master exclusive lock during this operation
-
deflateRep
protected void deflateRep()Deflate the underlying representation of the PrimaryBinaryLongMap to use the main key-tree to associate a single long value with each key (logically represented by this PrimaryBinaryLongMap).Note: it is the caller's responsibility to hold the master exclusive lock during this operation
-
addListener
Add the specified listener to the collection of listeners that this DelegatingPrimaryBinaryLongMap dispatches notifications to.- Parameters:
listener- the listener to add to the collection of listeners that this DelegatingPrimaryBinaryLongMap dispatches notifications to
-
removeListener
Remove the specified listener from the collection of listeners that this DelegatingPrimaryBinaryLongMap dispatches notifications to.- Parameters:
listener- the listener to remove from the collection of listeners that this DelegatingPrimaryBinaryLongMap dispatches notifications to
-
get
Find the specified key in the map and return the value associated with it.- Specified by:
getin interfaceBinaryLongMap- Overrides:
getin classMultiBinaryLongMap.WrapperBinaryLongMap- 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
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.
- Specified by:
putin interfaceBinaryLongMap- Overrides:
putin classMultiBinaryLongMap.WrapperBinaryLongMap- Parameters:
binKey- the Binary key to add or updatelValue- the value to associate with the key
-
putIfAbsent
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).
- Specified by:
putIfAbsentin interfaceBinaryLongMap- Overrides:
putIfAbsentin classMultiBinaryLongMap.WrapperBinaryLongMap- 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
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 asremovepassing the old value to match.- Specified by:
replacein interfaceBinaryLongMap- Overrides:
replacein classMultiBinaryLongMap.WrapperBinaryLongMap- 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
-
remove
Blindly remove the specified Binary key from the map.- Specified by:
removein interfaceBinaryLongMap- Overrides:
removein classMultiBinaryLongMap.WrapperBinaryLongMap- Parameters:
binKey- a Binary key
-
remove
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.
- Specified by:
removein interfaceBinaryLongMap- Overrides:
removein classMultiBinaryLongMap.WrapperBinaryLongMap- 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
-
clear
public void clear()Initialize the map to an empty state.- Specified by:
clearin interfaceBinaryLongMap- Overrides:
clearin classMultiBinaryLongMap.WrapperBinaryLongMap
-
size
public int size()Determine the size of the map.- Specified by:
sizein interfaceBinaryLongMap- Overrides:
sizein classMultiBinaryLongMap.WrapperBinaryLongMap- Returns:
- the number of unique keys stored in the map
-
keys
Obtain an iterator of the keys stored in the map.- Specified by:
keysin interfaceBinaryLongMap- Overrides:
keysin classMultiBinaryLongMap.WrapperBinaryLongMap- Returns:
- an Iterator of Binary keys
-
keys
Obtain an iterator of the keys stored in the map whose correspondingEntrymatches 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.EntryVisitorvia theBinaryLongMap.visit(com.tangosol.util.Binary, com.tangosol.util.BinaryLongMap.EntryVisitor)orBinaryLongMap.visitAll(com.tangosol.util.BinaryLongMap.EntryVisitor)methods.- Specified by:
keysin interfaceBinaryLongMap- Overrides:
keysin classMultiBinaryLongMap.WrapperBinaryLongMap- Parameters:
predicate- a Predicate<Entry> to apply to each Entry- Returns:
- an Iterator of Binary keys
-
visit
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:
visitin interfaceBinaryLongMap- Overrides:
visitin classMultiBinaryLongMap.WrapperBinaryLongMap- Parameters:
binKey- the key to visitvisitor- the visitor to apply
-
visitAll
Apply the specified visitor to all entries in the BinaryLongMap.- Specified by:
visitAllin interfaceBinaryLongMap- Overrides:
visitAllin classMultiBinaryLongMap.WrapperBinaryLongMap- Parameters:
visitor- the visitor to apply
-
internKeys
Internal opaque method: De-duplicate keys.- Specified by:
internKeysin interfaceBinaryLongMap- Overrides:
internKeysin classMultiBinaryLongMap.WrapperBinaryLongMap- Parameters:
o- some implementation-specific object
-
keyAdded
A notification that the primary map has added a new Binary/long key/value mapping; this implicitly creates a new key/value mapping in each delegating map, with the value being 0L.- Specified by:
keyAddedin interfaceMultiBinaryLongMap.BinaryLongMapListener- Parameters:
binKey- the key that was added
-
keyRemoving
A notification that the primary map is removing a Binary/long key/value mapping; this implies that the existing key/value mapping for the same Binary key in each delegating map is also being removed.- Specified by:
keyRemovingin interfaceMultiBinaryLongMap.BinaryLongMapListener- Parameters:
binKey- the key that is being removed
-
mapClearing
public void mapClearing()A notification that the primary map is about to be cleared; this implies that all of the existing key/value mappings in each delegating map are about to be removed, but that no per-mapping events will be generated in response to those removals.- Specified by:
mapClearingin interfaceMultiBinaryLongMap.BinaryLongMapListener
-
mapCleared
public void mapCleared()A notification that the primary map has been cleared; this implies that all of the existing key/value mappings in each delegating map have also been removed.- Specified by:
mapClearedin interfaceMultiBinaryLongMap.BinaryLongMapListener
-