public class SpringContextBootstrappingInitializer extends Object implements Declarable, ApplicationListener<ApplicationContextEvent>
Modifier and Type | Field and Description |
---|---|
static String |
BASE_PACKAGES_PARAMETER |
protected static String |
CHARS_TO_DELETE |
protected static String |
COMMA_DELIMITER |
static String |
CONTEXT_CONFIG_LOCATIONS_PARAMETER |
Constructor and Description |
---|
SpringContextBootstrappingInitializer() |
Modifier and Type | Method and Description |
---|---|
protected ConfigurableApplicationContext |
createApplicationContext(String[] configLocations)
Creates (constructs and configures) a ConfigurableApplicationContext instance based on the specified locations
of the context configuration meta-data files.
|
protected ConfigurableApplicationContext |
createApplicationContext(String[] basePackages,
String[] configLocations)
Creates (constructs and configures) an instance of the ConfigurableApplicationContext based on either the
specified base packages containing @Configuration, @Component or JSR 330 annotated classes to scan, or the
specified locations of context configuration meta-data files.
|
static ConfigurableApplicationContext |
getApplicationContext()
Gets a reference to the Spring ApplicationContext constructed, configured and initialized inside the GemFire
Server-based JVM process.
|
void |
init(Properties parameters)
Initializes a Spring ApplicationContext with the given parameters specified with a GemFire <initializer>
block in cache.xml.
|
protected ConfigurableApplicationContext |
initApplicationContext(ConfigurableApplicationContext applicationContext)
Initializes the given ApplicationContext by registering this SpringContextBootstrappingInitializer as an
ApplicationListener and registering a Runtime shutdown hook.
|
protected static void |
notifyOnExistingContextRefreshedEvent(ApplicationListener<ContextRefreshedEvent> listener)
Notifies any Spring ApplicationListeners of a current and existing ContextRefreshedEvent if the
ApplicationContext had been previously created, initialized and refreshed before any ApplicationListeners
interested in ContextRefreshedEvents were registered so that application components (such as the
GemFire CacheLoaders extending LazyWiringDeclarableSupport objects) registered late, requiring configuration
(auto-wiring), also get notified and wired accordingly.
|
protected String |
nullSafeGetApplicationContextId(ApplicationContext applicationContext)
Gets the the ID of the Spring ApplicationContext in a null-safe manner.
|
void |
onApplicationEvent(ApplicationContextEvent event)
Gets notified when the Spring ApplicationContext gets created and refreshed by GemFire, once the
<initializer> block is processed and the SpringContextBootstrappingInitializer Declarable component
is initialized.
|
protected ConfigurableApplicationContext |
refreshApplicationContext(ConfigurableApplicationContext applicationContext)
Refreshes the given ApplicationContext making the context active.
|
static <T extends ApplicationListener<ContextRefreshedEvent>> |
register(T listener)
Registers a Spring ApplicationListener to be notified when the Spring ApplicationContext is created by GemFire
when instantiating and initializing Declarables declared inside the <initializer> block inside GemFire's
cache.xml file.
|
static <T extends ApplicationListener<ContextRefreshedEvent>> |
unregister(T listener)
Un-registers the Spring ApplicationListener from this SpringContextBootstrappingInitializer in order to stop
receiving ApplicationEvents on Spring context refreshes.
|
public static final String BASE_PACKAGES_PARAMETER
public static final String CONTEXT_CONFIG_LOCATIONS_PARAMETER
protected static final String CHARS_TO_DELETE
protected static final String COMMA_DELIMITER
public SpringContextBootstrappingInitializer()
public static ConfigurableApplicationContext getApplicationContext()
ConfigurableApplicationContext
protected static void notifyOnExistingContextRefreshedEvent(ApplicationListener<ContextRefreshedEvent> listener)
listener
- a Spring ApplicationListener requiring notification of any ContextRefreshedEvents after the
ApplicationContext has already been created, initialized and/or refreshed.ApplicationListener.onApplicationEvent(org.springframework.context.ApplicationEvent)
,
ContextRefreshedEvent
public static <T extends ApplicationListener<ContextRefreshedEvent>> T register(T listener)
T
- the Class type of the Spring ApplicationListener.listener
- the ApplicationListener to register for ContextRefreshedEvents multi-casted by this
SpringContextBootstrappingInitializer.notifyOnExistingContextRefreshedEvent(org.springframework.context.ApplicationListener)
,
unregister(org.springframework.context.ApplicationListener)
,
ApplicationListener
,
ContextRefreshedEvent
,
#addApplicationListener(org.springframework.context.ApplicationListener)
public static <T extends ApplicationListener<ContextRefreshedEvent>> T unregister(T listener)
T
- the Class type of the Spring ApplicationListener.listener
- the ApplicationListener to unregister from receiving ContextRefreshedEvents by this
SpringContextBootstrappingInitializer.register(org.springframework.context.ApplicationListener)
,
ApplicationListener
,
ContextRefreshedEvent
,
#removeApplicationListener(org.springframework.context.ApplicationListener)
protected ConfigurableApplicationContext createApplicationContext(String[] configLocations)
configLocations
- a String array indicating the locations of the context configuration meta-data files
used to configure the ConfigurableApplicationContext instance.IllegalArgumentException
- if the configLocations parameter argument is null or empty.createApplicationContext(String[], String[])
,
ConfigurableApplicationContext
protected ConfigurableApplicationContext createApplicationContext(String[] basePackages, String[] configLocations)
basePackages
- the base packages to scan for application @Components and @Configuration classes.configLocations
- a String array indicating the locations of the context configuration meta-data files
used to configure the ClassPathXmlApplicationContext instance.IllegalArgumentException
- if both the basePackages and configLocation parameter arguments
are null or empty.createApplicationContext(String[])
,
AnnotationConfigApplicationContext
,
AnnotationConfigApplicationContext.scan(String...)
,
ClassPathXmlApplicationContext
protected ConfigurableApplicationContext initApplicationContext(ConfigurableApplicationContext applicationContext)
applicationContext
- the ConfigurableApplicationContext to initialize.IllegalArgumentException
- if the ApplicationContext reference is null!ConfigurableApplicationContext
,
ConfigurableApplicationContext.addApplicationListener(org.springframework.context.ApplicationListener)
,
ConfigurableApplicationContext.registerShutdownHook()
protected ConfigurableApplicationContext refreshApplicationContext(ConfigurableApplicationContext applicationContext)
applicationContext
- the ConfigurableApplicationContext to refresh.IllegalArgumentException
- if the ApplicationContext reference is null!ConfigurableApplicationContext
,
ConfigurableApplicationContext.refresh()
protected String nullSafeGetApplicationContextId(ApplicationContext applicationContext)
applicationContext
- the Spring ApplicationContext to retrieve the ID for.ApplicationContext.getId()
public void init(Properties parameters)
init
in interface Declarable
parameters
- a Properties object containing the configuration parameters and settings defined in the
GemFire cache.xml <initializer> block for the declared SpringContextBootstrappingInitializer
GemFire Declarable object.createApplicationContext(String[], String[])
,
initApplicationContext(org.springframework.context.ConfigurableApplicationContext)
,
refreshApplicationContext(org.springframework.context.ConfigurableApplicationContext)
,
Properties
public void onApplicationEvent(ApplicationContextEvent event)
onApplicationEvent
in interface ApplicationListener<ApplicationContextEvent>
event
- the ApplicationContextEvent signaling that the Spring ApplicationContext has been created
and refreshed by GemFire, or closed when the JVM process exits.ContextClosedEvent
,
ContextRefreshedEvent
,
#multicastEvent(org.springframework.context.ApplicationEvent)