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:
-
RegionApplicationContextApplicationContextAwareEnvironmentAwareLifecycleResourceLoaderAwareEnvironmentResourceLoaderSmartLifecycleSupportResourceReaderResourceResolverResourceWriterCacheDataImporterExporterResourceCapableCacheDataImporterExporter.ExportResourceResolverResourceCapableCacheDataImporterExporter.ImportResourceResolver- Decorator Software Design Pattern
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumAnEnumerationdefining the different modes for the cache data import lifecycle. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Stringprotected static final Stringprotected static final intFields inherited from interface org.springframework.data.gemfire.support.SmartLifecycleSupport
DEFAULT_AUTO_STARTUP, DEFAULT_IS_RUNNING, DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionLifecycleAwareCacheDataImporterExporter(CacheDataImporterExporter importerExporter) Constructs a new instance of theLifecycleAwareCacheDataImporterExporterinitialized with the given, targetCacheDataImporterExporterthat is wrapped by this implementation to decorate all cache import and export data operations in order to make themLifecycleaware and capable. -
Method Summary
Modifier and TypeMethodDescriptionvoidInitializes the wrappedCacheDataImporterExporterif the importer/exporter implementsInitializingBean.org.apache.geode.cache.RegionexportFrom(org.apache.geode.cache.Region region) Exports data contained in the givenRegion.protected CacheDataImporterExporterReturns a reference to the configuredCacheDataImporterExporterwrapped by thisLifecycleaware and capableCacheDataImporterExporter.protected Optional<org.springframework.core.env.Environment>Returns anOptionalreference to the configuredEnvironmentused to access configuration for the behavior of the cache data import.intgetPhase()org.apache.geode.cache.RegionimportInto(org.apache.geode.cache.Region region) Imports data into the givenRegion.Resolves the configuredLifecycleAwareCacheDataImporterExporter.ImportLifecycle.protected intResolves the configuredSmartLifecycle Phasein which the cache data import will be performed.voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) Configures a reference to the SpringApplicationContext.voidsetEnvironment(org.springframework.core.env.Environment environment) Configures a reference to theEnvironmentused to access configuration for the behavior of the cache data import.voidsetExportResourceResolver(ResourceCapableCacheDataImporterExporter.ExportResourceResolver exportResourceResolver) Configures theResourceCapableCacheDataImporterExporter.ExportResourceResolverof the wrappedCacheDataImporterExporterif theResourceCapableCacheDataImporterExporter.ExportResourceResolveris not null and theCacheDataImporterExporterisResourcecapable.voidsetImportResourceResolver(ResourceCapableCacheDataImporterExporter.ImportResourceResolver importResourceResolver) Configures theResourceCapableCacheDataImporterExporter.ImportResourceResolverof the wrappedCacheDataImporterExporterif theResourceCapableCacheDataImporterExporter.ImportResourceResolveris not null and theCacheDataImporterExporterisResourcecapable.voidsetResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader) voidsetResourceReader(ResourceReader resourceReader) Configures theResourceReaderof the wrappedCacheDataImporterExporterif theResourceReaderis not null and theCacheDataImporterExporterisResourcecapable.voidsetResourceWriter(ResourceWriter resourceWriter) Configures theResourceWriterof the wrappedCacheDataImporterExporterif theResourceWriteris not null and theCacheDataImporterExporterisResourcecapable.voidstart()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, waitMethods inherited from interface org.springframework.beans.factory.config.BeanPostProcessor
postProcessBeforeInitializationMethods inherited from interface org.springframework.geode.data.CacheDataExporter
postProcessBeforeDestructionMethods inherited from interface org.springframework.geode.data.CacheDataImporter
postProcessAfterInitializationMethods inherited from interface org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor
requiresDestructionMethods 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 theLifecycleAwareCacheDataImporterExporterinitialized with the given, targetCacheDataImporterExporterthat is wrapped by this implementation to decorate all cache import and export data operations in order to make themLifecycleaware and capable.- Parameters:
importerExporter-CacheDataImporterExporterwrapped by this implementation to decorate the cache data import/export operations to beLifecycleaware and capable; must not be null.- Throws:
IllegalArgumentException- ifCacheDataImporterExporteris null.- See Also:
-
-
Method Details
-
afterPropertiesSet
Initializes the wrappedCacheDataImporterExporterif the importer/exporter implementsInitializingBean.- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception- ifCacheDataImporterExporterinitialization fails.
-
setApplicationContext
public void setApplicationContext(@Nullable org.springframework.context.ApplicationContext applicationContext) Configures a reference to the SpringApplicationContext.- Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Parameters:
applicationContext- SpringApplicationContextin which this component operates.- See Also:
-
ApplicationContext
-
getCacheDataImporterExporter
Returns a reference to the configuredCacheDataImporterExporterwrapped by thisLifecycleaware and capableCacheDataImporterExporter.- Returns:
- the
CacheDataImporterExporterenhanced and used as the delegate for thisLifecycleaware and capableCacheDataImporterExporter; never null.
-
setEnvironment
public void setEnvironment(@Nullable org.springframework.core.env.Environment environment) Configures a reference to theEnvironmentused to access configuration for the behavior of the cache data import.- Specified by:
setEnvironmentin interfaceorg.springframework.context.EnvironmentAware- Parameters:
environment-Environmentused to access context specific configuration for the cache data import.- See Also:
-
Environment
-
getEnvironment
Returns anOptionalreference to the configuredEnvironmentused to access configuration for the behavior of the cache data import. If a reference toEnvironmentwas not configured, then this method will returnOptional.empty().- Returns:
- an
Optionalreference to the configuredEnvironment, orOptional.empty()if noEnvironmentwas configured. - See Also:
-
EnvironmentsetEnvironment(Environment)Optional
-
setExportResourceResolver
@Autowired(required=false) public void setExportResourceResolver(@Nullable ResourceCapableCacheDataImporterExporter.ExportResourceResolver exportResourceResolver) Configures theResourceCapableCacheDataImporterExporter.ExportResourceResolverof the wrappedCacheDataImporterExporterif theResourceCapableCacheDataImporterExporter.ExportResourceResolveris not null and theCacheDataImporterExporterisResourcecapable.- Parameters:
exportResourceResolver-ResourceResolverused to resolve aResourcefor export.- See Also:
-
setImportResourceResolver
@Autowired(required=false) public void setImportResourceResolver(@Nullable ResourceCapableCacheDataImporterExporter.ImportResourceResolver importResourceResolver) Configures theResourceCapableCacheDataImporterExporter.ImportResourceResolverof the wrappedCacheDataImporterExporterif theResourceCapableCacheDataImporterExporter.ImportResourceResolveris not null and theCacheDataImporterExporterisResourcecapable.- Parameters:
importResourceResolver-ResourceResolverused to resolve aResourcefor import.- See Also:
-
getPhase
public int getPhase()- Specified by:
getPhasein interfaceorg.springframework.context.Phased- Specified by:
getPhasein interfaceorg.springframework.context.SmartLifecycle- Specified by:
getPhasein interfaceorg.springframework.data.gemfire.support.SmartLifecycleSupport
-
setResourceLoader
public void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader) - Specified by:
setResourceLoaderin interfaceorg.springframework.context.ResourceLoaderAware
-
setResourceReader
Configures theResourceReaderof the wrappedCacheDataImporterExporterif theResourceReaderis not null and theCacheDataImporterExporterisResourcecapable.- Parameters:
resourceReader-ResourceReaderused to read data from aResourceon import.- See Also:
-
setResourceWriter
Configures theResourceWriterof the wrappedCacheDataImporterExporterif theResourceWriteris not null and theCacheDataImporterExporterisResourcecapable.- Parameters:
resourceWriter-ResourceWriterused to write data to aResourceon export.- See Also:
-
exportFrom
@NonNull public org.apache.geode.cache.Region exportFrom(@NonNull org.apache.geode.cache.Region region) Description copied from interface:CacheDataExporterExports data contained in the givenRegion.- Specified by:
exportFromin interfaceCacheDataExporter- Parameters:
region-Regionto 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) Description copied from interface:CacheDataImporterImports data into the givenRegion.- Specified by:
importIntoin interfaceCacheDataImporter- Parameters:
region-Regionto 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 Phasein 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:
startin interfaceorg.springframework.context.Lifecycle- See Also:
-
getCacheDataImporterExporter()getRegionsForImport()
-