RegionConfigRealizer implements ConfigurationRealizer<Region, RuntimeRegionInfo> { private RegionFactory getRegionFactory(Cache cache, RegionAttributesType regionAttributes) { RegionFactory factory = cache.createRegionFactory(); factory.setDataPolicy(DataPolicy.fromString(regionAttributes.getDataPolicy().name())); if (regionAttributes.getScope() != null) { factory.setScope(Scope.fromString(regionAttributes.getScope().name())); } if (regionAttributes.getCacheLoader() != null) { ((RegionFactory<Object, Object>) factory) .setCacheLoader(DeclarableTypeInstantiator.newInstance(regionAttributes.getCacheLoader(), cache)); } if (regionAttributes.getCacheWriter() != null) { ((RegionFactory<Object, Object>) factory) .setCacheWriter(DeclarableTypeInstantiator.newInstance(regionAttributes.getCacheWriter(), cache)); } if (regionAttributes.getCacheListeners() != null) { List<DeclarableType> configListeners = regionAttributes.getCacheListeners(); CacheListener[] listeners = new CacheListener[configListeners.size()]; for (int i = 0; i < configListeners.size(); i++) { listeners[i] = DeclarableTypeInstantiator.newInstance(configListeners.get(i), cache); } ((RegionFactory<Object, Object>) factory).initCacheListeners(listeners); } final String keyConstraint = regionAttributes.getKeyConstraint(); final String valueConstraint = regionAttributes.getValueConstraint(); if (keyConstraint != null && !keyConstraint.isEmpty()) { Class<Object> keyConstraintClass = ManagementUtils.forName(keyConstraint, CliStrings.CREATE_REGION__KEYCONSTRAINT); ((RegionFactory<Object, Object>) factory).setKeyConstraint(keyConstraintClass); } if (valueConstraint != null && !valueConstraint.isEmpty()) { Class<Object> valueConstraintClass = ManagementUtils.forName(valueConstraint, CliStrings.CREATE_REGION__VALUECONSTRAINT); ((RegionFactory<Object, Object>) factory).setValueConstraint(valueConstraintClass); } if (regionAttributes.getCompressor() != null) { ((RegionFactory<Object, Object>) factory) .setCompressor(DeclarableTypeInstantiator.newInstance(regionAttributes.getCompressor())); } if (regionAttributes.getPartitionAttributes() != null) { factory.setPartitionAttributes( convertToRegionFactoryPartitionAttributes(regionAttributes.getPartitionAttributes(), cache)); } if (regionAttributes.getEntryIdleTime() != null) { RegionAttributesType.ExpirationAttributesType eitl = regionAttributes.getEntryIdleTime(); ((RegionFactory<Object, Object>) factory).setEntryIdleTimeout( new ExpirationAttributes(Integer.valueOf(eitl.getTimeout()), ExpirationAction.fromXmlString(eitl.getAction()))); if (eitl.getCustomExpiry() != null) { ((RegionFactory<Object, Object>) factory).setCustomEntryIdleTimeout( DeclarableTypeInstantiator.newInstance(eitl.getCustomExpiry(), cache)); } } if (regionAttributes.getEntryTimeToLive() != null) { RegionAttributesType.ExpirationAttributesType ettl = regionAttributes.getEntryTimeToLive(); ((RegionFactory<Object, Object>) factory).setEntryTimeToLive( new ExpirationAttributes(Integer.valueOf(ettl.getTimeout()), ExpirationAction.fromXmlString(ettl.getAction()))); if (ettl.getCustomExpiry() != null) { ((RegionFactory<Object, Object>) factory) .setCustomEntryTimeToLive(DeclarableTypeInstantiator.newInstance(ettl.getCustomExpiry(), cache)); } } if (regionAttributes.getRegionIdleTime() != null) { RegionAttributesType.ExpirationAttributesType ritl = regionAttributes.getRegionIdleTime(); ((RegionFactory<Object, Object>) factory).setRegionIdleTimeout( new ExpirationAttributes(Integer.valueOf(ritl.getTimeout()), ExpirationAction.fromXmlString(ritl.getAction()))); } if (regionAttributes.getRegionTimeToLive() != null) { RegionAttributesType.ExpirationAttributesType rttl = regionAttributes.getRegionTimeToLive(); ((RegionFactory<Object, Object>) factory).setRegionTimeToLive( new ExpirationAttributes(Integer.valueOf(rttl.getTimeout()), ExpirationAction.fromXmlString(rttl.getAction()))); } if (regionAttributes.getEvictionAttributes() != null) { try { factory.setEvictionAttributes( EvictionAttributesImpl.fromConfig(regionAttributes.getEvictionAttributes())); } catch (Exception e) { throw new IllegalArgumentException( CliStrings.CREATE_REGION__MSG__OBJECT_SIZER_MUST_BE_OBJECTSIZER_AND_DECLARABLE); } } if (regionAttributes.getDiskStoreName() != null) { factory.setDiskStoreName(regionAttributes.getDiskStoreName()); } if (regionAttributes.isDiskSynchronous() != null) { factory.setDiskSynchronous(regionAttributes.isDiskSynchronous()); } if (regionAttributes.isOffHeap() != null) { factory.setOffHeap(regionAttributes.isOffHeap()); } if (regionAttributes.isStatisticsEnabled() != null) { factory.setStatisticsEnabled(regionAttributes.isStatisticsEnabled()); } if (regionAttributes.isEnableAsyncConflation() != null) { factory.setEnableAsyncConflation(regionAttributes.isEnableAsyncConflation()); } if (regionAttributes.isEnableSubscriptionConflation() != null) { factory.setEnableSubscriptionConflation(regionAttributes.isEnableSubscriptionConflation()); } if (regionAttributes.getGatewaySenderIds() != null) { Arrays.stream(regionAttributes.getGatewaySenderIds().split(",")) .forEach(gsi -> factory.addGatewaySenderId(gsi)); } if (regionAttributes.getAsyncEventQueueIds() != null) { Arrays.stream(regionAttributes.getAsyncEventQueueIds().split(",")) .forEach(gsi -> factory.addAsyncEventQueueId(gsi)); } factory.setConcurrencyChecksEnabled(regionAttributes.isConcurrencyChecksEnabled()); if (regionAttributes.getConcurrencyLevel() != null) { factory.setConcurrencyLevel(Integer.valueOf(regionAttributes.getConcurrencyLevel())); } if (regionAttributes.isCloningEnabled() != null) { factory.setCloningEnabled(regionAttributes.isCloningEnabled()); } if (regionAttributes.isMulticastEnabled() != null) { factory.setMulticastEnabled(regionAttributes.isMulticastEnabled()); } return factory; }  @Override RealizationResult create(Region regionConfig, InternalCache cache); RealizationResult create(RegionConfig regionConfig, String regionPath,
      InternalCache cache); @Override RuntimeRegionInfo get(Region config, InternalCache cache); @Override boolean exists(Region config, InternalCache cache); @Override RealizationResult update(Region config, InternalCache cache); @Override RealizationResult delete(Region config, InternalCache cache);  }
@Test public void getRegionFactory() throws Exception { config.setType(RegionType.REPLICATE); config.setDiskStoreName("diskstore"); config.setKeyConstraint("java.lang.String"); config.setValueConstraint("java.lang.Boolean"); realizer.create(config, cache); verify(regionFactory).setKeyConstraint(String.class); verify(regionFactory).setValueConstraint(Boolean.class); verify(regionFactory).setDiskStoreName("diskstore"); verify(regionFactory).setDataPolicy(DataPolicy.REPLICATE); }