Chapter 27. Component Implementation - Lesson 8 - Startup Time

Artur Hefczyc <> v2.0, June 2014: Reformatted for AsciiDoc. :toc: :numbered: :website: :Date: 2011-05-27 22:52

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

This is because you cannot really tell when exactly is the startup time. 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 the Tigase in the same sense as the shutdown hook.

There are a few methods which are called at startup time 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 call getDefaults(…​) and may be destroyed afterwards.
  2. void setName(String name) - the second call for the component is to set it’s unique name within the Tigase instance. It still does not mean too much from the component run-time point of view but some components initialise service discovery data at this point.
  3. void start() - this is a second which means the component can start it’s internal jobs or worker threads or whatever it needs for future activity. Component’s queues and threads are initialised at this point.
  4. Map<String, Object> getDefaults(Map params) - this is the next call made by configuration manager to collect all the default settings for the component. To help generate default settings, configuration manager passes general properties (starting with --) in the Map as parameter to the component. As a result it expects specific settings applicable to the component only (not starting with --).
  5. setProperties(Map<String, Object> props) - after collecting component’s defaults, the connection manager combines them with configuration options (not starting with --, but starting with the component name) loaded from configuration repository ( file, database, possibly other files). Then the final configuration is passed to the component with setProperties(…​) method call. Database connections are usually initialised at this point.
  6. void initializationCompleted() - this method is called for all components after all components are loaded and configuration was set (via setProperties(…​) method call) for all components.

Therefore, initializationCompleted() hook is the best point if you want to be sure that the Tigase server is fully loaded, initialised and functional