Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MasterAgent

MasterAgent Constructor

class

MasterAgent

constructor
param

construct parameter opts.consoleService {Object} consoleService opts.id {String} server id opts.type {String} server type, 'master', 'connector', etc. opts.socket {Object} socket-io object opts.reqId {Number} reqId add by 1 opts.callbacks {Object} callbacks opts.state {Number} MasterAgent state

api

public

Hierarchy

  • EventEmitter
    • MasterAgent

Index

Constructors

constructor

Properties

callbacks

callbacks: object

Type declaration

clients

clients: object

Type declaration

consoleService

consoleService: ConsoleService

idMap

idMap: object

Type declaration

msgMap

msgMap: object

Type declaration

  • [serverId: string]: object
    • [reqId: number]: object
      • moduleId: string
      • msg: any

reqId

reqId: number = 1

server

server: MqttServer = null

slaveMap

slaveMap: object

Type declaration

sockets

sockets: object

Type declaration

  • [id: string]: mqtt_connection

state

state: number = ST_INITED

typeMap

typeMap: object

Type declaration

whitelist

whitelist: WhiteList

Static defaultMaxListeners

defaultMaxListeners: number

Methods

addConnection

addListener

  • addListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

broadcastCommand

  • broadcastCommand(records: AgentClient[] | object, command: string, moduleId: string, msg: any): void

broadcastMonitors

  • broadcastMonitors(records: object | AgentClient[], moduleId: string, msg: any): void
  • broadcast msg to monitor

    api

    private

    Parameters

    • records: object | AgentClient[]
    • moduleId: string

      module id/name

    • msg: any

      message

    Returns void

close

  • close(): void

doAuthServer

doAuthUser

doSend

  • doSend(socket: MqttSocket, topic: string, msg: any): void

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

get

  • get(moduleId: string): any

getClientById

getMaxListeners

  • getMaxListeners(): number
  • Returns number

listen

  • listen(port: number, cb: function): void
  • master listen to a port and handle register and request

    api

    public

    Parameters

    • port: number
    • cb: function
        • (err?: Error): void
        • Parameters

          • Optional err: Error

          Returns void

    Returns void

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

notifyAll

  • notifyAll(moduleId: string, msg?: any): boolean
  • notify all the monitors without callback

    api

    public

    Parameters

    • moduleId: string

      module id/name

    • Optional msg: any

    Returns boolean

notifyById

  • notifyById(serverId: string, moduleId: string, msg: any): boolean
  • notify a monitor{master node} by id without callback

    api

    public

    Parameters

    • serverId: string
    • moduleId: string

      module id/name

    • msg: any

    Returns boolean

notifyByServer

  • notifyByServer(serverId: string, serverInfo: ServerInfo, moduleId: string, msg: any): boolean
  • notify a monitor by server{host:port} without callback

    api

    public

    Parameters

    • serverId: string
    • serverInfo: ServerInfo
    • moduleId: string

      module id/name

    • msg: any

    Returns boolean

notifyByType

  • notifyByType(type: string, moduleId: string, msg: any): boolean
  • notify monitors by type without callback

    api

    public

    Parameters

    • type: string

      serverType

    • moduleId: string

      module id/name

    • msg: any

    Returns boolean

notifyClient

  • notifyClient(clientId: string, moduleId: string, msg: any): boolean
  • notify a client by id without callback

    api

    public

    Parameters

    • clientId: string
    • moduleId: string

      module id/name

    • msg: any

    Returns boolean

notifyCommand

  • notifyCommand(command: string, moduleId: string, msg: any): boolean

notifySlavesById

  • notifySlavesById(serverId: string, moduleId: string, msg: any): boolean
  • notify slaves by id without callback

    api

    public

    Parameters

    • serverId: string
    • moduleId: string

      module id/name

    • msg: any

    Returns boolean

on

  • on(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

once

  • once(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependListener

  • prependListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Parameters

    • Optional event: string | symbol

    Returns this

removeConnection

  • removeConnection(id: string, type: string, info: ServerInfo): void

removeListener

  • removeListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

request

  • request(serverId: string, moduleId: string, msg: any, cb: function): boolean
  • request monitor{master node} data from monitor

    api

    public

    Parameters

    • serverId: string
    • moduleId: string

      module id/name

    • msg: any
    • cb: function
        • (errOrResult?: Error | any, body?: any): void
        • Parameters

          • Optional errOrResult: Error | any
          • Optional body: any

          Returns void

    Returns boolean

requestServer

  • requestServer(serverId: string, serverInfo: ServerInfo, moduleId: string, msg: any, cb: Callback): boolean
  • request server data from monitor by serverInfo{host:port}

    api

    public

    Parameters

    • serverId: string
    • serverInfo: ServerInfo
    • moduleId: string

      module id/name

    • msg: any
    • cb: Callback

    Returns boolean

sendToClient

  • sendToClient(socket: MqttSocket, reqId: number, moduleId: string, msg: any): void
  • send msg to client

    api

    private

    Parameters

    • socket: MqttSocket

      socket-io object

    • reqId: number

      request id

    • moduleId: string

      module id/name

    • msg: any

      message

    Returns void

sendToMonitor

  • sendToMonitor(socket: MqttSocket, reqId: number, moduleId: string, msg: any): void
  • send msg to monitor

    api

    private

    Parameters

    • socket: MqttSocket

      socket-io object

    • reqId: number

      request id

    • moduleId: string

      module id/name

    • msg: any

      message

    Returns void

set

  • set(moduleId: string, value: any): void
  • set module

    api

    public

    Parameters

    • moduleId: string

      module id/name

    • value: any

      module object

    Returns void

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number