use of org.apache.geode.management.internal.configuration.callbacks.ConfigurationChangeListener in project geode by apache.
the class ClusterConfigurationService method getConfigurationRegion.
/**
* Gets the region containing the shared configuration data. The region is created , if it does
* not exist already. Note : this could block if this locator contains stale persistent
* configuration data.
*
* @return {@link Region} ConfigurationRegion, this should never be null
*/
private Region<String, Configuration> getConfigurationRegion() {
Region<String, Configuration> configRegion = this.cache.getRegion(CONFIG_REGION_NAME);
try {
if (configRegion == null) {
File diskDir = new File(this.configDiskDirPath);
if (!diskDir.exists()) {
if (!diskDir.mkdirs()) {
// TODO: throw caught by containing try statement
throw new IOException("Cannot create directory at " + this.configDiskDirPath);
}
}
File[] diskDirs = { diskDir };
this.cache.createDiskStoreFactory().setDiskDirs(diskDirs).setAutoCompact(true).setMaxOplogSize(10).create(CLUSTER_CONFIG_DISK_STORE_NAME);
AttributesFactory<String, Configuration> regionAttrsFactory = new AttributesFactory<>();
regionAttrsFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
regionAttrsFactory.setCacheListener(new ConfigurationChangeListener(this));
regionAttrsFactory.setDiskStoreName(CLUSTER_CONFIG_DISK_STORE_NAME);
regionAttrsFactory.setScope(Scope.DISTRIBUTED_ACK);
InternalRegionArguments internalArgs = new InternalRegionArguments();
internalArgs.setIsUsedForMetaRegion(true);
internalArgs.setMetaRegionWithTransactions(false);
configRegion = this.cache.createVMRegion(CONFIG_REGION_NAME, regionAttrsFactory.create(), internalArgs);
}
} catch (CancelException e) {
if (configRegion == null) {
this.status.set(SharedConfigurationStatus.STOPPED);
}
// CONFIG: don't rethrow as Exception, keep it a subclass of CancelException
throw e;
} catch (Exception e) {
if (configRegion == null) {
this.status.set(SharedConfigurationStatus.STOPPED);
}
throw new RuntimeException("Error occurred while initializing cluster configuration", e);
}
return configRegion;
}
Aggregations