org.apache.hadoop.hbase.util
Class ConcurrentIndex<K,V>

java.lang.Object
  extended by org.apache.hadoop.hbase.util.ConcurrentIndex<K,V>
Type Parameters:
K - Key type
V - Value type

@InterfaceAudience.Private
@InterfaceStability.Evolving
public class ConcurrentIndex<K,V>
extends Object

A simple concurrent map of sets. This is similar in concept to Multiset, with the following exceptions:


Constructor Summary
ConcurrentIndex(Comparator<V> valueComparator)
          Creates an instance using the DefaultValueSetFactory for sets, which in turn creates instances of ConcurrentSkipListSet
ConcurrentIndex(com.google.common.base.Supplier<Set<V>> valueSetFactory)
          Creates an instance with a specified factory object for sets to be associated with a given key.
 
Method Summary
 void put(K key, V value)
          Associate a new unique value with a specified key.
 boolean remove(K key, V value)
          Removes the association between a specified key and value.
 Set<V> values(K key)
          Get all values associated with a specified key or null if no values are associated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConcurrentIndex

public ConcurrentIndex(com.google.common.base.Supplier<Set<V>> valueSetFactory)
Creates an instance with a specified factory object for sets to be associated with a given key.

Parameters:
valueSetFactory - The factory instance

ConcurrentIndex

public ConcurrentIndex(Comparator<V> valueComparator)
Creates an instance using the DefaultValueSetFactory for sets, which in turn creates instances of ConcurrentSkipListSet

Parameters:
valueComparator - A Comparator for value types
Method Detail

put

public void put(K key,
                V value)
Associate a new unique value with a specified key. Under the covers, the method employs optimistic concurrency: if no set is associated with a given key, we create a new set; if another thread comes in, creates, and associates a set with the same key in the mean-time, we simply add the value to the already created set.

Parameters:
key - The key
value - An additional unique value we want to associate with a key

values

public Set<V> values(K key)
Get all values associated with a specified key or null if no values are associated. Note: if the caller wishes to add or removes values to under the specified as they're iterating through the returned value, they should make a defensive copy; otherwise, a ConcurrentModificationException may be thrown.

Parameters:
key - The key
Returns:
All values associated with the specified key or null if no values are associated with the key.

remove

public boolean remove(K key,
                      V value)
Removes the association between a specified key and value. If as a result of removing a value a set becomes empty, we remove the given set from the mapping as well.

Parameters:
key - The specified key
value - The value to disassociate with the key


Copyright © 2007-2016 The Apache Software Foundation. All Rights Reserved.