More refactoring

This commit is contained in:
David Majdandžić
2023-03-29 19:15:49 +02:00
parent ad63061209
commit 7f00cffb40
6 changed files with 36 additions and 33 deletions

View File

@@ -2,7 +2,6 @@ import {Job} from "../Job/Job";
import Logger from "../Logger"; import Logger from "../Logger";
import {PduProcessor} from "../PDUProcessor/PduProcessor"; import {PduProcessor} from "../PDUProcessor/PduProcessor";
import {SmppSession} from "../SmppSession"; import {SmppSession} from "../SmppSession";
import CenterStatus from "./CenterStatus";
const NanoTimer = require('nanotimer'); const NanoTimer = require('nanotimer');
const smpp = require("smpp"); const smpp = require("smpp");
@@ -180,11 +179,11 @@ export class Center extends SmppSession {
private updateStatus(): void { private updateStatus(): void {
if (this.sessions.length > 0) { if (this.sessions.length > 0) {
this.status = CenterStatus.CONNECTED; this.setStatus(2);
} else if (this.pendingSessions.length > 0) { } else if (this.pendingSessions.length > 0) {
this.status = CenterStatus.CONNECTING; this.setStatus(1);
} else { } else {
this.status = CenterStatus.WAITING_CONNECTION; this.setStatus(0);
} }
} }
} }

View File

@@ -1,5 +0,0 @@
export default class CenterStatus {
static readonly WAITING_CONNECTION: string = "WAITING CONNECTION";
static readonly CONNECTING: string = "CONNECTING";
static readonly CONNECTED: string = "CONNECTED";
}

View File

@@ -8,7 +8,6 @@ const NanoTimer = require('nanotimer');
const smpp = require("smpp"); const smpp = require("smpp");
const AUTO_ENQUIRE_LINK_PERIOD: number = Number(process.env.AUTO_ENQUIRE_LINK_PERIOD) || 30000; const AUTO_ENQUIRE_LINK_PERIOD: number = Number(process.env.AUTO_ENQUIRE_LINK_PERIOD) || 30000;
const MESSAGE_SEND_UPDATE_DELAY: number = Number(process.env.MESSAGE_SEND_UPDATE_DELAY) || 500;
export class Client extends SmppSession { export class Client extends SmppSession {
readonly STATUS: string[] = [ readonly STATUS: string[] = [
@@ -103,12 +102,8 @@ export class Client extends SmppSession {
} }
close(): Promise<void> { close(): Promise<void> {
return new Promise((resolve, reject) => {
this.logger.log1(`Client-${this.getId()} closing connection`); this.logger.log1(`Client-${this.getId()} closing connection`);
this.session.close(); return Promise.resolve(this.session.close());
this.setStatus(0);
resolve();
});
} }
sendPdu(pdu: object, force?: boolean): Promise<object> { sendPdu(pdu: object, force?: boolean): Promise<object> {
@@ -141,7 +136,7 @@ export class Client extends SmppSession {
this.eventEmitter.emit(this.EVENT.MESSAGE_SEND_COUNTER_UPDATE_EVENT, counter); this.eventEmitter.emit(this.EVENT.MESSAGE_SEND_COUNTER_UPDATE_EVENT, counter);
previousUpdateCounter = counter; previousUpdateCounter = counter;
} }
}, '', `${MESSAGE_SEND_UPDATE_DELAY / 1000} s`); }, '', `${this.MESSAGE_SEND_UPDATE_DELAY / 1000} s`);
let count = job.count || 1; let count = job.count || 1;
let interval = 1 / (job.perSecond || 1); let interval = 1 / (job.perSecond || 1);

View File

@@ -1,2 +0,0 @@
export default class ClientStatus {
}

View File

@@ -0,0 +1,15 @@
import {PduProcessor} from "./PduProcessor";
export class PduDebugProcessor implements PduProcessor {
processPdu(session: any, pdu: any, ...args: any[]): Promise<any> {
return new Promise<any>((resolve, reject) => {
session.send(pdu.response(), (replyPdu: any) => {
resolve(replyPdu);
});
})
}
serialize(): object {
return {};
}
}

View File

@@ -1,8 +1,8 @@
import {Center} from "./Center/Center"; import {Center} from "./Center/Center";
import {Client} from "./Client/Client"; import {Client} from "./Client/Client";
import ClientSessionManager from "./Client/ClientSessionManager"; import ClientSessionManager from "./Client/ClientSessionManager";
import {Job} from "./Job/Job";
import Logger from "./Logger"; import Logger from "./Logger";
import {PduDebugProcessor} from "./PDUProcessor/PduDebugProcessor";
const smpp = require("smpp"); const smpp = require("smpp");
const fs = require("fs"); const fs = require("fs");
@@ -18,7 +18,6 @@ const {PDU} = require("smpp");
const app = express(); const app = express();
const SERVER_PORT: number = Number(process.env.SERVER_PORT) || 8190; const SERVER_PORT: number = Number(process.env.SERVER_PORT) || 8190;
const MESSAGE_SEND_UPDATE_DELAY: number = Number(process.env.MESSAGE_SEND_UPDATE_DELAY) || 500;
// TODO: Add support for encodings // TODO: Add support for encodings
// TODO: Implement some sort of metrics on frontend by counting the pdus // TODO: Implement some sort of metrics on frontend by counting the pdus
@@ -52,18 +51,20 @@ async function main() {
// }); // });
let center: Center = new Center(0, 7000, "test", "test"); let center: Center = new Center(0, 7000, "test", "test");
setTimeout(() => { // setInterval(() => {
center.sendMultiple(new Job(new PDU("deliver_sm", { // client.connectAndBind().then(() => {
source_addr: "1234567890", // console.log("POGGIES");
destination_addr: "1234567890", // client.close();
short_message: "Hello World" // });
}), 10, 100)); // }, 1000);
// center.close(); // setTimeout(() => {
}, 5000); // center.sendMultiple(new Job(new PDU("deliver_sm", {
// source_addr: "1234567890",
client.connectAndBind().then(() => { // destination_addr: "1234567890",
console.log("POGGIES"); // short_message: "Hello World"
}); // }), 10, 100));
// // center.close();
// }, 5000);
} }
main(); main();