/** * Sets the cache loader for the next {@code RegionAttributes} created. * * @param cacheLoader the cache loader or null if no loader * @return a reference to this RegionFactory object * @see AttributesFactory#setCacheLoader * */ public RegionFactory<K, V> setCacheLoader(CacheLoader<K, V> cacheLoader) { this.attrsFactory.setCacheLoader(cacheLoader); return this; }
result .setCacheLoaderClass(new ClassName<>(foundRegion.getCacheLoader().getClass().getName())); afactory.setCacheLoader(null);
public static void createReplicatedRegionWithCacheLoaderAndAsyncEventQueue(String regionName, String asyncQueueIds) { AttributesFactory fact = new AttributesFactory(); addAsyncEventQueueIds(fact, asyncQueueIds); fact.setDataPolicy(DataPolicy.REPLICATE); // set the CacheLoader fact.setCacheLoader(new MyCacheLoader()); RegionFactory regionFactory = cache.createRegionFactory(fact.create()); Region r = regionFactory.create(regionName); assertNotNull(r); }
factory.setEntryTimeToLive(expire); factory.setStatisticsEnabled(true); factory.setCacheLoader(new TestCacheLoader() { @Override public Object load2(LoaderHelper helper) {
@Override public void run2() throws CacheException { RegionAttributes<Object, Object> ra = getRegionAttributes(); AttributesFactory<Object, Object> factory = new AttributesFactory<>(ra); if (ra.getEvictionAttributes() == null || !ra.getEvictionAttributes().getAction().isOverflowToDisk()) { factory.setDiskStoreName(null); } factory.setDataPolicy(DataPolicy.REPLICATE); setLoader(new TestCacheLoader<Object, Object>() { @Override public Object load2(LoaderHelper<Object, Object> helper) throws CacheLoaderException { fail("Should not be invoked"); return null; } }); factory.setCacheLoader(loader()); createRegion(name, factory.create()); } };
f.setCacheLoader(loader1); Region<Object, Object> region = createRegion(name, f.create());
public static void createPartitionedRegionWithCacheLoaderAndAsyncQueue(String regionName, String asyncEventQueueId) { AttributesFactory fact = new AttributesFactory(); PartitionAttributesFactory pfact = new PartitionAttributesFactory(); pfact.setTotalNumBuckets(16); fact.setPartitionAttributes(pfact.create()); // set the CacheLoader implementation fact.setCacheLoader(new MyCacheLoader()); Region r = cache.createRegionFactory(fact.create()).addAsyncEventQueueId(asyncEventQueueId) .create(regionName); assertNotNull(r); }
f.setCacheLoader(loader1); Region<Object, Object> region = createRegion(name, f.create());
@Override public void run2() { try { AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.DISTRIBUTED_ACK); // can't be local since used with // registerInterest factory.setCacheLoader(new CacheServerCacheLoader()); beginCacheXml(); createRootRegion(rName, factory.create()); startBridgeServer(port); finishCacheXml(rName + "-" + port); Region region = getRootRegion(rName); assertNotNull(region); region.put(BridgeServerKey, new Integer(port)); // A unique key/value to identify the // BridgeServer } catch (Exception e) { getSystem().getLogWriter().severe(e); fail("Failed to start CacheServer " + e); } } });
public final <K, V> Region<K, V> createRegion(final String name, final String rootName, final RegionAttributes<K, V> attributes) throws CacheException { Region<K, V> root = getRootRegion(rootName); if (root == null) { // don't put listeners on root region AttributesFactory<K, V> attributesFactory = new AttributesFactory<>(attributes); ExpirationAttributes expiration = ExpirationAttributes.DEFAULT; attributesFactory.setCacheLoader(null); attributesFactory.setCacheWriter(null); attributesFactory.setPoolName(null); attributesFactory.setPartitionAttributes(null); attributesFactory.setRegionTimeToLive(expiration); attributesFactory.setEntryTimeToLive(expiration); attributesFactory.setRegionIdleTimeout(expiration); attributesFactory.setEntryIdleTimeout(expiration); RegionAttributes<K, V> rootAttrs = attributesFactory.create(); root = createRootRegion(rootName, rootAttrs); } return root.createSubregion(name, attributes); }
public static void main(String[] args) throws Exception { Region currRegion; Cache cache = null; // DistributedSystem system = null; // HashMap regionDefaultAttrMap = new HashMap(); tableName = CacheUtils.init("TestXACache"); cache = CacheUtils.getCache(); currRegion = cache.getRegion("root"); try { Context ctx = cache.getJNDIContext(); UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction"); utx.begin(); AttributesFactory fac = new AttributesFactory(currRegion.getAttributes()); fac.setCacheLoader(new TestXACacheLoader()); Region re = currRegion.createSubregion("employee", fac.create()); System.out.println(re.get(args[0])); utx.rollback(); System.out.println(re.get(args[0])); cache.close(); ExitCode.FATAL.doSystemExit(); } catch (Exception e) { e.printStackTrace(); cache.close(); } }
/** * @since GemFire 5.7 */ @Test public void testConnectionPool() { CacheLoader cl = new CacheLoader() { @Override public Object load(LoaderHelper helper) throws CacheLoaderException { return null; } @Override public void close() {} }; AttributesFactory factory = new AttributesFactory(); factory.setPoolName("mypool"); factory = new AttributesFactory(); factory.setCacheWriter(new CacheWriterAdapter()); factory.setPoolName("mypool"); factory = new AttributesFactory(); factory.setCacheLoader(cl); factory.setPoolName("mypool"); }