Class SubscriptionHandler

java.lang.Object
org.opentrafficsim.sim0mq.publisher.SubscriptionHandler

public class SubscriptionHandler extends Object
Data collection that can be listed and has subscription to change events.

Copyright (c) 2020-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Author:
Alexander Verbraeck, Peter Knoppers
  • Constructor Details

    • SubscriptionHandler

      public SubscriptionHandler(String id, TransceiverInterface listTransceiver, LookupEventProducer eventProducerForAddRemoveOrChange, org.djutils.event.EventType addedEventType, org.djutils.event.EventType removedEventType, org.djutils.event.EventType changeEventType, SubscriptionHandler elementSubscriptionHandler)
      Create a new SubscriptionHandler.
      Parameters:
      id - String; id of the new SubscriptionHandler
      listTransceiver - TransceiverInterface; transceiver to retrieve the data of the addressed object right now
      eventProducerForAddRemoveOrChange - LookupEventProducer; the event producer that can emit the addedEventType, removedEventType, or changeEventType events
      addedEventType - EventType; event type that signals that a new element has been added, should be null if there is no added event type for the data
      removedEventType - EventType; event type that signals that an element has been removed, should be null if there is no removed event type for the data
      changeEventType - EventType; event type that signals that an element has been changed, should be null if there is no change event type for the data
      elementSubscriptionHandler - SubscriptionHandler; SubscriptionHandler for events produced by the underlying elements
  • Method Details

    • listRequestMetaData

      public org.djutils.metadata.MetaData listRequestMetaData()
      Report what payload is required to retrieve a list of all elements, or data and what format a result would have.
      Returns:
      MetaData; description of the payload required to retrieve a list of all elements, or data and what format a result would have
    • listResultMetaData

      public org.djutils.metadata.MetaData listResultMetaData()
      Report what the payload format of the result of the list transceiver.
      Returns:
      MetaData; the payload format of the result of the list transceiver
    • get

      public void get(Object[] address, ReturnWrapper returnWrapper) throws RemoteException, org.sim0mq.Sim0MQException, org.djutils.serialization.SerializationException
      Retrieve a data collection.
      Parameters:
      address - Object[]; address of the requested data collection
      returnWrapper - ReturnWrapper; to send back the result
      Throws:
      RemoteException - when communication fails
      org.djutils.serialization.SerializationException - on context error
      org.sim0mq.Sim0MQException - on DSOL error
    • getListTransceiver

      public TransceiverInterface getListTransceiver()
      Retrieve the list transceiver (only for testing).
      Returns:
      TransceiverInterface; the list transceiver
    • subscriptionOptions

      public final EnumSet<SubscriptionHandler.Command> subscriptionOptions()
      Return the set of supported commands.
      Returns:
      EnumSet<Command>; the set of supported commands.
    • getId

      public final String getId()
      Retrieve the id of this SubscriptionHandler.
      Returns:
      String; the id of this SubscriptionHandler
    • lookupCommand

      public static SubscriptionHandler.Command lookupCommand(String commandString)
      Convert a String representing a Command into that Command.
      Parameters:
      commandString - String; the string
      Returns:
      Command; the corresponding Command, or null if the commandString is not a valid Command
    • executeCommand

      public void executeCommand(SubscriptionHandler.Command command, Object[] address, ReturnWrapper returnWrapper) throws RemoteException, org.sim0mq.Sim0MQException, org.djutils.serialization.SerializationException
      Execute one command.
      Parameters:
      command - Command; the command
      address - Object[] the address of the object on which the command must be applied
      returnWrapper - ReturnWrapper; envelope generator for replies
      Throws:
      RemoteException - on communication failure
      org.djutils.serialization.SerializationException - on illegal type in serialization
      org.sim0mq.Sim0MQException - on communication error
    • toString

      public String toString()
      Overrides:
      toString in class Object