com.sun.sgs.app.util
Class ScalableHashMap.PrefixEntry<K,V>

java.lang.Object
  extended by com.sun.sgs.app.util.ScalableHashMap.PrefixEntry<K,V>
All Implemented Interfaces:
Serializable, Map.Entry<K,V>
Enclosing class:
ScalableHashMap<K,V>

static class ScalableHashMap.PrefixEntry<K,V>
extends Object
implements Map.Entry<K,V>, Serializable

An implementation of Entry that incorporates information about the prefix at which it is stored, as well as whether the ScalableHashMap is responsible for the persistent lifetime of the key and value.

If a key or value that does not implement ManagedObject is stored in the map, then it is wrapped using the ManagedSerializable utility class so that the entry may have a ManagedReference to the value, rather than a standard reference.

This class performs an optimization if both key and value do not implement ManagedObject. In this case, both objects will be stored together in a KeyValuePair, which reduces the number of accesses to the data store.

Note that the ordering of entries depends on the object ID of the managed object that represents the key. To insure the proper behavior of the iterator, that object ID must not change after the entry is created. The object ID used is either that of the key itself, if the key is a managed object, or that of the ManagedSerializable wrapper created to wrap either the just key or both the key and value. In either case, the managed object associated with the key is determined in the constructor

See Also:
ManagedSerializable

Field Summary
(package private)  int hash
          The hash value for this entry.
(package private)  ScalableHashMap.PrefixEntry<K,V> next
          The next chained entry in this entry's bucket.
(package private)  byte state
          The state of the key and value, which is either a non-zero combination of the KEY_WRAPPED and VALUE_WRAPPED, or is KEY_VALUE_PAIR.
 
Constructor Summary
ScalableHashMap.PrefixEntry(int h, K k, V v)
          Constructs a new PrefixEntry.
 
Method Summary
 boolean equals(Object o)
          
 K getKey()
          Returns the key stored by this entry.
 V getValue()
          Returns the value stored by this entry.
 int hashCode()
          
(package private)  ManagedReference<?> keyRef()
          Returns the ManagedReference for the key used in this entry.
 V setValue(V newValue)
          Replaces the previous value of this entry with the provided value.
(package private)  void setValueInternal(V newValue)
          Replaces the previous value of this entry with the provided value.
 String toString()
          Returns the string form of this entry as entry=value.
(package private)  void unmanage()
          Removes any Serializable managed by this entry from the data manager.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

next

ScalableHashMap.PrefixEntry<K,V> next
The next chained entry in this entry's bucket.


hash

final int hash
The hash value for this entry. This value is also used to compute the prefix.


state

byte state
The state of the key and value, which is either a non-zero combination of the KEY_WRAPPED and VALUE_WRAPPED, or is KEY_VALUE_PAIR.

Constructor Detail

ScalableHashMap.PrefixEntry

ScalableHashMap.PrefixEntry(int h,
                            K k,
                            V v)
Constructs a new PrefixEntry.

Parameters:
h - the hash code for the key
k - the key
v - the value
Method Detail

getKey

public final K getKey()
Returns the key stored by this entry. If the mapping has been removed from the backing map before this call is made, an ObjectNotFoundException will be thrown.

Specified by:
getKey in interface Map.Entry<K,V>
Returns:
the key stored in this entry
Throws:
ObjectNotFoundException - if the key in the backing map was removed prior to this call

keyRef

ManagedReference<?> keyRef()
Returns the ManagedReference for the key used in this entry. These references are not guaranteed to stay valid across transactions and should therefore not be used except for comparisons.

Returns:
the ManagedReference for the key
See Also:
ScalableHashMap.ConcurrentIterator

getValue

public final V getValue()
Returns the value stored by this entry. If the mapping has been removed from the backing map before this call is made, an ObjectNotFoundException will be thrown.

Specified by:
getValue in interface Map.Entry<K,V>
Returns:
the value stored in this entry
Throws:
ObjectNotFoundException - if the value in the backing map was removed prior to this call

setValue

public final V setValue(V newValue)
Replaces the previous value of this entry with the provided value.

Specified by:
setValue in interface Map.Entry<K,V>
Parameters:
newValue - the value to be stored
Returns:
the previous value of this entry

setValueInternal

void setValueInternal(V newValue)
Replaces the previous value of this entry with the provided value. Does not check if the new value is serializable or return the old value.

Parameters:
newValue - the value to be stored

equals

public final boolean equals(Object o)

Specified by:
equals in interface Map.Entry<K,V>
Overrides:
equals in class Object

hashCode

public final int hashCode()

Specified by:
hashCode in interface Map.Entry<K,V>
Overrides:
hashCode in class Object

toString

public String toString()
Returns the string form of this entry as entry=value.

Overrides:
toString in class Object

unmanage

final void unmanage()
Removes any Serializable managed by this entry from the data manager. This should only be called from ScalableHashMap.clear, ScalableHashMap.remove, or remove under the condition that this entry's map-managed object will never be referenced again by the map.


RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved