Class LifecycleAwareCacheDataImporterExporter
java.lang.Object
org.springframework.geode.data.support.LifecycleAwareCacheDataImporterExporter
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.beans.factory.config.BeanPostProcessor
,org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor
,org.springframework.beans.factory.InitializingBean
,org.springframework.context.ApplicationContextAware
,org.springframework.context.EnvironmentAware
,org.springframework.context.Lifecycle
,org.springframework.context.Phased
,org.springframework.context.ResourceLoaderAware
,org.springframework.context.SmartLifecycle
,org.springframework.data.gemfire.support.SmartLifecycleSupport
,CacheDataExporter
,CacheDataImporter
,CacheDataImporterExporter
public class LifecycleAwareCacheDataImporterExporter
extends 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
A
CacheDataImporterExporter
implementation using the Decorator Software Design Pattern to wrap
an existing CacheDataImporterExporter
in order to decorate the cache (i.e. Region
) data
import and 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.- Since:
- 1.3.0
- See Also:
-
Region
ApplicationContext
ApplicationContextAware
EnvironmentAware
Lifecycle
ResourceLoaderAware
Environment
ResourceLoader
SmartLifecycleSupport
ResourceReader
ResourceResolver
ResourceWriter
CacheDataImporterExporter
ResourceCapableCacheDataImporterExporter.ExportResourceResolver
ResourceCapableCacheDataImporterExporter.ImportResourceResolver
- Decorator Software Design Pattern
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
AnEnumeration
defining the different modes for the cache data import lifecycle. -
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
protected static final String
protected static final int
Fields inherited from interface org.springframework.data.gemfire.support.SmartLifecycleSupport
DEFAULT_AUTO_STARTUP, DEFAULT_IS_RUNNING, DEFAULT_PHASE
-
Constructor Summary
ConstructorDescriptionLifecycleAwareCacheDataImporterExporter
(CacheDataImporterExporter importerExporter) Constructs a new instance of theLifecycleAwareCacheDataImporterExporter
initialized with the given, targetCacheDataImporterExporter
that is wrapped by this implementation to decorate all cache import and export data operations in order to make themLifecycle
aware and capable. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Initializes the wrappedCacheDataImporterExporter
if the importer/exporter implementsInitializingBean
.org.apache.geode.cache.Region
exportFrom
(org.apache.geode.cache.Region region) Exports data contained in the givenRegion
.protected CacheDataImporterExporter
Returns a reference to the configuredCacheDataImporterExporter
wrapped by thisLifecycle
aware and capableCacheDataImporterExporter
.protected Optional<org.springframework.core.env.Environment>
Returns anOptional
reference to the configuredEnvironment
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 givenRegion
.Resolves the configuredLifecycleAwareCacheDataImporterExporter.ImportLifecycle
.protected int
Resolves the configuredSmartLifecycle Phase
in which the cache data import will be performed.void
setApplicationContext
(org.springframework.context.ApplicationContext applicationContext) Configures a reference to the SpringApplicationContext
.void
setEnvironment
(org.springframework.core.env.Environment environment) Configures a reference to theEnvironment
used to access configuration for the behavior of the cache data import.void
setExportResourceResolver
(ResourceCapableCacheDataImporterExporter.ExportResourceResolver exportResourceResolver) Configures theResourceCapableCacheDataImporterExporter.ExportResourceResolver
of the wrappedCacheDataImporterExporter
if theResourceCapableCacheDataImporterExporter.ExportResourceResolver
is not null and theCacheDataImporterExporter
isResource
capable.void
setImportResourceResolver
(ResourceCapableCacheDataImporterExporter.ImportResourceResolver importResourceResolver) Configures theResourceCapableCacheDataImporterExporter.ImportResourceResolver
of the wrappedCacheDataImporterExporter
if theResourceCapableCacheDataImporterExporter.ImportResourceResolver
is not null and theCacheDataImporterExporter
isResource
capable.void
setResourceLoader
(org.springframework.core.io.ResourceLoader resourceLoader) void
setResourceReader
(ResourceReader resourceReader) Configures theResourceReader
of the wrappedCacheDataImporterExporter
if theResourceReader
is not null and theCacheDataImporterExporter
isResource
capable.void
setResourceWriter
(ResourceWriter resourceWriter) Configures theResourceWriter
of the wrappedCacheDataImporterExporter
if theResourceWriter
is not null and theCacheDataImporterExporter
isResource
capable.void
start()
Performs the cache data import for each of the targetedRegions
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.beans.factory.config.BeanPostProcessor
postProcessBeforeInitialization
Methods inherited from interface org.springframework.geode.data.CacheDataExporter
postProcessBeforeDestruction
Methods inherited from interface org.springframework.geode.data.CacheDataImporter
postProcessAfterInitialization
Methods inherited from interface org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor
requiresDestruction
Methods inherited from interface org.springframework.data.gemfire.support.SmartLifecycleSupport
isAutoStartup, isRunning, stop, stop
-
Field Details
-
DEFAULT_IMPORT_PHASE
protected static final int DEFAULT_IMPORT_PHASE- See Also:
-
CACHE_DATA_IMPORT_LIFECYCLE_PROPERTY_NAME
- See Also:
-
CACHE_DATA_IMPORT_PHASE_PROPERTY_NAME
- See Also:
-
-
Constructor Details
-
LifecycleAwareCacheDataImporterExporter
Constructs a new instance of theLifecycleAwareCacheDataImporterExporter
initialized with the given, targetCacheDataImporterExporter
that is wrapped by this implementation to decorate all cache import and export data operations in order to make themLifecycle
aware and capable.- Parameters:
importerExporter
-CacheDataImporterExporter
wrapped by this implementation to decorate the cache data import/export operations to beLifecycle
aware and capable; must not be null.- Throws:
IllegalArgumentException
- ifCacheDataImporterExporter
is null.- See Also:
-
-
Method Details
-
afterPropertiesSet
Initializes the wrappedCacheDataImporterExporter
if the importer/exporter implementsInitializingBean
.- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
- ifCacheDataImporterExporter
initialization fails.
-
setApplicationContext
public void setApplicationContext(@Nullable org.springframework.context.ApplicationContext applicationContext) Configures a reference to the SpringApplicationContext
.- Specified by:
setApplicationContext
in interfaceorg.springframework.context.ApplicationContextAware
- Parameters:
applicationContext
- SpringApplicationContext
in which this component operates.- See Also:
-
ApplicationContext
-
getCacheDataImporterExporter
Returns a reference to the configuredCacheDataImporterExporter
wrapped by thisLifecycle
aware and capableCacheDataImporterExporter
.- Returns:
- the
CacheDataImporterExporter
enhanced and used as the delegate for thisLifecycle
aware and capableCacheDataImporterExporter
; never null.
-
setEnvironment
public void setEnvironment(@Nullable org.springframework.core.env.Environment environment) Configures a reference to theEnvironment
used to access configuration for the behavior of the cache data import.- Specified by:
setEnvironment
in interfaceorg.springframework.context.EnvironmentAware
- Parameters:
environment
-Environment
used to access context specific configuration for the cache data import.- See Also:
-
Environment
-
getEnvironment
Returns anOptional
reference to the configuredEnvironment
used to access configuration for the behavior of the cache data import. If a reference toEnvironment
was not configured, then this method will returnOptional.empty()
.- Returns:
- an
Optional
reference to the configuredEnvironment
, orOptional.empty()
if noEnvironment
was configured. - See Also:
-
Environment
setEnvironment(Environment)
Optional
-
setExportResourceResolver
@Autowired(required=false) public void setExportResourceResolver(@Nullable ResourceCapableCacheDataImporterExporter.ExportResourceResolver exportResourceResolver) Configures theResourceCapableCacheDataImporterExporter.ExportResourceResolver
of the wrappedCacheDataImporterExporter
if theResourceCapableCacheDataImporterExporter.ExportResourceResolver
is not null and theCacheDataImporterExporter
isResource
capable.- Parameters:
exportResourceResolver
-ResourceResolver
used to resolve aResource
for export.- See Also:
-
setImportResourceResolver
@Autowired(required=false) public void setImportResourceResolver(@Nullable ResourceCapableCacheDataImporterExporter.ImportResourceResolver importResourceResolver) Configures theResourceCapableCacheDataImporterExporter.ImportResourceResolver
of the wrappedCacheDataImporterExporter
if theResourceCapableCacheDataImporterExporter.ImportResourceResolver
is not null and theCacheDataImporterExporter
isResource
capable.- Parameters:
importResourceResolver
-ResourceResolver
used to resolve aResource
for import.- See Also:
-
getPhase
public int getPhase()- Specified by:
getPhase
in interfaceorg.springframework.context.Phased
- Specified by:
getPhase
in interfaceorg.springframework.context.SmartLifecycle
- Specified by:
getPhase
in interfaceorg.springframework.data.gemfire.support.SmartLifecycleSupport
-
setResourceLoader
public void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader) - Specified by:
setResourceLoader
in interfaceorg.springframework.context.ResourceLoaderAware
-
setResourceReader
Configures theResourceReader
of the wrappedCacheDataImporterExporter
if theResourceReader
is not null and theCacheDataImporterExporter
isResource
capable.- Parameters:
resourceReader
-ResourceReader
used to read data from aResource
on import.- See Also:
-
setResourceWriter
Configures theResourceWriter
of the wrappedCacheDataImporterExporter
if theResourceWriter
is not null and theCacheDataImporterExporter
isResource
capable.- Parameters:
resourceWriter
-ResourceWriter
used to write data to aResource
on export.- See Also:
-
exportFrom
@NonNull public org.apache.geode.cache.Region exportFrom(@NonNull org.apache.geode.cache.Region region) Exports data contained in the givenRegion
.- Specified by:
exportFrom
in interfaceCacheDataExporter
- Parameters:
region
-Region
to export data from.- Returns:
- the given
Region
. - See Also:
-
Region
-
importInto
@NonNull public org.apache.geode.cache.Region importInto(@NonNull org.apache.geode.cache.Region region) Imports data into the givenRegion
.- Specified by:
importInto
in interfaceCacheDataImporter
- Parameters:
region
-Region
to import data into.- Returns:
- the given
Region
. - See Also:
-
Region
-
resolveImportLifecycle
Resolves the configuredLifecycleAwareCacheDataImporterExporter.ImportLifecycle
. The cache data import lifecycle is configured with the spring.boot.data.gemfire.cache.data.import.lifecycle property in Spring Boot application.properties.- Returns:
- the configured
LifecycleAwareCacheDataImporterExporter.ImportLifecycle
. - See Also:
-
resolveImportPhase
protected int resolveImportPhase()Resolves the configuredSmartLifecycle Phase
in which the cache data import will be performed.- Returns:
- the configured
SmartLifecycle Phase
. - See Also:
-
start
public void start()Performs the cache data import for each of the targetedRegions
.- Specified by:
start
in interfaceorg.springframework.context.Lifecycle
- See Also:
-
getCacheDataImporterExporter()
getRegionsForImport()
-