Object built-in object

Object Service

System Service Management Object

Inheritance

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 operation function
  • event : Object, service event processing

Static function

install

Install services 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 result:

  • Boolean , the service installation returns True

isRunning

Check if the service is running

1
static Boolean Service.isRunning(String name);

Call parameters:

  • name : String, service name

Return result:

  • Boolean , the service operation returns True

Static properties

defaultMaxListeners

Integer, the default global maximum number of listeners

1
static Integer Service.defaultMaxListeners;

Member attributes

name

String, query and set service name

1
String Service.name;

onstop

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

1
Function Service.onstop;

onpause

Function, query and bind service pause event, 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 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, specify the name of the event
  • func : Function, specify event processing function

Return result:

  • Object , returns the event object itself, easy to chain call

Bind an event handler to the object

1
Object Service.on(Object map);

Call parameters:

  • map : Object, specify the event mapping relationship, the object property name will be the event name, and the property value will be the event processing function

Return result:

  • Object , returns the event object itself, easy to chain call

addListener

Bind an event handler to the object

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

Call parameters:

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

Return result:

  • Object , returns the event object itself, easy to chain call

Bind an event handler to the object

1
Object Service.addListener(Object map);

Call parameters:

  • map : Object, specify the event mapping relationship, the object property name will be the event name, and the property value will be the event processing function

Return result:

  • Object , returns the event object itself, easy to chain call

prependListener

Bind an event handler to the object start

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

Call parameters:

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

Return result:

  • Object , returns the event object itself, easy to chain call

Bind an event handler to the object start

1
Object Service.prependListener(Object map);

Call parameters:

  • map : Object, specify the event mapping relationship, the object property name will be the event name, and the property value will be the event processing function

Return result:

  • Object , returns the event object itself, easy to chain call

once

Bind a one-time event processing function to the object, the one-time processing function will only be triggered once

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

Call parameters:

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

Return result:

  • Object , returns the event object itself, easy to chain call

Bind a one-time event processing function to the object, the one-time processing function will only be triggered once

1
Object Service.once(Object map);

Call parameters:

  • map : Object, specify the event mapping relationship, the object property name will be the event name, and the property value will be the event processing function

Return result:

  • Object , returns the event object itself, easy to chain call

prependOnceListener

Bind an event handler to the object start

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

Call parameters:

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

Return result:

  • Object , returns the event object itself, easy to chain call

Bind an event handler to the object start

1
Object Service.prependOnceListener(Object map);

Call parameters:

  • map : Object, specify the event mapping relationship, the object property name will be the event name, and the property value will be the event processing function

Return result:

  • Object , returns the event object itself, easy to chain call

off

Cancel the specified function from the object processing queue

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

Call parameters:

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

Return result:

  • Object , returns the event object itself, easy to chain call

Cancel all functions in the object processing queue

1
Object Service.off(String ev);

Call parameters:

  • ev : String, specify the name of the event

Return result:

  • Object , returns the event object itself, easy to chain call

Cancel the specified function from the object processing queue

1
Object Service.off(Object map);

Call parameters:

  • map : Object, specify the event mapping relationship, the object property name is used as the event name, and the property value is used as the event processing function

Return result:

  • Object , returns the event object itself, easy to chain call

removeListener

Cancel the specified function from the object processing queue

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

Call parameters:

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

Return result:

  • Object , returns the event object itself, easy to chain call

Cancel all functions in the object processing queue

1
Object Service.removeListener(String ev);

Call parameters:

  • ev : String, specify the name of the event

Return result:

  • Object , returns the event object itself, easy to chain call

Cancel the specified function from the object processing queue

1
Object Service.removeListener(Object map);

Call parameters:

  • map : Object, specify the event mapping relationship, the object property name is used as the event name, and the property value is used as the event processing function

Return result:

  • Object , returns the event object itself, easy to chain call

removeAllListeners

Cancel all listeners of all events from the object processing queue. If an event is specified, remove all listeners of the specified event.

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

Call parameters:

  • evs : Array, specify the name of the event

Return result:

  • Object , returns the event object itself, easy to chain call

setMaxListeners

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

1
Service.setMaxListeners(Integer n);

Call parameters:

  • n : Integer, specify the number of events

getMaxListeners

Get the default limit of the number of listeners, only for compatibility

1
Integer Service.getMaxListeners();

Return result:

  • Integer , returns the default limit number

listeners

Array of listeners for the specified event of the query object

1
Array Service.listeners(String ev);

Call parameters:

  • ev : String, specify the name of the event

Return result:

  • Array , returns an array of listeners for the specified event

listenerCount

The number of listeners for the specified event of the query object

1
Integer Service.listenerCount(String ev);

Call parameters:

  • ev : String, specify the name of the event

Return result:

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

eventNames

Query listener event name

1
Array Service.eventNames();

Return result:

  • Array , returns an array of event names

emit

Trigger an event actively

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

Call parameters:

  • ev : String, event name
  • args : ..., event parameters, which will be passed to the event handler

Return result:

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

toString

Returns the string representation of the object, generally returns "[Native Object]", the object can be re-implemented according to its own characteristics

1
String Service.toString();

Return result:

  • String , returns the string representation of the object

toJSON

Returns the JSON format representation of the object, generally returns a collection of readable attributes defined by the object

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

Call parameters:

  • key : String, unused

Return result:

  • Value , returns a value containing JSON serializable