Object built-in object

ObjectService

System service management object

inheritance relationship

Constructor

Service

System service management object constructor

1 2 3
new Service(String name, Function worker, Object event = {});

Call parameters:

  • name: String, service name
  • worker: Function, service running function
  • event: Object, service event processing

static function

install

Install the service to the system

1 2 3 4
static Service.install(String name, String cmd, String displayName = "", String description = "");

Call parameters:

  • name: String, service name
  • cmd: String, service command line
  • displayName: String, service display name
  • description: String, service description information

remove

Uninstall the service from the system

1
static Service.remove(String name);

Call parameters:

  • name: String, service name

start

Start service

1
static Service.start(String name);

Call parameters:

  • name: String, service name

stop

Out of service

1
static Service.stop(String name);

Call parameters:

  • name: String, service name

restart

Restart service

1
static Service.restart(String name);

Call parameters:

  • name: String, service name

isInstalled

Check whether the service is installed

1
static Boolean Service.isInstalled(String name);

Call parameters:

  • name: String, service name

Return results:

  • Boolean, service installation returns True

isRunning

Check whether the service is running

1
static Boolean Service.isRunning(String name);

Call parameters:

  • name: String, service name

Return results:

  • Boolean, the service returns True when running

static properties

defaultMaxListeners

Integer, the default global maximum number of listeners

1
static Integer Service.defaultMaxListeners;

member properties

name

String, query and set service name

1
String Service.name;

onstop

Function, query and bind service stop events, equivalent to on("stop", func);

1
Function Service.onstop;

onpause

Function, queries and binds service pause events, equivalent to on("pause", func);

1
Function Service.onpause;

oncontinue

Function, query and bind service recovery events, equivalent to on("continue", func);

1
Function Service.oncontinue;

member function

run

Start running the service entity

1
Service.run() async;

on

Bind an event handler to the object

1 2
Object Service.on(String ev, Function func);

Call parameters:

  • ev: String, specifies the name of the event
  • func: Function, specify the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

Bind an event handler to the object

1
Object Service.on(Object map);

Call parameters:

  • map: Object, specifies the event mapping relationship, the object attribute name will be used as the event name, and the value of the attribute will be used as the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

addListener

Bind an event handler to the object

1 2
Object Service.addListener(String ev, Function func);

Call parameters:

  • ev: String, specifies the name of the event
  • func: Function, specify the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

Bind an event handler to the object

1
Object Service.addListener(Object map);

Call parameters:

  • map: Object, specifies the event mapping relationship, the object attribute name will be used as the event name, and the value of the attribute will be used as the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

prependListener

Bind an event handler to the object's origin

1 2
Object Service.prependListener(String ev, Function func);

Call parameters:

  • ev: String, specifies the name of the event
  • func: Function, specify the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

Bind an event handler to the object's origin

1
Object Service.prependListener(Object map);

Call parameters:

  • map: Object, specifies the event mapping relationship, the object attribute name will be used as the event name, and the value of the attribute will be used as the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

once

Bind a one-time event handler to the object. The one-time handler will only be triggered once.

1 2
Object Service.once(String ev, Function func);

Call parameters:

  • ev: String, specifies the name of the event
  • func: Function, specify the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

Bind a one-time event handler to the object. The one-time handler will only be triggered once.

1
Object Service.once(Object map);

Call parameters:

  • map: Object, specifies the event mapping relationship, the object attribute name will be used as the event name, and the value of the attribute will be used as the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

prependOnceListener

Bind an event handler to the object's origin

1 2
Object Service.prependOnceListener(String ev, Function func);

Call parameters:

  • ev: String, specifies the name of the event
  • func: Function, specify the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

Bind an event handler to the object's origin

1
Object Service.prependOnceListener(Object map);

Call parameters:

  • map: Object, specifies the event mapping relationship, the object attribute name will be used as the event name, and the value of the attribute will be used as the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

off

Unassign a function from the object processing queue

1 2
Object Service.off(String ev, Function func);

Call parameters:

  • ev: String, specifies the name of the event
  • func: Function, specify the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

Cancel all functions in the object processing queue

1
Object Service.off(String ev);

Call parameters:

  • ev: String, specifies the name of the event

Return results:

  • Object, returns the event object itself to facilitate chain calls

Unassign a function from the object processing queue

1
Object Service.off(Object map);

Call parameters:

  • map: Object, specifies the event mapping relationship, the object attribute name is used as the event name, and the value of the attribute is used as the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

removeListener

Unassign a function from the object processing queue

1 2
Object Service.removeListener(String ev, Function func);

Call parameters:

  • ev: String, specifies the name of the event
  • func: Function, specify the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

Cancel all functions in the object processing queue

1
Object Service.removeListener(String ev);

Call parameters:

  • ev: String, specifies the name of the event

Return results:

  • Object, returns the event object itself to facilitate chain calls

Unassign a function from the object processing queue

1
Object Service.removeListener(Object map);

Call parameters:

  • map: Object, specifies the event mapping relationship, the object attribute name is used as the event name, and the value of the attribute is used as the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

removeAllListeners

Cancels all listeners for all events from the object's processing queue. If an event is specified, removes all listeners for the specified event.

1
Object Service.removeAllListeners(String ev);

Call parameters:

  • ev: String, specifies the name of the event

Return results:

  • Object, returns the event object itself to facilitate chain calls

Cancels all listeners for all events from the object's processing queue. If an event is specified, removes all listeners for the specified event.

1
Object Service.removeAllListeners(Array evs = []);

Call parameters:

  • evs: Array, specify the name of the event

Return results:

  • Object, returns the event object itself to facilitate chain calls

setMaxListeners

The default limit on the number of listeners, for compatibility only

1
Service.setMaxListeners(Integer n);

Call parameters:

  • n: Integer, specify the number of events

getMaxListeners

Gets the default limit number of listeners, for compatibility only

1
Integer Service.getMaxListeners();

Return results:

  • Integer, returns the default limit quantity

listeners

Query the listener array for the specified event of the object

1
Array Service.listeners(String ev);

Call parameters:

  • ev: String, specifies the name of the event

Return results:

  • Array, returns the listener array for the specified event

listenerCount

Query the number of listeners for the specified event of the object

1
Integer Service.listenerCount(String ev);

Call parameters:

  • ev: String, specifies the name of the event

Return results:

  • Integer, returns the number of listeners for the specified event

Query the number of listeners for the specified event of the object

1 2
Integer Service.listenerCount(Value o, String ev);

Call parameters:

  • o: Value, specifies the object of the query
  • ev: String, specifies the name of the event

Return results:

  • Integer, returns the number of listeners for the specified event

eventNames

Query listener event name

1
Array Service.eventNames();

Return results:

  • Array, returns an array of event names

emit

Actively trigger an event

1 2
Boolean Service.emit(String ev, ...args);

Call parameters:

  • ev: String, event name
  • args: ..., event parameters will be passed to the event processing function

Return results:

  • Boolean, returns the event trigger status, returns true if there is a response event, otherwise returns false

toString

Returns the string representation of the object. Generally, "[Native Object]" is returned. The object can be re-implemented according to its own characteristics.

1
String Service.toString();

Return results:

  • String, returns the string representation of the object

toJSON

Returns a JSON format representation of the object, generally returning a collection of readable properties defined by the object.

1
Value Service.toJSON(String key = "");

Call parameters:

  • key: String, not used

Return results:

  • Value, returns a value containing JSON serializable