Class StreamerManager

java.lang.Object
energy.eddie.aiida.streamers.StreamerManager
All Implemented Interfaces:
AutoCloseable

@Component public class StreamerManager extends Object implements AutoCloseable
The StreamerManager manages the lifecycle of AiidaStreamer. Other components should rely on the StreamerManager for creating or stopping streamers.
  • Constructor Details

    • StreamerManager

      @Autowired public StreamerManager(Aggregator aggregator, FailedToSendRepository failedToSendRepository, tools.jackson.databind.ObjectMapper mapper, SchemaFormatterRegistry schemaFormatterRegistry, PermissionLatestRecordMap permissionLatestRecordMap)
      The mapper is passed to the AiidaStreamer instances that which use it to convert POJOs to JSON. As the mapper is shared, make sure the used implementation is thread-safe and supports sharing.
  • Method Details

    • createNewStreamer

      public void createNewStreamer(Permission permission) throws IllegalArgumentException, org.eclipse.paho.mqttv5.common.MqttException
      Creates a new AiidaStreamer for the specified permission and stores it internally. The created streamer will receive any matching AiidaRecord as requested by the data need of the permission.
      Parameters:
      permission - Permission for which an AiidaStreamer should be created.
      Throws:
      IllegalArgumentException - If an AiidaStreamer for the passed permission has already been created.
      org.eclipse.paho.mqttv5.common.MqttException
    • setTransmissionEnabled

      public void setTransmissionEnabled(UUID permissionId, boolean enabled)
      Enables or disables data transmission for the streamer of the passed permission. While disabled, no records are published to the EP.
    • updateSchedule

      public void updateSchedule(Permission permission)
      Applies a new transmission schedule to the streamer of the passed permission by rebuilding its record flux with the new aggregation cadence.
    • commandFlux

      public reactor.core.publisher.Flux<PermissionCommand> commandFlux()
      Returns a Flux on which a PermissionCommand is published whenever the EP sends a control command for one of the managed permissions. The Flux allows only one subscriber and buffers, ensuring no values get lost.
      Returns:
      Flux of permission commands received from the EP.
    • stopStreamer

      public void stopStreamer(AiidaConnectionStatusMessageDto message)
      Sends the passed status message in a blocking manner and then terminally stops the streamer.
      Parameters:
      message - Message to send before stopping the streamer. The status should be one of PermissionStatus.TERMINATED, PermissionStatus.REVOKED or PermissionStatus.FULFILLED.
    • close

      public void close()
      Closes all streamers to allow for an orderly shutdown. Note that this blocks until all streamers have finished closing, which may be indefinitely in the current implementation.
      Specified by:
      close in interface AutoCloseable