com.googlecode.icegem.utils
Class CacheUtils

java.lang.Object
  extended by com.googlecode.icegem.utils.CacheUtils

public class CacheUtils
extends java.lang.Object

Help class for common operations with regions.

Author:
Andrey Stepanov aka standy

Constructor Summary
CacheUtils()
           
 
Method Summary
static java.lang.String addQueryLimit(java.lang.String queryString, int queryLimit)
          Limits query results.
static void clearRegion(com.gemstone.gemfire.cache.Region<?,?> region)
          Clears all types of regions.
static java.lang.String[] getFirstLocatorFromLocatorsString(java.lang.String locatorsString)
          Returns first locator host and port from locators string.
static int getRegionSize(com.gemstone.gemfire.cache.Region<?,?> region)
          Returns approximate number of entries in the region.
static
<K> void
removeAll(com.gemstone.gemfire.cache.Region<K,?> region, java.util.Set<K> keys)
          Removes several entries from region in a single hop.
static
<T> T
retryWithExponentialBackoff(Retryable<T> runnable, int maxRetries)
          Retries passed operation with random exponential back off delay.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheUtils

public CacheUtils()
Method Detail

addQueryLimit

public static java.lang.String addQueryLimit(java.lang.String queryString,
                                             int queryLimit)
Limits query results.

Parameters:
queryString - Query string.
Returns:
Query string with injected "LIMIT" clause.

getFirstLocatorFromLocatorsString

public static java.lang.String[] getFirstLocatorFromLocatorsString(java.lang.String locatorsString)
Returns first locator host and port from locators string.

Parameters:
locatorsString - of type String
Returns:
String[0] - locator host String[1] - locator port

clearRegion

public static void clearRegion(com.gemstone.gemfire.cache.Region<?,?> region)
Clears all types of regions. This method can clean both types of regions (REPLICATED, PARTITIONED). It can be used both on client and server side. Note: if this method is used from client configured as CACHING_PROXY: clearing of PARTITIONED regions: - if client's data should be cleared together with server's data, client interest should be registered on entries changes; clearing of REPLICATED regions: - if client's data should be cleared together with server's data, this method should be invoked from the client together with region.localClear() method.

Parameters:
region - partitioned region

getRegionSize

public static int getRegionSize(com.gemstone.gemfire.cache.Region<?,?> region)
Returns approximate number of entries in the region. As the function counts number of entries on different nodes in parallel, per node values may be captured on different moments. So the value may never be valid.

Parameters:
region - Region.
Returns:
Size of the given region.

removeAll

public static <K> void removeAll(com.gemstone.gemfire.cache.Region<K,?> region,
                                 java.util.Set<K> keys)
Removes several entries from region in a single hop. On partitioned region execution is done simultaneously on all partitions.

Type Parameters:
K - key type.
Parameters:
region - the region to remove entries.
keys - the keys of entries to remove.

retryWithExponentialBackoff

public static <T> T retryWithExponentialBackoff(Retryable<T> runnable,
                                                int maxRetries)
                                     throws java.lang.InterruptedException,
                                            OperationRetryFailedException
Retries passed operation with random exponential back off delay.

Type Parameters:
T - Type of returned value.
Parameters:
runnable - the operation.
maxRetries - the maximum number of retries.
Returns:
the value returned by operation
Throws:
OperationRetryFailedException
java.lang.InterruptedException


Copyright © 2011. All Rights Reserved.