More refactoring
This commit is contained in:
71
src/Job/Job.ts
Normal file
71
src/Job/Job.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import EventEmitter from "events";
|
||||
import {JobEvents} from "./JobEvents";
|
||||
|
||||
const smpp = require("smpp");
|
||||
|
||||
export class Job {
|
||||
private eventEmitter: EventEmitter = new EventEmitter();
|
||||
|
||||
constructor(pdu: any, perSecond?: number, count?: number) {
|
||||
this._pdu = pdu;
|
||||
this._perSecond = perSecond;
|
||||
this._count = count;
|
||||
}
|
||||
|
||||
private _pdu: any;
|
||||
|
||||
get pdu(): any {
|
||||
return this._pdu;
|
||||
}
|
||||
|
||||
set pdu(value: any) {
|
||||
this._pdu = value;
|
||||
this.eventEmitter.emit(JobEvents.STATE_CHANGED, {});
|
||||
}
|
||||
|
||||
private _perSecond?: number;
|
||||
|
||||
get perSecond(): number {
|
||||
return <number>this._perSecond;
|
||||
}
|
||||
|
||||
set perSecond(value: number) {
|
||||
this._perSecond = value;
|
||||
this.eventEmitter.emit(JobEvents.STATE_CHANGED, {});
|
||||
}
|
||||
|
||||
private _count?: number;
|
||||
|
||||
get count(): number {
|
||||
return <number>this._count;
|
||||
}
|
||||
|
||||
set count(value: number) {
|
||||
this._count = value;
|
||||
this.eventEmitter.emit(JobEvents.STATE_CHANGED, {});
|
||||
}
|
||||
|
||||
static deserialize(serialized: any): Job {
|
||||
if (!serialized._pdu) {
|
||||
return Job.createEmptyMultiple();
|
||||
}
|
||||
let pdu: any = new smpp.PDU(serialized._pdu.command, serialized._pdu);
|
||||
return new Job(pdu, serialized._perSecond, serialized._count);
|
||||
}
|
||||
|
||||
static createEmptySingle(): Job {
|
||||
return new Job({});
|
||||
}
|
||||
|
||||
static createEmptyMultiple(): Job {
|
||||
return new Job({}, 1, 1);
|
||||
}
|
||||
|
||||
serialize(): string {
|
||||
return JSON.stringify(this);
|
||||
}
|
||||
|
||||
on(event: string, callback: (...args: any[]) => void): void {
|
||||
this.eventEmitter.on(event, callback);
|
||||
}
|
||||
}
|
3
src/Job/JobEvents.ts
Normal file
3
src/Job/JobEvents.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export class JobEvents {
|
||||
static readonly STATE_CHANGED: string = "STATE_CHANGED";
|
||||
}
|
Reference in New Issue
Block a user