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

The following examples show how to use com.gemstone.gemfire.cache.Region#createSubregion() . 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: PRColocationDUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static void createSubPR(String partitionedRegionName, Integer redundancy,
    Integer localMaxMemory, Integer totalNumBuckets, Object colocatedWith, Boolean isPartitionResolver) {
  PartitionAttributesFactory paf = new PartitionAttributesFactory();
  paf.setRedundantCopies(redundancy.intValue())
      .setLocalMaxMemory(localMaxMemory.intValue()).setTotalNumBuckets(
          totalNumBuckets.intValue()).setColocatedWith((String)colocatedWith);
  if(isPartitionResolver.booleanValue()){
    paf.setPartitionResolver(new CustomerIDPartitionResolver("CustomerIDPartitionResolver"));
  }
  PartitionAttributes prAttr = paf.create();
  AttributesFactory attr = new AttributesFactory();
  assertNotNull(basicGetCache());
  Region root = basicGetCache().createRegion("root"+partitionedRegionName, attr.create());
  attr.setPartitionAttributes(prAttr);
  Region pr = root.createSubregion(partitionedRegionName, attr.create());
  assertNotNull(pr);
  getLogWriter().info(
      "Partitioned sub region " + pr.getName()
          + " created Successfully :" + pr.toString());
  if(localMaxMemory == 0){
    putInPartitionedRegion(pr);
  }
}
 
Example 2
Source File: Bug33726DUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static void createCacheAndRegion2() {
  try {
    ds = (new Bug33726DUnitTest("temp")).getSystem(new Properties());
    cache = CacheFactory.create(ds);
    AttributesFactory factory = new AttributesFactory();
    factory.setCacheListener(new TestCacheListener());
    factory.setScope(Scope.GLOBAL);
    factory.setDataPolicy(DataPolicy.REPLICATE);
    RegionAttributes attr = factory.create();
    Region region = cache.createRegion("testRegion", attr);
    region.createSubregion("testSubRegion",attr);
 }
  catch (Exception ex) {
      fail("failed due to "+ex);
    ex.printStackTrace();
  }
}
 
Example 3
Source File: LRUClockTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private Region getARegion() throws Exception {
  DistributedSystem ds = DistributedSystem.connect( sysProps );
  Cache c = null;
  try {
    c = CacheFactory.create( ds );
  } catch ( CacheExistsException cee ) {
    c = CacheFactory.getInstance( ds ); 
  }
  AttributesFactory af = new AttributesFactory();
  Region root = c.getRegion("root");
  if ( root == null ) {
    root = c.createRegion("root", af.create() );
  }
  Region sub = root.createSubregion( myTestName, af.create() );
  return sub;
}
 
Example 4
Source File: PRColocationDUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static void createSubPR(String partitionedRegionName, Integer redundancy,
    Integer localMaxMemory, Integer totalNumBuckets, Object colocatedWith, Boolean isPartitionResolver) {
  PartitionAttributesFactory paf = new PartitionAttributesFactory();
  paf.setRedundantCopies(redundancy.intValue())
      .setLocalMaxMemory(localMaxMemory.intValue()).setTotalNumBuckets(
          totalNumBuckets.intValue()).setColocatedWith((String)colocatedWith);
  if(isPartitionResolver.booleanValue()){
    paf.setPartitionResolver(new CustomerIDPartitionResolver("CustomerIDPartitionResolver"));
  }
  PartitionAttributes prAttr = paf.create();
  AttributesFactory attr = new AttributesFactory();
  assertNotNull(basicGetCache());
  Region root = basicGetCache().createRegion("root"+partitionedRegionName, attr.create());
  attr.setPartitionAttributes(prAttr);
  Region pr = root.createSubregion(partitionedRegionName, attr.create());
  assertNotNull(pr);
  getLogWriter().info(
      "Partitioned sub region " + pr.getName()
          + " created Successfully :" + pr.toString());
  if(localMaxMemory == 0){
    putInPartitionedRegion(pr);
  }
}
 
Example 5
Source File: Bug33726JUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void testAfterRegionCreate() {
  Properties props = new Properties();
  DistributedSystem ds = DistributedSystem.connect(props);
  AttributesFactory factory = new AttributesFactory();
  factory.setCacheListener(new TestCacheListener());
  Cache cache = null;
  try {
    cache = CacheFactory.create(ds);
   
    Region region = cache.createRegion("testRegion", factory.create());
    region.createSubregion("testSubRegion",factory.create());
  }
  catch (Exception e) {
    fail("Failed to create cache due to " + e);
    e.printStackTrace();
  }
  
 
  if(!testFlag()){
    fail("After create sent although region was not initialized");
  }
}
 
Example 6
Source File: Bug33726DUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static void createCacheAndRegion2() {
  try {
    ds = (new Bug33726DUnitTest("temp")).getSystem(new Properties());
    cache = CacheFactory.create(ds);
    AttributesFactory factory = new AttributesFactory();
    factory.setCacheListener(new TestCacheListener());
    factory.setScope(Scope.GLOBAL);
    factory.setDataPolicy(DataPolicy.REPLICATE);
    RegionAttributes attr = factory.create();
    Region region = cache.createRegion("testRegion", attr);
    region.createSubregion("testSubRegion",attr);
 }
  catch (Exception ex) {
      fail("failed due to "+ex);
    ex.printStackTrace();
  }
}
 
Example 7
Source File: Bug33726DUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static void createCacheAndPopulateRegion1() {
  try {
    ds = (new Bug33726DUnitTest("temp")).getSystem(new Properties());
    cache = CacheFactory.create(ds);
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.GLOBAL);
    factory.setDataPolicy(DataPolicy.REPLICATE);
    RegionAttributes attr = factory.create();
    Region region = cache.createRegion("testRegion", attr);
    Region subRegion = region.createSubregion("testSubRegion",attr);
    for(int i=1; i < 100; i++){
      region.put(new Integer(i), new Integer(i));      
      subRegion.put(new Integer(i), new Integer(i));
    }
   }
  catch (Exception ex) {
    fail("Creation of cache failed due to "+ex);
    ex.printStackTrace();
  }
}
 
Example 8
Source File: SerialCompressionTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private synchronized static void InitializeSubRegions() {
  Region parentRegion = RegionHelper.createRegion(parentRegionName);

  Region subRegion;
  String[] subRegionNames = DeterminRegionNames();
  for (String subRegionName : subRegionNames) {
    AttributesFactory attributesFactory = RegionHelper.getAttributesFactory(subRegionName);
    RegionAttributes regionAttributes = attributesFactory.createRegionAttributes();
    RecoveryTestVersionHelper.createDiskStore(regionAttributes);
    subRegion = parentRegion.createSubregion(subRegionName, regionAttributes);
    testInstance.theRegions.add(subRegion);
  }

  testInstance.logRegionHierarchy();
}
 
Example 9
Source File: MemberCommandsDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void createRegionsWithSubRegions() {
  final Cache cache = getCache();
  
  RegionFactory<String, Integer> dataRegionFactory = cache.createRegionFactory(RegionShortcut.REPLICATE);
  dataRegionFactory.setConcurrencyLevel(3);
  Region<String, Integer> region1 = dataRegionFactory.create(REGION1);
  region1.createSubregion(SUBREGION1C, region1.getAttributes());
  Region<String, Integer> subregion2 = region1.createSubregion(SUBREGION1A, region1.getAttributes());
  
  subregion2.createSubregion(SUBREGION1B, subregion2.getAttributes());
  dataRegionFactory.create(REGION2);
  dataRegionFactory.create(REGION3);
}
 
Example 10
Source File: PartitionedRegionAsSubRegionDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void run2() throws CacheException
{
  Cache cache = getCache();
  RegionAttributes ra = createRegionAttributesForDACKRegions();
  Region parentRegion = cache.createRegion(parentRegionName, ra);
  parentRegion.createSubregion(childRegionName, ra);
}
 
Example 11
Source File: RecycleSystem.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
protected static void createRegion(String regionConfig, Cache cache, int noOfRegToBeCreated, boolean registerInterest)
{	
	logger.info("RecycleSystem:createRegion:: Number of more Region to be created " + noOfRegToBeCreated);
	String regInfo = "\n\t";
	
	for (int i=0; i < noOfRegToBeCreated; i++)
	{
		AttributesFactory factory = RegionHelper.getAttributesFactory(regionConfig);
		RegionAttributes attributes = RegionHelper.getRegionAttributes(factory);
		regInfo = "\n\t";
		
		String name = REGION_NAME+"_"+ absoluteRegionCount;
		absoluteRegionCount = absoluteRegionCount +1;
		
		Region reg = RegionHelper.createRegion(name, attributes);
		if(registerInterest)
			registerInterest(reg);
		populateRegion(reg);
		regInfo = regInfo + reg.getFullPath()+"\n\t";
		int j=0;
		int subRegs = conftab.intAt(RecyclePrms.regionDepth, 0);
		while (j < subRegs) {
				reg = reg.createSubregion(reg.getName() + "_" + j,
						attributes);
				if(registerInterest)
					registerInterest(reg);
				populateRegion(reg);
				regInfo = regInfo + reg.getFullPath() + "\n\t";
			j++;
		}
	}
	logger.info("RecycleSystem:createRegion:: Region Created " + regInfo);
}
 
Example 12
Source File: RegionOperations.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public String createSubRegion(String name){
  synchronized (availableRegions) {      
      Region parent = RegionHelper.getRegion(name);
      String subregionName = "child" + OperationsBlackboard.getBB().getNextRegionCounter();
      logInfo("RegionOperations: Creating subregion named : " + subregionName + " with parent " + parent.getFullPath());
      RegionAttributes attr= parent.getAttributes();
      Region child = parent.createSubregion(subregionName, attr);
      logInfo("RegionOperations: Created subregion named " + child.getFullPath());
      availableRegions.add(child);
      operationRecorder.regionAdded(child);
      return child.getFullPath();      
  }   
}
 
Example 13
Source File: StructMemberAcessTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testBugNumber_32354() {
  String queries[] = { "select distinct * from /root/portfolios.values, positions.values ",};
  int i = 0;
  try {
    tearDown();
    CacheUtils.startCache();
    Region rootRegion = CacheUtils.createRegion("root", null);
    AttributesFactory attributesFactory = new AttributesFactory();
    attributesFactory.setValueConstraint(Portfolio.class);
    RegionAttributes regionAttributes = attributesFactory
        .create();
    Region region = rootRegion
        .createSubregion("portfolios", regionAttributes);
    for (i = 0; i < 4; i++) {
      region.put("" + i, new Portfolio(i));
    }
    for (i = 0; i < queries.length; i++) {
      Query q = CacheUtils.getQueryService().newQuery(queries[i]);
      Object r = q.execute();
      System.out.println(Utils.printResult(r));
      StructType type = ((StructType) ((SelectResults) r).getCollectionType()
          .getElementType());
      String fieldNames[] = type.getFieldNames();
      for (i = 0; i < fieldNames.length; ++i) {
        String name = fieldNames[i];
        System.out.println("Struct Field name = " + name);
        if (name.equals("/root/portfolios")
            || name.equals("positions.values")) {
          fail("The field name in struct = " + name);
        }
      }
    }
  } catch (Exception e) {
    e.printStackTrace();
    fail(queries[i]);
  }
}
 
Example 14
Source File: CacheXml75Test.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "deprecation", "unchecked" })
public void testEnableOffHeapMemorySubRegionWithoutOffHeapMemoryThrowsException() {
  final String rootRegionName = getUniqueName();
  final String subRegionName = "subRegion";
  
  final CacheCreation cache = new CacheCreation();
  final RegionAttributesCreation rootRegionAttrs = new RegionAttributesCreation(cache);
  assertEquals(false, rootRegionAttrs.getEnableOffHeapMemory());
  
  final Region rootRegionBefore = cache.createRegion(rootRegionName, rootRegionAttrs);
  assertNotNull(rootRegionBefore);
  assertEquals(false, rootRegionBefore.getAttributes().getEnableOffHeapMemory());
  
  final RegionAttributesCreation subRegionAttrs = new RegionAttributesCreation(cache);
  subRegionAttrs.setEnableOffHeapMemory(true);
  assertEquals(true, subRegionAttrs.getEnableOffHeapMemory());
  
  final Region subRegionBefore = rootRegionBefore.createSubregion(subRegionName, subRegionAttrs);
  assertNotNull(subRegionBefore);
  assertEquals(true, subRegionBefore.getAttributes().getEnableOffHeapMemory());

  try {
    testXml(cache);
  } catch (IllegalStateException e) {
    // expected
    final String msg = "The region /" + rootRegionName + "/" + subRegionName +
        " was configured to use off heap memory but no off heap memory was configured.";
    assertEquals(msg, e.getMessage());
  }
}
 
Example 15
Source File: RegionOperations.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public String createSubRegion(String name){
  synchronized (availableRegions) {      
      Region parent = RegionHelper.getRegion(name);
      String subregionName = "child" + OperationsBlackboard.getBB().getNextRegionCounter();
      logInfo("RegionOperations: Creating subregion named : " + subregionName + " with parent " + parent.getFullPath());
      RegionAttributes attr= parent.getAttributes();
      Region child = parent.createSubregion(subregionName, attr);
      logInfo("RegionOperations: Created subregion named " + child.getFullPath());
      availableRegions.add(child);
      operationRecorder.regionAdded(child);
      return child.getFullPath();      
  }   
}
 
Example 16
Source File: DeltaClientPostAuthorizationDUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private static Region createSubregion(Region region) {

    Region subregion = getSubregion();
    if (subregion == null) {
      subregion = region.createSubregion(subregionName, region.getAttributes());
    }
    return subregion;
  }
 
Example 17
Source File: RegionUtil.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public static Region getRegion(String regionPath, Scope scope, DataPolicy dataPolicy, Pool pool,
		boolean enableBridgeConflation) throws CacheException
{
	Cache cache = null;
	Region region = null;

	try {
		cache = CacheFactory.getAnyInstance();
		region = cache.getRegion(regionPath);

		if (region != null) {
			return region;
		}
	} catch (CacheClosedException ex) {
		Properties props = new Properties();
		DistributedSystem system = DistributedSystem.connect(props);
		cache = CacheFactory.create(system);
	}

	// Parse region path
	StringTokenizer st = new StringTokenizer(regionPath, "/");
	String regionName;
	int index = 0;
	int count = st.countTokens();
	AttributesFactory factory = new AttributesFactory();
	factory.setDataPolicy(DataPolicy.NORMAL);

	while (st.hasMoreTokens()) {
		regionName = st.nextToken();
		index++;

		if (index == count) {
			factory.setDataPolicy(dataPolicy);
			factory.setPoolName(pool.getName());
		}

		if (index == 1) {
			region = cache.getRegion(regionName);

			if (region == null) {
				factory.setScope(scope);
				region = cache.createRegion(regionName, factory.create());
			}
		} else {
			Region subregion = region.getSubregion(regionName);
			if (subregion == null) {
				factory.setScope(scope);
				subregion = region.createSubregion(regionName, factory.create());
			}

			region = subregion;
		}
	}

	return region;
}
 
Example 18
Source File: CLITest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
private void createDataRegions(){
  RegionOperations regionOps = getRegionOperations();    
  logInfo("Creating data-regions on gemfire bridges : ");
  String dataRegionCreated = regionOps.createRegion(dataRegionName);
  dataStringRegion = RegionHelper.getRegion(dataRegionCreated);
  if(dataStringRegion==null)
    throw new TestException("Error in creating data region, its null");
  
  for(int i=0;i<1000;i++){
    dataStringRegion.put("KEY_"+i,"VALUE_"+i);
  }
  
  dataRegionCreated = regionOps.createRegion(jsonRegionName);
  dataJsonRegion = RegionHelper.getRegion(dataRegionCreated);
  if(dataJsonRegion==null)
    throw new TestException("Error in creating data region, its null");
  
  int numTopRegions = TestConfig.tab().intAt(GfshPrms.regionHierarchyWidth);
  int numChildRegions = TestConfig.tab().intAt(GfshPrms.regionHierarchyWidth);
  int regionCount = 0;
  int totalRegions = numTopRegions + numTopRegions*numChildRegions;
  regionHierarchyRegions = new Region[totalRegions];
  for(int i=0;i<numTopRegions;i++){
     String genName = regionOps.createRegion(childRegionNames);
     Region topRegion = RegionHelper.getRegion(genName);
     regionHierarchyRegions[regionCount++] = topRegion;
     Region parentRegion = topRegion;
     for(int j=0;j<numChildRegions;j++){
       logInfo("Creating subregion named " + (parentRegion.getName() +"_" + j));
       Region childRegion = parentRegion.createSubregion(parentRegion.getName() +"_" + j, parentRegion.getAttributes());
       logInfo("Created subregion named " + childRegion.getFullPath());
       regionHierarchyRegions[regionCount++] = childRegion;
       getRegionOperations().getOperationRecorder().regionAdded(childRegion);//manually generate events
       parentRegion = childRegion;         
     }
  }
  
  for(int i=0;i<1000;i++){
    Key1 key = new Key1();
    String keyId = "KEY_" + i;  
    key.setId(keyId);
    key.setName(keyId);
    Value2 value = new Value2();
    value.setStateName(key.toString());
    value.setAreaInSqKm(0);
    value.setCapitalCity(key.toString());
    value.setPopulation(0);
    dataJsonRegion.put(key,value);
  }
  
  for(int i=0;i<1000;i++){
    Region region = HydraUtil.getRandomElement(regionHierarchyRegions);
    region.put("KEY_"+i,"VALUE_"+i);
  }
  
  RegionEvents regionEvents = (RegionEvents) regionOps.getOperationRecorder();
  regionEvents.exportToBlackBoard(OperationsBlackboard.getBB());
  
  
  
  /*regionKeyValueConfigHL.set(value)
  EntryOperations eOps = getEntryOperations(dataRegion.getName());
  for(int i=0;i>1000;i++){
    eOps.add();
  }*/
  
  
}
 
Example 19
Source File: RegionCreateTask.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
private CommandResults createRegion()
{
	CommandResults results = new CommandResults();
	results.setCode(SUCCESS_CREATED);

	Cache cache = CacheFactory.getAnyInstance();
	MemberInfo memberInfo = new MemberInfo();
	DistributedMember member = cache.getDistributedSystem().getDistributedMember();
	memberInfo.setHost(member.getHost());
	memberInfo.setMemberId(member.getId());
	memberInfo.setMemberName(cache.getName());
	memberInfo.setPid(member.getProcessId());
	results.setDataObject(memberInfo);

	if (regionFullPath == null) {
		results.setCode(ERROR_REGION_INVALID_PATH);
		results.setCodeMessage("Invalid region path: " + regionFullPath);
		return results;
	}
	int index = regionFullPath.lastIndexOf("/");
	if (index == regionFullPath.length() - 1) {
		results.setCode(ERROR_REGION_INVALID_PATH);
		results.setCodeMessage("Invalid region path: " + regionFullPath);
		return results;
	}

	String regionName = regionFullPath.substring(index + 1);
	try {

		Region region = cache.getRegion(regionFullPath);
		if (region != null) {
			results.setCode(ERROR_REGION_ALREADY_EXIST);
			results.setCodeMessage("Region already exist: " + regionFullPath);
		} else {
			Region parentRegion = RegionUtil.getParentRegion(regionFullPath);
			if (parentRegion == null) {
				if (regionFullPath.split("/").length > 2) {
					results.setCode(ERROR_REGION_PARENT_DOES_NOT_EXIST);
					results.setCodeMessage("Parent region does not exist: " + regionFullPath);
				} else {
					if (attrInfo == null) {
						region = cache.createRegion(regionName, new AttributesFactory().create());
					} else {
						region = cache.createRegion(regionName, attrInfo.createRegionAttributes());
					}
					if (region == null) {
						results.setCode(ERROR_REGION_NOT_CREATED);
						results.setCodeMessage("Unable create region: " + regionFullPath);
					} else {
						results.setCodeMessage("Region created: " + region.getFullPath());
					}
				}
			} else {
				if (attrInfo == null) {
					region = parentRegion.createSubregion(regionName, new AttributesFactory().create());
				} else {
					region = parentRegion.createSubregion(regionName, attrInfo.createRegionAttributes());
				}
				if (region == null) {
					results.setCode(ERROR_REGION_NOT_CREATED);
					results.setCodeMessage("Unable create region: " + regionFullPath);
				} else {
					results.setCodeMessage("Region created: " + region.getFullPath());
				}
			}
		}
	} catch (CacheException ex) {
		results.setCode(ERROR_REGION_NOT_CREATED);
		results.setException(ex);
	}
	return results;
}
 
Example 20
Source File: CacheXml57Test.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Test both customEntryIdleTime and customEntryTimeToLife
 */
public void testCustomEntryXml() {
  CacheCreation cache = new CacheCreation();

  RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
  attrs.setScope(Scope.DISTRIBUTED_NO_ACK);

  RegionCreation root =
    (RegionCreation) cache.createRegion("root", attrs);

  {
    attrs = new RegionAttributesCreation(cache);
    attrs.setScope(Scope.DISTRIBUTED_NO_ACK);
    attrs.setInitialCapacity(142);
    attrs.setLoadFactor(42.42f);
    attrs.setStatisticsEnabled(true);
    attrs.setCustomEntryIdleTimeout(new Expiry1());
    attrs.setCustomEntryTimeToLive(new Expiry5());

    root.createSubregion("one", attrs);
  }

  {
    attrs = new RegionAttributesCreation(cache);
    attrs.setScope(Scope.DISTRIBUTED_ACK);
    attrs.setInitialCapacity(242);
    attrs.setStatisticsEnabled(true);
    attrs.setCustomEntryIdleTimeout(new Expiry2());

    Region region = root.createSubregion("two", attrs);

    {
      attrs = new RegionAttributesCreation(cache);
      attrs.setScope(Scope.DISTRIBUTED_ACK);
      attrs.setLoadFactor(43.43f);
      attrs.setStatisticsEnabled(true);
      attrs.setCustomEntryIdleTimeout(new Expiry3());
      attrs.setCustomEntryTimeToLive(new Expiry4());

      region.createSubregion("three", attrs);
    }
  }

  testXml(cache);
}