Java Code Examples for com.gemstone.gemfire.cache.Region#keys()

The following examples show how to use com.gemstone.gemfire.cache.Region#keys() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WANTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void printSequentialKeys(Region region) throws Exception {
  if (region == null) {
    throw new TestException("Region in printSequentialKeys is null");
  }

  // print the value of each entry in the local cache
  StringBuffer buffer = new StringBuffer();
  buffer.append("Contents of region");
  buffer.append(region.getFullPath());
  buffer.append(":");

  Set keys = region.keys();
  Iterator kI = keys.iterator();
  while (kI.hasNext()) {
    Object key = kI.next();
    Object val = DiskRegUtil.getValueInVM(region, key);
    if (val != null) {
      buffer.append("\n\tENTRY ");
      buffer.append(key);
      buffer.append(":");
      buffer.append(val);
    }
  }
  Log.getLogWriter().info(buffer.toString());
}
 
Example 2
Source File: WANClient.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/** perform updates */
public static void updateEntries() {
  Region region = RegionHelper.getRegion(REGION_NAME);
  Set aSet = region.keys();
  if (aSet.size() == 0) {
     Log.getLogWriter().info("updateEntries: No keys in region");
     return;
  }
  Object[] keyList = aSet.toArray();
  int index = rand.nextInt(aSet.size() - 1);
  Log.getLogWriter().info("Number of keys in region = " + aSet.size());
  try {
     Object key = keyList[index];
     Log.getLogWriter().info("Updating " + key + " in region " + region.getName());
     Long val = (Long)region.get(key);
     WANClientVersionHelper.updateEntry(region, key, new Long(val.intValue()+1));
     Log.getLogWriter().info("Done updating key " + key + " in region " + region.getName());
  } catch (Exception e) {
     throw new TestException("updateEntries throws " + e + " " + TestHelper.getStackTrace(e));
  }
}
 
Example 3
Source File: WANClient.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Closes an edge cache.
 */
public static synchronized void closeEdgeClientCacheTask() {
  Cache cache = CacheHelper.getCache();
  if (cache != null ) {  // another thread has closed the cache
    Region region = RegionHelper.getRegion(REGION_NAME);
    if (region != null) {
      Set keySet = region.keys();
      int numEntries = keySet.size();
      Log.getLogWriter().info("Client's region " + REGION_NAME + " contains " + numEntries + " entries");

      // Don't close the cache if we're using partitionedRegions, we need to allow
      // all servers to complete validation prior to cache close so we don't
      // lose any portion of the PR
      if (region.getAttributes().getPartitionAttributes() == null) {
         CacheHelper.closeCache();
      }
    }
  }
}
 
Example 4
Source File: WANTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void printSequentialKeys(Region region) throws Exception {
  if (region == null) {
    throw new TestException("Region in printSequentialKeys is null");
  }

  // print the value of each entry in the local cache
  StringBuffer buffer = new StringBuffer();
  buffer.append("Contents of region");
  buffer.append(region.getFullPath());
  buffer.append(":");

  Set keys = region.keys();
  Iterator kI = keys.iterator();
  while (kI.hasNext()) {
    Object key = kI.next();
    Object val = DiskRegUtil.getValueInVM(region, key);
    if (val != null) {
      buffer.append("\n\tENTRY ");
      buffer.append(key);
      buffer.append(":");
      buffer.append(val);
    }
  }
  Log.getLogWriter().info(buffer.toString());
}
 
Example 5
Source File: WANClient.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/** perform updates */
public static void updateEntries() {
  Region region = RegionHelper.getRegion(REGION_NAME);
  Set aSet = region.keys();
  if (aSet.size() == 0) {
     Log.getLogWriter().info("updateEntries: No keys in region");
     return;
  }
  Object[] keyList = aSet.toArray();
  int index = rand.nextInt(aSet.size() - 1);
  Log.getLogWriter().info("Number of keys in region = " + aSet.size());
  try {
     Object key = keyList[index];
     Log.getLogWriter().info("Updating " + key + " in region " + region.getName());
     Long val = (Long)region.get(key);
     WANClientVersionHelper.updateEntry(region, key, new Long(val.intValue()+1));
     Log.getLogWriter().info("Done updating key " + key + " in region " + region.getName());
  } catch (Exception e) {
     throw new TestException("updateEntries throws " + e + " " + TestHelper.getStackTrace(e));
  }
}
 
Example 6
Source File: WANClient.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Closes an edge cache.
 */
public static synchronized void closeEdgeClientCacheTask() {
  Cache cache = CacheHelper.getCache();
  if (cache != null ) {  // another thread has closed the cache
    Region region = RegionHelper.getRegion(REGION_NAME);
    if (region != null) {
      Set keySet = region.keys();
      int numEntries = keySet.size();
      Log.getLogWriter().info("Client's region " + REGION_NAME + " contains " + numEntries + " entries");

      // Don't close the cache if we're using partitionedRegions, we need to allow
      // all servers to complete validation prior to cache close so we don't
      // lose any portion of the PR
      if (region.getAttributes().getPartitionAttributes() == null) {
         CacheHelper.closeCache();
      }
    }
  }
}
 
Example 7
Source File: DefaultRegionKeyValueConfig.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public Object getUsedKey(Region region) {
  Set set = region.keys();
  if (set.size() == 0) {
    Log.getLogWriter().info("getExistingKey: No names in region");
    return null;
  }
  long maxNames = NameFactory.getPositiveNameCounter();
  if (maxNames <= 0) {
    Log.getLogWriter().info("getExistingKey: max positive name counter is " + maxNames);
    return null;
  }
  String name = NameFactory.getObjectNameForCounter(TestConfig.tab().getRandGen().nextInt(1, (int) maxNames));
  return name;
}
 
Example 8
Source File: WANClient.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/** Prints the contents of the local cache. */
public static void printSequentialKeysTask() throws Exception {
  PdxTest.initClassLoader();
  // get the number of cache entries (one for each thread in the group)
  long size = WANBlackboard.getInstance().getSharedCounters()
                           .read(WANBlackboard.MaxKeys);

  Region region = RegionHelper.getRegion(REGION_NAME);
  // print the value of each entry in the local cache
  StringBuffer buffer = new StringBuffer();
  buffer.append("Contents of region");
  buffer.append(region.getFullPath());
  buffer.append(":");

  Set keys = region.keys();
  Iterator kI = keys.iterator();
  while(kI.hasNext()) {
    Object key = kI.next();
    Object val = DiskRegUtil.getValueInVM(region, key);
      if (val != null) {
        buffer.append("\n\tENTRY ");
        buffer.append(key);
        buffer.append(":");
        buffer.append(val);
      }
  }
  Log.getLogWriter().info(buffer.toString());
}
 
Example 9
Source File: WANClient.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Writes the regionSize to the sharedMap in the BB (distinguished by
 * clientName).  An ENDTASK is required to validate the regionSizes
 * at test end.
 *
 * @see WANBlackboard.REGION_SIZE
 */
public static void HydraCloseTask_regionSizeToBB() {
  String clientName = System.getProperty(ClientPrms.CLIENT_NAME_PROPERTY);
  Cache cache = CacheHelper.getCache();
  if (cache != null ) {  // another thread has closed the cache
    Region region = RegionHelper.getRegion(REGION_NAME);
    Set myKeys = region.keys();
    Log.getLogWriter().info("Region " + region.getName() + " contains " + myKeys.size() + " entries");

    // write this to the BB for the ENDTASK to use for validation
    Object mapKey = clientName + "_" + WANBlackboard.REGION_SIZE;
    WANBlackboard.getInstance().getSharedMap().put(mapKey, new Integer(myKeys.size()));
    CacheHelper.closeCache();
  }
}
 
Example 10
Source File: DefaultRegionKeyValueConfig.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public Object getUsedKey(Region region) {
  Set set = region.keys();
  if (set.size() == 0) {
    Log.getLogWriter().info("getExistingKey: No names in region");
    return null;
  }
  long maxNames = NameFactory.getPositiveNameCounter();
  if (maxNames <= 0) {
    Log.getLogWriter().info("getExistingKey: max positive name counter is " + maxNames);
    return null;
  }
  String name = NameFactory.getObjectNameForCounter(TestConfig.tab().getRandGen().nextInt(1, (int) maxNames));
  return name;
}
 
Example 11
Source File: WANClient.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/** Prints the contents of the local cache. */
public static void printSequentialKeysTask() throws Exception {
  PdxTest.initClassLoader();
  // get the number of cache entries (one for each thread in the group)
  long size = WANBlackboard.getInstance().getSharedCounters()
                           .read(WANBlackboard.MaxKeys);

  Region region = RegionHelper.getRegion(REGION_NAME);
  // print the value of each entry in the local cache
  StringBuffer buffer = new StringBuffer();
  buffer.append("Contents of region");
  buffer.append(region.getFullPath());
  buffer.append(":");

  Set keys = region.keys();
  Iterator kI = keys.iterator();
  while(kI.hasNext()) {
    Object key = kI.next();
    Object val = DiskRegUtil.getValueInVM(region, key);
      if (val != null) {
        buffer.append("\n\tENTRY ");
        buffer.append(key);
        buffer.append(":");
        buffer.append(val);
      }
  }
  Log.getLogWriter().info(buffer.toString());
}
 
Example 12
Source File: WANClient.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Writes the regionSize to the sharedMap in the BB (distinguished by
 * clientName).  An ENDTASK is required to validate the regionSizes
 * at test end.
 *
 * @see WANBlackboard.REGION_SIZE
 */
public static void HydraCloseTask_regionSizeToBB() {
  String clientName = System.getProperty(ClientPrms.CLIENT_NAME_PROPERTY);
  Cache cache = CacheHelper.getCache();
  if (cache != null ) {  // another thread has closed the cache
    Region region = RegionHelper.getRegion(REGION_NAME);
    Set myKeys = region.keys();
    Log.getLogWriter().info("Region " + region.getName() + " contains " + myKeys.size() + " entries");

    // write this to the BB for the ENDTASK to use for validation
    Object mapKey = clientName + "_" + WANBlackboard.REGION_SIZE;
    WANBlackboard.getInstance().getSharedMap().put(mapKey, new Integer(myKeys.size()));
    CacheHelper.closeCache();
  }
}
 
Example 13
Source File: InitImageTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
protected Set getRegionKeySet(Region aRegion) {
   return aRegion.keys();
}
 
Example 14
Source File: WANClient.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/** Destroys numEntries randomKeys in REGION_NAME */
public static void destroyRandomEntriesTask() {
  Region region = RegionHelper.getRegion(REGION_NAME);
  Set aSet = region.keys();

  if (aSet.size() == 0) {
     Log.getLogWriter().info("destroyRandomEntryTask: No keys in region");
     return;
  }

  int numEntries = CacheClientPrms.getNumEntries();
  for (int i = 0; i < numEntries; i++) {
    aSet = region.keys();
    if (aSet.size() == 0) {
      Log.getLogWriter().info("destroyRandomEntriesTask: No keys remain to destroy");
      return;
    }

    Object[] keyList = aSet.toArray();
    int index = rand.nextInt(aSet.size() - 1);
    Log.getLogWriter().info("Number of keys in region = " + aSet.size());
    try {
       Object key = keyList[index];
       Log.getLogWriter().info("Destroying key " + key + " from region " + region.getName());
       if (TestConfig.tab().getRandGen().nextBoolean()) {
       region.destroy(key);
       } else {
         boolean removed = region.remove(key, region.get(key));
         if (!removed) { // might happen with concurrent execution, force destroy
           region.destroy(key);
         }
       }
       Log.getLogWriter().info("Done destroying key " + key + " from region " + region.getName());
    } catch (Exception e) {
       throw new TestException("destroyRandomEntryTask throws " + e + " " + TestHelper.getStackTrace(e));
    }
  }

  // allow time for distribution
  int sleepMs = CacheClientPrms.getSleepSec() * 1000;
  MasterController.sleepForMs( sleepMs );
}
 
Example 15
Source File: InitImageTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
protected Set getRegionKeySet(Region aRegion) {
   return aRegion.keys();
}
 
Example 16
Source File: WANClient.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/** Destroys numEntries randomKeys in REGION_NAME */
public static void destroyRandomEntriesTask() {
  Region region = RegionHelper.getRegion(REGION_NAME);
  Set aSet = region.keys();

  if (aSet.size() == 0) {
     Log.getLogWriter().info("destroyRandomEntryTask: No keys in region");
     return;
  }

  int numEntries = CacheClientPrms.getNumEntries();
  for (int i = 0; i < numEntries; i++) {
    aSet = region.keys();
    if (aSet.size() == 0) {
      Log.getLogWriter().info("destroyRandomEntriesTask: No keys remain to destroy");
      return;
    }

    Object[] keyList = aSet.toArray();
    int index = rand.nextInt(aSet.size() - 1);
    Log.getLogWriter().info("Number of keys in region = " + aSet.size());
    try {
       Object key = keyList[index];
       Log.getLogWriter().info("Destroying key " + key + " from region " + region.getName());
       if (TestConfig.tab().getRandGen().nextBoolean()) {
       region.destroy(key);
       } else {
         boolean removed = region.remove(key, region.get(key));
         if (!removed) { // might happen with concurrent execution, force destroy
           region.destroy(key);
         }
       }
       Log.getLogWriter().info("Done destroying key " + key + " from region " + region.getName());
    } catch (Exception e) {
       throw new TestException("destroyRandomEntryTask throws " + e + " " + TestHelper.getStackTrace(e));
    }
  }

  // allow time for distribution
  int sleepMs = CacheClientPrms.getSleepSec() * 1000;
  MasterController.sleepForMs( sleepMs );
}