diff --git a/Project.njsproj b/Project.njsproj
index f1c1237bd..2d9bfbc32 100644
--- a/Project.njsproj
+++ b/Project.njsproj
@@ -6,14 +6,15 @@
{ae0a3fe2-7021-4cc2-9922-a887ca5cdd7c}
ShowAllFiles
- Run.js
+ server.js
.\
.
{3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{349c5851-65df-11da-9384-00065b846f21};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}
14.0
$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
Project
- Trading-Process
+
+
C:\Program Files\nodejs\node.exe
False
Debug|Any CPU
@@ -24,9 +25,6 @@
Code
-
- Code
-
@@ -67,7 +65,7 @@
Code
-
+
Code
diff --git a/SystemEventHandler.js b/SystemEventHandler.js
deleted file mode 100644
index a5d231b2b..000000000
--- a/SystemEventHandler.js
+++ /dev/null
@@ -1,138 +0,0 @@
-exports.newSystemEventHandler = function newSystemEventHandler() {
- let thisObject = {
- initialize: initialize,
- createEventHandler: createEventHandler,
- deleteEventHandler: deleteEventHandler,
- listenToEvent: listenToEvent,
- stopListening: stopListening,
- raiseEvent: raiseEvent
- }
-
- let ipc = require('node-ipc');
- let eventListeners = new Map()
- let responseWaiters = new Map()
-
- ipc.config.id = 'Clone Executor';
- ipc.config.retry = 1500;
-
- return thisObject
-
- function initialize(callBackFunction) {
-
- ipc.connectTo(
- 'world',
- function () {
- ipc.of.world.on(
- 'connect',
- function () {
- ipc.log('## Connected to Superalgos Event Server ##'.rainbow, ipc.config.delay);
-
- let eventCommand = {
- action: 'greetings',
- from: 'Clone Executor'
- }
-
- sendCommand(eventCommand)
-
- callBackFunction()
- }
- );
- ipc.of.world.on(
- 'disconnect',
- function () {
- ipc.log('Disconnected from Superalgos Event Server '.notice);
- }
- );
- ipc.of.world.on(
- 'message', // here is where all incomming messages are processed.
- function (data) {
- ipc.log('Got a message from Superalgos Event Server: '.debug, data);
-
- let message = JSON.parse(data)
-
- if (message.action === 'Event Raised') {
- let handler = eventListeners.get(message.eventHandlerName + '-' + message.eventType)
- if (handler) {
- handler(message)
- }
- return
- }
-
- if (message.action === 'Event Server Response') {
- let handler = responseWaiters.get(message.callerId)
- if (handler) {
- handler(message)
- }
- return
- }
- }
- );
- }
- );
- }
-
- function sendCommand(command, responseCallBack, eventsCallBack) {
-
- if (command.action === 'listenToEvent') {
- eventListeners.set(command.eventHandlerName + '-' + command.eventType, eventsCallBack)
- }
- if (command.callerId && responseCallBack) {
- responseWaiters.set(command.callerId, responseCallBack)
- }
-
- ipc.of.world.emit(
- 'message',
- JSON.stringify(command)
- )
- }
-
- function createEventHandler(eventHandlerName, callerId, responseCallBack) {
- let eventCommand = {
- action: 'createEventHandler',
- eventHandlerName: eventHandlerName,
- callerId: callerId
- }
- sendCommand(eventCommand, responseCallBack)
- }
-
- function deleteEventHandler(eventHandlerName, callerId, responseCallBack) {
- let eventCommand = {
- action: 'deleteEventHandler',
- eventHandlerName: eventHandlerName,
- callerId: callerId
- }
- sendCommand(eventCommand, responseCallBack)
- }
-
- function listenToEvent(eventHandlerName, eventType, extraData, callerId, responseCallBack, eventsCallBack) {
- let eventCommand = {
- action: 'listenToEvent',
- eventHandlerName: eventHandlerName,
- eventType: eventType,
- extraData: extraData,
- callerId: callerId
- }
- sendCommand(eventCommand, responseCallBack, eventsCallBack)
- }
-
- function stopListening(eventHandlerName, eventSubscriptionId, callerId, responseCallBack) {
- let eventCommand = {
- action: 'stopListening',
- eventHandlerName: eventHandlerName,
- eventSubscriptionId: eventSubscriptionId,
- callerId: callerId
- }
- sendCommand(eventCommand, responseCallBack)
- }
-
- function raiseEvent(eventHandlerName, eventType, event, callerId, responseCallBack) {
- let eventCommand = {
- action: 'raiseEvent',
- eventHandlerName: eventHandlerName,
- eventType: eventType,
- event: event,
- callerId: callerId
- }
- sendCommand(eventCommand, responseCallBack)
- }
-}
\ No newline at end of file
diff --git a/Run.js b/server.js
similarity index 95%
rename from Run.js
rename to server.js
index 1a1891aeb..6958dcdf1 100644
--- a/Run.js
+++ b/server.js
@@ -25,10 +25,12 @@ global.CUSTOM_FAIL_RESPONSE = {
message: "Custom Message"
};
-const EVENT_HANDLER_MODULE = require('./SystemEventHandler.js');
+console.log('NEW INSTANCE OF BACKEND SEVER RUNNING')
+
+const EVENT_HANDLER_MODULE = require('../Libraries/SystemEventsClient/SystemEventHandler.js');
global.systemEventHandler = EVENT_HANDLER_MODULE.newSystemEventHandler()
-global.systemEventHandler.initialize(bootLoader)
+global.systemEventHandler.initialize('Clone Executor', bootLoader)
function bootLoader() {
@@ -48,6 +50,24 @@ function bootLoader() {
}
}
+/*
+
+We read the first string sent as an argument when the process was created by the Backend Server. Ther we will find the information of the identity
+of this backend process and know exactly what to run within this server instance.
+
+*/
+
+let backendProcessDefinition = process.argv[2]
+if (backendProcessDefinition !== undefined) {
+ console.log('RECIBI ESTA DEFINICION: ' + backendProcessDefinition)
+ backendProcessDefinition = JSON.parse(backendProcessDefinition)
+} else {
+ /* Debugging Definition goes here */
+ backendProcessDefinition = {
+
+ }
+}
+
/* Old Run.js code follows... */
require('dotenv').config();
@@ -97,6 +117,8 @@ function startSequence () {
process.on('message', message => {
if (message === 'STOP') {
runClonExecutor = false;
+ global.systemEventHandler.finalize()
+ global.systemEventHandler = undefined
console.log("[INFO] CloneExecutor -> Clone Executor Stopped.");
}
});