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

The following examples show how to use com.gemstone.gemfire.cache.Region#subregions() . 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: CliUtil.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static Set<String> getAllRegionNames() {
  Cache cache = CacheFactory.getAnyInstance();
  Set<String> regionNames = new HashSet<String>();
  Set<Region<?,?>> rootRegions = cache.rootRegions();

  Iterator<Region<?,?>> rootRegionIters = rootRegions.iterator();

  while (rootRegionIters.hasNext()) {
    Region<?,?> rootRegion = rootRegionIters.next();
    regionNames.add(rootRegion.getFullPath().substring(1));

    Set<Region<?, ?>> subRegions = rootRegion.subregions(true);
    Iterator<Region<?,?>> subRegionIters = subRegions.iterator();

    while (subRegionIters.hasNext()) {
      Region<?,?> subRegion = subRegionIters.next();
      regionNames.add(subRegion.getFullPath().substring(1));
    }
  }
  return regionNames;
}
 
Example 2
Source File: RegionOperations.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private void _destroyRegion(Region region){
  if (region != null) {
    String name = region.getName();
    String path = region.getFullPath();     
    String callback = callback("RegionOperations: Destroying region" + name + " in ");
    logInfo(callback);
    // TODO Optional dumping of region snapshot
    try {
      Region r = CacheFactory.getAnyInstance().getRegion(name);
      Set<Region> children = r.subregions(true);
      HashSet<String> childrennames = new HashSet<String>();
      if (children != null && children.size() > 0) {
        for (Region child : children) {
          childrennames.add(child.getFullPath());
        }
      }
      region.destroyRegion();
      removeAvailableRegion(region);
      operationRecorder.regionDestroyed(path, childrennames);
    } catch (Exception e) {
      handleException("RegionOperationError : destroyRegion", e, region);
    }
  } else {
    logInfo("No region Found continuing test list : " + availableRegions);
  }
}
 
Example 3
Source File: RegionUtil.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static List getAllRegionPathList(Region region, boolean recursive)
  {
  	List list = new ArrayList();
  	if (region == null) {
  		return list;
  	}
  	
  	Set subregionSet = region.subregions(true);
if (recursive) {
	for (Iterator subIter = subregionSet.iterator(); subIter.hasNext(); ){
		list.add(((Region)subIter.next()).getFullPath());
	}
}

      Collections.sort(list);
      return list;
  }
 
Example 4
Source File: CacheSnapshotServiceImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void save(File dir, SnapshotFormat format,
    SnapshotOptions<Object, Object> options) throws IOException {
  if (!dir.exists()) {
    boolean created = dir.mkdirs();
    if (!created) {
      throw new IOException(LocalizedStrings.Snapshot_UNABLE_TO_CREATE_DIR_0.toLocalizedString(dir));
    }
  }
  
  for (Region<?, ?> r : (Set<Region<?, ?>>) cache.rootRegions()) {
    for (Region<?, ?> sub : r.subregions(true)) {
      saveRegion(sub, dir, format, options);
    }
    saveRegion(r, dir, format, options);
  }
}
 
Example 5
Source File: RegionInformation.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public RegionInformation(Region<?, ?> region, boolean recursive) {
	this.name = region.getFullPath().substring(1);
	this.path = region.getFullPath().substring(1);
	this.scope = region.getAttributes().getScope();
	this.dataPolicy = region.getAttributes().getDataPolicy();
	
	if (region.getParentRegion() == null) {
		this.isRoot = true;
		
		if (recursive) {
			Set<Region<?,?>> subRegions = region.subregions(recursive);
			subRegionInformationSet = getSubRegions(subRegions);
		}
	} else {
		this.isRoot = false;
		this.parentRegion = region.getParentRegion().getFullPath();
	}
}
 
Example 6
Source File: CliUtil.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static Set<String> getAllRegionNames() {
  Cache cache = CacheFactory.getAnyInstance();
  Set<String> regionNames = new HashSet<String>();
  Set<Region<?,?>> rootRegions = cache.rootRegions();

  Iterator<Region<?,?>> rootRegionIters = rootRegions.iterator();

  while (rootRegionIters.hasNext()) {
    Region<?,?> rootRegion = rootRegionIters.next();
    regionNames.add(rootRegion.getFullPath().substring(1));

    Set<Region<?, ?>> subRegions = rootRegion.subregions(true);
    Iterator<Region<?,?>> subRegionIters = subRegions.iterator();

    while (subRegionIters.hasNext()) {
      Region<?,?> subRegion = subRegionIters.next();
      regionNames.add(subRegion.getFullPath().substring(1));
    }
  }
  return regionNames;
}
 
Example 7
Source File: RegionOperations.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private void _destroyRegion(Region region){
  if (region != null) {
    String name = region.getName();
    String path = region.getFullPath();     
    String callback = callback("RegionOperations: Destroying region" + name + " in ");
    logInfo(callback);
    // TODO Optional dumping of region snapshot
    try {
      Region r = CacheFactory.getAnyInstance().getRegion(name);
      Set<Region> children = r.subregions(true);
      HashSet<String> childrennames = new HashSet<String>();
      if (children != null && children.size() > 0) {
        for (Region child : children) {
          childrennames.add(child.getFullPath());
        }
      }
      region.destroyRegion();
      removeAvailableRegion(region);
      operationRecorder.regionDestroyed(path, childrennames);
    } catch (Exception e) {
      handleException("RegionOperationError : destroyRegion", e, region);
    }
  } else {
    logInfo("No region Found continuing test list : " + availableRegions);
  }
}
 
Example 8
Source File: RegionUtil.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static List getAllRegionPathList(Region region, boolean recursive)
  {
  	List list = new ArrayList();
  	if (region == null) {
  		return list;
  	}
  	
  	Set subregionSet = region.subregions(true);
if (recursive) {
	for (Iterator subIter = subregionSet.iterator(); subIter.hasNext(); ){
		list.add(((Region)subIter.next()).getFullPath());
	}
}

      Collections.sort(list);
      return list;
  }
 
Example 9
Source File: CacheSnapshotServiceImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void save(File dir, SnapshotFormat format,
    SnapshotOptions<Object, Object> options) throws IOException {
  if (!dir.exists()) {
    boolean created = dir.mkdirs();
    if (!created) {
      throw new IOException(LocalizedStrings.Snapshot_UNABLE_TO_CREATE_DIR_0.toLocalizedString(dir));
    }
  }
  
  for (Region<?, ?> r : (Set<Region<?, ?>>) cache.rootRegions()) {
    for (Region<?, ?> sub : r.subregions(true)) {
      saveRegion(sub, dir, format, options);
    }
    saveRegion(r, dir, format, options);
  }
}
 
Example 10
Source File: RegionInformation.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public RegionInformation(Region<?, ?> region, boolean recursive) {
	this.name = region.getFullPath().substring(1);
	this.path = region.getFullPath().substring(1);
	this.scope = region.getAttributes().getScope();
	this.dataPolicy = region.getAttributes().getDataPolicy();
	
	if (region.getParentRegion() == null) {
		this.isRoot = true;
		
		if (recursive) {
			Set<Region<?,?>> subRegions = region.subregions(recursive);
			subRegionInformationSet = getSubRegions(subRegions);
		}
	} else {
		this.isRoot = false;
		this.parentRegion = region.getParentRegion().getFullPath();
	}
}
 
Example 11
Source File: RegionUtil.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
   * Returns a sorted list of all region full paths found in the specified
   * cache.
   * @param cache The cache to search.
   * @return Returns a sorted list of all region paths defined in the 
   *         distributed system.  
   */
  public static List getAllRegionPathList(Cache cache, boolean recursive)
  {
  	ArrayList list = new ArrayList();
  	if (cache == null) {
  		return list;
  	}
  	
  	// get a list of all root regions
Set regions = cache.rootRegions();
Iterator itor = regions.iterator();

while (itor.hasNext()) {
	String regionPath = ((Region)itor.next()).getFullPath();

	Region region = cache.getRegion(regionPath);
	list.add(regionPath);
	Set subregionSet = region.subregions(true);
	if (recursive) {
		for (Iterator subIter = subregionSet.iterator(); subIter.hasNext(); ){
			list.add(((Region)subIter.next()).getFullPath());
		}
	}
}
Collections.sort(list);
return list;
  }
 
Example 12
Source File: DistributedSQLTestBase.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static String getRegionsStr(Cache gfCache) {
  StringBuilder sb = new StringBuilder();
  sb.append("Available regions: \n");
  for (Object regionObj : gfCache.rootRegions()) {
    Region<?, ?> region = (Region<?, ?>)regionObj;
    sb.append("\tRoot region: " + region.getFullPath() + "\n");
    for (Object subRegionObj : region.subregions(true)) {
      Region<?, ?> subRegion = (Region<?, ?>)subRegionObj;
      sb.append("\t\tSubregion: " + subRegion.getFullPath() + "\n");
    }
  }
  return sb.toString();
}
 
Example 13
Source File: DescribeDiskStoreFunction.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void setRegionDetails(final Region<?, ?> region, final DiskStore diskStore, final DiskStoreDetails diskStoreDetails) {
  if (isUsingDiskStore(region, diskStore)) {
    final String regionFullPath = region.getFullPath();
    final DiskStoreDetails.RegionDetails regionDetails = new DiskStoreDetails.RegionDetails(regionFullPath,
      StringUtils.defaultIfBlank(region.getName(), regionFullPath));
    regionDetails.setOverflowToDisk(isOverflowToDisk(region));
    regionDetails.setPersistent(isPersistent(region));
    diskStoreDetails.add(regionDetails);
  }

  for (Region<?, ?> subregion : region.subregions(false)) {
    setRegionDetails(subregion, diskStore, diskStoreDetails); // depth-first, recursive strategy
  }
}
 
Example 14
Source File: DataCommandFunction.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a sorted list of all region full paths found in the specified
 * cache.
 * @param cache The cache to search.
 * @param recursive recursive search for sub-regions
 * @return Returns a sorted list of all region paths defined in the 
 *         distributed system.  
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static List getAllRegionPaths(Cache cache, boolean recursive)
{
  ArrayList list = new ArrayList();
  if (cache == null) {
    return list;
  }
  
  // get a list of all root regions
Set regions = cache.rootRegions();
Iterator itor = regions.iterator();

while (itor.hasNext()) {
  String regionPath = ((Region)itor.next()).getFullPath();

  Region region = cache.getRegion(regionPath);
  list.add(regionPath);
  Set subregionSet = region.subregions(true);
  if (recursive) {
    for (Iterator subIter = subregionSet.iterator(); subIter.hasNext(); ){
      list.add(((Region)subIter.next()).getFullPath());
    }
  }
}
Collections.sort(list);
return list;
}
 
Example 15
Source File: DataCommandFunction.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a sorted list of all region full paths found in the specified
 * cache.
 * @param cache The cache to search.
 * @param recursive recursive search for sub-regions
 * @return Returns a sorted list of all region paths defined in the 
 *         distributed system.  
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static List getAllRegionPaths(Cache cache, boolean recursive)
{
  ArrayList list = new ArrayList();
  if (cache == null) {
    return list;
  }
  
  // get a list of all root regions
Set regions = cache.rootRegions();
Iterator itor = regions.iterator();

while (itor.hasNext()) {
  String regionPath = ((Region)itor.next()).getFullPath();

  Region region = cache.getRegion(regionPath);
  list.add(regionPath);
  Set subregionSet = region.subregions(true);
  if (recursive) {
    for (Iterator subIter = subregionSet.iterator(); subIter.hasNext(); ){
      list.add(((Region)subIter.next()).getFullPath());
    }
  }
}
Collections.sort(list);
return list;
}
 
Example 16
Source File: RegionUtil.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
   * Returns a sorted list of all region full paths found in the specified
   * cache.
   * @param cache The cache to search.
   * @return Returns a sorted list of all region paths defined in the 
   *         distributed system.  
   */
  public static List getAllRegionPathList(Cache cache, boolean recursive)
  {
  	ArrayList list = new ArrayList();
  	if (cache == null) {
  		return list;
  	}
  	
  	// get a list of all root regions
Set regions = cache.rootRegions();
Iterator itor = regions.iterator();

while (itor.hasNext()) {
	String regionPath = ((Region)itor.next()).getFullPath();

	Region region = cache.getRegion(regionPath);
	list.add(regionPath);
	Set subregionSet = region.subregions(true);
	if (recursive) {
		for (Iterator subIter = subregionSet.iterator(); subIter.hasNext(); ){
			list.add(((Region)subIter.next()).getFullPath());
		}
	}
}
Collections.sort(list);
return list;
  }
 
Example 17
Source File: DescribeDiskStoreFunction.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void setRegionDetails(final Region<?, ?> region, final DiskStore diskStore, final DiskStoreDetails diskStoreDetails) {
  if (isUsingDiskStore(region, diskStore)) {
    final String regionFullPath = region.getFullPath();
    final DiskStoreDetails.RegionDetails regionDetails = new DiskStoreDetails.RegionDetails(regionFullPath,
      StringUtils.defaultIfBlank(region.getName(), regionFullPath));
    regionDetails.setOverflowToDisk(isOverflowToDisk(region));
    regionDetails.setPersistent(isPersistent(region));
    diskStoreDetails.add(regionDetails);
  }

  for (Region<?, ?> subregion : region.subregions(false)) {
    setRegionDetails(subregion, diskStore, diskStoreDetails); // depth-first, recursive strategy
  }
}
 
Example 18
Source File: DistributedSQLTestBase.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static String getRegionsStr(Cache gfCache) {
  StringBuilder sb = new StringBuilder();
  sb.append("Available regions: \n");
  for (Object regionObj : gfCache.rootRegions()) {
    Region<?, ?> region = (Region<?, ?>)regionObj;
    sb.append("\tRoot region: " + region.getFullPath() + "\n");
    for (Object subRegionObj : region.subregions(true)) {
      Region<?, ?> subRegion = (Region<?, ?>)subRegionObj;
      sb.append("\t\tSubregion: " + subRegion.getFullPath() + "\n");
    }
  }
  return sb.toString();
}