protected Region createRegion(String regionName, RegionShortcut shortcut) { return this.cache.createRegionFactory(shortcut).create(regionName); } }
@SuppressWarnings("unchecked") private LocalRegion createOrRetrieveGatewayDeltaRegion() { Region region = this.cache.getRegion(GatewayDelta.GATEWAY_DELTA_REGION_NAME); if (region == null) { region = new RegionFactory().setScope(Scope.LOCAL).setDataPolicy(DataPolicy.EMPTY) .setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL)) // TODO: Disabled for WAN // .setEnableGateway(true) .addCacheListener(new GatewayDeltaEventApplicationCacheListener()) .create(GatewayDelta.GATEWAY_DELTA_REGION_NAME); } if (this.cache.getLogger().fineEnabled()) { StringBuilder builder = new StringBuilder(); builder.append("GatewayDeltaForwarderCacheListener: Created gateway delta region: ") .append(region); this.cache.getLogger().fine(builder.toString()); } return (LocalRegion) region; }
factory.setCacheLoader(new LocalSessionCacheLoader(this.sessionRegion)); factory.setCacheWriter(new LocalSessionCacheWriter(this.sessionRegion)); factory.setStatisticsEnabled(true); factory.setCustomEntryIdleTimeout(new SessionCustomExpiry()); factory.addCacheListener(new SessionExpirationCacheListener()); frontingRegion = factory.create(frontingRegionName); if (getSessionManager().getLogger().isDebugEnabled()) { getSessionManager().getLogger()
private static Region<?, ?> createPartitionedRegion(String regionName, Cache cache, Class keyConstraint, Class valueConstraint) { RegionFactory regionFactory = cache.createRegionFactory(); regionFactory.setDataPolicy(DataPolicy.PARTITION); regionFactory.setKeyConstraint(keyConstraint); regionFactory.setValueConstraint(valueConstraint); return regionFactory.create(regionName); }
public MemoryHog(String n, Cache c, AtomicBoolean critical) { this.name = n; this.cache = c; this.tenuredData = new RegionFactory().setScope(Scope.LOCAL).create(this.name); this.criticalState = critical; }
public void createPartitionRegion(String name, Class constraint) { ExpirationAttributes expiration = ExpirationAttributes.DEFAULT; PartitionAttributesFactory paf = new PartitionAttributesFactory(); RegionFactory factory = cache.createRegionFactory(RegionShortcut.PARTITION).setPartitionAttributes(paf.create()); if (constraint != null) { factory.setValueConstraint(constraint); } factory.create(name); }
when(mockRegionFactory.addAsyncEventQueueId(anyString())) .thenAnswer(newAdder(asyncEventQueueIds, mockRegionFactory)); when(mockRegionFactory.addCacheListener(any(CacheListener.class))) .thenAnswer(newAdder(cacheListeners, mockRegionFactory)); when(mockRegionFactory.addGatewaySenderId(anyString())) .thenAnswer(newAdder(gatewaySenderIds, mockRegionFactory)); when(mockRegionFactory.initCacheListeners(any(CacheListener[].class))).thenAnswer(invocation -> { cacheListeners.clear(); Collections.addAll(cacheListeners, invocation.getArgument(0)); when(mockRegionFactory.setCacheLoader(any(CacheLoader.class))) .thenAnswer(newSetter(cacheLoader, mockRegionFactory)); when(mockRegionFactory.setCacheWriter(any(CacheWriter.class))) .thenAnswer(newSetter(cacheWriter, mockRegionFactory)); when(mockRegionFactory.setCloningEnabled(anyBoolean())) .thenAnswer(newSetter(cloningEnabled, mockRegionFactory)); when(mockRegionFactory.setCompressor(any(Compressor.class))) .thenAnswer(newSetter(compressor, mockRegionFactory)); when(mockRegionFactory.setConcurrencyChecksEnabled(anyBoolean())) .then(newSetter(concurrencyChecksEnabled, mockRegionFactory)); when(mockRegionFactory.setConcurrencyLevel(anyInt()))
regionFactory.setCloningEnabled(regionAttributes.getCloningEnabled()); regionFactory.setCompressor(regionAttributes.getCompressor()); regionFactory.setConcurrencyChecksEnabled(regionAttributes.getConcurrencyChecksEnabled()); regionFactory.setConcurrencyLevel(regionAttributes.getConcurrencyLevel()); regionFactory.setCustomEntryIdleTimeout(regionAttributes.getCustomEntryIdleTimeout()); regionFactory.setCustomEntryTimeToLive(regionAttributes.getCustomEntryTimeToLive()); regionFactory.setDiskSynchronous(regionAttributes.isDiskSynchronous()); regionFactory.setEnableAsyncConflation(regionAttributes.getEnableAsyncConflation()); regionFactory.setEnableSubscriptionConflation(regionAttributes.getEnableSubscriptionConflation()); regionFactory.setEntryIdleTimeout(regionAttributes.getEntryIdleTimeout()); regionFactory.setEntryTimeToLive(regionAttributes.getEntryTimeToLive()); regionFactory.setEvictionAttributes(regionAttributes.getEvictionAttributes()); regionFactory.setIgnoreJTA(regionAttributes.getIgnoreJTA()); regionFactory.setIndexMaintenanceSynchronous(regionAttributes.getIndexMaintenanceSynchronous()); regionFactory.setInitialCapacity(regionAttributes.getInitialCapacity()); regionFactory.setKeyConstraint(regionAttributes.getKeyConstraint()); regionFactory.setLoadFactor(regionAttributes.getLoadFactor()); regionFactory.setLockGrantor(regionAttributes.isLockGrantor()); regionFactory.setMembershipAttributes(regionAttributes.getMembershipAttributes()); regionFactory.setMulticastEnabled(regionAttributes.getMulticastEnabled()); regionFactory.setOffHeap(regionAttributes.getOffHeap()); regionFactory.setPoolName(regionAttributes.getPoolName()); regionFactory.setRegionIdleTimeout(regionAttributes.getRegionIdleTimeout()); regionFactory.setRegionTimeToLive(regionAttributes.getRegionTimeToLive()); regionFactory.setStatisticsEnabled(regionAttributes.getStatisticsEnabled()); regionFactory.setSubscriptionAttributes(regionAttributes.getSubscriptionAttributes());
factory.setDataPolicy(DataPolicy.fromString(regionAttributes.getDataPolicy().name())); factory.setScope(Scope.fromString(regionAttributes.getScope().name())); .setCacheLoader(DeclarableTypeInstantiator.newInstance(regionAttributes.getCacheLoader(), cache)); .setCacheWriter(DeclarableTypeInstantiator.newInstance(regionAttributes.getCacheWriter(), cache)); ((RegionFactory<Object, Object>) factory).initCacheListeners(listeners); Class<Object> keyConstraintClass = CliUtil.forName(keyConstraint, CliStrings.CREATE_REGION__KEYCONSTRAINT); ((RegionFactory<Object, Object>) factory).setKeyConstraint(keyConstraintClass); Class<Object> valueConstraintClass = CliUtil.forName(valueConstraint, CliStrings.CREATE_REGION__VALUECONSTRAINT); ((RegionFactory<Object, Object>) factory).setValueConstraint(valueConstraintClass); .setCompressor(DeclarableTypeInstantiator.newInstance(regionAttributes.getCompressor())); factory.setPartitionAttributes( PartitionAttributesImpl.fromConfig(regionAttributes.getPartitionAttributes(), cache)); ((RegionFactory<Object, Object>) factory).setEntryIdleTimeout( new ExpirationAttributes(Integer.valueOf(eitl.getTimeout()), ExpirationAction.fromXmlString(eitl.getAction())));
public static void createReplicatedRegionWithSenderAndAsyncEventQueue(String regionName, String senderIds, String asyncChannelId, Boolean offHeap) { IgnoredException exp = IgnoredException.addIgnoredException(ForceReattemptException.class.getName()); try { AttributesFactory fact = new AttributesFactory(); if (senderIds != null) { StringTokenizer tokenizer = new StringTokenizer(senderIds, ","); while (tokenizer.hasMoreTokens()) { String senderId = tokenizer.nextToken(); fact.addGatewaySenderId(senderId); } } fact.setDataPolicy(DataPolicy.REPLICATE); fact.setOffHeap(offHeap); fact.setScope(Scope.DISTRIBUTED_ACK); RegionFactory regionFactory = cache.createRegionFactory(fact.create()); regionFactory.addAsyncEventQueueId(asyncChannelId); Region r = regionFactory.create(regionName); assertNotNull(r); } finally { exp.remove(); } }
private static void setupDataRegionAndSubregions() { InternalCache cache = ClusterStartupRule.getCache(); RegionFactory regionFactory = cache.createRegionFactory(RegionShortcut.REPLICATE); Region dataRegion = regionFactory.create(DATA_REGION_NAME); assertThat(dataRegion).isNotNull(); Region dataSubRegion = regionFactory.createSubregion(dataRegion, DATA_REGION_NAME_CHILD_1); assertThat(dataSubRegion).isNotNull(); dataSubRegion = regionFactory.createSubregion(dataSubRegion, DATA_REGION_NAME_CHILD_1_2); assertThat(dataSubRegion).isNotNull(); assertThat(dataRegion).isNotNull(); }
private static void setupPartitionedRegion(String regionName) { InternalCache cache = ClusterStartupRule.getCache(); PartitionAttributes partitionAttrs = new PartitionAttributesFactory().setRedundantCopies(2).create(); RegionFactory<Object, Object> partitionRegionFactory = cache.createRegionFactory(RegionShortcut.PARTITION); partitionRegionFactory.setPartitionAttributes(partitionAttrs); Region dataParRegion = partitionRegionFactory.create(regionName); assertThat(dataParRegion).isNotNull(); assertThat(dataParRegion.getFullPath()).contains(regionName); }
@Test public void createsPartitionedInCache() { RegionConfig config = new RegionConfig(); config.setName("regionName"); config.setType("PARTITION"); RegionConfigRealizer realizer = new RegionConfigRealizer(); realizer.create(config, cache); ArgumentCaptor<DataPolicy> dataPolicyArgumentCaptor = ArgumentCaptor.forClass(DataPolicy.class); verify(regionFactory).setDataPolicy(dataPolicyArgumentCaptor.capture()); assertThat(dataPolicyArgumentCaptor.getValue()).isEqualTo(DataPolicy.PARTITION); verify(regionFactory).create("regionName"); }
public <K, V> Region<K, V> createRegion(Cache c, String diskStore, RegionType type, String name) { Region<Integer, MyObject> r = c.getRegion(name); switch (type) { case REPLICATE: return c.<K, V>createRegionFactory(RegionShortcut.REPLICATE).create(name); case REPLICATE_PERSISTENT: return c.<K, V>createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT) .setDiskStoreName(diskStore).create(name); case REPLICATE_PERSISTENT_OVERFLOW: return c.<K, V>createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT_OVERFLOW) .setEvictionAttributes( EvictionAttributes.createLIFOEntryAttributes(1, EvictionAction.OVERFLOW_TO_DISK)) .setDiskStoreName(diskStore).create(name); case PARTITION: return c.<K, V>createRegionFactory(RegionShortcut.PARTITION).create(name); case PARTITION_PERSISTENT: return c.<K, V>createRegionFactory(RegionShortcut.PARTITION_PERSISTENT) .setDiskStoreName(diskStore).create(name); case PARTITION_PERSISTENT_OVERFLOW: return c.<K, V>createRegionFactory(RegionShortcut.PARTITION_PERSISTENT_OVERFLOW) .setEvictionAttributes( EvictionAttributes.createLIFOEntryAttributes(5, EvictionAction.OVERFLOW_TO_DISK)) .setDiskStoreName(diskStore).create(name); } throw new IllegalArgumentException(); }
/** * Create a local region fronting the main region. * */ private Region<String, HttpSession> createOrRetrieveLocalRegion() { // Attempt to retrieve the fronting region String frontingRegionName = this.sessionRegion.getName() + "_local"; Region<String, HttpSession> frontingRegion = this.cache.getRegion(frontingRegionName); if (frontingRegion == null) { // Create the region factory RegionFactory<String, HttpSession> factory = this.cache.createRegionFactory(RegionShortcut.LOCAL_HEAP_LRU); // Add the cache loader and writer factory.setCacheLoader(new LocalSessionCacheLoader(this.sessionRegion)); factory.setCacheWriter(new LocalSessionCacheWriter(this.sessionRegion)); // Create the region frontingRegion = factory.create(frontingRegionName); LOG.info("Created new local session region: {}", frontingRegion); } else { LOG.info("Retrieved existing local session region: {}", frontingRegion); } return frontingRegion; } }
protected int startBridgeServer(final String[] groups, final String locators, final String[] regions, final ServerLoadProbe probe, final boolean useGroupsProperty) throws IOException { CacheFactory cacheFactory = new CacheFactory().set(MCAST_PORT, "0").set(LOCATORS, locators); if (useGroupsProperty && groups != null) { cacheFactory.set(GROUPS, StringUtils.join(groups, ",")); } Cache cache = cacheFactory.create(); for (String regionName : regions) { cache.createRegionFactory(RegionShortcut.REPLICATE).setEnableSubscriptionConflation(true) .create(regionName); } CacheServer server = cache.addCacheServer(); server.setPort(0); if (!useGroupsProperty) { server.setGroups(groups); } server.setLoadProbe(probe); server.start(); remoteObjects.put(CACHE_KEY, cache); return server.getPort(); }
@Override public Object call() throws Exception { RegionFactory factory = getCache().createRegionFactory(RegionShortcut.REPLICATE); if (valueConstraint != null) { factory.setValueConstraint(valueConstraint); } factory.create(regionName); return true; } });
@Override protected void resolveDataPolicy(RegionFactory<K, V> regionFactory, Boolean persistent, DataPolicy dataPolicy) { if (dataPolicy == null) { dataPolicy = (isPersistent() ? DataPolicy.PERSISTENT_PARTITION : DataPolicy.PARTITION); } else { // Validate that the user-defined Data Policy matches the appropriate Spring GemFire XML namespace // configuration meta-data element for Region (i.e. <gfe:partitioned-region .../>)! Assert.isTrue(dataPolicy.withPartitioning(), String.format( "Data Policy '%1$s' is not supported in Partitioned Regions.", dataPolicy)); } // Validate the data-policy and persistent attributes are compatible when specified! RegionUtils.assertDataPolicyAndPersistentAttributeAreCompatible(dataPolicy, persistent); regionFactory.setDataPolicy(dataPolicy); setDataPolicy(dataPolicy); }
private static void setupReplicatedRegionWithEviction(String regionName) { InternalCache cache = ClusterStartupRule.getCache(); EvictionAttributesImpl evictionAttributes = new EvictionAttributesImpl(); evictionAttributes.setMaximum(1).setAction(EvictionAction.OVERFLOW_TO_DISK) .setAlgorithm(EvictionAlgorithm.LRU_ENTRY); RegionFactory regionFactory = cache.createRegionFactory(RegionShortcut.REPLICATE) .setEvictionAttributes(evictionAttributes); Region dataRegion = regionFactory.create(regionName); assertThat(dataRegion).isNotNull(); assertThat(dataRegion.getFullPath()).contains(regionName); }