msa.core package

Submodules

msa.core.config_manager module

class msa.core.config_manager.ConfigManager(cli_config)[source]

Bases: object

A class that reads, validates, and exposes the application configuration.

apply_cli_overrides()[source]

Applies any command line interface overrides of configuration file values.

get_config()[source]

Returns the validated application configuration.

load()[source]

Loads the configuration value into memory. The file location is derived from the command line interface options.

validate()[source]

Validates the configfile against the config schema.

msa.core.event module

class msa.core.event.Event(priority: int, schema: schema.Schema)[source]

Bases: object

The base Event Class. All other events should be subclasses of this class.

get_metadata() → Dict[KT, VT][source]

Returns the metadata of this event. Used for network serialization of an event.

init(data: Dict[KT, VT] = None) → None[source]

Sets the data property on this event. Used when creating a new event, and when deserializing an event.

Parameters:data (Dict) – Event specific data. Must follow the defined schema for the event type.
set_metadata(metadata: Dict[KT, VT]) → None[source]

Sets the metadata of this event. Used for network deserialization of an event.

Parameters:metadata (Dict) – A dictionary containing the event metadata

msa.core.event_bus module

class msa.core.event_bus.EventBus(loop)[source]

Bases: object

The event bus is responsible for tracking event queues and pushing new events into the event queues so that the event handlers can wait until a new event is sent to them via their event queue.

create_event_queue()[source]

Creates a new event queue. Each handler should receive its own event queue.

fire_event(new_event)[source]

Fires an event to each event handler via its corresponding event queue.

Parameters:new_event (msa.core.event.Event) – A subclass of msa.core.event.Event to propagate to event handlers.

msa.core.event_handler module

class msa.core.event_handler.EventHandler(loop: asyncio.events.AbstractEventLoop, event_queue: asyncio.queues.Queue, logger: logging.Logger, config: Optional[Dict[KT, VT]] = None)[source]

Bases: object

The base event handler class, all other event handlers should be a subclass of this type.

Variables:
handle()[source]

An abstract method which must be overwritten. Once the system is started, the handle method will be called repeatedly until the system shuts down. The handler must be non-blocking.

handle_wrapper()[source]

A method that wraps self.handle and handles repeatedly calling the handler while the system is still running. Called automatically by the supervisor during startup.

init()[source]

An optional initialization hook, may be used for executing setup code before all handlers have benn fully started.

msa.core.loader module

msa.core.loader.load_builtin_modules()[source]

Loads builtin modules.

msa.core.loader.load_plugin_modules(plugin_module_names, mode)[source]

Loads plugin modules as specified in the configuration file.

Parameters:
  • plugin_module_names (List[str]) – Plugin module names to load. Module names should be fully qualified modules existing in msa.plugins.
  • mode (msa.core.RunMode) – The mode the system is being run in.

msa.core.supervisor module

class msa.core.supervisor.Supervisor[source]

Bases: object

The supervisor is responsible for managing the execution of the application and orchestrating the event system.

apply_granular_log_levels(granular_level_config)[source]

Applies the granular log levels configured in the conficuration file.

Parameters:granular_level_config (List[Dict[String, String]]) – A list of namespace to log level mappings to be applied.
exit()[source]

Shuts down running tasks and stops the event loop, exiting the application.

fire_event(new_event)[source]

Fires an event to all event listeners.

Parameters:new_event (Event) – A new instance of a subclass of Event to be propagated to other event handlers.
get_handler(handler_type)[source]

Returns the handler instance for a given type of handler. Used for unit tests.

Parameters:- handler_type (A type of handler.)
init(mode, cli_config)[source]

Initializes the supervisor.

Parameters:
  • mode (int) – A msa.core.RunMode enum value to configure which modules should be started based on the environment the system is being run in.
  • cli_config (Dict) – A dictionary containing configuration options derived from the command line interface.
init_logging(logging_config)[source]

Initializes application logging, setting up the global log namespace, and the supervisor log namespace.

main_coro(additional_coros=[])[source]

The main coroutine that manages starting the handlers, and waiting for a shutdown signal.

Parameters:additional_coros (List[Coroutines]) – Additional coroutines to be run in the event loop.
should_stop()[source]

Indicates whether the supervisor is in the process is shutting down. Used for signaling event_handlers to cancel rescheduling.

start(additional_coros=[])[source]

Starts the supervisor.

Parameters:additional_coros (List[Coroutines]) – a list of other coroutines to be started. Acts as a hook for specialized startup scenarios.
stop()[source]

Schedules the supervisor to stop, and exit the application.

Module contents

class msa.core.RunMode[source]

Bases: object

CLI = 0
CLIENT = 2
SERVER = 1