本文整理汇总了Java中com.gemstone.gemfire.cache.Cache.createRegion方法的典型用法代码示例。如果您正苦于以下问题:Java Cache.createRegion方法的具体用法?Java Cache.createRegion怎么用?Java Cache.createRegion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.gemstone.gemfire.cache.Cache
的用法示例。
在下文中一共展示了Cache.createRegion方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createColocatedPRs
import com.gemstone.gemfire.cache.Cache; //导入方法依赖的package包/类
/**
* Create three PRs on a VM, named region1, region2, and region3.
* The colocated with attribute describes which region region3
* should be colocated with.
* @param vm0
* @param colocatedWith
*/
private void createColocatedPRs(final String colocatedWith) {
Cache cache = getCache();
DiskStore ds = cache.findDiskStore("disk");
if(ds == null) {
ds = cache.createDiskStoreFactory()
.setDiskDirs(getDiskDirs()).create("disk");
}
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(0);
af.setPartitionAttributes(paf.create());
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk");
cache.createRegion("region1", af.create());
cache.createRegion("region2", af.create());
if(colocatedWith != null) {
paf.setColocatedWith(colocatedWith);
}
af.setPartitionAttributes(paf.create());
cache.createRegion("region3", af.create());
}
示例2: testConcurrentOperations
import com.gemstone.gemfire.cache.Cache; //导入方法依赖的package包/类
/**
* This is a for the ConcurrentMap operations.
* 4 VMs are used to
* create the region and operations are performed on one of the nodes
*/
public void testConcurrentOperations() throws Exception {
SerializableRunnable createRegion = new CacheSerializableRunnable(
"createRegion") {
public void run2() throws CacheException {
Cache cache = getCache();
RegionAttributes regionAttribs = getRegionAttributes();
cache.createRegion("R1",
regionAttribs);
}
};
Host host = Host.getHost(0);
// create the VM(0 - 4)
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
VM vm3 = host.getVM(3);
vm0.invoke(createRegion);
vm1.invoke(createRegion);
vm2.invoke(createRegion);
vm3.invoke(createRegion);
concurrentMapTest("/R1");
}
示例3: doClientTest
import com.gemstone.gemfire.cache.Cache; //导入方法依赖的package包/类
private void doClientTest(final boolean clone, final boolean copyOnRead) throws Exception {
AccessorFactory factory = new AccessorFactory() {
public Region<Integer, TestDelta> createRegion(Host host, Cache cache, int port1,
int port2) {
AttributesFactory<Integer, TestDelta> attr = new AttributesFactory<Integer, TestDelta>();
PoolFactory pf = PoolManager.createFactory();
pf.addServer(getServerHostName(host), port1);
pf.addServer(getServerHostName(host), port2);
pf.create("pool");
attr.setCloningEnabled(clone);
attr.setDataPolicy(DataPolicy.EMPTY);
attr.setScope(Scope.LOCAL);
attr.setPoolName("pool");
Region<Integer, TestDelta> region = cache.createRegion("region1", attr.create());
return region;
}
};
doTest(factory, clone, copyOnRead);
}
示例4: getARegion
import com.gemstone.gemfire.cache.Cache; //导入方法依赖的package包/类
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;
}
示例5: createClientCache
import com.gemstone.gemfire.cache.Cache; //导入方法依赖的package包/类
public Cache createClientCache(String host, Integer port1) throws Exception {
Properties props = new Properties();
props.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
props.setProperty(DistributionConfig.LOCATORS_NAME, "");
Cache cache = createCache(props);
PoolImpl p = (PoolImpl) PoolManager.createFactory()
.addServer(host, port1.intValue()).setSubscriptionEnabled(false)
.setThreadLocalConnections(true).setMinConnections(1)
.setReadTimeout(20000).setPingInterval(10000).setRetryAttempts(1)
.setSubscriptionEnabled(true).setStatisticInterval(1000)
.create("CacheServerManagementDUnitTest");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setPoolName(p.getName());
RegionAttributes attrs = factory.create();
Region region = cache.createRegion(REGION_NAME, attrs);
return cache;
}
示例6: createLDMRegion
import com.gemstone.gemfire.cache.Cache; //导入方法依赖的package包/类
private Region createLDMRegion(String regionName) throws ParseException {
IndexManager.IS_TEST_LDM = true;
Cache cache = CacheUtils.getCache();
AttributesFactory attributesFactory = new AttributesFactory();
attributesFactory.setDataPolicy(DataPolicy.REPLICATE);
RegionAttributes regionAttributes = attributesFactory.create();
return cache.createRegion(regionName, regionAttributes);
}
示例7: createSecondLocalRegion
import com.gemstone.gemfire.cache.Cache; //导入方法依赖的package包/类
private void createSecondLocalRegion() {
Cache cache = CacheUtils.getCache();
AttributesFactory attributesFactory = new AttributesFactory();
attributesFactory.setDataPolicy(DataPolicy.NORMAL);
RegionAttributes regionAttributes = attributesFactory.create();
Region region = cache.createRegion(exampleRegionName, regionAttributes);
for(int i=1; i<=numElem; i++) {
Portfolio obj = new Portfolio(i);
region.put(i, obj);
System.out.println(obj);
}
}
示例8: generateDummyRegion
import com.gemstone.gemfire.cache.Cache; //导入方法依赖的package包/类
/**
* Generates a dummy region from the given cache, region configuration, and
* region name.
*/
private static void generateDummyRegion(Cache dummyCache, String regionConfig,
String regionName, String fn) {
if (regionConfig != null) {
// create and configure the dummy region
log("Creating dummy region attributes from config: " + regionConfig);
RegionDescription rd = RegionHelper.getRegionDescription(regionConfig);
AttributesFactory regFactory = new AttributesFactory();
rd.configure(regionName, regFactory, false);
RegionAttributes dummyRatts =
CacheVersionHelper.getDummyRegionAttributes(dummyCache,
regFactory.create());
String rName = regionName;
if (rName == null) {
rName = RegionHelper.getRegionDescription(regionConfig).getRegionName();
}
log("Creating dummy region named: " + rName + " with attributes: "
+ RegionHelper.regionAttributesToString(dummyRatts));
try {
Region region = dummyCache.createRegion(rName, dummyRatts);
log("Created dummy region named: " + rName);
} catch (RegionExistsException e) {
throw new HydraInternalException("Should not happen", e);
}
// save the region config for future reference
XmlRegionConfigs.put(fn, regionConfig);
}
}
示例9: createUserDefinedRegion
import com.gemstone.gemfire.cache.Cache; //导入方法依赖的package包/类
/**
* Creates user defined regions based on the region attributes specified.
*
*/
protected static void createUserDefinedRegion(Cache cache) {
Vector regionNames = TestConfig.tab().vecAt(RegionPrms.names, null);
logger
.info("RecycleSystem:createRegion:: Number of more Region to be created "
+ regionNames.size());
for (int i = 0; i < regionNames.size(); i++) {
String regionDescriptName = (String) (regionNames.get(i));
Region aRegion = null;
String regionName = RegionHelper.getRegionDescription(regionDescriptName)
.getRegionName();
try {
aRegion = cache.createRegion(regionName, RegionHelper
.getRegionAttributes(regionDescriptName));
Log.getLogWriter().info(
"Created region " + regionName + " with region descript name "
+ regionDescriptName);
populateRegion(aRegion);
} catch (RegionExistsException e) {
// region already exists; ok
Log.getLogWriter().info("Using existing region " + regionName);
aRegion = e.getRegion();
if (aRegion == null) {
throw new TestException(
"RegionExistsException.getRegion returned null");
}
}
}
}
示例10: startBridgeServerInVM
import com.gemstone.gemfire.cache.Cache; //导入方法依赖的package包/类
protected int startBridgeServerInVM(final VM vm, final String[] groups,
String locators, final String[] regions) {
SerializableCallable connect =
new SerializableCallable("Start bridge server") {
public Object call() throws IOException {
Properties props = new Properties();
props.setProperty(DistributionConfig.MCAST_PORT_NAME, String.valueOf(mCastPort));
props.setProperty(DistributionConfig.MCAST_ADDRESS_NAME, DistributionConfig.DEFAULT_MCAST_ADDRESS.getHostAddress());
props.setProperty(DistributionConfig.LOCATORS_NAME, "");
props.setProperty(DistributionConfig.BIND_ADDRESS_NAME,
getServerHostName(vm.getHost()));
DistributedSystem ds = getSystem(props);
Cache cache = CacheFactory.create(ds);
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setEnableBridgeConflation(true);
factory.setDataPolicy(DataPolicy.REPLICATE);
RegionAttributes attrs = factory.create();
for(int i = 0; i < regions.length; i++) {
cache.createRegion(regions[i], attrs);
}
BridgeServer server = cache.addBridgeServer();
final int serverPort = AvailablePortHelper.getRandomAvailableTCPPort();
server.setPort(serverPort);
server.setGroups(groups);
server.start();
remoteObjects.put(CACHE_KEY, cache);
return new Integer(serverPort);
}
};
Integer port = (Integer) vm.invoke(connect);
return port.intValue();
}
示例11: bug41118
import com.gemstone.gemfire.cache.Cache; //导入方法依赖的package包/类
public static void bug41118(){
InternalDistributedSystem ds = new DistributedRegionFunctionExecutionDUnitTest("temp").getSystem();
assertNotNull(ds);
ds.disconnect();
Properties props = new Properties();
props.setProperty("mcast-port", "0");
ds = (InternalDistributedSystem)DistributedSystem.connect(props);
DM dm = ds.getDistributionManager();
assertEquals("Distributed System is not loner", true, dm instanceof LonerDistributionManager);
Cache cache = CacheFactory.create(ds);
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setDataPolicy(DataPolicy.REPLICATE);
assertNotNull(cache);
region = cache.createRegion(REGION_NAME, factory.create());
try {
executeInlineFunction();
ds.disconnect();
}
catch (Exception e) {
getLogWriter().info("Exception Occured : " + e.getMessage());
e.printStackTrace();
fail("Test failed", e);
}
}
示例12: main4
import com.gemstone.gemfire.cache.Cache; //导入方法依赖的package包/类
/**
* Byte arrays
*/
public static void main4(String[] args) throws Exception {
DistributedSystem system =
DistributedSystem.connect(new java.util.Properties());
Cache cache = CacheFactory.create(system);
AttributesFactory factory = new AttributesFactory();
factory.setEvictionAttributes(EvictionAttributes
.createLRUMemoryAttributes(2, (ObjectSizer) null, EvictionAction.OVERFLOW_TO_DISK));
LocalRegion region = (LocalRegion)
cache.createRegion("TestDiskRegion",
factory.create());
// DiskRegion dr = region.getDiskRegion();
// DiskRegionStats diskStats = dr.getStats();
// LRUStatistics lruStats = getLRUStats(region);
// int total;
// for (total = 0; lruStats.getEvictions() > 100; total++) {
// region.put(new Integer(total), String.valueOf(total).getBytes());
// }
// for (int i = 0; i < total; i++) {
// byte[] bytes = (byte[]) region.get(new Integer(i));
// Assert.assertTrue((new String(bytes)).equals(String.valueOf(i)));
// }
for (int i = 0; i < 100000; i++) {
System.out.println(i);
region.put(String.valueOf(i), String.valueOf(i).getBytes());
}
}
示例13: createPartitionedRegion
import com.gemstone.gemfire.cache.Cache; //导入方法依赖的package包/类
private Region createPartitionedRegion(String regionName) throws ParseException {
Cache cache = CacheUtils.getCache();
PartitionAttributesFactory prAttFactory = new PartitionAttributesFactory();
AttributesFactory attributesFactory = new AttributesFactory();
attributesFactory.setPartitionAttributes(prAttFactory.create());
RegionAttributes regionAttributes = attributesFactory.create();
return cache.createRegion(regionName, regionAttributes);
}
示例14: run2
import com.gemstone.gemfire.cache.Cache; //导入方法依赖的package包/类
public void run2() throws CacheException
{
Cache cache = getCache();
RegionAttributes ra = createRegionAttributesForDACKRegions();
Region parentRegion = cache.createRegion(parentRegionName, ra);
parentRegion.createSubregion(childRegionName, ra);
}
示例15: createLocalRegion
import com.gemstone.gemfire.cache.Cache; //导入方法依赖的package包/类
/******** Region Creation Helper Methods *********/
private Region createLocalRegion(String regionName) throws ParseException {
Cache cache = CacheUtils.getCache();
AttributesFactory attributesFactory = new AttributesFactory();
attributesFactory.setDataPolicy(DataPolicy.NORMAL);
RegionAttributes regionAttributes = attributesFactory.create();
return cache.createRegion(regionName, regionAttributes);
}