Class SubscriptionHandler
java.lang.Object
org.opentrafficsim.sim0mq.publisher.SubscriptionHandler
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
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
The commands that a SubscriptionHandler understands. -
Constructor Summary
ConstructorDescriptionSubscriptionHandler
(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. -
Method Summary
Modifier and TypeMethodDescriptionvoid
executeCommand
(SubscriptionHandler.Command command, Object[] address, ReturnWrapper returnWrapper) Execute one command.void
get
(Object[] address, ReturnWrapper returnWrapper) Retrieve a data collection.final String
getId()
Retrieve the id of this SubscriptionHandler.Retrieve the list transceiver (only for testing).org.djutils.metadata.MetaData
Report what payload is required to retrieve a list of all elements, or data and what format a result would have.org.djutils.metadata.MetaData
Report what the payload format of the result of the list transceiver.static SubscriptionHandler.Command
lookupCommand
(String commandString) Convert a String representing a Command into that Command.Return the set of supported commands.toString()
-
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 SubscriptionHandlerlistTransceiver
- TransceiverInterface; transceiver to retrieve the data of the addressed object right noweventProducerForAddRemoveOrChange
- LookupEventProducer; the event producer that can emit theaddedEventType
,removedEventType
, orchangeEventType
eventsaddedEventType
- EventType; event type that signals that a new element has been added, should be null if there is no added event type for the dataremovedEventType
- EventType; event type that signals that an element has been removed, should be null if there is no removed event type for the datachangeEventType
- EventType; event type that signals that an element has been changed, should be null if there is no change event type for the dataelementSubscriptionHandler
- 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 collectionreturnWrapper
- ReturnWrapper; to send back the result- Throws:
RemoteException
- when communication failsorg.djutils.serialization.SerializationException
- on context errororg.sim0mq.Sim0MQException
- on DSOL error
-
getListTransceiver
Retrieve the list transceiver (only for testing).- Returns:
- TransceiverInterface; the list transceiver
-
subscriptionOptions
Return the set of supported commands.- Returns:
- EnumSet<Command>; the set of supported commands.
-
getId
Retrieve the id of this SubscriptionHandler.- Returns:
- String; the id of this SubscriptionHandler
-
lookupCommand
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 commandaddress
- Object[] the address of the object on which the command must be appliedreturnWrapper
- ReturnWrapper; envelope generator for replies- Throws:
RemoteException
- on communication failureorg.djutils.serialization.SerializationException
- on illegal type in serializationorg.sim0mq.Sim0MQException
- on communication error
-
toString
-