Class AbstractService

java.lang.Object
com.tccc.kos.commons.util.ready.ReadyBean
com.tccc.kos.commons.core.service.AbstractService
All Implemented Interfaces:
CtxEventListener, ContextHandleAware, HandleAware, Ready, ReadyListener
Direct Known Subclasses:
AbstractConfigurableService, AnalyticsClient, AnalyticsServer, ApiClient, AppService, AssemblyService, BrokerClient, BrowserService, ConfigServer, ConfigService, CriticalDataService, DeviceService, ExtensionService, FirmwareService, FuseService, HandleService, HardwareService, KeyValService, LocalizationService, LogService, ManifestService, NetworkService, NodeMgrService, NodeResolverService, OTAService, RegionService, SerialService, SpawnService, StateService, StorageService, TimeService, TroubleService, UdevService, UpdateService

public abstract class AbstractService extends ReadyBean implements ContextHandleAware, CtxEventListener
Abstract base class for all services. It implements HandleAware and uses @HandleRoot so that subclasses are automatically added to the handle cache, as long as the service is added to the context.

This class implements Ready and ReadyListener in order to make all services easily consumable as ReadyListener targets. By default, this class calls ready() from the onReady() callback, which means by default a service will cascade ready events up as soon as they are ready.

To make ready status of this service dependent on other services, simply annotate the corresponding fields with @WhenReady. In order to do work when all dependencies are ready, simply override onReady() and either call super.onReady() or getReady().ready() when done, which cascades the ready event up.

If your service is configurable, use the AbstractConfigurableService instead.

Since:
1.0
Version:
2023-03-06
  • Method Details

    • getHandlePrefix

      public String getHandlePrefix()
      Description copied from interface: ContextHandleAware
      Returns the prefix for the object to be used when the handle is allocated by the context. The prefix typically reflects the type of the object, such that two objects with the same name but different types are uniquely identified. This value should be the name of the getter if this object was to be fetched from a parent object. For example, if class was Pump there may be two instances: water and carb. The prefix for the water pump may be "water" while the prefix for carb may be "carb", as this distinguishes them. In cases where there is a single getter, it's not uncommon for the prefix to be the type of the object or null. The default implementation returns null.
      Specified by:
      getHandlePrefix in interface ContextHandleAware
    • getHandle

      public Handle getHandle()
      Description copied from interface: HandleAware
      Returns the handle for this bean. This is used by the context to compute the opaque handle for the object.
      Specified by:
      getHandle in interface HandleAware
      Returns:
      the handle node for the bean