Class Publisher
java.lang.Object
org.opentrafficsim.sim0mq.publisher.AbstractTransceiver
org.opentrafficsim.sim0mq.publisher.Publisher
- All Implemented Interfaces:
org.djutils.base.Identifiable
,TransceiverInterface
Publish all available transceivers for an OTS network to a Sim0MQ master and handle its requests.
Example sequence of events:
Example sequence of events:
- Network is somehow constructed and then a Publisher for that network is constructed.
- Sim0MQ master requests names of all available subscription handlers
- 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
- 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.
- Sim0MQ master requests publisher to list all the elements of the GTUs_in_network SubscriptionHandler
- 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
- 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.
- 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 Summary
Modifier and TypeFieldDescription(package private) final org.opentrafficsim.core.network.Network
The OTS network.(package private) final Map<String,
SubscriptionHandler> Map Publisher names to the corresponding Publisher object. -
Constructor Summary
ConstructorDescriptionPublisher
(org.opentrafficsim.core.network.Network network) Construct a Publisher for an OTS network with no additional subscription handlers.Publisher
(org.opentrafficsim.core.network.Network network, List<SubscriptionHandler> additionalSubscriptionHandlers, List<IncomingDataHandler> incomingDataHandlers) Construct a Publisher for an OTS network. -
Method Summary
Modifier and TypeMethodDescriptionvoid
executeCommand
(String subscriptionHandlerName, String commandString, Object[] address, ReturnWrapperImpl returnWrapper) Execute one command.void
executeCommand
(String subscriptionHandlerName, SubscriptionHandler.Command command, Object[] address, ReturnWrapper returnWrapper) Execute one command.Object[]
get
(Object[] address, ReturnWrapper returnWrapper) Retrieve the data.getIdSource
(int addressLevel, ReturnWrapper returnWrapper) Retrieve the TransceiverInterface that can be used to get detailed information about a single object.boolean
Report if this transceiver has an id source.Find the IncomingDataHandler for a particular key.Methods inherited from class org.opentrafficsim.sim0mq.publisher.AbstractTransceiver
getAddressFields, getId, getResultFields, toString, verifyMetaData
-
Field Details
-
subscriptionHandlerMap
Map Publisher names to the corresponding Publisher object. -
network
final org.opentrafficsim.core.network.Network networkThe OTS network.
-
-
Constructor Details
-
Publisher
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 networkadditionalSubscriptionHandlers
- 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 retrievereturnWrapper
- 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 failsorg.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 fieldsreturnWrapper
- 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 indexaddressLevel
can not be obtained through a TransceiverInterface object - Throws:
org.sim0mq.Sim0MQException
- when the ReturnWrapper failsorg.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 destinedcommand
- SubscriptionHandler.Command; the operation to performaddress
- Object[]; the address on which to perform the operationreturnWrapper
- ReturnWrapper; to transmit the result- Throws:
RemoteException
- on RMI network failureorg.djutils.serialization.SerializationException
- on illegal type in serializationorg.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 destinedcommandString
- String; the operation to performaddress
- Object[]; the address on which to perform the operationreturnWrapper
- ReturnWrapper; to transmit the result- Throws:
RemoteException
- on RMI network failureorg.djutils.serialization.SerializationException
- on illegal type in serializationorg.sim0mq.Sim0MQException
- on communication error
-
lookupIncomingDataHandler
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
-