com.google.common.collect
Interface CustomConcurrentHashMap.Strategy<K,V,E>

Type Parameters:
K - the type of keys to be stored in the returned map
V - the type of values to be stored in the returned map
E - internal entry type, not directly exposed to clients in map views
All Known Subinterfaces:
CustomConcurrentHashMap.ComputingStrategy<K,V,E>
Enclosing class:
CustomConcurrentHashMap

public static interface CustomConcurrentHashMap.Strategy<K,V,E>

Implements behavior specific to the client's concurrent hash map implementation. Used by the framework to create new entries and perform operations on them.

Method parameters are never null unless otherwise specified.

Partially Reclaimed Entries

This class does not allow null to be used as a key. Setting values to null is not permitted, but entries may have null keys or values for various reasons. For example, the key or value may have been garbage collected or reclaimed through other means. CustomConcurrentHashMap treats entries with null keys and values as "partially reclaimed" and ignores them for the most part. Entries may enter a partially reclaimed state but they must not leave it. Partially reclaimed entries will not be copied over during table expansions, for example. Strategy implementations should proactively remove partially reclaimed entries so that Map.isEmpty() and Map.size() return up-to-date results.


Method Summary
 E copyEntry(K key, E original, E newNext)
          Creates a copy of the given entry pointing to the given next entry.
 boolean equalKeys(K a, java.lang.Object b)
          Returns true if the two given keys are equal, false otherwise.
 boolean equalValues(V a, java.lang.Object b)
          Returns true if the two given values are equal, false otherwise.
 int getHash(E entry)
          Returns the hash code that was passed to newEntry(K, int, E)) when the given entry was created.
 K getKey(E entry)
          Gets the key for the given entry.
 E getNext(E entry)
          Gets the next entry relative to the given entry, the exact same entry that was provided to newEntry(K, int, E) when the given entry was created.
 V getValue(E entry)
          Gets the value of an entry using volatile semantics.
 int hashKey(java.lang.Object key)
          Returns a hash code for the given key.
 E newEntry(K key, int hash, E next)
          Constructs a new entry for the given key with a pointer to the given next entry.
 void setInternals(CustomConcurrentHashMap.Internals<K,V,E> internals)
          Provides an API for interacting directly with the map's internal entries to this strategy.
 void setValue(E entry, V value)
          Sets the value of an entry using volatile semantics.
 

Method Detail

newEntry

E newEntry(K key,
           int hash,
           E next)
Constructs a new entry for the given key with a pointer to the given next entry.

This method may return different entry implementations depending upon whether next is null or not. For example, if next is null (as will often be the case), this factory might use an entry class that doesn't waste memory on an unnecessary field.

Parameters:
key - for this entry
hash - of key returned by hashKey(java.lang.Object)
next - entry (used when implementing a hash bucket as a linked list, for example), possibly null
Returns:
a new entry

copyEntry

E copyEntry(K key,
            E original,
            E newNext)
Creates a copy of the given entry pointing to the given next entry. Copies the value and any other implementation-specific state from original to the returned entry. For example, CustomConcurrentHashMap might use this method when removing other entries or expanding the internal table.

Parameters:
key - for original as well as the returned entry. Explicitly provided here to prevent reclamation of the key at an inopportune time in implementations that don't otherwise keep a strong reference to the key.
original - entry from which the value and other implementation-specific state should be copied
newNext - the next entry the new entry should point to, possibly null

setValue

void setValue(E entry,
              V value)
Sets the value of an entry using volatile semantics. Values are set synchronously on a per-entry basis.

Parameters:
entry - to set the value on
value - to set

getValue

V getValue(E entry)
Gets the value of an entry using volatile semantics.

Parameters:
entry - to get the value from

equalKeys

boolean equalKeys(K a,
                  java.lang.Object b)
Returns true if the two given keys are equal, false otherwise. Neither key will be null.

Parameters:
a - key from inside the map
b - key passed from caller, not necesarily of type K
See Also:
the same contractual obligations apply here

equalValues

boolean equalValues(V a,
                    java.lang.Object b)
Returns true if the two given values are equal, false otherwise. Neither value will be null.

Parameters:
a - value from inside the map
b - value passed from caller, not necesarily of type V
See Also:
the same contractual obligations apply here

hashKey

int hashKey(java.lang.Object key)
Returns a hash code for the given key.

See Also:
the same contractual obligations apply here

getKey

K getKey(E entry)
Gets the key for the given entry. This may return null (for example, if the key was reclaimed by the garbage collector).

Parameters:
entry - to get key from
Returns:
key from the given entry

getNext

E getNext(E entry)
Gets the next entry relative to the given entry, the exact same entry that was provided to newEntry(K, int, E) when the given entry was created.

Returns:
the next entry or null if null was passed to newEntry(K, int, E)

getHash

int getHash(E entry)
Returns the hash code that was passed to newEntry(K, int, E)) when the given entry was created.


setInternals

void setInternals(CustomConcurrentHashMap.Internals<K,V,E> internals)
Provides an API for interacting directly with the map's internal entries to this strategy. Invoked once when the map is created. Strategies that don't need access to the map's internal entries can simply ignore the argument.

Parameters:
internals - of the map, enables direct interaction with the internal entries


Copyright © 2007-2009 Google. All Rights Reserved.