First commit
This commit is contained in:
307
framework/server/applicationManager.js
Normal file
307
framework/server/applicationManager.js
Normal file
@@ -0,0 +1,307 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2020, 2023, The Unified Company.
|
||||
|
||||
This code is part of Unify.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
|
||||
as published by the ESA.
|
||||
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
|
||||
|
||||
https://unifyjs.org - The Unified Company
|
||||
|
||||
*/
|
||||
|
||||
import file from './file.js';
|
||||
|
||||
import socketManager from './socketManagerServer.js';
|
||||
|
||||
import core from './core.js';
|
||||
|
||||
import tools from '../unify/tools.js';
|
||||
|
||||
import defaultObject from '../unify/defaultObject.js';
|
||||
|
||||
import moduleLoader from '../server/moduleLoader.js';
|
||||
|
||||
import Console from '../server/console.js';
|
||||
|
||||
import path from 'path';
|
||||
|
||||
import process from 'process';
|
||||
|
||||
import imports from './imports.js';
|
||||
|
||||
import simplePath from "../unify/simplePath.js";
|
||||
|
||||
import { inspect } from 'util'
|
||||
|
||||
import deepclone from '../unify/clonedeep.js';
|
||||
|
||||
|
||||
|
||||
export default class applicationManager{
|
||||
|
||||
defaultSocketPort = 5002;
|
||||
|
||||
runExampleApplications = true;
|
||||
|
||||
defaultObject = new defaultObject();
|
||||
|
||||
moduleLoader = new moduleLoader();
|
||||
|
||||
serverAddress = "localhost";
|
||||
|
||||
serverPort = false;
|
||||
|
||||
httpsServer;
|
||||
|
||||
serverManager;
|
||||
|
||||
|
||||
|
||||
|
||||
groomApplicationObject( application ) {
|
||||
|
||||
//console.log("before groom: ", tools.sizeOf( application ) )
|
||||
|
||||
//tools.groomApplicationObject( application );
|
||||
|
||||
//console.log("after groom: ", tools.sizeOf( application ) );
|
||||
|
||||
}
|
||||
|
||||
|
||||
importApplication( applicationID ) {
|
||||
|
||||
var app = new imports[ applicationID ]();
|
||||
|
||||
this.groomApplicationObject( app );
|
||||
|
||||
this.defaultObject.agregateDefaultObject( app );
|
||||
|
||||
app.setApplicationID( applicationID );
|
||||
|
||||
return app;
|
||||
|
||||
}
|
||||
|
||||
setupCore( socket, applicationID ) {
|
||||
|
||||
var unifyCore = new core();
|
||||
|
||||
if( applicationID == 0 ) {
|
||||
|
||||
global.core = unifyCore;
|
||||
|
||||
}
|
||||
|
||||
unifyCore.socket = socket;
|
||||
|
||||
return unifyCore;
|
||||
|
||||
}
|
||||
|
||||
parseApplication( unifyCore, app, client ) {
|
||||
|
||||
unifyCore.parse( app, client );
|
||||
|
||||
unifyCore.createDependencyMap( client );
|
||||
|
||||
}
|
||||
|
||||
setGlobals( client, application ) {
|
||||
|
||||
global.objects = client.objects;
|
||||
|
||||
global.classObjects = client.classObjects;
|
||||
|
||||
global.dependencieMap = client.dependencieMap;
|
||||
|
||||
global.maxClients = application.maxClients;
|
||||
|
||||
global.cacheBuildSpeed = application.cacheBuildSpeed;
|
||||
|
||||
}
|
||||
|
||||
loadUnloadedFiles( client, unifyCore ) {
|
||||
|
||||
if( global.mode == "development" ) {
|
||||
|
||||
this.moduleLoader.client = client;
|
||||
|
||||
this.moduleLoader.loadModulesFromFiles( "/", unifyCore, client );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
createTables( unifyCore ) {
|
||||
|
||||
if( global.mode == "development" ) {
|
||||
|
||||
unifyCore.tableManager.createTables();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
createDummyClient() {
|
||||
|
||||
var client = new Object();
|
||||
|
||||
client.objects = new Array();
|
||||
|
||||
client.classObjects = new Array();
|
||||
|
||||
return client;
|
||||
|
||||
}
|
||||
|
||||
setApplicationGlobals( applicationID, unifyCore, socket ) {
|
||||
|
||||
global.cores[ applicationID ] = unifyCore;
|
||||
|
||||
global.sockets[ applicationID ] = socket;
|
||||
|
||||
}
|
||||
|
||||
prepareApplication( unifyCore, app, applicationID ) {
|
||||
|
||||
if( applicationID == 0 ) {
|
||||
|
||||
var client = this.createDummyClient();
|
||||
|
||||
|
||||
|
||||
this.parseApplication( unifyCore, app, client );
|
||||
|
||||
this.loadUnloadedFiles( client, unifyCore );
|
||||
|
||||
this.setGlobals( client, app );
|
||||
|
||||
this.createTables( unifyCore );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
instantiateSocket( applicationID, app ) {
|
||||
|
||||
var socket = new socketManager( this.defaultSocketPort + applicationID );
|
||||
|
||||
socket.serverManager = this.serverManager;
|
||||
|
||||
socket.httpsServer = this.httpsServer;
|
||||
|
||||
socket.applicationURLArray = this.applicationURLArray;
|
||||
|
||||
|
||||
var unifyCore = new core();
|
||||
|
||||
//unifyCore.prepareClone( app );
|
||||
|
||||
socket.setApplication( deepclone( app ) );
|
||||
|
||||
socket.setApplicationID( applicationID );
|
||||
|
||||
//socket.setApplication( app );
|
||||
|
||||
return socket;
|
||||
|
||||
}
|
||||
|
||||
setupSocketConnection( socket, unifyCore ) {
|
||||
|
||||
socket.create();
|
||||
|
||||
socket.core = unifyCore;
|
||||
|
||||
}
|
||||
|
||||
async runApplication( applicationThree, applicationID ) {
|
||||
|
||||
var app = this.importApplication( applicationID );
|
||||
|
||||
|
||||
var socket = this.instantiateSocket( applicationID, app );
|
||||
|
||||
var unifyCore = this.setupCore( socket, applicationID );
|
||||
|
||||
|
||||
this.prepareApplication( unifyCore, app, applicationID );
|
||||
|
||||
this.setupSocketConnection( socket, unifyCore );
|
||||
|
||||
this.setApplicationGlobals( applicationID, unifyCore, socket );
|
||||
|
||||
|
||||
await unifyCore.findDuplicates( app );
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
setApplicationURL( applications ) {
|
||||
|
||||
if( this.runExampleApplications ) {
|
||||
|
||||
this.applicationURLArray = applications;
|
||||
|
||||
} else {
|
||||
|
||||
this.applicationURLArray = new Array( applications[0] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
createGlobals() {
|
||||
|
||||
global.applications = new Object();
|
||||
|
||||
global.cores = new Array();
|
||||
|
||||
}
|
||||
|
||||
getNumberOfApplication() {
|
||||
|
||||
if( this.runExampleApplications ) {
|
||||
|
||||
var number_applications = this.applications.length;
|
||||
|
||||
} else {
|
||||
|
||||
var number_applications = 1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
async runApplications( applications ) {
|
||||
|
||||
this.createGlobals();
|
||||
|
||||
this.setApplicationURL( applications );
|
||||
|
||||
// remove later
|
||||
this.applications = applications;
|
||||
|
||||
var n = this.getNumberOfApplication();
|
||||
|
||||
for( var c = 0; c < 1; c++ ) {
|
||||
|
||||
var applicationThree = this.applications[ c ];
|
||||
|
||||
|
||||
await this.runApplication( applicationThree, c );
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user