Chapter 15. Massiv Application Skeleton

Table of Contents

15.1. Overview
15.2. Initializing the Core
15.3. Downloading Prerequisite Data
15.4. Connecting To the Simulation
15.5. Running the Main Loop
15.6. Disconnecting From the Simulation
15.7. Shutting Down the Core
15.8. More On the System Loops
15.9. An Example

15.1. Overview

By now you should already be familiar with the distributed object model used in the Massiv. While the knowledge of the model is essential and allows you to write the logic of the distributed application, it does not give you any information about how to configure, setup, control and run the Core. This chapter will focus on these topics.

The Core can be controlled by utilizing two main classes: Massiv::System and Massiv::Core::Global. These are singleton objects with static methods. While the System class allows to control the Core in a more abstract way, the Global class enables to get access to concrete Core subsystems and allows a lower level access. Some of the accessed subsystems are private to the Core and need not (must not) be used by the application at all. See Chapter 16, Global Objects And System Interface for more information about the global objects.

Besides the application-to-Core communication, the Core sometimes needs to upcall/callback the application. The upcalls are either on the object level (special methods of managed objects are upcalled from the Core; mainly the migration deliveries and upcalls on special objects, see Chapter 14, Special Objects) or on the application level (they are global to the simulation). For example when a node connects to the simulation, the Core asks the application to create an object level representation of the local node (the application's response should be instantiation of an object derived from Lib::NodeObjectInterface, see Section 14.2, “Node Object”). Also since the model has been designed in such way that it is the Core that runs, the Core provides a next tick callback called at the end of each tick. This allows to perform additional application specific work that does not relate to the simulation directly, like redrawing the screen, handling keyboard input, etc.

As the application runs the system undergoes state changes. The states are called the system phases. It is strictly specified what can and what cannot be done in each particular system phase. When the application starts, the system is in the uninitialized state. The states can be changed using various calls to methods of the System class. Note that the Core can not be used if it is not initialized. The following diagram shows the system states, the transitions among them and the corresponding calls that cause the state changes:

Figure 15.1. System Phases
System Phases

Table 15.1. System Phases
PhaseSemantics
PHASE_UNINITIALIZEDThe Core is uninitialized and can not be used. This is the initial state.
PHASE_INITIALIZEDThe Core has been initialized. It runs in an anonymous mode.
PHASE_DOWNLOADING_DATAThe Core is downloading minimal data required to start regular operation.
PHASE_DATA_DOWNLOADEDThe minimal data was downloaded. The Core is ready to change its identity and register to the simulation.
PHASE_CONNECTINGThe node is connecting / registering to the simulation using its real identity.
PHASE_CONNECTEDThe node has connected to the simulation.
PHASE_RUNNINGThe simulation is running.
PHASE_DISCONNECTINGThe node is disconnecting from the simulation and changes its identity back to anonymous.
PHASE_SHUTTING_DOWNThe Core is shutting down and deinitializing itself.

Application's main function usually does the following steps. The steps will be discussed in the sections below in detail:

  • Initializes the Core

  • Downloads minimal prerequisite data

  • Connects to the simulation

  • Starts the main loop

  • Disconnects from the simulation

  • Shutdowns the Core