Save This Page
Home » spring-framework-2.5.5-with-dependencies » org.springframework » beans » factory » support » [javadoc | source]
org.springframework.beans.factory.support
public class: DefaultSingletonBeanRegistry [javadoc | source]
java.lang.Object
   org.springframework.core.SimpleAliasRegistry
      org.springframework.beans.factory.support.DefaultSingletonBeanRegistry

All Implemented Interfaces:
    SingletonBeanRegistry, AliasRegistry

Direct Known Subclasses:
    DefaultListableBeanFactory, FactoryBeanRegistrySupport, AbstractAutowireCapableBeanFactory, AbstractBeanFactory, XmlBeanFactory

Generic registry for shared bean instances, implementing the org.springframework.beans.factory.config.SingletonBeanRegistry . Allows for registering singleton instances that should be shared for all callers of the registry, to be obtained via bean name.

Also supports registration of org.springframework.beans.factory.DisposableBean instances, (which might or might not correspond to registered singletons), to be destroyed on shutdown of the registry. Dependencies between beans can be registered to enforce an appropriate shutdown order.

This class mainly serves as base class for org.springframework.beans.factory.BeanFactory implementations, factoring out the common management of singleton bean instances. Note that the org.springframework.beans.factory.config.ConfigurableBeanFactory interface extends the SingletonBeanRegistry interface.

Note that this class assumes neither a bean definition concept nor a specific creation process for bean instances, in contrast to AbstractBeanFactory and DefaultListableBeanFactory (which inherit from it). Can alternatively also be used as a nested helper to delegate to.

Field Summary
protected static final  Object NULL_OBJECT    Internal marker for a null singleton object: used as marker value for concurrent Maps (which don't support null values). 
protected final  Log logger    Logger available to subclasses 
Method from org.springframework.beans.factory.support.DefaultSingletonBeanRegistry Summary:
addSingleton,   addSingletonFactory,   afterSingletonCreation,   beforeSingletonCreation,   containsSingleton,   destroyBean,   destroySingleton,   destroySingletons,   getDependenciesForBean,   getDependentBeans,   getSingleton,   getSingleton,   getSingleton,   getSingletonCount,   getSingletonMutex,   getSingletonNames,   hasDependentBean,   isSingletonCurrentlyInCreation,   onSuppressedException,   registerDependentBean,   registerDisposableBean,   registerSingleton,   removeSingleton
Methods from org.springframework.core.SimpleAliasRegistry:
allowAliasOverriding,   canonicalName,   getAliases,   isAlias,   registerAlias,   removeAlias,   resolveAliases
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.springframework.beans.factory.support.DefaultSingletonBeanRegistry Detail:
 protected  void addSingleton(String beanName,
    Object singletonObject) 
    Add the given singleton object to the singleton cache of this factory.

    To be called for eager registration of singletons.

 protected  void addSingletonFactory(String beanName,
    ObjectFactory singletonFactory) 
    Add the given singleton factory for building the specified singleton if necessary.

    To be called for eager registration of singletons, e.g. to be able to resolve circular references.

 protected  void afterSingletonCreation(String beanName) 
    Callback after singleton creation.

    Default implementation marks the singleton as not in creation anymore.

 protected  void beforeSingletonCreation(String beanName) 
    Callback before singleton creation.

    Default implementation register the singleton as currently in creation.

 public boolean containsSingleton(String beanName) 
 protected  void destroyBean(String beanName,
    DisposableBean bean) 
    Destroy the given bean. Must destroy beans that depend on the given bean before the bean itself. Should not throw any exceptions.
 public  void destroySingleton(String beanName) 
    Destroy the given bean. Delegates to destroyBean if a corresponding disposable bean instance is found.
 public  void destroySingletons() 
 public String[] getDependenciesForBean(String beanName) 
    Return the names of all beans that the specified bean depends on, if any.
 public String[] getDependentBeans(String beanName) 
    Return the names of all beans which depend on the specified bean, if any.
 public Object getSingleton(String beanName) 
 protected Object getSingleton(String beanName,
    boolean allowEarlyReference) 
    Return the (raw) singleton object registered under the given name.

    Checks already instantiated singletons and also allows for an early reference to a currently created singleton (resolving a circular reference).

 public Object getSingleton(String beanName,
    ObjectFactory singletonFactory) 
    Return the (raw) singleton object registered under the given name, creating and registering a new one if none registered yet.
 public int getSingletonCount() 
 protected final Object getSingletonMutex() 
    Expose the singleton mutex to subclasses.

    Subclasses should synchronize on the given Object if they perform any sort of extended singleton creation phase. In particular, subclasses should not have their own mutexes involved in singleton creation, to avoid the potential for deadlocks in lazy-init situations.

 public String[] getSingletonNames() 
 protected boolean hasDependentBean(String beanName) 
    Determine whether a dependent bean has been registered under the given name.
 public final boolean isSingletonCurrentlyInCreation(String beanName) 
    Return whether the specified singleton bean is currently in creation (within the entire factory).
 protected  void onSuppressedException(Exception ex) 
    Register an Exception that happened to get suppressed during the creation of a singleton bean instance, e.g. a temporary circular reference resolution problem.
 public  void registerDependentBean(String beanName,
    String dependentBeanName) 
    Register a dependent bean for the given bean, to be destroyed before the given bean is destroyed.
 public  void registerDisposableBean(String beanName,
    DisposableBean bean) 
    Add the given bean to the list of disposable beans in this registry. Disposable beans usually correspond to registered singletons, matching the bean name but potentially being a different instance (for example, a DisposableBean adapter for a singleton that does not naturally implement Spring's DisposableBean interface).
 public  void registerSingleton(String beanName,
    Object singletonObject) throws IllegalStateException 
 protected  void removeSingleton(String beanName) 
    Remove the bean with the given name from the singleton cache of this factory, to be able to clean up eager registration of a singleton if creation failed.