use of org.apache.geode.internal.cache.InternalRegionArguments in project geode by apache.
the class RegionNameValidationJUnitTest method testInvalidNames.
@Test
public void testInvalidNames() {
InternalRegionArguments ira = new InternalRegionArguments();
ira.setInternalRegion(false);
try {
LocalRegion.validateRegionName(null, ira);
fail();
} catch (IllegalArgumentException ignore) {
}
try {
LocalRegion.validateRegionName("", ira);
fail();
} catch (IllegalArgumentException ignore) {
}
try {
LocalRegion.validateRegionName("FOO" + Region.SEPARATOR, ira);
fail();
} catch (IllegalArgumentException ignore) {
}
}
use of org.apache.geode.internal.cache.InternalRegionArguments in project geode by apache.
the class CreateRegionFunction method createRegionConfigurationMetadataRegion.
private Region<String, RegionConfiguration> createRegionConfigurationMetadataRegion() {
// a sessionFactory in hibernate could have been re-started
// so, it is possible that this region exists already
Region<String, RegionConfiguration> r = this.cache.getRegion(REGION_CONFIGURATION_METADATA_REGION);
if (r != null) {
return r;
}
GemFireCacheImpl gemFireCache = (GemFireCacheImpl) cache;
InternalRegionArguments ira = new InternalRegionArguments().setInternalRegion(true);
AttributesFactory af = new AttributesFactory();
af.setScope(Scope.LOCAL);
af.addCacheListener(new RegionConfigurationCacheListener());
RegionAttributes ra = af.create();
try {
return gemFireCache.createVMRegion(REGION_CONFIGURATION_METADATA_REGION, ra, ira);
} catch (IOException | ClassNotFoundException e) {
InternalGemFireError assErr = new InternalGemFireError(LocalizedStrings.GemFireCache_UNEXPECTED_EXCEPTION.toLocalizedString());
assErr.initCause(e);
throw assErr;
}
}
use of org.apache.geode.internal.cache.InternalRegionArguments in project geode by apache.
the class ClientHealthMonitoringRegion method initialize.
/**
* This method creates the client health monitoring region.
* <p>
* GuardedBy ClientHealthMonitoringRegion.class
*
* @param cache The current GemFire Cache
*/
private static void initialize(InternalCache cache) {
try {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setEntryTimeToLive(new ExpirationAttributes(ADMIN_REGION_EXPIRY_INTERVAL, ExpirationAction.DESTROY));
cache.getLogger().fine("ClientHealthMonitoringRegion, setting TTL for entry....");
factory.addCacheListener(prepareCacheListener());
factory.setStatisticsEnabled(true);
RegionAttributes regionAttrs = factory.create();
InternalRegionArguments internalArgs = new InternalRegionArguments();
internalArgs.setIsUsedForMetaRegion(true);
internalArgs.setIsUsedForPartitionedRegionAdmin(false);
currentInstance = cache.createVMRegion(ADMIN_REGION_NAME, regionAttrs, internalArgs);
} catch (Exception ex) {
cache.getLoggerI18n().error(LocalizedStrings.ClientHealthMonitoringRegion_ERROR_WHILE_CREATING_AN_ADMIN_REGION, ex);
}
}
use of org.apache.geode.internal.cache.InternalRegionArguments in project geode by apache.
the class DynamicRegionFactory method doInternalInit.
/**
* The method is for internal use only. It is called implicitly during cache creation.
* <p>
* This method is called internally during cache initialization at the correct time. Initialize
* the factory with a GemFire Cache. We create the metadata Region which holds all our dynamically
* created regions.
*
* @param theCache The GemFire {@code Cache}
*/
protected void doInternalInit(InternalCache theCache) throws CacheException {
if (isClosed()) {
// DynamicRegions are not enabled in this vm. Just return.
return;
}
try {
this.cache = theCache;
this.dynamicRegionList = theCache.getRegion(dynamicRegionListName);
final boolean isClient = this.config.getPoolName() != null;
if (this.dynamicRegionList == null) {
InternalRegionArguments ira = new InternalRegionArguments().setDestroyLockFlag(true).setInternalRegion(true).setSnapshotInputStream(null).setImageTarget(null);
AttributesFactory af = new AttributesFactory();
if (this.config.getPersistBackup()) {
af.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
af.setDiskWriteAttributes(new DiskWriteAttributesFactory().create());
if (this.config.getDiskDir() != null) {
af.setDiskDirs(new File[] { this.config.getDiskDir() });
}
}
if (isClient) {
af.setScope(Scope.LOCAL);
// MirrorType(MirrorType.NONE);
af.setDataPolicy(DataPolicy.NORMAL);
af.setStatisticsEnabled(true);
String cpName = this.config.getPoolName();
if (cpName != null) {
Pool cp = PoolManager.find(cpName);
if (cp == null) {
throw new IllegalStateException("Invalid pool name specified. This pool is not registered with the cache: " + cpName);
} else {
if (!cp.getSubscriptionEnabled()) {
throw new IllegalStateException("The client pool of a DynamicRegionFactory must be configured with queue-enabled set to true.");
}
af.setPoolName(cpName);
}
}
ira.setInternalMetaRegion(new LocalMetaRegion(af.create(), ira));
} else {
af.setScope(Scope.DISTRIBUTED_ACK);
if (!this.config.getPersistBackup()) {
// if persistBackup, the data policy has already
// been set
// setMirrorType(MirrorType.KEYS_VALUES);
af.setDataPolicy(DataPolicy.REPLICATE);
}
for (GatewaySender gs : this.cache.getGatewaySenders()) {
if (!gs.isParallel())
af.addGatewaySenderId(gs.getId());
}
// bug fix 35432
ira.setInternalMetaRegion(new DistributedMetaRegion(af.create()));
}
try {
this.dynamicRegionList = theCache.createVMRegion(dynamicRegionListName, af.create(), ira);
} catch (IOException e) {
// only if loading snapshot, not here
throw new InternalGemFireError(LocalizedStrings.DynamicRegionFactory_UNEXPECTED_EXCEPTION.toLocalizedString(), e);
} catch (ClassNotFoundException e) {
// only if loading snapshot, not here
throw new InternalGemFireError(LocalizedStrings.DynamicRegionFactory_UNEXPECTED_EXCEPTION.toLocalizedString(), e);
}
if (isClient) {
this.dynamicRegionList.registerInterest("ALL_KEYS");
}
if (theCache.getLoggerI18n().fineEnabled()) {
theCache.getLoggerI18n().fine("Created dynamic region: " + this.dynamicRegionList);
}
} else {
if (theCache.getLoggerI18n().fineEnabled()) {
theCache.getLoggerI18n().fine("Retrieved dynamic region: " + this.dynamicRegionList);
}
}
createDefinedDynamicRegions();
} catch (CacheException e) {
theCache.getLoggerI18n().warning(LocalizedStrings.DynamicRegionFactory_ERROR_INITIALIZING_DYNAMICREGIONFACTORY, e);
throw e;
}
}
use of org.apache.geode.internal.cache.InternalRegionArguments in project geode by apache.
the class SerialGatewaySenderQueue method initializeRegion.
/**
* Initializes the <code>Region</code> backing this queue. The <code>Region</code>'s scope is
* DISTRIBUTED_NO_ACK and mirror type is KEYS_VALUES and is set to overflow to disk based on the
* <code>GatewayQueueAttributes</code>.
*
* @param sender The GatewaySender <code>SerialGatewaySenderImpl</code>
* @param listener The GemFire <code>CacheListener</code>. The <code>CacheListener</code> can be
* null.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
private void initializeRegion(AbstractGatewaySender sender, CacheListener listener) {
final InternalCache gemCache = sender.getCache();
this.region = gemCache.getRegion(this.regionName);
if (this.region == null) {
AttributesFactory<Long, AsyncEvent> factory = new AttributesFactory<Long, AsyncEvent>();
factory.setScope(NO_ACK ? Scope.DISTRIBUTED_NO_ACK : Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(this.enablePersistence ? DataPolicy.PERSISTENT_REPLICATE : DataPolicy.REPLICATE);
if (logger.isDebugEnabled()) {
logger.debug("The policy of region is {}", (this.enablePersistence ? DataPolicy.PERSISTENT_REPLICATE : DataPolicy.REPLICATE));
}
// when the user of this queue is a secondary VM.
if (listener != null) {
factory.addCacheListener(listener);
}
// allow for no overflow directory
EvictionAttributes ea = EvictionAttributes.createLIFOMemoryAttributes(this.maximumQueueMemory, EvictionAction.OVERFLOW_TO_DISK);
factory.setEvictionAttributes(ea);
factory.setConcurrencyChecksEnabled(false);
factory.setDiskStoreName(this.diskStoreName);
// In case of persistence write to disk sync and in case of eviction write in async
factory.setDiskSynchronous(this.isDiskSynchronous);
// Create the region
if (logger.isDebugEnabled()) {
logger.debug("{}: Attempting to create queue region: {}", this, this.regionName);
}
final RegionAttributes<Long, AsyncEvent> ra = factory.create();
try {
SerialGatewaySenderQueueMetaRegion meta = new SerialGatewaySenderQueueMetaRegion(this.regionName, ra, null, gemCache, sender);
try {
this.region = gemCache.createVMRegion(this.regionName, ra, new InternalRegionArguments().setInternalMetaRegion(meta).setDestroyLockFlag(true).setSnapshotInputStream(null).setImageTarget(null).setIsUsedForSerialGatewaySenderQueue(true).setInternalRegion(true).setSerialGatewaySender(sender));
} catch (IOException veryUnLikely) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.SingleWriteSingleReadRegionQueue_UNEXPECTED_EXCEPTION_DURING_INIT_OF_0, this.getClass()), veryUnLikely);
} catch (ClassNotFoundException alsoUnlikely) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.SingleWriteSingleReadRegionQueue_UNEXPECTED_EXCEPTION_DURING_INIT_OF_0, this.getClass()), alsoUnlikely);
}
if (logger.isDebugEnabled()) {
logger.debug("{}: Created queue region: {}", this, this.region);
}
} catch (CacheException e) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.SingleWriteSingleReadRegionQueue_0_THE_QUEUE_REGION_NAMED_1_COULD_NOT_BE_CREATED, new Object[] { this, this.regionName }), e);
}
} else {
throw new IllegalStateException("Queue region " + this.region.getFullPath() + " already exists.");
}
}
Aggregations