Fantom

 

mixin

sys::Service

sys::Obj
  sys::Service

Services are used to publish functionality in a VM for use by other software components. The service registry for the VM is keyed by public types each service implements. Service are automatically mapped into the namespace under "/sys/service/{qname}" for all their public types.

The following table illustrates the service lifecycle:

Method        isInstalled  isRunning
-----------   -----------  ----------
constructed   false        false
install       true         false
start         true         true
stop          true         false
uninstall     false        false

While the service is installed, it may be looked up in the registry via find and findAll. The running state is used to invoke the onStart and onStop callbacks which gives the service a chance to setup/shutdown its actors and associated resources.

Slots

equalsSource

Bool equals(Obj? that)

Overrides sys::Obj.equals

Services are required to implement equality by reference.

findSource

static Service? find(Type t, Bool checked := true)

Find an installed service by type. If not found and checked is false return null, otherwise throw UnknownServiceErr. If multiple services are registered for the given type then return the first one registered.

findAllSource

static Service[] findAll(Type t)

Find all services installed for the given type. If no services are found then return an empty list.

hashSource

Int hash()

Overrides sys::Obj.hash

Services are required to implement equality by reference.

installSource

This install()

Install this service into the VM's service registry. If already installed, do nothing. Return this.

isInstalledSource

Bool isInstalled()

Is the service in the installed state. Note this method requires accessing a global hash table, so it should not be heavily polled in a concurrent environment.

isRunningSource

Bool isRunning()

Is the service in the running state. Note this method requires accessing a global hash table, so it should not be heavily polled in a concurrent environment.

listSource

static Service[] list()

List all the installed services.

onStartSource

virtual protected Void onStart()

Callback when service transitions into running state.

onStopSource

virtual protected Void onStop()

Callback when service transitions out of the running state.

startSource

This start()

Start this service. If not installed, this method autoamatically calls install. If already running, do nothing. Return this.

stopSource

This stop()

Stop this service. If not running, do nothing. Return this.

uninstallSource

This uninstall()

Uninstall this service from the VM's service registry. If the service is running, this method automatically calls stop. If not installed, do nothing. Return this.