/** * Sets the data policy for the next {@code RegionAttributes} created. * * @param dataPolicy The type of mirroring to use for the region * @return a reference to this RegionFactory object * @throws IllegalArgumentException if dataPolicy is null * @see AttributesFactory#setDataPolicy */ public RegionFactory<K, V> setDataPolicy(DataPolicy dataPolicy) { this.attrsFactory.setDataPolicy(dataPolicy); return this; }
/** * Sets whether or not a persistent backup should be made of the region. * * @since GemFire 3.2 * @deprecated as of GemFire 5.0, use {@link DataPolicy#PERSISTENT_REPLICATE} instead */ @Deprecated public void setPersistBackup(boolean persistBackup) { if (persistBackup) { if (!this.regionAttributes.getDataPolicy().withPersistence()) { if (this.regionAttributes.getDataPolicy().withPartitioning()) { setDataPolicy(DataPolicy.PERSISTENT_PARTITION); } else { setDataPolicy(DataPolicy.PERSISTENT_REPLICATE); } } } else { // It is less clear what we should do here for backwards compat. // If the current data policy is persist then we need to change it // otherwise just leave it alone if (this.regionAttributes.getDataPolicy().withReplication()) { setDataPolicy(DataPolicy.REPLICATE); } else if (this.regionAttributes.getDataPolicy().withPartitioning()) { setDataPolicy(DataPolicy.PARTITION); } } }
private RegionAttributes createRegionAttributes(final boolean withPersistence, PartitionAttributes partitionAttributes) { AttributesFactory factory = new AttributesFactory(); if (withPersistence) { factory.setDataPolicy(DataPolicy.PERSISTENT_PARTITION); } else { factory.setDataPolicy(DataPolicy.PARTITION); } factory.setPartitionAttributes(partitionAttributes); RegionAttributes ra = factory.create(); return ra; }
/** * Sets the mirror type for the next {@code RegionAttributes} created. * * @param mirrorType The type of mirroring to use for the region * @throws IllegalArgumentException if mirrorType is null * @deprecated use {@link #setDataPolicy} instead. */ @Deprecated public void setMirrorType(MirrorType mirrorType) { if (mirrorType == null) { throw new IllegalArgumentException( "mirrorType must not be null"); } DataPolicy dp = mirrorType.getDataPolicy(); if (dp.withReplication()) { // requested a mirror type that has replication // if current data policy is not replicated change it if (!this.regionAttributes.getDataPolicy().withReplication()) { setDataPolicy(dp); } } else { // requested a mirror type none; // if current data policy is replicated change it if (this.regionAttributes.getDataPolicy().withReplication()) { setDataPolicy(dp); } } }
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(); }
/** * This method creates a partitioned region with the given PR attributes. The cache created is a * loner, so this is only suitable for single VM tests. */ public static Region createPartionedRegion(String regionname, PartitionAttributes prattribs) throws RegionExistsException { AttributesFactory attribFactory = new AttributesFactory(); attribFactory.setDataPolicy(DataPolicy.PARTITION); attribFactory.setPartitionAttributes(prattribs); RegionAttributes regionAttribs = attribFactory.create(); Region partitionedregion = createCache().createRegion(regionname, regionAttribs); return partitionedregion; }
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(); } }
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()); }
@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); createRegion(name, factory.create()); } });
public static void createReplicatedRegionWithAsyncEventQueue(String regionName, String asyncQueueIds, Boolean offHeap) { IgnoredException exp1 = IgnoredException.addIgnoredException(ForceReattemptException.class.getName()); try { AttributesFactory fact = new AttributesFactory(); addAsyncEventQueueIds(fact, asyncQueueIds); fact.setDataPolicy(DataPolicy.REPLICATE); fact.setOffHeap(offHeap); RegionFactory regionFactory = cache.createRegionFactory(fact.create()); Region r = regionFactory.create(regionName); assertNotNull(r); } finally { exp1.remove(); } }
@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); factory.addCacheListener(new MirroredDataFromNonMirroredListener()); createRegion(name, factory.create()); } });
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); }
@Override public void run() { CacheTransactionManager txMgr2 = getCache().getCacheTransactionManager(); MyTransactionListener<Object, Object> tl = new MyTransactionListener<>(); setTxListener(txMgr2, tl); try { AttributesFactory<?, ?> rgnAtts = new AttributesFactory<>(getRegionAttributes()); rgnAtts.setDataPolicy(DataPolicy.NORMAL); createRegion(rgnName, rgnAtts.create()); } catch (CacheException e) { fail("While creating region", e); } } };
private RegionAttributes createRegionAttributes(boolean isConcurrencyChecksEnabled) { AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.DISTRIBUTED_ACK); factory.setDataPolicy(DataPolicy.REPLICATE); factory.setConcurrencyChecksEnabled(isConcurrencyChecksEnabled); // RegionAttributes ra = factory.create(); return ra; }
private RegionAttributes createRegionAttributes(boolean isConcurrencyChecksEnabled) { AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.DISTRIBUTED_ACK); factory.setDataPolicy(DataPolicy.REPLICATE); factory.setConcurrencyChecksEnabled(isConcurrencyChecksEnabled); // RegionAttributes ra = factory.create(); return ra; }
@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()); } };
/** * This function creates Region attributes with provided scope,redundancy and localmaxMemory */ public static RegionAttributes createRegionAttrsForPR(int red, int localMaxMem, long recoveryDelay, EvictionAttributes evictionAttrs, PartitionResolver resolver) { AttributesFactory attr = new AttributesFactory(); attr.setDataPolicy(DataPolicy.PARTITION); PartitionAttributesFactory paf = new PartitionAttributesFactory(); paf.setRedundantCopies(red).setLocalMaxMemory(localMaxMem).setRecoveryDelay(recoveryDelay); if (resolver != null) { paf.setPartitionResolver(resolver); } PartitionAttributes<?, ?> prAttr = paf.create(); attr.setPartitionAttributes(prAttr); attr.setEvictionAttributes(evictionAttrs); return attr.create(); }
public static Region createOrGetExistingExportLogsRegion(boolean isInitiatingMember, InternalCache cache) throws IOException, ClassNotFoundException { InternalCacheForClientAccess cacheForClientAccess = cache.getCacheForProcessingClientRequests(); Region exportLogsRegion = cacheForClientAccess.getInternalRegion(EXPORT_LOGS_REGION); if (exportLogsRegion == null) { AttributesFactory<String, Configuration> regionAttrsFactory = new AttributesFactory<>(); regionAttrsFactory.setDataPolicy(DataPolicy.EMPTY); regionAttrsFactory.setScope(Scope.DISTRIBUTED_ACK); if (isInitiatingMember) { regionAttrsFactory.setCacheWriter(new ExportLogsCacheWriter()); } InternalRegionArguments internalArgs = new InternalRegionArguments(); internalArgs.setIsUsedForMetaRegion(true); exportLogsRegion = cacheForClientAccess.createInternalRegion(EXPORT_LOGS_REGION, regionAttrsFactory.create(), internalArgs); } return exportLogsRegion; }
private Region<String, RegionConfiguration> createRegionConfigurationMetadataRegion() { // a sessionFactory in hibernate could have been re-started // so, it is possible that this region exists already Region<String, RegionConfiguration> r = this.cache.getRegion(REGION_CONFIGURATION_METADATA_REGION); if (r != null) { return r; } GemFireCacheImpl gemFireCache = (GemFireCacheImpl) cache; InternalRegionArguments ira = new InternalRegionArguments().setInternalRegion(true); AttributesFactory af = new AttributesFactory(); af.setDataPolicy(DataPolicy.REPLICATE); af.setScope(Scope.DISTRIBUTED_ACK); af.addCacheListener(new RegionConfigurationCacheListener()); RegionAttributes ra = af.create(); try { return gemFireCache.createVMRegion(REGION_CONFIGURATION_METADATA_REGION, ra, ira); } catch (IOException | ClassNotFoundException e) { InternalGemFireError assErr = new InternalGemFireError( "unexpected exception"); assErr.initCause(e); throw assErr; } }
factory.setScope(Scope.DISTRIBUTED_ACK); factory.setEnableConflation(true); factory.setDataPolicy(DataPolicy.REPLICATE); factory.setConcurrencyChecksEnabled(true); RegionAttributes myAttrs = factory.create(); Region r2 = cache.createRegion(REGION_NAME2, myAttrs); factory = new AttributesFactory(); factory.setDataPolicy(DataPolicy.PARTITION); if (isHA) { PartitionAttributesFactory paf = new PartitionAttributesFactory().setRedundantCopies(1);