Class Service

java.lang.Object
com.framed.core.Service
Direct Known Subclasses:
Dispatcher, Parser, Protocol, Reactor, Writer

public abstract class Service extends Object
An abstract base class for application services that provides access to an EventBus for inter-component communication / services and a Logger for logging.

Subclasses can use the event bus to send or receive messages and the logger for diagnostic output. This class also provides a default stop() method that can be overridden to implement custom shutdown logic.

  • Field Details

    • ADDRESS_REGISTRY_SUFFIX

      public static final String ADDRESS_REGISTRY_SUFFIX
      Topic suffix for the producer→sink address-discovery protocol.

      A producing service announces each of its output channel names on the topic "<group>" + ADDRESS_REGISTRY_SUFFIX (see announceAddress(String, String)). Sinks such as dispatchers and writers subscribe to that same topic (using addressRegistry(String)) to dynamically discover and bind the channels a producer emits. The group is typically a device name or a logical producer id.

      See Also:
    • eventBus

      protected EventBus eventBus
      The event bus used for communication between components.
    • logger

      protected final Logger logger
      Logger instance for this service, initialized with the class name.
    • formatter

      protected static final DateTimeFormatter formatter
      Shared timestamp formatter (see Timer.formatter) available to all services for consistent serialization and parsing of timestamps.
  • Constructor Details

    • Service

      protected Service(EventBus eventBus)
      Creates a new service instance with the specified event bus.
      Parameters:
      eventBus - the event bus used for communication
  • Method Details

    • addressRegistry

      public static String addressRegistry(String group)
      Returns the address-discovery topic for the given producer group.
      Parameters:
      group - device name or logical producer id
      Returns:
      the topic sinks subscribe to in order to discover group's output channels
    • announceAddress

      protected void announceAddress(String group, String address)
      Announces that address is an output channel of the producer group, so that sinks subscribed to addressRegistry(String) can discover and bind it.
      Parameters:
      group - device name or logical producer id this service emits under
      address - the output channel name being announced
    • stop

      public void stop()
      Stops the service.

      By default, this method logs a message indicating that no stop logic is implemented. Subclasses should override this method to provide custom shutdown behavior when necessary.