Example #1
0
  public boolean isDataPolicyPersistentReplicateRegion(boolean recursive) {
    if (attrInfo == null) {
      return false;
    }
    String dataPolicy =
        ((GemfireRegionAttributeInfo) attrInfo)
            .getAttribute(GemfireRegionAttributeInfo.DATA_POLICY);
    boolean flag =
        dataPolicy != null && dataPolicy.equals(DataPolicy.PERSISTENT_REPLICATE.toString());

    if (flag == false && recursive) {
      for (PathInfo pathInfo : childList) {
        GemfireRegionInfo regionInfo = (GemfireRegionInfo) pathInfo;
        flag = regionInfo.isDataPolicyPersistentReplicateRegion(recursive);
        if (flag) {
          break;
        }
      }
    }
    return flag;
  }
  @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;
  }