Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Application

Hierarchy

  • Application

Index

Properties

aconfigure

aconfigure: AConfigureFunc1 | AConfigureFunc2 | AConfigureFunc3 = utils.promisify(this.configure) as any

astart

astart: function = utils.promisify(this.start)

Type declaration

    • (): Promise<TResult>
    • Returns Promise<TResult>

Optional backendSessionService

backendSessionService: BackendSessionService

base

base: string

Optional channelService

channelService: ChannelService

clusterSeq

clusterSeq: object

Type declaration

  • [serverType: string]: number

components

components: object

Type declaration

curServer

curServer: ServerInfo

event

event: EventEmitter = new EventEmitter()

loaded

loaded: IComponent[] = []

master

master: ServerStartArgs = null

Optional rpc

rpc: any

Optional rpcInvoke

rpcInvoke: function

Proxy for rpc client rpcInvoke.

param

remote server id

param

rpc message: {serverType: serverType, service: serviceName, method: methodName, args: arguments}

param

callback function

Type declaration

    • (serverId: FRONTENDID, msg: any, cb: Function): void
    • Parameters

      Returns void

serverId

serverId: string

serverType

serverType: string

serverTypeMaps

serverTypeMaps: object

Type declaration

  • [type: string]: ServerInfo[]

serverTypes

serverTypes: string[] = []

servers

servers: object

Type declaration

  • [id: string]: ServerInfo

Optional sessionService

sessionService: SessionService

settings

settings: object

Type declaration

  • [key: string]: any

startId

startId: string

startTime

startTime: number

state

state: number

stopTimer

stopTimer: any

Optional sysrpc

sysrpc: any

type

type: string

usedPlugins

usedPlugins: IPlugin[] = []

Methods

addCrons

  • addCrons(crons: Cron[]): void
  • Add crons from current application at runtime.

    memberof

    Application

    Parameters

    • crons: Cron[]

      new crons would be added in application

    Returns void

addServers

  • addServers(servers: ServerInfo[]): void
  • Add new server info to current application in runtime.

    memberof

    Application

    Parameters

    • servers: ServerInfo[]

      new server info list

    Returns void

after

afterStart

  • afterStart(cb?: function): void
  • Lifecycle callback for after start.

    Parameters

    • Optional cb: function

      callback function

        • (err?: Error): void
        • Parameters

          • Optional err: Error

          Returns void

    Returns void

before

beforeStopHook

configure

  • Configure callback for the specified env and server type. When no env is specified that callback will be invoked for all environments and when no type is specified that callback will be invoked for all server types.

    Examples:

    app.configure(function(){ // executed for all envs and server types });

    app.configure('development', function(){ // executed development env });

    app.configure('development', 'connector', function(){ // executed for development env and connector server type });

    memberof

    Application

    Parameters

    Returns Application

    for chaining

  • Parameters

    Returns Application

  • Parameters

    Returns Application

configureLogger

  • configureLogger(logger: "C:/pinus/pinus/node_modules/pinus-logger/dist/index"): void
  • Configure logger with {$base}/config/log4js.json

    memberof

    Application

    Parameters

    • logger: "C:/pinus/pinus/node_modules/pinus-logger/dist/index"

      pinus-logger instance without configuration

    Returns void

disable

  • Disable setting.

    memberof

    Application

    Parameters

    • setting: string

      application setting

    Returns Application

    for chaining

disabled

  • disabled(setting: string): boolean
  • Check if setting is disabled.

    memberof

    Application

    Parameters

    • setting: string

      application setting

    Returns boolean

enable

  • Enable setting.

    memberof

    Application

    Parameters

    • setting: string

      application setting

    Returns Application

    for chaining

enabled

  • enabled(setting: string): boolean
  • Check if setting is enabled.

    memberof

    Application

    Parameters

    • setting: string

      application setting

    Returns boolean

filter

  • add a filter to before and after filter

    memberof

    Application

    Parameters

    • filter: IHandlerFilter

      provide before and after filter method. A filter should have two methods: before and after.

    Returns void

get

getBase

  • getBase(): string
  • Get application base path

    // cwd: /home/game/ pinus start // app.getBase() -> /home/game

    memberof

    Application

    Returns string

    application base path

getCurServer

  • getCurServer(): ServerInfo
  • Get current server info.

    memberof

    Application

    Returns ServerInfo

    current server info, {id, serverType, host, port}

getCurrentServer

  • getCurrentServer(): ServerInfo

getMaster

getServerById

  • getServerById(serverId: string): ServerInfo
  • Get server info by server id from current server cluster.

    memberof

    Application

    Parameters

    • serverId: string

      server id

    Returns ServerInfo

    server info or undefined

getServerFromConfig

  • getServerFromConfig(serverId: string): any
  • Get server info by server id from servers.json.

    memberof

    Application

    Parameters

    • serverId: string

      server id

    Returns any

    server info or undefined

getServerId

  • getServerId(): string
  • Get current server id.

    memberof

    Application

    Returns string

    current server id from servers.json

getServerType

  • getServerType(): string
  • Get current server type.

    memberof

    Application

    Returns string

    current server type from servers.json

getServerTypes

  • getServerTypes(): string[]
  • Get all the server type.

    memberof

    Application

    Returns string[]

    server type list

getServers

  • getServers(): object
  • Get all the current server infos.

    memberof

    Application

    Returns object

    server info map, key: server id, value: server info

    • [id: string]: ServerInfo

getServersByType

  • getServersByType(serverType: string): ServerInfo[]
  • Get server infos by server type.

    memberof

    Application

    Parameters

    • serverType: string

      server type

    Returns ServerInfo[]

    server info list

getServersFromConfig

  • getServersFromConfig(): any
  • Get all server infos from servers.json.

    memberof

    Application

    Returns any

    server info map, key: server id, value: server info

globalAfter

globalBefore

globalFilter

  • add a global filter to before and after global filter

    memberof

    Application

    Parameters

    • filter: IHandlerFilter

      provide before and after filter method. A filter should have two methods: before and after.

    Returns void

init

isBackend

  • isBackend(server: ServerInfo): boolean
  • Check the server whether is a backend server

    memberof

    Application

    Parameters

    • server: ServerInfo

      server info. it would check current server if server not specified

    Returns boolean

isFrontend

  • isFrontend(server?: any): boolean
  • Check the server whether is a frontend server

    memberof

    Application

    Parameters

    • Optional server: any

      server info. it would check current server if server not specified

    Returns boolean

isMaster

  • isMaster(): boolean
  • Check whether current server is a master server

    memberof

    Application

    Returns boolean

load

  • load<T>(component: ObjectType<T>, opts?: any): T
  • load<T>(name: string, component: ObjectType<T>, opts?: any): T
  • load<T>(component: T, opts?: any): T
  • load<T>(name: string, component: T, opts?: any): T
  • Load component

    memberof

    Application

    Type parameters

    Parameters

    • component: ObjectType<T>

      component instance or factory function of the component

    • Optional opts: any

      (optional) construct parameters for the factory function

    Returns T

    app instance for chain invoke

  • Type parameters

    Parameters

    • name: string
    • component: ObjectType<T>
    • Optional opts: any

    Returns T

  • Type parameters

    Parameters

    • component: T
    • Optional opts: any

    Returns T

  • Type parameters

    Parameters

    • name: string
    • component: T
    • Optional opts: any

    Returns T

loadConfig

  • loadConfig(key: string, val: string): void
  • Load Configure json file to settings.

    memberof

    Application

    Parameters

    • key: string

      environment key

    • val: string

      environment value

    Returns void

    for chaining, or the setting value

loadConfigBaseApp

  • loadConfigBaseApp(key: string, val: string, reload?: boolean): void
  • Load Configure json file to settings.(support different enviroment directory & compatible for old path)

    memberof

    Application

    Parameters

    • key: string

      environment key

    • val: string

      environment value

    • Default value reload: boolean = false

      whether reload after change default false

    Returns void

    for chaining, or the setting value

loadEvent

registerAdmin

  • registerAdmin(module: IModule, opts?: any): void
  • registerAdmin(moduleId: string, module?: IModule, opts?: any): void
  • registerAdmin(module: IModuleFactory, opts?: any): void
  • registerAdmin(moduleId: string, module?: IModuleFactory, opts?: any): void
  • Register admin modules. Admin modules is the extends point of the monitor system.

    memberof

    Application

    Parameters

    • module: IModule

      module object or factory function for module

    • Optional opts: any

      construct parameter for module

    Returns void

  • Parameters

    • moduleId: string
    • Optional module: IModule
    • Optional opts: any

    Returns void

  • Parameters

    • module: IModuleFactory
    • Optional opts: any

    Returns void

  • Parameters

    • moduleId: string
    • Optional module: IModuleFactory
    • Optional opts: any

    Returns void

removeCrons

  • removeCrons(crons: Cron[]): void
  • Remove crons from current application at runtime.

    memberof

    Application

    Parameters

    • crons: Cron[]

      old crons would be removed in application

    Returns void

removeServers

  • removeServers(ids: string[]): void
  • Remove server info from current application at runtime.

    memberof

    Application

    Parameters

    • ids: string[]

      server id list

    Returns void

replaceServers

  • replaceServers(servers: object): void
  • Replace server info from current application at runtime.

    memberof

    Application

    Parameters

    • servers: object
      • [serverId: string]: ServerInfo

    Returns void

require

  • require(ph: string): any
  • Override require method in application

    memberof

    Application

    Parameters

    • ph: string

    Returns any

route

  • Set the route function for the specified server type.

    Examples:

    app.route('area', routeFunc);

    let routeFunc = function(session, msg, app, cb) { // all request to area would be route to the first area server let areas = app.getServersByType('area'); cb(null, areas[0].id); };

    memberof

    Application

    Parameters

    • serverType: string

      server type string

    • routeFunc: RouteFunction

      route function. routeFunc(session, msg, app, cb)

    Returns this

    current application instance for chain invoking

rpcAfter

  • rpcAfter(af: RpcFilter | RpcFilter[]): void
  • Add rpc after filter.

    memberof

    Application

    Parameters

    • af: RpcFilter | RpcFilter[]

      after filter, af(serverId, msg, opts, next)

    Returns void

rpcBefore

  • rpcBefore(bf: RpcFilter | RpcFilter[]): void
  • Add rpc before filter.

    memberof

    Application

    Parameters

    • bf: RpcFilter | RpcFilter[]

      before fileter, bf(serverId, msg, opts, next)

    Returns void

rpcFilter

  • rpcFilter(filter: RpcFilter): void
  • add a rpc filter to before and after rpc filter

    memberof

    Application

    Parameters

    • filter: RpcFilter

      provide before and after filter method. A filter should have two methods: before and after.

    Returns void

set

start

  • start(cb?: function): void
  • Start application. It would load the default components and start all the loaded components.

    memberof

    Application

    Parameters

    • Optional cb: function

      callback function

        • (err?: Error, result?: void): void
        • Parameters

          • Optional err: Error
          • Optional result: void

          Returns void

    Returns void

stop

  • stop(force: boolean): void
  • Stop components.

    Parameters

    • force: boolean

      whether stop the app immediately

    Returns void

transaction

  • Application transaction. Transcation includes conditions and handlers, if conditions are satisfied, handlers would be executed. And you can set retry times to execute handlers. The transaction log is in file logs/transaction.log.

    memberof

    Application

    Parameters

    • name: string

      transaction name

    • conditions: TransactionCondictionFunction[]

      functions which are called before transaction

    • handlers: TransactionHandlerFunction[]

      functions which are called during transaction

    • retry: number

      retry times to execute handlers if conditions are successfully executed

    Returns void

use

  • use(plugin: IPlugin, opts?: any): void
  • Use plugin.

    memberof

    Application

    Parameters

    • plugin: IPlugin

      plugin instance

    • Optional opts: any

      (optional) construct parameters for the factory function

    Returns void