tigase.kernel.core

## Class Kernel

- java.lang.Object
- - tigase.kernel.core.Kernel

- Direct Known Subclasses:
    RegistrarKernel

      public class Kernel
      extends Object

  Main class of Kernel.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `Kernel.DelayedDependencyInjectionQueue` Class implements a queue for delayed dependency injection.
    `static class` | `Kernel.DelegatedBeanConfig` Class used for delegating beans from one kernel to the other kernel.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static Logger` | `log`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Kernel()` Creates instance of Kernel.
    `Kernel(String name)` Creates instance of kernel.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Kernel.DelayedDependencyInjectionQueue` | `beginDependencyDelayedInjection()` Calling this method instructs Kernel to delay dependency injection until `finishDependecyDelayedInjection()` method is called.
    `void` | `finishDependecyDelayedInjection(Kernel.DelayedDependencyInjectionQueue queue)` Calling this method instructs Kernel to end delaying dependency injection and inject all queued items.
    `void` | `gc()`
    `DependencyManager` | `getDependencyManager()` Returns `DependencyManager` 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.
    `String` | `getName()` Returns name of Kernel.
    `Collection<String>` | `getNamesOf(Class<?> beanType)` Returns name of beans matching to given type.
    `Kernel` | `getParent()` 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` | `ln(String exportingBeanName, Kernel destinationKernel, String destinationName)` Makes symlink to bean in another Kernel.
    `protected BeanConfig` | `registerBean(BeanConfig beanConfig, BeanConfig factoryBeanConfig, Object beanInstance)`
    `BeanConfigBuilder` | `registerBean(Class<?> beanClass)` Registers bean as class in Kernel.
    `BeanConfigBuilder` | `registerBean(String beanName)` Registers bean with given name.
    `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` | `setName(String name)` 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.
    `String` | `toPrintable()`
    `String` | `toString()`
    `void` | `unregister(String beanName)` Removes bean from Kernel.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### log

          protected static final Logger log

  - ### Constructor Detail

    - #### Kernel

          public Kernel()

      Creates instance of Kernel.

    - #### Kernel

          public Kernel(String name)

      Creates instance of kernel.
      Parameters:
        `name` - kernel name.

  - ### Method Detail

    - #### initBean

          protected void initBean(BeanConfig tmpBC,
                                  Set<BeanConfig> createdBeansConfig,
                                  int deep)
                           throws IllegalAccessException,
                                  IllegalArgumentException,
                                  InvocationTargetException,
                                  InstantiationException

      Throws:
        `IllegalAccessException`
        `IllegalArgumentException`
        `InvocationTargetException`
        `InstantiationException`

    - #### gc

          public void gc()

    - #### getDependencyManager

          public DependencyManager getDependencyManager()

      Returns `DependencyManager` used in Kernel.
      Returns:
        `depenency manager`.

    - #### getInstance

          public <T> T getInstance(Class<T> beanClass)
                            throws KernelException

      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

          public <T> T getInstance(String beanName)

      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

          public <T> T getInstanceIfExistsOr(String beanName,
                                             Function<BeanConfig,T> function)

      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

          public String getName()

      Returns name of Kernel.
      Returns:
        name of Kernel.

    - #### setName

          public void setName(String name)

      Set name of the Kernel.
      Parameters:
        `name` - to set

    - #### registerLinks

          public void registerLinks(String beanName)

      Register links for bean of the passed name.

    - #### getNamesOf

          public Collection<String> getNamesOf(Class<?> beanType)

      Returns name of beans matching to given type.
      Parameters:
        `beanType` - type of searched beans.
      Returns:
        collection of matching bean names.

    - #### getParent

          public Kernel getParent()

      Returns parent Kernel.
      Returns:
        parent Kernel or `null` if there is no parent Kernel.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### initAll

          public void initAll()

      Forces initiate all registered beans.

    - #### isBeanClassRegistered

          public boolean isBeanClassRegistered(String beanName)

      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

          public boolean isBeanClassRegistered(String beanName,
                                               boolean checkInParent)

      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

          public void ln(String exportingBeanName,
                         Kernel destinationKernel,
                         String destinationName)

      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

          public BeanConfigBuilder registerBean(Class<?> beanClass)

      Registers bean as class in Kernel. Class must be annotated with `Bean` 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

          public BeanConfigBuilder registerBean(String beanName)

      Registers bean with given name. Class or instance of bean must be defined in returned `config 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

          public Kernel.DelayedDependencyInjectionQueue beginDependencyDelayedInjection()

      Calling this method instructs Kernel to delay dependency injection until `finishDependecyDelayedInjection()` 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.
      Throws:
        `IllegalAccessException`
        `InstantiationException`
        `InvocationTargetException`

    - #### setBeanActive

          public void setBeanActive(String beanName,
                                    boolean value)

      Change state of a bean (activate/deactivate).
      Parameters:
        `beanName` - name of a bean
        `value` - 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

          public void shutdown(Comparator<BeanConfig> shutdownOrder)

      Shutdown kernel with passed comparator to define order in which bean will be stopped.
      Parameters:
        `shutdownOrder` - comparator defining order of beans for shutdown

    - #### unregister

          public void unregister(String beanName)

      Removes bean from Kernel.
      Parameters:
        `beanName` - name of bean to be removed.

    - #### toPrintable

          public String toPrintable()

    - #### getInstance

          protected <T> T getInstance(Class<T> beanClass,
                                      boolean allowNonExportable)

    - #### injectIfRequired

          protected void injectIfRequired(BeanConfig beanConfig)

    - #### registerBean

          protected BeanConfig registerBean(BeanConfig beanConfig,
                                            BeanConfig factoryBeanConfig,
                                            Object beanInstance)

Copyright © 2004–2021 "Tigase, Inc.". All rights reserved.