Reference Source

Design - runtime starting process

Starting code

var devapt = require('devapt/base/runtime'); // for ES5
import runtime from 'devapt/base/runtime' // for ES6 / ES2015

var runtime_settings = {
    'is_master':true,
    'name':'NodeA',

    // BUSES SERVERS (for inter nodex communication)
    "master":{
        "name":"NodeA",

        "msg_bus":{
            "type":"simplebus_server",
            "host":"localhost",
            "port":5000
        },
        "logs_bus":{
            "type":"simplebus_server",
            "host":"localhost",
            "port":5001
        },
        "metrics_bus":{
            "type":"simplebus_server",
            "host":"localhost",
            "port":5002
        }
    },

    "base_dir": "",

    "settings_provider": {
        "source":"local_file",
        "relative_path":"resources/apps.json"
    }
}

runtime.load(runtime_settings)

Starting sequence brief

import runtime from 'devapt/base/runtime'

The first time the file is loaded, the singleton instance of Runtime class is created.

Runtime.constructor is called to define instance attributes:

this.is_runtime = true
this.is_master = this.get_setting('is_master', false)

this.node = null

this.nodes = new Collection()
this.servers = new Collection()
this.services = new Collection()
this.registered_services = new Collection()

this.modules = new Collection()
this.plugins = new Collection()
this.resources = new Collection()

this.transactions = new Collection()
this.applications = new Collection()

this.security = new Security()

Security.constructor

runtime.load

Load method register runtime settings and call a sequence of executable instances.


Starting sequence details

Runtime loading stage 0 - RuntimeStage0Executable

Example of code

this.runtime.node = new Node(node_name, this.runtime.get_settings())
this.runtime.node.load()

Node.constructor

Node.load (for a master node)

Node.load (not for a master node)

Runtime loading stage 1 - RuntimeStage1Executable

dispatch_store_config_set_all(settings) for master node only

runtime.security.load = Security.load

AuthenticationManager.load

Runtime loading stage 2 - RuntimeStage2Executable

runtime.node.load_master_settings(node_settings)
make_services()

Node.load_master_settings call Node.load_servers for each servers settings call Node.create_server

let server = this.create_server(server_type, server_name, server_cfg)
server.load()
server.node = this
server.init_bus_client(host, port)
this.servers.add(server)

Node.create_server create a Server instance (ExpressServer, RestifyServer...)

Server.load load server settings call Server.build_server

Server.build_server build a Server.server instance as an Express or Restify object for example. load server middlewares for errors, security, metrics...

make_services for each service config of node settings services

Runtime loading stage 3 - RuntimeStage3Executable

Module.load loop on resources settings and create Resource instances (Model, View, Menu, Menubar, Database)

Runtime loading stage 4 - RuntimeStage4Executable

If node is master

Application.load

Runtime loading stage 5 - RuntimeStage5Executable

if node is master node, call runtime.node.start()

runtime.node.start call server.enable() on each runtime servers

Server.enable apply security middlewares !!! TODO start listening