use of org.apache.geode.internal.cache.DynamicRegionAttributes in project geode by apache.
the class DynamicRegionFactory method createDefinedDynamicRegions.
/**
* This creates Dynamic Regions that already exist in other publishing processes
*/
private void createDefinedDynamicRegions() throws CacheException {
// TODO: perhaps add some logic here to avoid the possibility of synchronization issues
Set set = this.dynamicRegionList.entrySet(false);
Iterator iterator = set.iterator();
SortedMap sorted = new TreeMap();
// sort by region name before creating (bug 35528)
while (iterator.hasNext()) {
Region.Entry e = (Region.Entry) iterator.next();
DynamicRegionAttributes dda = (DynamicRegionAttributes) e.getValue();
sorted.put(dda.rootRegionName + '/' + dda.name, dda);
}
iterator = sorted.values().iterator();
while (iterator.hasNext()) {
DynamicRegionAttributes dda = (DynamicRegionAttributes) iterator.next();
doBeforeRegionCreated(dda.rootRegionName, dda.name);
Region region = createDynamicRegionImpl(dda.rootRegionName, dda.name, false);
doAfterRegionCreated(region, false, false, null);
}
}
use of org.apache.geode.internal.cache.DynamicRegionAttributes in project geode by apache.
the class DynamicRegionFactory method buildDynamicRegion.
protected void buildDynamicRegion(EntryEvent event) {
if (!DynamicRegionFactory.this.isOpen())
return;
// will already have been created) and the event is not a client event
if (!event.isOriginRemote() && !event.hasClientOrigin())
return;
//
DynamicRegionAttributes dra = (DynamicRegionAttributes) event.getNewValue();
String parentRegionName = dra.rootRegionName;
String newRegionName = dra.name;
try {
doBeforeRegionCreated(parentRegionName, newRegionName);
Region region = createDynamicRegionImpl(parentRegionName, newRegionName, false);
doAfterRegionCreated(region, true, true, event.getDistributedMember());
} catch (Exception e) {
cache.getLoggerI18n().warning(LocalizedStrings.DynamicRegionFactory_ERROR_ATTEMPTING_TO_LOCALLY_CREATE_DYNAMIC_REGION__0, newRegionName, e);
}
}
use of org.apache.geode.internal.cache.DynamicRegionAttributes in project geode by apache.
the class DynamicRegionFactory method createDynamicRegionImpl.
private Region createDynamicRegionImpl(String parentRegionName, String newRegionName, boolean addEntry) throws CacheException {
Region parentRegion = this.cache.getRegion(parentRegionName);
if (parentRegion == null) {
String errMsg = LocalizedStrings.DynamicRegionFactory_ERROR__COULD_NOT_FIND_A_REGION_NAMED___0_.toLocalizedString(parentRegionName);
RegionDestroyedException e = new RegionDestroyedException(errMsg, parentRegionName);
this.cache.getLoggerI18n().warning(LocalizedStrings.DynamicRegionFactory_ERROR__COULD_NOT_FIND_A_REGION_NAMED___0_, parentRegionName, e);
throw e;
}
// Create RegionAttributes by inheriting from the parent
RegionAttributes rra = parentRegion.getAttributes();
AttributesFactory af = new AttributesFactory(rra);
EvictionAttributes ev = rra.getEvictionAttributes();
if (ev != null && ev.getAlgorithm().isLRU()) {
EvictionAttributes rev = new EvictionAttributesImpl((EvictionAttributesImpl) ev);
af.setEvictionAttributes(rev);
}
// regions
if (newRegionName.endsWith("_PRTEST_")) {
af.setPartitionAttributes(new PartitionAttributesFactory().create());
}
RegionAttributes newRegionAttributes = af.create();
Region newRegion;
try {
newRegion = parentRegion.createSubregion(newRegionName, newRegionAttributes);
this.cache.getLoggerI18n().fine("Created dynamic region " + newRegion);
} catch (RegionExistsException ex) {
// a race condition exists that can cause this so just fine log it
this.cache.getLoggerI18n().fine("DynamicRegion " + newRegionName + " in parent " + parentRegionName + " already existed");
newRegion = ex.getRegion();
}
if (addEntry) {
DynamicRegionAttributes dra = new DynamicRegionAttributes();
dra.name = newRegionName;
dra.rootRegionName = parentRegion.getFullPath();
if (this.cache.getLoggerI18n().fineEnabled()) {
this.cache.getLoggerI18n().fine("Putting entry into dynamic region list at key: " + newRegion.getFullPath());
}
this.dynamicRegionList.put(newRegion.getFullPath(), dra);
}
if (this.config.getRegisterInterest()) {
ServerRegionProxy proxy = ((LocalRegion) newRegion).getServerProxy();
if (proxy != null) {
if (((Pool) proxy.getPool()).getSubscriptionEnabled()) {
try {
newRegion.registerInterest("ALL_KEYS");
} catch (GemFireSecurityException ex) {
// Ignore security exceptions here
this.cache.getSecurityLoggerI18n().warning(LocalizedStrings.DynamicRegionFactory_EXCEPTION_WHEN_REGISTERING_INTEREST_FOR_ALL_KEYS_IN_DYNAMIC_REGION_0_1, new Object[] { newRegion.getFullPath(), ex });
}
}
}
}
if (regionCreateSleepMillis > 0) {
try {
Thread.sleep(regionCreateSleepMillis);
} catch (InterruptedException ignore) {
Thread.currentThread().interrupt();
}
}
if (this.cache.getLoggerI18n().fineEnabled()) {
this.cache.getLoggerI18n().fine("Created Dynamic Region " + newRegion.getFullPath());
}
return newRegion;
}
Aggregations