public class LifecycleAwareCacheDataImporterExporter extends java.lang.Object implements CacheDataImporterExporter, org.springframework.context.ApplicationContextAware, org.springframework.context.EnvironmentAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ResourceLoaderAware, org.springframework.data.gemfire.support.SmartLifecycleSupport
CacheDataImporterExporter implementation using the Decorator Software Design Pattern to wrap
an existing CacheDataImporterExporter in order to decorate the cache (i.e. Region) data
import & export operations, making them Spring ApplicationContext, Environment, Lifecycle,
ResourceLoader aware and capable.
This wrapper decorates the Apache Geode cache Region data import operation enabling it
to be configured eagerly, after the Region bean as been initialized,
or lazily, once all beans have been fully initialized and the Spring
ApplicationContext is refreshed.Region,
ApplicationContext,
ApplicationContextAware,
EnvironmentAware,
Lifecycle,
ResourceLoaderAware,
Environment,
ResourceLoader,
SmartLifecycleSupport,
ResourceReader,
ResourceResolver,
ResourceWriter,
CacheDataImporterExporter,
ResourceCapableCacheDataImporterExporter.ExportResourceResolver,
ResourceCapableCacheDataImporterExporter.ImportResourceResolver,
Decorator Software Design Pattern| Modifier and Type | Class and Description |
|---|---|
static class |
LifecycleAwareCacheDataImporterExporter.ImportLifecycle
An
Enumeration defining the different modes for the cache data import lifecycle. |
| Modifier and Type | Field and Description |
|---|---|
protected static java.lang.String |
CACHE_DATA_IMPORT_LIFECYCLE_PROPERTY_NAME |
protected static java.lang.String |
CACHE_DATA_IMPORT_PHASE_PROPERTY_NAME |
protected static int |
DEFAULT_IMPORT_PHASE |
| Constructor and Description |
|---|
LifecycleAwareCacheDataImporterExporter(CacheDataImporterExporter importerExporter)
Constructs a new instance of the
LifecycleAwareCacheDataImporterExporter initialized with the given,
target CacheDataImporterExporter that is wrapped by this implementation to decorate all cache import
& export data operations in order to make them Lifecycle aware and capable. |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet()
Initializes the wrapped
CacheDataImporterExporter if the importer/exporter
implements InitializingBean. |
org.apache.geode.cache.Region |
exportFrom(org.apache.geode.cache.Region region)
Exports data contained in the given
Region. |
protected CacheDataImporterExporter |
getCacheDataImporterExporter()
Returns a reference to the configured
CacheDataImporterExporter wrapped by this Lifecycle aware
and capable CacheDataImporterExporter. |
protected java.util.Optional<org.springframework.core.env.Environment> |
getEnvironment()
Returns an
Optional reference to the configured Environment used to access configuration
for the behavior of the cache data import. |
int |
getPhase() |
org.apache.geode.cache.Region |
importInto(org.apache.geode.cache.Region region)
Imports data into the given
Region. |
protected LifecycleAwareCacheDataImporterExporter.ImportLifecycle |
resolveImportLifecycle()
Resolves the configured
LifecycleAwareCacheDataImporterExporter.ImportLifecycle. |
protected int |
resolveImportPhase()
Resolves the configured
SmartLifecycle Phase in which the cache data
import will be performed. |
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
Configures a reference to the Spring
ApplicationContext. |
void |
setEnvironment(org.springframework.core.env.Environment environment)
Configures a reference to the
Environment used to access configuration for the behavior of
the cache data import. |
void |
setExportResourceResolver(ResourceCapableCacheDataImporterExporter.ExportResourceResolver exportResourceResolver)
Configures the
ResourceCapableCacheDataImporterExporter.ExportResourceResolver of the wrapped CacheDataImporterExporter
if the ResourceCapableCacheDataImporterExporter.ExportResourceResolver is not null and the CacheDataImporterExporter
is Resource capable. |
void |
setImportResourceResolver(ResourceCapableCacheDataImporterExporter.ImportResourceResolver importResourceResolver)
Configures the
ResourceCapableCacheDataImporterExporter.ImportResourceResolver of the wrapped CacheDataImporterExporter
if the ResourceCapableCacheDataImporterExporter.ImportResourceResolver is not null and the CacheDataImporterExporter
is Resource capable. |
void |
setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader) |
void |
setResourceReader(ResourceReader resourceReader)
Configures the
ResourceReader of the wrapped CacheDataImporterExporter
if the ResourceReader is not null and the CacheDataImporterExporter
is Resource capable. |
void |
setResourceWriter(ResourceWriter resourceWriter)
Configures the
ResourceWriter of the wrapped CacheDataImporterExporter
if the ResourceWriter is not null and the CacheDataImporterExporter
is Resource capable. |
void |
start()
Performs the cache data import for each of the targeted
Regions. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitpostProcessBeforeDestructionrequiresDestructionpostProcessAfterInitialization, postProcessBeforeInitializationpostProcessAfterInitializationprotected static final int DEFAULT_IMPORT_PHASE
protected static final java.lang.String CACHE_DATA_IMPORT_LIFECYCLE_PROPERTY_NAME
protected static final java.lang.String CACHE_DATA_IMPORT_PHASE_PROPERTY_NAME
public LifecycleAwareCacheDataImporterExporter(@NonNull
CacheDataImporterExporter importerExporter)
LifecycleAwareCacheDataImporterExporter initialized with the given,
target CacheDataImporterExporter that is wrapped by this implementation to decorate all cache import
& export data operations in order to make them Lifecycle aware and capable.importerExporter - CacheDataImporterExporter wrapped by this implementation to decorate
the cache data import/export operations to be Lifecycle aware and capable; must not be null.java.lang.IllegalArgumentException - if CacheDataImporterExporter is null.CacheDataImporterExporterpublic void afterPropertiesSet()
throws java.lang.Exception
CacheDataImporterExporter if the importer/exporter
implements InitializingBean.afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanjava.lang.Exception - if CacheDataImporterExporter initialization fails.public void setApplicationContext(@Nullable
org.springframework.context.ApplicationContext applicationContext)
ApplicationContext.setApplicationContext in interface org.springframework.context.ApplicationContextAwareapplicationContext - Spring ApplicationContext in which this component operates.ApplicationContext@NonNull protected CacheDataImporterExporter getCacheDataImporterExporter()
CacheDataImporterExporter wrapped by this Lifecycle aware
and capable CacheDataImporterExporter.CacheDataImporterExporter enhanced and used as the delegate for this Lifecycle aware
and capable CacheDataImporterExporter; never null.public void setEnvironment(@Nullable
org.springframework.core.env.Environment environment)
Environment used to access configuration for the behavior of
the cache data import.setEnvironment in interface org.springframework.context.EnvironmentAwareenvironment - Environment used to access context specific configuration for the cache data import.Environmentprotected java.util.Optional<org.springframework.core.env.Environment> getEnvironment()
Optional reference to the configured Environment used to access configuration
for the behavior of the cache data import.
If a reference to Environment was not configured, then this method will return Optional.empty().Optional reference to the configured Environment, or Optional.empty() if no
Environment was configured.Environment,
setEnvironment(Environment),
Optional@Autowired(required=false)
public void setExportResourceResolver(@Nullable
ResourceCapableCacheDataImporterExporter.ExportResourceResolver exportResourceResolver)
ResourceCapableCacheDataImporterExporter.ExportResourceResolver of the wrapped CacheDataImporterExporter
if the ResourceCapableCacheDataImporterExporter.ExportResourceResolver is not null and the CacheDataImporterExporter
is Resource capable.exportResourceResolver - ResourceResolver used to resolve a Resource for export.ResourceCapableCacheDataImporterExporter.ExportResourceResolver,
getCacheDataImporterExporter()@Autowired(required=false)
public void setImportResourceResolver(@Nullable
ResourceCapableCacheDataImporterExporter.ImportResourceResolver importResourceResolver)
ResourceCapableCacheDataImporterExporter.ImportResourceResolver of the wrapped CacheDataImporterExporter
if the ResourceCapableCacheDataImporterExporter.ImportResourceResolver is not null and the CacheDataImporterExporter
is Resource capable.importResourceResolver - ResourceResolver used to resolve a Resource for import.ResourceCapableCacheDataImporterExporter.ImportResourceResolver,
getCacheDataImporterExporter()public int getPhase()
getPhase in interface org.springframework.context.PhasedgetPhase in interface org.springframework.context.SmartLifecyclegetPhase in interface org.springframework.data.gemfire.support.SmartLifecycleSupportpublic void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)
setResourceLoader in interface org.springframework.context.ResourceLoaderAware@Autowired(required=false)
public void setResourceReader(@Nullable
ResourceReader resourceReader)
ResourceReader of the wrapped CacheDataImporterExporter
if the ResourceReader is not null and the CacheDataImporterExporter
is Resource capable.resourceReader - ResourceReader used to read data from a Resource on import.ResourceReader,
getCacheDataImporterExporter()@Autowired(required=false)
public void setResourceWriter(@Nullable
ResourceWriter resourceWriter)
ResourceWriter of the wrapped CacheDataImporterExporter
if the ResourceWriter is not null and the CacheDataImporterExporter
is Resource capable.resourceWriter - ResourceWriter used to write data to a Resource on export.ResourceWriter,
getCacheDataImporterExporter()@NonNull
public org.apache.geode.cache.Region exportFrom(@NonNull
org.apache.geode.cache.Region region)
CacheDataExporterRegion.exportFrom in interface CacheDataExporterregion - Region to export data from.Region.Region@NonNull
public org.apache.geode.cache.Region importInto(@NonNull
org.apache.geode.cache.Region region)
CacheDataImporterRegion.importInto in interface CacheDataImporterregion - Region to import data into.Region.Regionprotected LifecycleAwareCacheDataImporterExporter.ImportLifecycle resolveImportLifecycle()
LifecycleAwareCacheDataImporterExporter.ImportLifecycle.
The cache data import lifecycle is configured with the
spring.boot.data.gemfire.cache.data.import.lifecycle property
in Spring Boot application.properties.LifecycleAwareCacheDataImporterExporter.ImportLifecycle.LifecycleAwareCacheDataImporterExporter.ImportLifecycleprotected int resolveImportPhase()
SmartLifecycle Phase in which the cache data
import will be performed.SmartLifecycle Phase.getPhase()public void start()
Regions.start in interface org.springframework.context.LifecyclegetCacheDataImporterExporter(),
getRegionsForImport()