Initialization of a component

A startup hook in the Tigase is different from the shutdown hook.

This is because you cannot really tell when exactly the startup time is. Is it when the application started, is it when configuration is loaded, is it when all objects are initialized. And this might be even different for each component. Therefore, in fact, there is no startup hook in Tigase in the same sense as the shutdown hook.

There are a few methods which are called at startup time of a component in the following order:

  1. Constructor - there is of course constructor which has no parameters. However it does not guarantee that this instance of the component will be used at all. The object could be created just to get default values of a config fields and may be destroyed afterwards.
  2. Getters/Setters - at second step of initialization of a component, Kernel configures component by reading and setting values of fields annotated with @ConfigField() annotation. If there is a public getter or setter for the same name as an annotated field - it will be used.
  3. void beanConfigurationChanged(Collection<String> changedFields) (optional) - if component implements ConfigurationChangedAware interface, this method will be called to notify component about fields which values were changed. It is useful if case in which component internals depends on configuration stored in more than one field, as it allows you to reconfigure component internals only once.
  4. void register(Kernel kernel) (optional) - if component implements RegistrarBean interface this method is called to allow registration of component private beans.
  5. Dependency Injection - during this time Kernel injects beans to component fields annotated with @Inject. If public getters or setters for this fields exist - kernel will use them.
  6. void initialized() (optional) - called if component implements Initializable interface to notify it that configuration is set and dependencies are injected.
  7. void start() - during this call component starts it’s internal jobs or worker threads or whatever it needs for future activity. Component’s queues and threads are initialized at this point. (after this method returns the component is ready)

Therefore, the start() hook is the best point if you want to be sure that component is fully loaded, initialized and functional.

Tip

Component instance may be started and stopped only once, however new instances of the same component with the same name may be created during Tigase XMPP Server uptime, ie. as a result of a server reconfiguration.