public static Integer createCacheServer(String regionName1, String regionName2, Boolean notifyBySubscription) throws Exception { new CacheServerTestUtil().createCache(new Properties()); AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.DISTRIBUTED_ACK); factory.setEnableBridgeConflation(true); factory.setDataPolicy(DataPolicy.REPLICATE); RegionAttributes attrs = factory.create(); if (!regionName1.equals("")) { cache.createRegion(regionName1, attrs); } if (!regionName2.equals("")) { cache.createRegion(regionName2, attrs); } CacheServer server1 = cache.addCacheServer(); int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); server1.setPort(port); server1.setNotifyBySubscription(notifyBySubscription.booleanValue()); server1.start(); return new Integer(server1.getPort()); }
protected void startBridgeClient(final Pool pool, final String[] regions) throws Exception { Properties props = new Properties(); props.setProperty(MCAST_PORT, String.valueOf(0)); props.setProperty(LOCATORS, ""); DistributedSystem ds = getSystem(props); Cache cache = CacheFactory.create(ds); AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.LOCAL); factory.setPoolName(POOL_NAME); PoolFactoryImpl pf = (PoolFactoryImpl) PoolManager.createFactory(); pf.init(pool); LocatorDiscoveryCallback locatorCallback = new MyLocatorCallback(); remoteObjects.put(CALLBACK_KEY, locatorCallback); pf.setLocatorDiscoveryCallback(locatorCallback); pf.create(POOL_NAME); RegionAttributes attrs = factory.create(); for (int i = 0; i < regions.length; i++) { cache.createRegion(regions[i], attrs); } remoteObjects.put(CACHE_KEY, cache); }
public static void main(String[] args) throws Throwable { Properties props = new Properties(); DistributedSystem system = DistributedSystem.connect(props); Cache cache = CacheFactory.create(system); AttributesFactory factory = new AttributesFactory(); Region region = cache.createRegion("DataSerializable", factory.create()); region.put("User", new User("Fred", 42)); new CompanySerializer(); Address address = new Address(); Company company = new Company("My Company", address); region.put("Company", company); region.put("Employee", new Employee(43, "Bob", new Date(), company)); Thread.sleep(60 * 1000); }
public static void createCacheServer(String regionName, Boolean notifyBySubscription, Integer serverPort) throws Exception { Properties props = new Properties(); props.setProperty(MCAST_PORT, "0"); props.setProperty(LOCATORS, "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]"); new CacheServerTestUtil().createCache(props); AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.DISTRIBUTED_ACK); factory.setEnableBridgeConflation(true); factory.setDataPolicy(DataPolicy.REPLICATE); RegionAttributes attrs = factory.create(); cache.createRegion(regionName, attrs); CacheServer server = cache.addCacheServer(); server.setPort(serverPort.intValue()); server.setNotifyBySubscription(notifyBySubscription.booleanValue()); server.start(); }
public static void createCacheClient(Pool poolAttr, String regionName, Properties dsProperties, Boolean addControlListener, Properties javaSystemProperties) throws Exception { new CacheServerTestUtil().createCache(dsProperties); IgnoredException.addIgnoredException("java.net.ConnectException||java.net.SocketException"); if (javaSystemProperties != null && javaSystemProperties.size() > 0) { Enumeration e = javaSystemProperties.propertyNames(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); System.setProperty(key, javaSystemProperties.getProperty(key)); } } PoolFactoryImpl pf = (PoolFactoryImpl) PoolManager.createFactory(); pf.init(poolAttr); PoolImpl p = (PoolImpl) pf.create("CacheServerTestUtil"); AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.LOCAL); factory.setPoolName(p.getName()); if (addControlListener.booleanValue()) { factory.addCacheListener(new ControlListener()); } RegionAttributes attrs = factory.create(); cache.createRegion(regionName, attrs); pool = p; }
public static void createCacheClient(Pool poolAttr, String regionName1, String regionName2) throws Exception { new CacheServerTestUtil().createCache(getClientProperties()); PoolFactoryImpl pf = (PoolFactoryImpl) PoolManager.createFactory(); pf.init(poolAttr); PoolImpl p = (PoolImpl) pf.create("CacheServerTestUtil"); AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.LOCAL); factory.setPoolName(p.getName()); RegionAttributes attrs = factory.create(); cache.createRegion(regionName1, attrs); cache.createRegion(regionName2, attrs); pool = p; }
private void warmUpIndexCreation() throws CacheException, QueryException { System.out.println("Populating Cache with 1000 Portfolios"); if (this.region != null) { this.region.localDestroyRegion(); } this.region = cache.createRegion("portfolios", this.regionAttributes); for (int i = 0; i < 1000; i++) { this.region.put(String.valueOf(i), new Portfolio(i)); } System.out.println("Warming up index creation..."); for (int i = 0; i < 20000; i++) { Index index = this.qs.createIndex("portfolios", IndexType.FUNCTIONAL, "type", "/portfolios"); this.qs.removeIndex(index); } }
static Region createRegion(String regionName, Class valueConstraint) throws Exception { AttributesFactory attributesFactory = new AttributesFactory(); attributesFactory.setValueConstraint(valueConstraint); RegionAttributes regionAttributes = attributesFactory.create(); Region region = _cache.createRegion(regionName, regionAttributes); return region; }
public static Region createRegion(Cache cache, RegionConfiguration configuration) { // Use the createRegion method so that the RegionAttributes creation can be reused by validate. RegionAttributes requestedRegionAttributes = getRegionAttributes(cache, configuration); Region region = cache.createRegion(configuration.getRegionName(), requestedRegionAttributes); // Log the cache xml if debugging is enabled. I'd like to be able to just // log the region, but that API is not available. if (configuration.getEnableDebugListener()) { cache.getLogger().info("Created new session region: " + region); cache.getLogger().info(generateCacheXml(cache)); } return region; }
Region region1 = cache.createRegion(REGION_NAME1, attrs); Region region2 = cache.createRegion(REGION_NAME2, attrs); Region prRegion = cache.createRegion(PR_REGION_NAME, attrs); assertNotNull(region1); assertNotNull(region2);
private void populate(int numPortfolios, boolean indexed) throws CacheException, QueryException { System.out.println("Populating Cache with " + numPortfolios + " Portfolios"); if (this.region != null) { this.region.localDestroyRegion(); } this.region = cache.createRegion("portfolios", this.regionAttributes); for (int i = 0; i < numPortfolios; i++) { this.region.put(String.valueOf(i), new Portfolio(i)); } if (indexed) { System.out.println("Creating index..."); long startNanos = NanoTimer.getTime(); this.qs.createIndex("portfolios", IndexType.FUNCTIONAL, "type", "/portfolios"); float createTime = (NanoTimer.getTime() - startNanos) / 1e6f; System.out.println("Index created in " + createTime + " ms."); this.results[INDEX_CREATE].add(createTime); } }
r = cache.createRegion(request.newRegionName, request.newRegionAttributes); break;
Region region1 = cache.createRegion(REGION_NAME1, myAttrs); Region region2 = cache.createRegion(REGION_NAME2, myAttrs); assertNotNull(region1); assertNotNull(region2); assertThatThrownBy(() -> cacheForLamda.createRegion(REGION_NAME1, attrs1)) .isInstanceOfAny(IllegalStateException.class, DistributedSystemDisconnectedException.class);
/** * 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(); // EvictionStatistics 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()); } }
/** * Create client regions */ public static void createCacheClients(Pool poolAttr, String regionName1, String regionName2, Properties dsProperties) throws Exception { new CacheServerTestUtil().createCache(dsProperties); // Initialize region1 PoolFactoryImpl pf = (PoolFactoryImpl) PoolManager.createFactory(); pf.init(poolAttr); Pool p = pf.create("CacheServerTestUtil1"); AttributesFactory factory1 = new AttributesFactory(); factory1.setScope(Scope.LOCAL); factory1.setPoolName(p.getName()); cache.createRegion(regionName1, factory1.create()); // Initialize region2 p = pf.create("CacheServerTestUtil2"); AttributesFactory factory2 = new AttributesFactory(); factory2.setScope(Scope.LOCAL); factory2.setPoolName(p.getName()); cache.createRegion(regionName2, factory2.create()); }
public static void main1(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)); factory.setCacheListener(new CacheListenerAdapter() { @Override public void afterUpdate(EntryEvent event) { System.out.println("UPDATE: " + event.getKey() + " -> (" + event.getOldValue() + " -> " + event.getNewValue() + ")"); } }); LocalRegion region = (LocalRegion) cache.createRegion("TestDiskRegion", factory.create()); DiskRegion dr = region.getDiskRegion(); DiskRegionStats diskStats = dr.getStats(); EvictionCounters lruStats = getLRUStats(region); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Hit enter to perform action"); for (int i = 0; true; i++) { br.readLine(); // Thread.sleep(500); Object key = new Integer(i); Object value = new byte[200000]; region.put(key, value); System.out.println(key + " -> " + value + " evictions = " + lruStats.getEvictions() + ", writes = " + diskStats.getWrites()); } }
Region region1 = cache.createRegion(REGION_NAME1, myAttrs); Region region2 = cache.createRegion(REGION_NAME2, myAttrs); assertNotNull(region1); assertNotNull(region2);
.setDiskDirs(new java.io.File[] {new java.io.File(System.getProperty("user.dir"))}) .create("TestHeapLRU").getName()); Region region = cache.createRegion("TestDiskRegion", factory.create());
/** * Filling up the region with keys and values */ public static void main5(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(); EvictionCounters lruStats = getLRUStats(region); for (int i = 0; i < 10000; i++) { int[] array = new int[1000]; array[0] = i; try { region.put(array, new Integer(i)); } catch (IllegalStateException ex) { System.out.println("Ran out of space: " + ex); return; } } String s = "Limit is " + lruStats.getLimit() + " evictions are " + lruStats.getEvictions(); throw new RuntimeException(s); }
factory.setConcurrencyChecksEnabled(true); RegionAttributes myAttrs = factory.create(); Region r1 = cache.createRegion(REGION_NAME1, myAttrs); Region r2 = cache.createRegion(REGION_NAME2, myAttrs); factory = new AttributesFactory(); factory.setDataPolicy(DataPolicy.PARTITION); Region pr = cache.createRegion(PR_REGION_NAME, prAttrs); assertNotNull(r1); assertNotNull(r2);