Package tigase.kernel.core
Class Kernel
java.lang.Object
tigase.kernel.core.Kernel
- Direct Known Subclasses:
RegistrarKernel
Main class of Kernel.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
Class implements a queue for delayed dependency injection.static class
Class used for delegating beans from one kernel to the other kernel. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCalling this method instructs Kernel to delay dependency injection untilfinishDependecyDelayedInjection()
method is called.void
Calling this method instructs Kernel to end delaying dependency injection and inject all queued items.void
gc()
ReturnsDependencyManager
used in Kernel.<T> T
getInstance
(Class<T> beanClass) Returns instance of bean.protected <T> T
getInstance
(Class<T> beanClass, boolean allowNonExportable) <T> T
getInstance
(String beanName) Returns instance of bean.<T> T
getInstanceIfExistsOr
(String beanName, Function<BeanConfig, T> function) Returns instance of bean if instance exists already or calls passed function.getName()
Returns name of Kernel.getNamesOf
(Class<?> beanType) Returns name of beans matching to given type.Returns parent Kernel.void
initAll()
Forces initiate all registered beans.protected void
initBean
(BeanConfig tmpBC, Set<BeanConfig> createdBeansConfig, int deep) protected void
injectIfRequired
(BeanConfig beanConfig) boolean
isBeanClassRegistered
(String beanName) Checks if bean with given name is registered in Kernel.boolean
isBeanClassRegistered
(String beanName, boolean checkInParent) Checks if bean with given name is registered in Kernel.void
Makes symlink to bean in another Kernel.registerBean
(Class<?> beanClass) Registers bean as class in Kernel.registerBean
(String beanName) Registers bean with given name.protected BeanConfig
registerBean
(BeanConfig beanConfig, BeanConfig factoryBeanConfig, Object beanInstance) void
registerLinks
(String beanName) Register links for bean of the passed name.void
setBeanActive
(String beanName, boolean value) Change state of a bean (activate/deactivate).void
setForceAllowNull
(boolean forceAllowNull) Force injection of nulls in all dependency injection fields of all beans if required bean for injections are not available.void
Set name of the Kernel.void
shutdown()
Shutdown kernel.void
shutdown
(Comparator<BeanConfig> shutdownOrder) Shutdown kernel with passed comparator to define order in which bean will be stopped.toString()
void
unregister
(String beanName) Removes bean from Kernel.
-
Field Details
-
log
-
-
Constructor Details
-
Kernel
public Kernel()Creates instance of Kernel. -
Kernel
Creates instance of kernel.- Parameters:
name
- kernel name.
-
-
Method Details
-
initBean
protected void initBean(BeanConfig tmpBC, Set<BeanConfig> createdBeansConfig, int deep) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException -
gc
public void gc() -
getDependencyManager
ReturnsDependencyManager
used in Kernel.- Returns:
depenency manager
.
-
getInstance
Returns instance of bean.- Type Parameters:
T
- type of bean to be returned.- Parameters:
beanClass
- type of requested bean. Note that if more than one instance of bean will match, then Kernel throws exception.- Returns:
- instance of bean if bean exists and there is only single instance of it.
- Throws:
KernelException
- when more than one instance of matching beans will be found or none of matching beans is registered.
-
getInstance
Returns instance of bean. It creates bean if it is required.- Type Parameters:
T
- type of bean to be returned.- Parameters:
beanName
- name of bean to be returned.- Returns:
- instance of bean if bean exists and there is only single instance of it.
- Throws:
KernelException
- when bean with given name doesn't exists.
-
getInstanceIfExistsOr
Returns instance of bean if instance exists already or calls passed function.- Type Parameters:
T
- type of bean to be returned.- Parameters:
beanName
- name of bean to be returned.function
- function to call if instance does not exist.- Returns:
- instance of bean if bean exists and there is only single instance of it or .
- Throws:
KernelException
- when bean with given name doesn't exists.
-
getName
Returns name of Kernel.- Returns:
- name of Kernel.
-
setName
Set name of the Kernel.- Parameters:
name
- to set
-
registerLinks
Register links for bean of the passed name. -
getNamesOf
Returns name of beans matching to given type.- Parameters:
beanType
- type of searched beans.- Returns:
- collection of matching bean names.
-
getParent
Returns parent Kernel.- Returns:
- parent Kernel or
null
if there is no parent Kernel.
-
toString
-
initAll
public void initAll()Forces initiate all registered beans. -
isBeanClassRegistered
Checks if bean with given name is registered in Kernel.- Parameters:
beanName
- name of bean to check.- Returns:
true
if bean is registered (it may be not initialized!).
-
isBeanClassRegistered
Checks if bean with given name is registered in Kernel.- Parameters:
beanName
- name of bean to check.checkInParent
- should check in parent kernel if not found in the current Kernel.- Returns:
true
if bean is registered (it may be not initialized!).
-
ln
Makes symlink to bean in another Kernel.- Parameters:
exportingBeanName
- name bean to be linked.destinationKernel
- destination Kernel.destinationName
- name of bean in destination Kernel.
-
registerBean
Registers bean as class in Kernel. Class must be annotated withBean
annotation.For example:
// If Bean1.class is annotated by @Bean annotation. registerBean(Bean1.class).exec();
- Parameters:
beanClass
- class of bean to register.- Returns:
config builder
what allows to finish bean registering.
-
registerBean
Registers bean with given name. Class or instance of bean must be defined in returnedconfig builder
.For example:
// To register already created variable bean4 as bean "bean4". krnl.registerBean("bean4").asInstance(bean4).exec(); // If Bean5 have to been created by Bean5Factory. krnl.registerBean("bean5").asClass(Bean5.class).withFactory(Bean5Factory.class).exec();
- Parameters:
beanName
- name of bean.- Returns:
config builder
what allows to finish bean registering.
-
beginDependencyDelayedInjection
Calling this method instructs Kernel to delay dependency injection untilfinishDependecyDelayedInjection()
method is called.- Returns:
- instance of a queue with delayed dependency injections
-
finishDependecyDelayedInjection
public void finishDependecyDelayedInjection(Kernel.DelayedDependencyInjectionQueue queue) throws IllegalAccessException, InstantiationException, InvocationTargetException Calling this method instructs Kernel to end delaying dependency injection and inject all queued items. -
setBeanActive
Change state of a bean (activate/deactivate).- Parameters:
beanName
- name of a beanvalue
- new state of a bean
-
setForceAllowNull
public void setForceAllowNull(boolean forceAllowNull) Force injection of nulls in all dependency injection fields of all beans if required bean for injections are not available. -
shutdown
public void shutdown()Shutdown kernel. -
shutdown
Shutdown kernel with passed comparator to define order in which bean will be stopped.- Parameters:
shutdownOrder
- comparator defining order of beans for shutdown
-
unregister
Removes bean from Kernel.- Parameters:
beanName
- name of bean to be removed.
-
toPrintable
-
getInstance
-
injectIfRequired
-
registerBean
protected BeanConfig registerBean(BeanConfig beanConfig, BeanConfig factoryBeanConfig, Object beanInstance)
-