boolean isUsedInPartitioning() {
    boolean ok = false;
    // TODO: Asif: Handle this case where region is turning out to be null
    // Ideally Bug 39923 workaround should ensure that region is not null. But we are doing
    // this check only for Update type statements. For Select queries, it may stll be null,
    // hence the check

    if (this.tqi == null) {
      return ok;
    }
    Region rgnOwningColumn = this.tqi.getRegion();
    assert rgnOwningColumn != null;
    RegionAttributes ra = rgnOwningColumn.getAttributes();
    // If the region is a Replicated Region or if it is a PR with just
    // itself
    // as a member then we should go with Derby's Activation Object
    DataPolicy policy = ra.getDataPolicy();

    if (policy.withPartitioning()) {
      PartitionedRegion pr = (PartitionedRegion) rgnOwningColumn;
      GfxdPartitionResolver rslvr = (GfxdPartitionResolver) pr.getPartitionResolver();
      ok = rslvr != null && rslvr.isUsedInPartitioning(this.actualColumnName);
    }
    return ok;
  }
  @Override
  @SuppressWarnings({"rawtypes", "unchecked"})
  public Family createMappedForm(PersistentEntity entity) {
    ClassPropertyFetcher cpf = ClassPropertyFetcher.forClass(entity.getJavaClass());
    final Closure value = cpf.getStaticPropertyValue(GormProperties.MAPPING, Closure.class);
    if (value == null) {
      return new Region();
    }

    final Region family = new Region();
    AttributesFactory factory =
        new AttributesFactory() {
          @SuppressWarnings("unused")
          public void setRegion(String name) {
            family.setRegion(name);
          }
        };
    factory.setDataPolicy(defaultDataPolicy);

    MappingConfigurationBuilder builder = new MappingConfigurationBuilder(factory, KeyValue.class);
    builder.evaluate(value);
    entityToPropertyMap.put(entity, builder.getProperties());
    final RegionAttributes regionAttributes = factory.create();
    family.setRegionAttributes(regionAttributes);
    family.setCacheListeners(regionAttributes.getCacheListeners());
    family.setDataPolicy(regionAttributes.getDataPolicy());
    family.setCacheLoader(regionAttributes.getCacheLoader());
    family.setCacheWriter(regionAttributes.getCacheWriter());

    builder = new MappingConfigurationBuilder(family, KeyValue.class);
    builder.evaluate(value);
    return family;
  }
 @SuppressWarnings("rawtypes")
 @Test
 public void testPublishingReplica() throws Exception {
   assertTrue(context.containsBean("pub"));
   RegionFactoryBean fb = context.getBean("&pub", RegionFactoryBean.class);
   assertTrue(fb instanceof ReplicatedRegionFactoryBean);
   assertEquals(Scope.DISTRIBUTED_ACK, TestUtils.readField("scope", fb));
   assertEquals("publisher", TestUtils.readField("name", fb));
   RegionAttributes attrs = TestUtils.readField("attributes", fb);
   assertFalse(attrs.getPublisher());
 }
 @SuppressWarnings({"rawtypes", "unchecked"})
 @Override
 protected RegionAttributes getRegionAttributes(String type) {
   Compressor compressor = null;
   try {
     compressor = SnappyCompressor.getDefaultInstance();
   } catch (Throwable t) {
     // Not a supported OS
     return super.getRegionAttributes(type);
   }
   RegionAttributes ra = super.getRegionAttributes(type);
   AttributesFactory factory = new AttributesFactory(ra);
   if (!ra.getDataPolicy().isEmpty()) {
     factory.setCompressor(compressor);
   }
   return factory.create();
 }
 /**
  * Choose a random DiskStore and set it in the attributes factory.
  *
  * @param baseAttr The region attributes we start with (without a DiskStore set)
  * @param attrFac The attributes factory to set the DiskStore in.
  * @param diskStoreNames A List of potential DiskStore names to choose from.
  * @param rand The random number generator used while creating regions and attributes.
  */
 public static void setRandomDiskStore(
     RegionAttributes baseAttr,
     AttributesFactory attrFac,
     List<String> diskStoreNames,
     GsRandom rand) {
   if ((baseAttr.getDiskStoreName() != null)
       && (baseAttr
           .getDiskStoreName()
           .equals("notUsed"))) { // disk store should be chosen randomly
     // setting the diskStoreName to unused is a signal that we do need a disk store and to choose
     // randomly
     String diskStoreName = diskStoreNames.get(rand.nextInt(1, diskStoreNames.size() - 1));
     if (diskStoreName.equals("unused")) {
       throw new TestException("Error in test, diskStoreName is " + diskStoreName);
     }
     Log.getLogWriter().info("Test is setting diskStoreName to " + diskStoreName);
     attrFac.setDiskStoreName(diskStoreName);
   }
 }
  protected RegionMBeanBridge(Region<K, V> region) {
    this.region = region;
    this.regAttrs = region.getAttributes();

    this.isStatisticsEnabled = regAttrs.getStatisticsEnabled();

    this.regionAttributesData = RegionMBeanCompositeDataFactory.getRegionAttributesData(regAttrs);
    this.membershipAttributesData =
        RegionMBeanCompositeDataFactory.getMembershipAttributesData(regAttrs);
    this.evictionAttributesData =
        RegionMBeanCompositeDataFactory.getEvictionAttributesData(regAttrs);

    this.regionMonitor =
        new MBeanStatsMonitor(ManagementStrings.REGION_MONITOR.toLocalizedString());

    configureRegionMetrics();

    this.persistentEnabled = region.getAttributes().getDataPolicy().withPersistence();

    this.regionStats = ((LocalRegion) region).getRegionPerfStats();
    if (regionStats != null) {
      regionMonitor.addStatisticsToMonitor(regionStats.getStats()); // fixes 46692
    }

    LocalRegion l = (LocalRegion) region;
    if (l.getEvictionController() != null) {
      LRUStatistics stats = l.getEvictionController().getLRUHelper().getStats();
      if (stats != null) {
        regionMonitor.addStatisticsToMonitor(stats.getStats());
        EvictionAttributes ea = region.getAttributes().getEvictionAttributes();
        if (ea != null && ea.getAlgorithm().isLRUMemory()) {
          this.lruMemoryStats = stats;
        }
      }
    }

    if (regAttrs.getGatewaySenderIds() != null && regAttrs.getGatewaySenderIds().size() > 0) {
      this.isGatewayEnabled = true;
    }

    this.member = GemFireCacheImpl.getInstance().getDistributedSystem().getMemberId();
  }
  /* (non-Javadoc) */
  private boolean isDiskStoreConfigurationAllowed() {
    boolean allow = (diskStoreName != null);

    allow &=
        (getDataPolicy().withPersistence()
            || (getAttributes() != null
                && getAttributes().getEvictionAttributes() != null
                && EvictionAction.OVERFLOW_TO_DISK.equals(
                    attributes.getEvictionAttributes().getAction())));

    return allow;
  }
 /**
  * Create the DiskStore if the RegionAttributes specifies it.
  *
  * @param attr The RegionAttributes that could specify a DiskStore.
  * @return A String description of the DiskStore, useful for logging.
  */
 public static String createDiskStore(RegionAttributes attr) {
   String diskDirsStr = "";
   Log.getLogWriter().info("DiskStore name in attributes is " + attr.getDiskStoreName());
   if ((attr.getDiskStoreName() != null) && (!attr.getDiskStoreName().equals("notUsed"))) {
     Log.getLogWriter().info("Creating diskStore " + attr.getDiskStoreName());
     DiskStoreFactory dsFactory = DiskStoreHelper.getDiskStoreFactory(attr.getDiskStoreName());
     dsFactory.create(attr.getDiskStoreName());
     File[] diskDirs = CacheHelper.getCache().findDiskStore(attr.getDiskStoreName()).getDiskDirs();
     for (File diskDir : diskDirs) {
       diskDirsStr = diskDirsStr + diskDir.getName() + " ";
     }
     diskDirsStr = " with disk dirs " + diskDirsStr;
   }
   return "disk store name is " + attr.getDiskStoreName() + " " + diskDirsStr;
 }
  protected <K, V> void mergePartitionAttributes(
      final RegionFactory<K, V> regionFactory, final RegionAttributes<K, V> regionAttributes) {

    // NOTE PartitionAttributes are created by certain RegionShortcuts; need the null check since
    // RegionAttributes
    // can technically return null!
    // NOTE most likely, the PartitionAttributes will never be null since the
    // PartitionRegionFactoryBean always
    // sets a PartitionAttributesFactoryBean BeanBuilder on the RegionAttributesFactoryBean
    // "partitionAttributes"
    // property.
    if (regionAttributes.getPartitionAttributes() != null) {
      PartitionAttributes partitionAttributes = regionAttributes.getPartitionAttributes();
      PartitionAttributesFactory partitionAttributesFactory =
          new PartitionAttributesFactory(partitionAttributes);
      RegionShortcutWrapper shortcutWrapper = RegionShortcutWrapper.valueOf(shortcut);

      // NOTE however, since the default value of redundancy is 0, we need to account for
      // 'redundant'
      // RegionShortcut types, which specify a redundancy of 1.
      if (shortcutWrapper.isRedundant() && partitionAttributes.getRedundantCopies() == 0) {
        partitionAttributesFactory.setRedundantCopies(1);
      }

      // NOTE and, since the default value of localMaxMemory is based on the system memory, we need
      // to account for
      // 'proxy' RegionShortcut types, which specify a local max memory of 0.
      if (shortcutWrapper.isProxy()) {
        partitionAttributesFactory.setLocalMaxMemory(0);
      }

      // NOTE internally, RegionFactory.setPartitionAttributes handles merging the
      // PartitionAttributes, hooray!
      regionFactory.setPartitionAttributes(partitionAttributesFactory.create());
    }
  }
  @SuppressWarnings("rawtypes")
  @Test
  public void testReplicaWithAttributes() throws Exception {
    assertTrue(context.containsBean("replicated-with-attributes"));
    Region region = context.getBean("replicated-with-attributes", Region.class);
    RegionAttributes attrs = region.getAttributes();

    assertEquals(10, attrs.getInitialCapacity());
    assertEquals(true, attrs.getIgnoreJTA());
    assertEquals(false, attrs.getIndexMaintenanceSynchronous());
    assertEquals(String.class, attrs.getKeyConstraint());
    assertEquals(String.class, attrs.getValueConstraint());
    assertEquals(true, attrs.isDiskSynchronous());
    assertEquals(Scope.GLOBAL, attrs.getScope());
    // assertEquals(true, attrs.isLockGrantor());
    assertEquals(true, attrs.getEnableAsyncConflation());
    assertEquals(true, attrs.getEnableSubscriptionConflation());
    assertEquals(0.50, attrs.getLoadFactor(), 0.001);
    assertEquals(false, attrs.getCloningEnabled());
    assertEquals(10, attrs.getConcurrencyLevel());
    assertEquals(true, attrs.getMulticastEnabled());
  }
Exemple #11
0
  /**
   * Initializes without children.
   *
   * @param region The region from which RegionInfo is extracted.
   */
  @SuppressWarnings({"unchecked", "rawtypes"})
  private void init(Region region) {
    if (region == null) {
      return;
    }
    DistributedMember member =
        CacheFactory.getAnyInstance().getDistributedSystem().getDistributedMember();
    setName(region.getName());
    setFullPath(region.getFullPath());
    GemfireRegionAttributeInfo attrInfo = new GemfireRegionAttributeInfo();
    RegionAttributes<?, ?> attr = region.getAttributes();
    attrInfo.setAttribute(GemfireRegionAttributeInfo.DATA_POLICY, attr.getDataPolicy().toString());
    attrInfo.setAttribute(GemfireRegionAttributeInfo.SCOPE, attr.getScope().toString());
    if (region instanceof PartitionedRegion) {
      PartitionedRegion pr = (PartitionedRegion) region;
      PartitionAttributes pattr = pr.getPartitionAttributes();
      attrInfo.setAttribute(
          GemfireRegionAttributeInfo.LOCAL_MAX_MEMORY, pattr.getLocalMaxMemory() + "");
      attrInfo.setAttribute(
          GemfireRegionAttributeInfo.REDUNDANT_COPIES, pattr.getRedundantCopies() + "");
      attrInfo.setAttribute(
          GemfireRegionAttributeInfo.TOTAL_MAX_MEMORY, pattr.getTotalMaxMemory() + "");
      attrInfo.setAttribute(
          GemfireRegionAttributeInfo.TOTAL_NUM_BUCKETS, pattr.getTotalNumBuckets() + "");

      // data store is null if it's a proxy, i.e., LOCAL_MAX_MEMORY=0
      if (pr.getDataStore() != null) {
        Set<BucketRegion> localtBuketSet = pr.getDataStore().getAllLocalBucketRegions();
        List<BucketInfo> primaryList = new ArrayList<BucketInfo>();
        List<BucketInfo> redundantList = new ArrayList<BucketInfo>();
        this.size = 0;
        for (BucketRegion br : localtBuketSet) {
          BucketInfo bucketInfo =
              new GemfireBucketInfo(
                  br.getId(), br.getBucketAdvisor().isPrimary(), br.size(), br.getTotalBytes());
          //					InternalDistributedMember m = pr.getBucketPrimary(br.getId());
          //					if (m.getId().equals(member.getId())) {
          if (bucketInfo.isPrimary()) {
            primaryList.add(bucketInfo);
            this.size += bucketInfo.getSize();
          } else {
            redundantList.add(bucketInfo);
          }
        }
        Collections.sort(primaryList);
        Collections.sort(redundantList);
        setPrimaryBucketInfoList(primaryList);
        setRedundantBucketInfoList(redundantList);
      }
    } else {
      this.size = region.size();
    }
    setAttrInfo(attrInfo);
    temporalType = GemfireTemporalManager.getTemporalType(region);
    if (region.isDestroyed() == false && region.isEmpty() == false) {
      Set<Map.Entry> regionEntrySet = region.entrySet();
      for (Map.Entry entry : regionEntrySet) {
        Object key = entry.getKey();
        Object value = entry.getValue();
        keyTypeName = key.getClass().getName();
        valueTypeName = value.getClass().getName();
        break;
      }
    }
  }
  public RegionAttributesInfo(RegionAttributes<?, ?> ra) {

    cloningEnabled = ra.getCloningEnabled();
    concurrencyChecksEnabled = ra.getConcurrencyChecksEnabled();
    concurrencyLevel = ra.getConcurrencyLevel();
    dataPolicy = ra.getDataPolicy();
    diskStoreName = ra.getDiskStoreName();
    enableAsyncConflation = ra.getEnableAsyncConflation();
    enableGateway = ra.getEnableGateway();
    enableSubscriptionConflation = ra.getEnableSubscriptionConflation();
    gatewayHubId = ra.getGatewayHubId();
    ignoreJTA = ra.getIgnoreJTA();
    indexMaintenanceSynchronous = ra.getIndexMaintenanceSynchronous();
    initialCapacity = ra.getInitialCapacity();
    loadFactor = ra.getLoadFactor();
    multicastEnabled = ra.getMulticastEnabled();
    poolName = ra.getPoolName();
    scope = ra.getScope();
    statisticsEnabled = ra.getStatisticsEnabled();
    entryTimeToLive = ra.getEntryTimeToLive().getTimeout();
    isLockGrantor = ra.isLockGrantor();
    entryIdleTimeout = ra.getEntryIdleTimeout().getTimeout();
    regionIdleTimeout = ra.getRegionIdleTimeout().getTimeout();
    regionTimeToLive = ra.getRegionTimeToLive().getTimeout();

    Compressor compressor = ra.getCompressor();
    if (compressor != null) {
      compressorClassName = compressor.getClass().getCanonicalName();
    }

    ExpirationAction expAction = ra.getEntryIdleTimeout().getAction();
    if (expAction != null) {
      entryIdleTimeoutAction = expAction.toString();
    }

    expAction = ra.getEntryTimeToLive().getAction();
    if (expAction != null) {
      entryTimeToLiveAction = expAction.toString();
    }

    expAction = ra.getRegionTimeToLive().getAction();

    if (expAction != null) {
      regionTimeToLiveAction = expAction.toString();
    }

    expAction = ra.getRegionIdleTimeout().getAction();
    if (expAction != null) {
      regionIdleTimeoutAction = expAction.toString();
    }

    // Collecting information about all the CacheListeners, CacheWriters, CacheLoaders
    CacheListener<?, ?>[] cacheListeners = ra.getCacheListeners();

    // TODO: The cacheListeners should be added one by one by delimited by a "\n"
    if (cacheListeners.length > 0) {
      cacheListenerClassNames = new ArrayList<String>();
      for (CacheListener<?, ?> cacheListener : cacheListeners) {
        cacheListenerClassNames.add(cacheListener.getClass().getCanonicalName());
      }
      Collections.sort(cacheListenerClassNames);
    }

    // CacheLoader
    CacheLoader<?, ?> cacheLoader = ra.getCacheLoader();

    if (cacheLoader != null) {
      cacheLoaderClassName = cacheLoader.getClass().getCanonicalName();
    }

    // CacheWriter
    CacheWriter<?, ?> cacheWriter = ra.getCacheWriter();

    if (cacheWriter != null) {
      cacheWriterClassName = cacheWriter.getClass().getCanonicalName();
    }

    // Setting the Partition Attributes and Eviction Attributes
    PartitionAttributes<?, ?> partitionAttributes = ra.getPartitionAttributes();
    EvictionAttributes evictionAttributes = ra.getEvictionAttributes();

    if (partitionAttributes != null)
      partitionAttributesInfo = new PartitionAttributesInfo(partitionAttributes);

    if (evictionAttributes != null) {
      evictionAttributesInfo = new EvictionAttributesInfo(evictionAttributes);
    }
  }
  @Override
  protected Region<K, V> lookupFallback(GemFireCache cache, String regionName) throws Exception {
    Assert.isTrue(cache instanceof ClientCache, "Unable to create regions from " + cache);

    ClientCache c = (ClientCache) cache;

    // first look at shortcut
    ClientRegionShortcut s = null;

    if (shortcut == null) {
      if (dataPolicy != null) {
        if (DataPolicy.EMPTY.equals(dataPolicy)) {
          s = ClientRegionShortcut.PROXY;
        } else if (DataPolicy.PERSISTENT_REPLICATE.equals(dataPolicy)) {
          s = ClientRegionShortcut.LOCAL_PERSISTENT;
        }
      }
      s = ClientRegionShortcut.LOCAL;
    } else {
      s = shortcut;
    }

    ClientRegionFactory<K, V> factory = c.createClientRegionFactory(s);

    // map the attributes onto the client
    if (attributes != null) {
      CacheListener<K, V>[] listeners = attributes.getCacheListeners();
      if (!ObjectUtils.isEmpty(listeners)) {
        for (CacheListener<K, V> listener : listeners) {
          factory.addCacheListener(listener);
        }
      }
      factory.setCloningEnabled(attributes.getCloningEnabled());
      factory.setConcurrencyLevel(attributes.getConcurrencyLevel());
      factory.setCustomEntryIdleTimeout(attributes.getCustomEntryIdleTimeout());
      factory.setCustomEntryTimeToLive(attributes.getCustomEntryTimeToLive());
      factory.setDiskStoreName(attributes.getDiskStoreName());
      factory.setDiskSynchronous(attributes.isDiskSynchronous());
      factory.setEntryIdleTimeout(attributes.getEntryIdleTimeout());
      factory.setEntryTimeToLive(attributes.getEntryTimeToLive());
      factory.setEvictionAttributes(attributes.getEvictionAttributes());
      factory.setInitialCapacity(attributes.getInitialCapacity());
      factory.setKeyConstraint(attributes.getKeyConstraint());
      factory.setLoadFactor(attributes.getLoadFactor());
      factory.setPoolName(attributes.getPoolName());
      factory.setRegionIdleTimeout(attributes.getRegionIdleTimeout());
      factory.setRegionTimeToLive(attributes.getRegionTimeToLive());
      factory.setStatisticsEnabled(attributes.getStatisticsEnabled());
      factory.setValueConstraint(attributes.getValueConstraint());
    }

    if (!ObjectUtils.isEmpty(cacheListeners)) {
      for (CacheListener<K, V> listener : cacheListeners) {
        factory.addCacheListener(listener);
      }
    }

    if (StringUtils.hasText(poolName)) {
      // try to eagerly initialize the pool name, if defined as a bean
      if (beanFactory.isTypeMatch(poolName, Pool.class)) {
        if (log.isDebugEnabled()) {
          log.debug(
              "Found bean definition for pool '" + poolName + "'. Eagerly initializing it...");
        }
        beanFactory.getBean(poolName, Pool.class);
      }

      factory.setPoolName(poolName);
    }

    Region<K, V> reg = factory.create(regionName);
    log.info("Created new cache region [" + regionName + "]");
    if (snapshot != null) {
      reg.loadSnapshot(snapshot.getInputStream());
    }

    return reg;
  }
 /* (non-Javadoc) */
 private DataPolicy getDataPolicy(
     final RegionAttributes regionAttributes, final DataPolicy defaultDataPolicy) {
   return (regionAttributes != null ? regionAttributes.getDataPolicy() : defaultDataPolicy);
 }
  /**
   * Intelligently merges the given RegionAttributes with the configuration setting of the
   * RegionFactory. This method is used to merge the RegionAttributes and PartitionAttributes with
   * the RegionFactory that is created when the user specified a RegionShortcut. This method gets
   * called by the createRegionFactory method depending upon the value passed to the
   * Cache.createRegionFactory() method (i.e. whether there was a RegionShortcut specified or not).
   *
   * @param <K> the Class type fo the Region key.
   * @param <V> the Class type of the Region value.
   * @param regionFactory the GemFire RegionFactory used to configure and create the Region that is
   *     the product of this RegionFactoryBean.
   * @param regionAttributes the RegionAttributes containing the Region configuration settings to
   *     merge to the RegionFactory.
   * @return the RegionFactory with the configuration settings of the RegionAttributes merged.
   * @see #isUserSpecifiedEvictionAttributes(com.gemstone.gemfire.cache.RegionAttributes)
   * @see #validateRegionAttributes(com.gemstone.gemfire.cache.RegionAttributes)
   * @see com.gemstone.gemfire.cache.RegionAttributes
   * @see com.gemstone.gemfire.cache.RegionFactory
   */
  @SuppressWarnings("unchecked")
  protected <K, V> RegionFactory<K, V> mergeRegionAttributes(
      final RegionFactory<K, V> regionFactory, final RegionAttributes<K, V> regionAttributes) {

    if (regionAttributes != null) {
      // NOTE this validation may not be strictly required depending on how the RegionAttributes
      // were "created",
      // but...
      validateRegionAttributes(regionAttributes);

      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());

      // NOTE EvictionAttributes are created by certain RegionShortcuts; need the null check!
      if (isUserSpecifiedEvictionAttributes(regionAttributes)) {
        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());
      mergePartitionAttributes(regionFactory, regionAttributes);
      regionFactory.setPoolName(regionAttributes.getPoolName());
      regionFactory.setRegionIdleTimeout(regionAttributes.getRegionIdleTimeout());
      regionFactory.setRegionTimeToLive(regionAttributes.getRegionTimeToLive());
      regionFactory.setStatisticsEnabled(regionAttributes.getStatisticsEnabled());
      regionFactory.setSubscriptionAttributes(regionAttributes.getSubscriptionAttributes());
      regionFactory.setValueConstraint(regionAttributes.getValueConstraint());
    }

    return regionFactory;
  }
  @Override
  @SuppressWarnings("deprecation")
  protected Region<K, V> lookupFallback(GemFireCache gemfireCache, String regionName)
      throws Exception {
    Assert.isTrue(
        gemfireCache instanceof Cache,
        String.format("Unable to create Regions from '%1$s'.", gemfireCache));

    Cache cache = (Cache) gemfireCache;

    RegionFactory<K, V> regionFactory = createRegionFactory(cache);

    if (hubId != null) {
      enableGateway = (enableGateway == null || enableGateway);
      Assert.isTrue(enableGateway, "The 'hubId' requires the 'enableGateway' property to be true.");
      regionFactory.setGatewayHubId(hubId);
    }

    if (enableGateway != null) {
      if (enableGateway) {
        Assert.notNull(
            hubId, "The 'enableGateway' property requires the 'hubId' property to be set.");
      }
      regionFactory.setEnableGateway(enableGateway);
    }

    if (!ObjectUtils.isEmpty(gatewaySenders)) {
      Assert.isTrue(
          hubId == null,
          "It is invalid to configure a region with both a hubId and gatewaySenders."
              + " Note that the enableGateway and hubId properties are deprecated since Gemfire 7.0");

      for (Object gatewaySender : gatewaySenders) {
        regionFactory.addGatewaySenderId(((GatewaySender) gatewaySender).getId());
      }
    }

    if (!ObjectUtils.isEmpty(asyncEventQueues)) {
      for (Object asyncEventQueue : asyncEventQueues) {
        regionFactory.addAsyncEventQueueId(((AsyncEventQueue) asyncEventQueue).getId());
      }
    }

    if (!ObjectUtils.isEmpty(cacheListeners)) {
      for (CacheListener<K, V> listener : cacheListeners) {
        regionFactory.addCacheListener(listener);
      }
    }

    if (cacheLoader != null) {
      regionFactory.setCacheLoader(cacheLoader);
    }

    if (cacheWriter != null) {
      regionFactory.setCacheWriter(cacheWriter);
    }

    resolveDataPolicy(regionFactory, persistent, dataPolicy);

    if (isDiskStoreConfigurationAllowed()) {
      regionFactory.setDiskStoreName(diskStoreName);
    }

    if (scope != null) {
      regionFactory.setScope(scope);
    }

    if (attributes != null) {
      Assert.state(
          !attributes.isLockGrantor() || (scope == null) || scope.isGlobal(),
          "Lock Grantor only applies to a 'GLOBAL' scoped Region.");
    }

    postProcess(regionFactory);

    Region<K, V> region =
        (getParent() != null
            ? regionFactory.createSubregion(getParent(), regionName)
            : regionFactory.create(regionName));

    if (log.isInfoEnabled()) {
      if (getParent() != null) {
        log.info(
            String.format(
                "Created new Cache sub-Region [%1$s] under parent Region [%2$s].",
                regionName, getParent().getName()));
      } else {
        log.info(String.format("Created new Cache Region [%1$s].", regionName));
      }
    }

    if (snapshot != null) {
      region.loadSnapshot(snapshot.getInputStream());
    }

    if (attributes != null && attributes.isLockGrantor()) {
      region.becomeLockGrantor();
    }

    return region;
  }