public abstract class AbstractSpaceFactoryBean extends Object implements org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.FactoryBean, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationListener, MemberAliveIndicator, ServiceDetailsProvider, InternalDumpProcessor
IJSpace
implementation.
Provides support for raising Spring application events: BeforeSpaceModeChangeEvent
and
AfterSpaceModeChangeEvent
alerting other beans of the current space mode
(primary/backup). Beans that wish to be notified of it should implement Spring ApplicationListener
. Note that this space mode events might be
raised more than once for the same space mode, and beans that listen to it should take it into
account.
The space mode event will be raised regardless of the space "type" that is used. For embedded
spaces, an actual space mode event listener will be registered with the actual cluster member (if
not in cluster mode, the actual space). For remote space lookups (jini/rmi), no listener will be
registered and Space mode events will still be raised during context refresh with a
PRIMARY
mode in order to allow beans to be written regardless of how the space is
looked up.
Derived classes should implement the doCreateSpace()
to obtain the IJSpace
.
Modifier and Type | Field and Description |
---|---|
protected org.apache.commons.logging.Log |
logger |
Constructor and Description |
---|
AbstractSpaceFactoryBean() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Initializes the space by calling the
doCreateSpace() . |
void |
close()
Destroys the space and unregisters the internal space mode listener (if registered).
|
void |
destroy()
Destroys the space and unregisters the internal space mode listener (if registered).
|
protected abstract IJSpace |
doCreateSpace()
Responsible for creating/finding the actual
IJSpace implementation. |
protected void |
fireSpaceAfterBackupEvent()
Sends
AfterSpaceModeChangeEvent events with space mode SpaceMode.BACKUP to
all beans in the application context that implement the SpaceAfterBackupListener
interface. |
protected void |
fireSpaceAfterPrimaryEvent()
Sends
AfterSpaceModeChangeEvent events with space mode SpaceMode.PRIMARY to
all beans in the application context that implement the SpaceAfterPrimaryListener
interface. |
protected void |
fireSpaceBeforeBackupEvent()
Sends
BeforeSpaceModeChangeEvent events with space mode SpaceMode.BACKUP to
all beans in the application context that implement the SpaceBeforeBackupListener
interface. |
protected void |
fireSpaceBeforePrimaryEvent()
Sends
BeforeSpaceModeChangeEvent events with space mode SpaceMode.PRIMARY to
all beans in the application context that implement the SpaceBeforePrimaryListener
interface. |
protected org.springframework.context.ApplicationContext |
getApplicationContext() |
String |
getName() |
Object |
getObject()
Spring factory bean returning the
IJSpace created during the bean initialization
(afterPropertiesSet() ). |
Class<? extends IJSpace> |
getObjectType()
Returns the object type of the factory bean.
|
protected SecurityConfig |
getSecurityConfig() |
ServiceDetails[] |
getServicesDetails()
Retruns one or more service details that the service exposes.
|
boolean |
isAlive()
Returns if this space is alive or not by pinging the Space and if it is considered healthy.
|
boolean |
isMemberAliveEnabled()
Should this space be checked to see if it is alive or not.
|
protected boolean |
isRegisterForSpaceModeNotifications()
Returns if the space should register for primary backup notifications.
|
boolean |
isSingleton()
Returns
true since this factory is a singleton. |
void |
onApplicationEvent(org.springframework.context.ApplicationEvent applicationEvent)
If
ContextRefreshedEvent is raised will send two extra events: BeforeSpaceModeChangeEvent and AfterSpaceModeChangeEvent with the current space
mode. |
void |
process(InternalDump dump) |
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
Injected by Spring thanks to
ApplicationContextAware . |
void |
setBeanName(String name) |
void |
setCredentialsProvider(CredentialsProvider credentialsProvider)
Sets the security configuration with the provided custom credentials provider.
|
void |
setEnableMemberAliveIndicator(Boolean enableMemberAliveIndicator)
Should this Space bean control if the cluster member is alive or not.
|
void |
setPrimaryBackupListener(ISpaceModeListener primaryBackupListener)
Sets a custom primary backup listener
|
void |
setRegisterForSpaceModeNotifications(boolean registerForSpaceMode)
Sets if the space should register for primary backup (mode) notifications.
|
void |
setSecurityConfig(SecurityConfig securityConfig)
Sets security configuration for the Space.
|
void |
setUserDetails(UserDetails userDetails)
Sets the security configuration with the provided custom user details.
|
public void setRegisterForSpaceModeNotifications(boolean registerForSpaceMode)
rmi
or jini
protocols.public void setUserDetails(UserDetails userDetails)
userDetails
- a custom user details.public void setCredentialsProvider(CredentialsProvider credentialsProvider)
credentialsProvider
- a custom credentials provider.public void setSecurityConfig(SecurityConfig securityConfig)
protected SecurityConfig getSecurityConfig()
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
ApplicationContextAware
.setApplicationContext
in interface org.springframework.context.ApplicationContextAware
org.springframework.beans.BeansException
protected org.springframework.context.ApplicationContext getApplicationContext()
public void setBeanName(String name)
setBeanName
in interface org.springframework.beans.factory.BeanNameAware
public void setPrimaryBackupListener(ISpaceModeListener primaryBackupListener)
public void setEnableMemberAliveIndicator(Boolean enableMemberAliveIndicator)
true
if the Space started is an embedded Space, and false
if the it
is connected to a remote Space.public void afterPropertiesSet() throws org.springframework.dao.DataAccessException
doCreateSpace()
.
Registers with the Space an internal space mode listener in order to be able to send
Spring level BeforeSpaceModeChangeEvent
and AfterSpaceModeChangeEvent
for
primary and backup handling of different beans within the context. The registration is based
on isRegisterForSpaceModeNotifications()
.
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
org.springframework.dao.DataAccessException
public void destroy() throws Exception
destroy
in interface org.springframework.beans.factory.DisposableBean
Exception
public void close()
public void onApplicationEvent(org.springframework.context.ApplicationEvent applicationEvent)
ContextRefreshedEvent
is raised will send two extra events: BeforeSpaceModeChangeEvent
and AfterSpaceModeChangeEvent
with the current space
mode. This is done since other beans that use this events might not catch them while the
context is constructed.
Note, this will mean that events with the same Space mode might be raised, one after the other, and Spring beans that listens for them should take it into account.
onApplicationEvent
in interface org.springframework.context.ApplicationListener
public Object getObject()
IJSpace
created during the bean initialization
(afterPropertiesSet()
).getObject
in interface org.springframework.beans.factory.FactoryBean
IJSpace
implementationpublic Class<? extends IJSpace> getObjectType()
IJSpace
implementation class.getObjectType
in interface org.springframework.beans.factory.FactoryBean
public boolean isSingleton()
true
since this factory is a singleton.isSingleton
in interface org.springframework.beans.factory.FactoryBean
public boolean isMemberAliveEnabled()
isMemberAliveEnabled
in interface MemberAliveIndicator
public boolean isAlive() throws Exception
isAlive
in interface MemberAliveIndicator
Exception
protected abstract IJSpace doCreateSpace() throws org.springframework.dao.DataAccessException
IJSpace
implementation.org.springframework.dao.DataAccessException
protected boolean isRegisterForSpaceModeNotifications()
setRegisterForSpaceModeNotifications(boolean)
was set, will return this flag. If not, will
register to primary backup notification if the space was found using an embedded protocol,
and will not register for notification if the space was found using rmi
or
jini
protocols.protected void fireSpaceBeforeBackupEvent()
BeforeSpaceModeChangeEvent
events with space mode SpaceMode.BACKUP
to
all beans in the application context that implement the SpaceBeforeBackupListener
interface.protected void fireSpaceAfterBackupEvent()
AfterSpaceModeChangeEvent
events with space mode SpaceMode.BACKUP
to
all beans in the application context that implement the SpaceAfterBackupListener
interface.protected void fireSpaceBeforePrimaryEvent()
BeforeSpaceModeChangeEvent
events with space mode SpaceMode.PRIMARY
to
all beans in the application context that implement the SpaceBeforePrimaryListener
interface.protected void fireSpaceAfterPrimaryEvent()
AfterSpaceModeChangeEvent
events with space mode SpaceMode.PRIMARY
to
all beans in the application context that implement the SpaceAfterPrimaryListener
interface.public ServiceDetails[] getServicesDetails()
ServiceDetailsProvider
getServicesDetails
in interface ServiceDetailsProvider
public String getName()
getName
in interface InternalDumpProcessor
public void process(InternalDump dump) throws InternalDumpProcessorFailedException
process
in interface InternalDumpProcessor
InternalDumpProcessorFailedException
Copyright © GigaSpaces.