com.apama.correlator.memstore
Class ConcurrentMapAdapter<K,V>

java.lang.Object
  extended by com.apama.correlator.memstore.AbstractTable
      extended by com.apama.correlator.memstore.ConcurrentMapAdapter<K,V>
Type Parameters:
K - The class used to represent keys. Typically this is String, but could alternatively be an application-specific class (if a custom converter is supplied).
V - The class used to represent row values. Typically this is RowValue, but could alternatively be an application-specific class (if a custom converter is supplied).
All Implemented Interfaces:
java.lang.Iterable<java.util.Map.Entry<java.lang.String,RowValue>>

public class ConcurrentMapAdapter<K,V>
extends AbstractTable

Helper class for implementing the distributed MemoryStore AbstractTable class using an instance of ConcurrentMap, which is exposed by many providers.

Usually the type parameters for this class will be String,RowValue, but if the distributed data is being shared with other non-Apama applications it is possible to use any desired Java class for the K and V type parameters, provided an appropriate converter is supplied when the constructor is invoked.

Drivers may optionally provide support for 'row changed' notifications. See the documentation for AbstractTable for further details.

See Also:
ConcurrentMap, AbstractTable

Constructor Summary
ConcurrentMapAdapter(java.util.concurrent.ConcurrentMap<K,V> map)
          Create a table implementation that handles all accessor methods by calling the supplied map, translating keys and values by casting to/from String (for keys) and RowValue (for row values).
ConcurrentMapAdapter(java.util.concurrent.ConcurrentMap<K,V> map, RowKeyValueConverter<K,V> converter)
          Create a table implementation that handles all accessor methods by calling the supplied map, translating keys and values via the supplied converter.
 
Method Summary
 void clear()
          Removes all of the mappings from this map (optional operation).
 boolean containsKey(java.lang.String key)
          Returns true if this map contains a mapping for the specified key.
 RowValue get(java.lang.String key)
          Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
 java.util.Iterator<java.util.Map.Entry<java.lang.String,RowValue>> iterator()
          Returns an iterator over all the rows of this table.
 RowValue putIfAbsent(java.lang.String key, RowValue value)
          If the specified key is not already associated with a value, associates it with the given value.
 RowValue remove(java.lang.String key)
          Removes the mapping for a key from this map if it is present.
 boolean remove(java.lang.String key, RowValue value)
          Removes the entry for a key only if currently mapped to a given value.
 boolean replace(java.lang.String key, RowValue oldValue, RowValue newValue)
          Replaces the entry for a key only if it is currently mapped to a given value.
 int size()
          Returns the number of key-value mappings in this map.
 java.lang.String toString()
           
 
Methods inherited from class com.apama.correlator.memstore.AbstractTable
close, getRowChangedSubscriptionManager
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConcurrentMapAdapter

public ConcurrentMapAdapter(java.util.concurrent.ConcurrentMap<K,V> map,
                            RowKeyValueConverter<K,V> converter)
Create a table implementation that handles all accessor methods by calling the supplied map, translating keys and values via the supplied converter.

Parameters:
map - the map this class will be adapting to

ConcurrentMapAdapter

public ConcurrentMapAdapter(java.util.concurrent.ConcurrentMap<K,V> map)
Create a table implementation that handles all accessor methods by calling the supplied map, translating keys and values by casting to/from String (for keys) and RowValue (for row values).

Do not use this constructor overload if the map may contain keys and values put there by another (non-Apama) application, using some custom class other than RowValue to represent the values in the map (or a class other than String to represent the keys).

Parameters:
map - the map this class will be adapting to
Method Detail

get

public RowValue get(java.lang.String key)
Description copied from class: AbstractTable
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Specified by:
get in class AbstractTable
Parameters:
key - the key whose associated value is to be returned
Returns:
the value to which the specified key is mapped, or null if this map contains no mapping for the key

clear

public void clear()
Description copied from class: AbstractTable
Removes all of the mappings from this map (optional operation). The map will be empty after this call returns.

Specified by:
clear in class AbstractTable

remove

public RowValue remove(java.lang.String key)
Description copied from class: AbstractTable
Removes the mapping for a key from this map if it is present. More formally, if this map contains a mapping from key k to value v such that (key==null ? k==null : key.equals(k)), that mapping is removed. (The map can contain at most one such mapping.)

Returns the value to which this map previously associated the key, or null if the map contained no mapping for the key.

Specified by:
remove in class AbstractTable
Parameters:
key - key whose mapping is to be removed from the map
Returns:
the previous value associated with key, or null if there was no mapping for key

remove

public boolean remove(java.lang.String key,
                      RowValue value)
Description copied from class: AbstractTable
Removes the entry for a key only if currently mapped to a given value.

Specified by:
remove in class AbstractTable
Parameters:
key - key with which the specified value is associated
value - value expected to be associated with the specified key
Returns:
true if the value was removed

replace

public boolean replace(java.lang.String key,
                       RowValue oldValue,
                       RowValue newValue)
Description copied from class: AbstractTable
Replaces the entry for a key only if it is currently mapped to a given value. Compare and swap.

Specified by:
replace in class AbstractTable
Parameters:
key - key with which the specified value is associated
oldValue - value expected to be associated with the specified key
newValue - value to be associated with the specified key
Returns:
true if the value was replaced

putIfAbsent

public RowValue putIfAbsent(java.lang.String key,
                            RowValue value)
Description copied from class: AbstractTable
If the specified key is not already associated with a value, associates it with the given value.

Specified by:
putIfAbsent in class AbstractTable
Parameters:
key - key with which the specified value is to be associated
value - value to be associated with the specified key
Returns:
null if there was no mapping for the key. The current value associated with the specified key if a mapping already existed.

containsKey

public boolean containsKey(java.lang.String key)
Description copied from class: AbstractTable
Returns true if this map contains a mapping for the specified key.

Specified by:
containsKey in class AbstractTable
Parameters:
key - key whose presence in this map is to be tested
Returns:
true if this map contains a mapping for the specified key

size

public int size()
Description copied from class: AbstractTable
Returns the number of key-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Specified by:
size in class AbstractTable
Returns:
the number of key-value mappings in this map

iterator

public java.util.Iterator<java.util.Map.Entry<java.lang.String,RowValue>> iterator()
Description copied from class: AbstractTable
Returns an iterator over all the rows of this table.

Note: a simple way to construct a Map.Entry is to use the AbstractMap.SimpleEntry class.

Specified by:
iterator in interface java.lang.Iterable<java.util.Map.Entry<java.lang.String,RowValue>>
Specified by:
iterator in class AbstractTable
Returns:
an iterator

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Submit a bug or feature
Copyright (c) 2013 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors. Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG