Search in sources :

Example 1 with DynamicRegionAttributes

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);
    }
}
Also used : RegionEntry(org.apache.geode.internal.cache.RegionEntry) Set(java.util.Set) DynamicRegionAttributes(org.apache.geode.internal.cache.DynamicRegionAttributes) SortedMap(java.util.SortedMap) Iterator(java.util.Iterator) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) TreeMap(java.util.TreeMap)

Example 2 with DynamicRegionAttributes

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);
    }
}
Also used : DynamicRegionAttributes(org.apache.geode.internal.cache.DynamicRegionAttributes) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) IOException(java.io.IOException)

Example 3 with DynamicRegionAttributes

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;
}
Also used : DynamicRegionAttributes(org.apache.geode.internal.cache.DynamicRegionAttributes) DynamicRegionAttributes(org.apache.geode.internal.cache.DynamicRegionAttributes) LocalRegion(org.apache.geode.internal.cache.LocalRegion) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) EvictionAttributesImpl(org.apache.geode.internal.cache.EvictionAttributesImpl) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Pool(org.apache.geode.cache.client.Pool)

Aggregations

DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)3 DynamicRegionAttributes (org.apache.geode.internal.cache.DynamicRegionAttributes)3 LocalRegion (org.apache.geode.internal.cache.LocalRegion)3 GemFireSecurityException (org.apache.geode.security.GemFireSecurityException)2 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 Pool (org.apache.geode.cache.client.Pool)1 ServerRegionProxy (org.apache.geode.cache.client.internal.ServerRegionProxy)1 EvictionAttributesImpl (org.apache.geode.internal.cache.EvictionAttributesImpl)1 RegionEntry (org.apache.geode.internal.cache.RegionEntry)1