System variables
Our application will display moving lines and for this we need to store these lines on the server side with the ability to edit them. For this we will use system variables.
System variables are application data stored in one instance and available in different processes of an FCF application. System variables have a special string name format that stores the package/section name and variable names separated by the ":" character. The full name format is: "[PACKAGE_NAME]:[VARIABLE_NAME]".
Before using system variables, they must be registered in the system.
Data about system variables is stored in the application configuration in the systemVariables object, where the key is the fully qualified variable name, and the value is an object with the following fields:
- string value - The value of the variable when it was created.
- string description - Description of the system variable.
Before editing the configuration file, stop the fcfserver application, because when updating the configuration files (as well as JS files and projection files), the nodejs processes are restarted and when the process is started again, a system variable will be created, and if you save the file with an unfinished value parameter, then The initial value of the system variable will have to be set manually.
Let's create a system variable called "application:strings" in which we will store the strings as an array. Open the settings.config file in the editor and add information about the new variable to the systemVariables variable.
"settings.config" file:
...
// The object containing the initial values of system variables.
// The key is the full name of the system variable, and the value is a object with a description
systemVariables: {
"application:strings": {
description: "Output lines",
value: [
"Hello world",
"Javascript",
"CSS",
"HTML"
],
}
},
...
Now run fcfserver and in the output of the application you will see an entry about the creation of a new variable.
2022-06-25 13:51:43.476 [LOG] [SERVER]: --------------------------------------------
2022-06-25 13:51:43.477 [LOG] [SERVER]: Found a free [20410] port for the "Server control port (innerControlPort parameter)" ...
2022-06-25 13:51:43.477 [LOG] [SERVER]: Start server
2022-06-25 13:51:43.477 [LOG] [SERVER]: Start listening control port 20410 for the local event server
2022-06-25 13:51:43.487 [LOG] [SERVER]: Running processes...
2022-06-25 13:51:43.488 [LOG] [SERVER]: Found a free [20411] port for the "NODEJS application data port(dataPorts parameter)" ...
2022-06-25 13:51:43.488 [LOG] [SERVER]: Start process: /home/phoenix/development/fcf/fcfnode --max-old-space-size=275 fcf-example-moving-containers.js --server-name main --main-server-name main --handler-name application --process-index 0 --inner-control-port 20410 --port 20411 --host localhost --keep-alive-timeout 10 --leading --leak-protected
2022-06-25 13:51:43.775 [PID:213206] [LOG] [MOD:FCF]: Checking NODEJS dependencies...
2022-06-25 13:51:44.692 [PID:213206] [LOG] [MOD:FCF]: Initialize package fcf ...
2022-06-25 13:51:44.902 [PID:213206] [LOG] [MOD:FCF]: Initialize package defaultTheme ...
2022-06-25 13:51:44.955 [PID:213206] [LOG] [MOD:FCF]: Initialize package fcfStyles ...
2022-06-25 13:51:44.956 [PID:213206] [LOG] [MOD:FCF]: Initialize package fcfControls ...
2022-06-25 13:51:44.968 [PID:213206] [LOG] [MOD:FCF]: Initialize package fcfDBControls ...
2022-06-25 13:51:44.991 [PID:213206] [LOG] [MOD:FCF]: Initialize package managementTheme ...
2022-06-25 13:51:44.994 [PID:213206] [LOG] [MOD:FCF]: Initialize package fcfManagement ...
2022-06-25 13:51:45.028 [PID:213206] [LOG] [MOD:FCF]: Initialize package fcfSimpleAuthorization ...
2022-06-25 13:51:45.061 [PID:213206] [LOG] [MOD:FCF]: Install system variable application:strings
2022-06-25 13:51:45.081 [PID:213206] [LOG] [MOD:FCF]: Listing on port 20411
2022-06-25 13:51:45.082 [PID:213206] [LOG] [MOD:FCF]: Applications is running ...
2022-06-25 13:51:45.219 [LOG] [SERVER]: Process started successfully (PID:213200): /home/phoenix/development/fcf/fcfnode --max-old-space-size=275 fcf-example-moving-containers.js --server-name main --main-server-name main --handler-name application --process-index 0 --inner-control-port 20410 --port 20411 --host localhost --keep-alive-timeout 10 --leading --leak-protected
2022-06-25 13:51:45.221 [LOG] [SERVER]: Listening started with port 8080
2022-06-25 13:51:45.221 [LOG] [SERVER]: Listening started :: with port 8080
The list of available system variables can be viewed on the package page of the fcfManagement at the link http://localhost:8080/fcfpackages/fcfManagement/system/variables. You should also see our new system variable there.
The functions of the fcf.application object are used to access system variables:
-
mixed fcf.application.getSystemVariable(srtring a_path);
-
fcf.Actions fcf.application.setSystemVariable(srtring a_path, mixed a_value);