Search in sources :

Example 1 with ConfigurationChangeListener

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;
}
Also used : Configuration(org.apache.geode.management.internal.configuration.domain.Configuration) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) IOException(java.io.IOException) TimeoutException(org.apache.geode.cache.TimeoutException) CancelException(org.apache.geode.CancelException) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) IOException(java.io.IOException) LeaseExpiredException(org.apache.geode.distributed.LeaseExpiredException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) AttributesFactory(org.apache.geode.cache.AttributesFactory) ConfigurationChangeListener(org.apache.geode.management.internal.configuration.callbacks.ConfigurationChangeListener) CancelException(org.apache.geode.CancelException) File(java.io.File)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 CancelException (org.apache.geode.CancelException)1 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)1 TimeoutException (org.apache.geode.cache.TimeoutException)1 LeaseExpiredException (org.apache.geode.distributed.LeaseExpiredException)1 InternalRegionArguments (org.apache.geode.internal.cache.InternalRegionArguments)1 ConfigurationChangeListener (org.apache.geode.management.internal.configuration.callbacks.ConfigurationChangeListener)1 Configuration (org.apache.geode.management.internal.configuration.domain.Configuration)1 SAXException (org.xml.sax.SAXException)1