123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import { BehaviorSubject, Subject } from 'rxjs';
- import { ColorCode, Message, ReportStatus, ConnectionAttribute, ConnectionRequest, ConnectionState, MessageLog } from '../interfaces/general.interface';
- import { GrpcServiceMethod } from './grpc.service.method';
- import { FisRetransmissionService } from './fis.retransmission.service';
- import { BufferService } from './buffer.service';
- import * as dotenv from 'dotenv'
- dotenv.config()
- export class ServerClientManager {
- private connectionAttributes: ConnectionAttribute[] = []
- private request: ConnectionRequest | any
- constructor(private grpcService: GrpcServiceMethod) {
- }
- // putting it here for later use. to be used for testing
- public restartServerInDuration(time: number) {
- console.log(this.request)
- console.log(this.connectionAttributes)
- this.grpcService.shutDownServer().then((msg: string) => {
- console.log(msg)
- setTimeout(() => {
- this.generateConnection(this.request)
- }, time * 1000)
- })
- }
- public generateConnection(request: ConnectionRequest) {
- this.request = request
- let database: string
- if (request.database) {
- database = request.database
- } else {
- database = request.server.name + request.client.name
- }
- /* Inject retransmission here */
- let initialReport: ConnectionState = { status: 'BUFFER' }
- let reportSubject: BehaviorSubject<ConnectionState> = new BehaviorSubject(initialReport)
- let retransmission: BufferService = new BufferService(request.server.messageToBePublishedFromApplication, reportSubject, database)
- // let initialReport: ReportStatus = { code: ColorCode.RED, message: 'Initialization of the subject' }
- // let reportSubject: BehaviorSubject<ReportStatus> = new BehaviorSubject(initialReport)
- // let retransmission: FisRetransmissionService = new FisRetransmissionService(database, reportSubject)
- // let messageToBePublished: Subject<Message> = retransmission.handleMessage(request.server.messageToBePublishedFromApplication) ?? request.server.messageToBePublishedFromApplication
- let connectionAttribute: ConnectionAttribute = {
- ConnectionID: {
- local: '',
- remote: ''
- },
- outGoing: {
- MessageToBePublished: retransmission.getMessages(),
- MessageToBeReceived: null
- },
- inComing: {
- MessageToBePublished: null,
- MessageToBeReceived: request.client.messageToBeReceivedFromRemote
- },
- connectionStatus: reportSubject
- }
- // This is default connection
- if (!request.server.connectionType) {
- request.server.connectionType = 'GRPC'
- }
- // For each connection type:
- if (request.server.connectionType == 'GRPC') {
- this.grpcService.create(request, connectionAttribute)
- this.connectionAttributes.push(connectionAttribute)
- }
- }
- }
|