/** * Sets the {@code PartitionAttributes} that describe how the region is partitioned among members * of the distributed system. * * @return a reference to this RegionFactory object * @see AttributesFactory#setPartitionAttributes */ public RegionFactory<K, V> setPartitionAttributes(PartitionAttributes partition) { this.attrsFactory.setPartitionAttributes(partition); return this; }
/** * 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; }
@Override public Region createRegion(String regionName, Class valueConstraint) { PartitionAttributesFactory paf = new PartitionAttributesFactory(); AttributesFactory af = new AttributesFactory(); af.setPartitionAttributes(paf.create()); af.setValueConstraint(valueConstraint); Region r1 = CacheUtils.createRegion(regionName, af.create(), false); return r1; }
public static void createPartitionedRegion(String regionName, String senderIds, Integer redundantCopies, Integer totalNumBuckets) { IgnoredException exp = IgnoredException.addIgnoredException(ForceReattemptException.class.getName()); IgnoredException exp1 = IgnoredException.addIgnoredException(PartitionOfflineException.class.getName()); try { AttributesFactory fact = new AttributesFactory(); if (senderIds != null) { StringTokenizer tokenizer = new StringTokenizer(senderIds, ","); while (tokenizer.hasMoreTokens()) { String senderId = tokenizer.nextToken(); // GatewaySender sender = cache.getGatewaySender(senderId); // assertNotNull(sender); fact.addGatewaySenderId(senderId); } } PartitionAttributesFactory pfact = new PartitionAttributesFactory(); pfact.setTotalNumBuckets(totalNumBuckets); pfact.setRedundantCopies(redundantCopies); pfact.setRecoveryDelay(0); fact.setPartitionAttributes(pfact.create()); Region r = cache.createRegionFactory(fact.create()).create(regionName); assertNotNull(r); } finally { exp.remove(); exp1.remove(); } }
public static Region createFixedPartitionedRegion(final Cache cache, String regionName, List<FixedPartitionAttributes> fpaList, int localMaxMemory) { List<String> allPartitions = new ArrayList(); if (fpaList != null) { for (FixedPartitionAttributes fpa : fpaList) { allPartitions.add(fpa.getPartitionName()); } } else { allPartitions.add("Q1"); allPartitions.add("Q2"); } AttributesFactory fact = new AttributesFactory(); PartitionAttributesFactory pfact = new PartitionAttributesFactory(); pfact.setTotalNumBuckets(16); pfact.setRedundantCopies(1); pfact.setLocalMaxMemory(localMaxMemory); if (fpaList != null) { for (FixedPartitionAttributes fpa : fpaList) { pfact.addFixedPartitionAttributes(fpa); } } pfact.setPartitionResolver(new MyFixedPartitionResolver(allPartitions)); fact.setPartitionAttributes(pfact.create()); Region r = cache.createRegionFactory(fact.create()).create(regionName); assertNotNull(r); return r; }
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; }
@Before public void setup() { InternalCache internalCache = Fakes.cache(); InternalResourceManager resourceManager = mock(InternalResourceManager.class, RETURNS_DEEP_STUBS); when(internalCache.getInternalResourceManager()).thenReturn(resourceManager); AttributesFactory attributesFactory = new AttributesFactory(); attributesFactory.setPartitionAttributes( new PartitionAttributesFactory().setTotalNumBuckets(1).setRedundantCopies(1).create()); partitionedRegion = new PartitionedRegion(regionName, attributesFactory.create(), null, internalCache, mock(InternalRegionArguments.class)); }
public static void createColocatedPartitionedRegionWithAsyncEventQueue(String regionName, String asyncEventQueueId, Integer totalNumBuckets, String colocatedWith) { IgnoredException exp = IgnoredException.addIgnoredException(ForceReattemptException.class.getName()); IgnoredException exp1 = IgnoredException.addIgnoredException(PartitionOfflineException.class.getName()); try { AttributesFactory fact = new AttributesFactory(); PartitionAttributesFactory pfact = new PartitionAttributesFactory(); pfact.setTotalNumBuckets(totalNumBuckets); pfact.setColocatedWith(colocatedWith); fact.setPartitionAttributes(pfact.create()); Region r = cache.createRegionFactory(fact.create()).addAsyncEventQueueId(asyncEventQueueId) .create(regionName); assertNotNull(r); } finally { exp.remove(); exp1.remove(); } }
/** * Create PartitionedRegion with 1 redundant copy */ public static void createPRWithRedundantCopyWithAsyncEventQueue(String regionName, String asyncEventQueueId, Boolean offHeap) throws InterruptedException { IgnoredException exp = IgnoredException.addIgnoredException(ForceReattemptException.class.getName()); CountDownLatch recoveryDone = new CountDownLatch(2); ResourceObserver observer = new InternalResourceManager.ResourceObserverAdapter() { @Override public void recoveryFinished(Region region) { recoveryDone.countDown(); } }; InternalResourceManager.setResourceObserver(observer); try { AttributesFactory fact = new AttributesFactory(); PartitionAttributesFactory pfact = new PartitionAttributesFactory(); pfact.setTotalNumBuckets(16); pfact.setRedundantCopies(1); fact.setPartitionAttributes(pfact.create()); fact.setOffHeap(offHeap); Region r = cache.createRegionFactory(fact.create()).addAsyncEventQueueId(asyncEventQueueId) .create(regionName); assertNotNull(r); recoveryDone.await(); } finally { exp.remove(); } }
public static void createPartitionedRegionAccessorWithAsyncEventQueue(String regionName, String asyncEventQueueId) { AttributesFactory fact = new AttributesFactory(); PartitionAttributesFactory pfact = new PartitionAttributesFactory(); pfact.setTotalNumBuckets(16); pfact.setLocalMaxMemory(0); fact.setPartitionAttributes(pfact.create()); Region r = cache.createRegionFactory(fact.create()).addAsyncEventQueueId(asyncEventQueueId) .create(regionName); // fact.create()).create(regionName); assertNotNull(r); }
public static void createPartitionedRegionWithAsyncEventQueue(String regionName, String asyncEventQueueId, Boolean offHeap) { IgnoredException exp = IgnoredException.addIgnoredException(ForceReattemptException.class.getName()); IgnoredException exp1 = IgnoredException.addIgnoredException(PartitionOfflineException.class.getName()); try { AttributesFactory fact = new AttributesFactory(); PartitionAttributesFactory pfact = new PartitionAttributesFactory(); pfact.setTotalNumBuckets(16); fact.setPartitionAttributes(pfact.create()); fact.setOffHeap(offHeap); Region r = cache.createRegionFactory(fact.create()).addAsyncEventQueueId(asyncEventQueueId) .create(regionName); assertNotNull(r); } finally { exp.remove(); exp1.remove(); } }
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); }
/** * 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 void createFixedPartitionedRegionWithAsyncEventQueue(String regionName, String asyncEventQueueId, String partitionName, final List<String> allPartitions, boolean offHeap) { IgnoredException exp = IgnoredException.addIgnoredException(ForceReattemptException.class.getName()); IgnoredException exp1 = IgnoredException.addIgnoredException(PartitionOfflineException.class.getName()); try { AttributesFactory fact = new AttributesFactory(); PartitionAttributesFactory pfact = new PartitionAttributesFactory(); pfact.setTotalNumBuckets(16); pfact.addFixedPartitionAttributes( FixedPartitionAttributes.createFixedPartition(partitionName, true)); pfact.setPartitionResolver(new MyFixedPartitionResolver(allPartitions)); fact.setPartitionAttributes(pfact.create()); fact.setOffHeap(offHeap); Region r = cache.createRegionFactory(fact.create()).addAsyncEventQueueId(asyncEventQueueId) .create(regionName); assertNotNull(r); } finally { exp.remove(); exp1.remove(); } }
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); }
protected <K, V> Region<K, V> createRegion(final String regionName, final RegionShortcut regionShortCut, final String colocatedWithRegionName, final PartitionAttributes partitionAttributes, final RegionAttributes regionAttributes, PartitionListener lucenePrimaryBucketListener) { PartitionAttributesFactory partitionAttributesFactory = new PartitionAttributesFactory(); if (lucenePrimaryBucketListener != null) { partitionAttributesFactory.addPartitionListener(lucenePrimaryBucketListener); } partitionAttributesFactory.setColocatedWith(colocatedWithRegionName); configureLuceneRegionAttributesFactory(partitionAttributesFactory, partitionAttributes); // Create AttributesFactory based on input RegionShortcut RegionAttributes baseAttributes = this.cache.getRegionAttributes(regionShortCut.toString()); AttributesFactory factory = new AttributesFactory(baseAttributes); factory.setPartitionAttributes(partitionAttributesFactory.create()); if (regionAttributes.getDataPolicy().withPersistence()) { factory.setDiskStoreName(regionAttributes.getDiskStoreName()); } RegionAttributes<K, V> attributes = factory.create(); return createRegion(regionName, attributes); }
af.setPartitionAttributes(paf.create()); Region r1 = CacheUtils.createRegion("portfolio1", af.create(), false);
af.setPartitionAttributes(paf.create()); Region r1 = CacheUtils.createRegion("portfolio1", af.create(), false);
if (isHA) { PartitionAttributesFactory paf = new PartitionAttributesFactory().setRedundantCopies(1); factory.setPartitionAttributes(paf.create());