Class Publisher

java.lang.Object
org.opentrafficsim.sim0mq.publisher.AbstractTransceiver
org.opentrafficsim.sim0mq.publisher.Publisher
All Implemented Interfaces:
org.djutils.base.Identifiable, TransceiverInterface

public class Publisher extends AbstractTransceiver
Publish all available transceivers for an OTS network to a Sim0MQ master and handle its requests.
Example sequence of events:
  1. Network is somehow constructed and then a Publisher for that network is constructed.
  2. Sim0MQ master requests names of all available subscription handlers
  3. Sim0MQ master decides that it wants all GTU MOVE events of all GTUs. To do that it needs to know about all GTUs when they are created and about all GTUs that have already been created. The Sim0MQ master issues to the publisher a request to subscribe to all Network.GTU_ADD_EVENTs of the GTUs_in_network SubscriptionHandler
  4. This Publisher requests the GTUs_in_network SubscriptionHandler to subscribe to the add events. From now on, the GTUs_in_network SubscriptionHandler will receive these events generated by the Network and transcribe those into a Sim0MQ events which are transmitted to the Sim0MQ master.
  5. Sim0MQ master requests publisher to list all the elements of the GTUs_in_network SubscriptionHandler
  6. This Publisher calls the list method of the GTUs_in_network SubscriptionHandler which results in a list of all active GTUs being sent to the Sim0MQ master
  7. The Sim0MQ master requests this Publisher to create a subscription for the update events of the GTU_move SubscriptionHandler, providing the GTU id as address. It does that once for every GTU id.
  8. This Publishers creates the subscriptions. From now on any GTU.MOVE_EVENT event is transcribed by the GTU_move SubscriptionHandler in to a corresponding Sim0MQ event and sent to the Sim0MQ master.

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
  • Field Details

    • subscriptionHandlerMap

      final Map<String,SubscriptionHandler> subscriptionHandlerMap
      Map Publisher names to the corresponding Publisher object.
    • network

      final org.opentrafficsim.core.network.Network network
      The OTS network.
  • Constructor Details

    • Publisher

      public Publisher(org.opentrafficsim.core.network.Network network) throws RemoteException
      Construct a Publisher for an OTS network with no additional subscription handlers.
      Parameters:
      network - Network; the OTS network
      Throws:
      RemoteException - ...
    • Publisher

      public Publisher(org.opentrafficsim.core.network.Network network, List<SubscriptionHandler> additionalSubscriptionHandlers, List<IncomingDataHandler> incomingDataHandlers) throws RemoteException
      Construct a Publisher for an OTS network.
      Parameters:
      network - Network; the OTS network
      additionalSubscriptionHandlers - List<SubscriptionHandler>; list of additional subscription handlers to register (may be null)
      incomingDataHandlers - List<IncomingDataHandler>; handlers for data not handled directly by the Publisher (may be null).
      Throws:
      RemoteException - ...
  • Method Details

    • get

      public Object[] get(Object[] address, ReturnWrapper returnWrapper) throws org.sim0mq.Sim0MQException, org.djutils.serialization.SerializationException
      Retrieve the data.
      Parameters:
      address - Object[]; the address of the data to retrieve
      returnWrapper - ReturnWrapper; to be used to report problems
      Returns:
      Object[]; the retrieved data, or null when no object with the address could be found
      Throws:
      org.sim0mq.Sim0MQException - when encoding an error message fails
      org.djutils.serialization.SerializationException - when encoding an error message fails
    • getIdSource

      public TransceiverInterface getIdSource(int addressLevel, ReturnWrapper returnWrapper) throws org.sim0mq.Sim0MQException, org.djutils.serialization.SerializationException
      Retrieve the TransceiverInterface that can be used to get detailed information about a single object.
      Parameters:
      addressLevel - int; index of the argument in the address fields
      returnWrapper - ReturnWrapper; to be used to report problems
      Returns:
      TransceiverInterface; to be used to get valid values for argument addressLevel, or null if valid values for the argument at index addressLevel can not be obtained through a TransceiverInterface object
      Throws:
      org.sim0mq.Sim0MQException - when the ReturnWrapper fails
      org.djutils.serialization.SerializationException - when the ReturnWrapper fails
    • hasIdSource

      public boolean hasIdSource()
      Report if this transceiver has an id source.
      Returns:
      boolean; true if this transceiver has an id source; false if this transceiver does not have an id source
    • executeCommand

      public void executeCommand(String subscriptionHandlerName, SubscriptionHandler.Command command, Object[] address, ReturnWrapper returnWrapper) throws RemoteException, org.sim0mq.Sim0MQException, org.djutils.serialization.SerializationException
      Execute one command.
      Parameters:
      subscriptionHandlerName - String; name of the SubscriptionHandler for which the command is destined
      command - SubscriptionHandler.Command; the operation to perform
      address - Object[]; the address on which to perform the operation
      returnWrapper - ReturnWrapper; to transmit the result
      Throws:
      RemoteException - on RMI network failure
      org.djutils.serialization.SerializationException - on illegal type in serialization
      org.sim0mq.Sim0MQException - on communication error
    • executeCommand

      public void executeCommand(String subscriptionHandlerName, String commandString, Object[] address, ReturnWrapperImpl returnWrapper) throws RemoteException, org.sim0mq.Sim0MQException, org.djutils.serialization.SerializationException
      Execute one command.
      Parameters:
      subscriptionHandlerName - String; name of the SubscriptionHandler for which the command is destined
      commandString - String; the operation to perform
      address - Object[]; the address on which to perform the operation
      returnWrapper - ReturnWrapper; to transmit the result
      Throws:
      RemoteException - on RMI network failure
      org.djutils.serialization.SerializationException - on illegal type in serialization
      org.sim0mq.Sim0MQException - on communication error
    • lookupIncomingDataHandler

      public IncomingDataHandler lookupIncomingDataHandler(String key)
      Find the IncomingDataHandler for a particular key.
      Parameters:
      key - String; the key of the IncomingDataHandler
      Returns:
      IncomingDataHandler; or null if there is no IncomingDataHandler for the key