本文整理汇总了Java中com.gemstone.gemfire.cache.Cache类的典型用法代码示例。如果您正苦于以下问题:Java Cache类的具体用法?Java Cache怎么用?Java Cache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Cache类属于com.gemstone.gemfire.cache包,在下文中一共展示了Cache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testIsServing
import com.gemstone.gemfire.cache.Cache; //导入依赖的package包/类
@Test
public void testIsServing() {
final Cache mockCache = mockContext.mock(Cache.class, "Cache");
final CacheServer mockCacheServer = mockContext.mock(CacheServer.class, "CacheServer");
mockContext.checking(new Expectations() {{
oneOf(mockCache).getCacheServers();
will(returnValue(Collections.singletonList(mockCacheServer)));
}});
final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").build();
assertNotNull(serverLauncher);
assertEquals("serverOne", serverLauncher.getMemberName());
assertTrue(serverLauncher.isServing(mockCache));
}
示例2: testPDXObject
import com.gemstone.gemfire.cache.Cache; //导入依赖的package包/类
public void testPDXObject() {
final Properties props = new Properties();
props.setProperty(DistributionConfig.MCAST_ADDRESS_NAME, "239.192.81.10");
DistributedSystem.connect(props);
Cache cache = new CacheFactory().create();
PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
Portfolio p = new Portfolio(2);
pf.writeInt("ID", 111);
pf.writeString("status", "active");
pf.writeString("secId", "IBM");
pf.writeObject("portfolio", p);
PdxInstance pi = pf.create();
TypedJson tJsonObj = new TypedJson(RESULT,pi);
System.out.println(tJsonObj);
cache.close();
}
示例3: getHARegionQueueInstance
import com.gemstone.gemfire.cache.Cache; //导入依赖的package包/类
/**
* Creates a HARegionQueue object with default attributes.
* used by tests
*
* @param regionName
* @param cache
* @param hrqa
* @param haRgnQType
* @param isDurable
* @return an instance of HARegionQueue
* @throws IOException
* @throws ClassNotFoundException
* @throws CacheException
* @throws InterruptedException
* @since 5.7
*/
public static HARegionQueue getHARegionQueueInstance(String regionName,
Cache cache, HARegionQueueAttributes hrqa, final int haRgnQType,
final boolean isDurable)
throws IOException, ClassNotFoundException, CacheException, InterruptedException
{
Map container = null;
if (haRgnQType == HARegionQueue.BLOCKING_HA_QUEUE) {
container = new HAContainerMap(new HashMap());
}
else {
// Should actually be HAContainerRegion, but ok if only JUnits using this
// method.
container = new HashMap();
}
return getHARegionQueueInstance(regionName, (GemFireCacheImpl)cache, hrqa, haRgnQType,
isDurable, container, null, HandShake.CONFLATION_DEFAULT, false, Boolean.FALSE);
}
示例4: invokeRegionEntryPut
import com.gemstone.gemfire.cache.Cache; //导入依赖的package包/类
public static void invokeRegionEntryPut() {
int noOfEntity = conftab.intAt(RecyclePrms.numberOfEntitiesInRegion, 0);
Cache cache = CacheFactory.getInstance(DistributedSystemHelper.getDistributedSystem());
Object[] regionList = cache.rootRegions().toArray();
int numRegs = regionList.length;
for (int i = 0; i < numRegs; i++) {
Region reg = (Region)regionList[i];
if (!(reg instanceof HARegion)) {
Set keys = reg.keySet();
Iterator ite=keys.iterator();
for (int j = 0; ite.hasNext() && j < noOfEntity ; j++ ) {
Object key = ite.next();
reg.put(key,key);
}
}
}
}
示例5: createPersistentRegionAsync
import com.gemstone.gemfire.cache.Cache; //导入依赖的package包/类
/**
* Creates a persistent region in async manner
*
* @param vm
* reference to VM
* @return reference to AsyncInvocation
*/
@SuppressWarnings("serial")
protected AsyncInvocation createPersistentRegionAsync(final VM vm) {
SerializableRunnable createRegion = new SerializableRunnable(
"Create persistent region") {
public void run() {
Cache cache = getCache();
DiskStoreFactory dsf = cache.createDiskStoreFactory();
File dir = getDiskDirForVM(vm);
dir.mkdirs();
dsf.setDiskDirs(new File[] { dir });
dsf.setMaxOplogSize(1);
dsf.setAllowForceCompaction(true);
dsf.setAutoCompact(false);
DiskStore ds = dsf.create(REGION_NAME);
RegionFactory rf = cache.createRegionFactory();
rf.setDiskStoreName(ds.getName());
rf.setDiskSynchronous(true);
rf.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
rf.setScope(Scope.DISTRIBUTED_ACK);
rf.create(REGION_NAME);
}
};
return vm.invokeAsync(createRegion);
}
示例6: testPersistenceExplicitDiskStore
import com.gemstone.gemfire.cache.Cache; //导入依赖的package包/类
public void testPersistenceExplicitDiskStore() throws Throwable {
SerializableCallable createRegion = new SerializableCallable() {
public Object call() throws Exception {
//Make sure the type registry is persistent
CacheFactory cf = new CacheFactory();
cf.setPdxPersistent(true);
cf.setPdxDiskStore("store1");
Cache cache = getCache(cf);
cache.createDiskStoreFactory()
.setMaxOplogSize(1)
.setDiskDirs(getDiskDirs())
.create("store1");
AttributesFactory af = new AttributesFactory();
af.setScope(Scope.DISTRIBUTED_ACK);
af.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
af.setDiskStoreName("store1");
createRootRegion("testSimplePdx", af.create());
return null;
}
};
persistenceTest(createRegion);
}
示例7: testQueriesOnLocalRegion
import com.gemstone.gemfire.cache.Cache; //导入依赖的package包/类
/**
* Test on Local Region data
*/
public void testQueriesOnLocalRegion() {
Cache cache = CacheUtils.getCache();
createLocalRegion();
assertNotNull(cache.getRegion(regionName));
assertEquals(numElem * 2, cache.getRegion(regionName).size());
QueryService queryService = cache.getQueryService();
Query query1 = null;
try {
for (String queryStr : queries) {
query1 = queryService.newQuery(queryStr);
SelectResults result1 = (SelectResults) query1.execute();
assertEquals(queryStr, numElem * 2, result1.size());
verifyDistinctResults(result1);
}
} catch (Exception e) {
e.printStackTrace();
fail("Query " + query1 + " Execution Failed!");
}
// Destroy current Region for other tests
cache.getRegion(regionName).destroyRegion();
}
示例8: testMembershipPortRangeWithExactThreeValues
import com.gemstone.gemfire.cache.Cache; //导入依赖的package包/类
public void testMembershipPortRangeWithExactThreeValues() throws Exception {
Properties config = new Properties();
int mcastPort = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS);
config.setProperty("mcast-port", String.valueOf(mcastPort));
config.setProperty("locators", "");
config.setProperty(DistributionConfig.MEMBERSHIP_PORT_RANGE_NAME, ""
+ (DistributionConfig.DEFAULT_MEMBERSHIP_PORT_RANGE[1] - 2) + "-"
+ (DistributionConfig.DEFAULT_MEMBERSHIP_PORT_RANGE[1]));
system = (InternalDistributedSystem)DistributedSystem.connect(config);
Cache cache = CacheFactory.create(system);
cache.addCacheServer();
DistributionManager dm = (DistributionManager) system.getDistributionManager();
InternalDistributedMember idm = dm.getDistributionManagerId();
system.disconnect();
assertTrue(idm.getPort() <= DistributionConfig.DEFAULT_MEMBERSHIP_PORT_RANGE[1]);
assertTrue(idm.getPort() >= DistributionConfig.DEFAULT_MEMBERSHIP_PORT_RANGE[0]);
assertTrue(idm.getDirectChannelPort() <= DistributionConfig.DEFAULT_MEMBERSHIP_PORT_RANGE[1]);
assertTrue(idm.getDirectChannelPort() >= DistributionConfig.DEFAULT_MEMBERSHIP_PORT_RANGE[0]);
}
示例9: testIsDefaultServerEnabledWhenCacheServersExist
import com.gemstone.gemfire.cache.Cache; //导入依赖的package包/类
@Test
public void testIsDefaultServerEnabledWhenCacheServersExist() {
final Cache mockCache = mockContext.mock(Cache.class, "Cache");
final CacheServer mockCacheServer = mockContext.mock(CacheServer.class, "CacheServer");
mockContext.checking(new Expectations() {{
oneOf(mockCache).getCacheServers();
will(returnValue(Collections.singletonList(mockCacheServer)));
}});
final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").setDisableDefaultServer(false).build();
assertNotNull(serverLauncher);
assertEquals("serverOne", serverLauncher.getMemberName());
assertFalse(serverLauncher.isDisableDefaultServer());
assertFalse(serverLauncher.isDefaultServerEnabled(mockCache));
}
示例10: testDefaultPartitionWhenNoConditionForDefaultExists
import com.gemstone.gemfire.cache.Cache; //导入依赖的package包/类
public void testDefaultPartitionWhenNoConditionForDefaultExists()
throws SQLException, StandardException {
Connection conn = getConnection();
Statement s = conn.createStatement();
s.execute("create schema EMP");
Cache cache = CacheFactory.getAnyInstance();
s
.execute("create table EMP.PARTITIONTESTTABLE (ID int, SECONDID int, THIRDID int)");
Region regtwo = cache.getRegion("/EMP/PARTITIONTESTTABLE");
RegionAttributes rattr = regtwo.getAttributes();
PartitionResolver pr = rattr.getPartitionAttributes()
.getPartitionResolver();
assertNotNull(pr);
GfxdPartitionByExpressionResolver scpr = (GfxdPartitionByExpressionResolver)pr;
assert(scpr.isDefaultPartitioning());
assertEquals(0, scpr.getColumnNames().length);
EntryOperationImpl dEntryOp = new EntryOperationImpl(null, null,
new Integer(10), null, null);
Serializable srobj = scpr.getRoutingObject(dEntryOp);
Integer robj = (Integer)srobj;
assertEquals(10, robj.intValue());
}
示例11: run2
import com.gemstone.gemfire.cache.Cache; //导入依赖的package包/类
public void run2() throws CacheException
{
Cache cache = getCache();
Region parentRegion = cache
.getRegion(Region.SEPARATOR + parentRegionName);
Region childRegion = null;
childRegion = parentRegion.createSubregion(childRegionName, parentRegion
.getAttributes());
PartitionedRegion pr = null;
pr = (PartitionedRegion)cache.getRegion(Region.SEPARATOR
+ parentRegionName + Region.SEPARATOR + childRegionName
+ Region.SEPARATOR + PR_PREFIX);
if (pr != null)
fail("PR strill exists");
pr = (PartitionedRegion)childRegion.createSubregion(PR_PREFIX,
createRegionAttributesForPR(1, 200));
// Assert.assertTrue(pr.getBucket2Node().size()==0, "B2N cleanup was not
// done");
assertEquals(0, pr.getRegionAdvisor().getCreatedBucketsCount());
}
示例12: init
import com.gemstone.gemfire.cache.Cache; //导入依赖的package包/类
public void init(Principal principal,
DistributedMember remoteMember,
Cache cache) throws NotAuthorizedException {
if (principal != null) {
String name = principal.getName().toLowerCase();
if (name != null) {
if (name.equals("root") || name.equals("admin")
|| name.equals("administrator")) {
addReaderOps();
addWriterOps();
this.allowedOps.add(OperationCode.REGION_CREATE);
this.allowedOps.add(OperationCode.REGION_DESTROY);
}
else if (name.startsWith("writer")) {
addWriterOps();
}
else if (name.startsWith("reader")) {
addReaderOps();
}
}
}
this.remoteDistributedMember = remoteMember;
this.logger = cache.getSecurityLogger();
}
示例13: execute
import com.gemstone.gemfire.cache.Cache; //导入依赖的package包/类
public void execute(FunctionContext context) {
final String [] args = (String [])context.getArguments();
final String regionName = args[0];
final String importFileName = args[1];
try {
final Cache cache = CacheFactory.getAnyInstance();
final Region<?,?> region = cache.getRegion(regionName);
final String hostName = cache.getDistributedSystem().getDistributedMember().getHost();
if (region != null) {
RegionSnapshotService<?, ?> snapshotService = region.getSnapshotService();
File importFile = new File(importFileName);
snapshotService.load(new File(importFileName), SnapshotFormat.GEMFIRE);
String successMessage = CliStrings.format(CliStrings.IMPORT_DATA__SUCCESS__MESSAGE, importFile.getCanonicalPath(), hostName, regionName);
context.getResultSender().lastResult(successMessage);
} else {
throw new IllegalArgumentException(CliStrings.format(CliStrings.REGION_NOT_FOUND, regionName));
}
} catch (Exception e) {
context.getResultSender().sendException(e);
}
}
示例14: setupForGC
import com.gemstone.gemfire.cache.Cache; //导入依赖的package包/类
void setupForGC(){
final VM vm1 = Host.getHost(0).getVM(1);
final VM vm2 = Host.getHost(0).getVM(2);
createDefaultSetup(null);
vm1.invoke(new SerializableRunnable() {
public void run() {
// no need to close cache as it will be closed as part of teardown2
Cache cache = getCache();
RegionFactory<Integer, Integer> dataRegionFactory = cache
.createRegionFactory(RegionShortcut.PARTITION);
Region region = dataRegionFactory.create("testRegion");
for (int i = 0; i < 10; i++) {
region.put("key" + (i + 200), "value" + (i + 200));
}
}
});
}
示例15: createRegion
import com.gemstone.gemfire.cache.Cache; //导入依赖的package包/类
private Region<Integer, MyObject> createRegion(final RegionType rt, final SerializationType st) throws Exception {
final String name = "snapshot-" + rt.name() + "-" + st.name();
Region<Integer, MyObject> region = getCache().getRegion(name);
if (region != null) {
region.destroyRegion();
}
SerializableCallable setup = new SerializableCallable() {
@Override
public Object call() throws Exception {
Cache cache = getCache();
new RegionGenerator().createRegion(cache, null, rt, name);
return null;
}
};
SnapshotDUnitTest.forEachVm(setup, true);
return getCache().getRegion(name);
}