Class AbstractTransceiver
- java.lang.Object
-
- org.djutils.event.EventProducer
-
- org.opentrafficsim.imb.transceiver.AbstractTransceiver
-
- All Implemented Interfaces:
Serializable,EventListener,EventListenerInterface,EventProducerInterface,Identifiable,org.opentrafficsim.imb.transceiver.EventTransceiver,org.opentrafficsim.imb.transceiver.Transceiver
- Direct Known Subclasses:
GraphTransceiver,GTUTransceiver,LaneGTUTransceiver,LinkGTUTransceiver,NetworkTransceiver,NodeTransceiver,SensorGTUTransceiver,SimulatorTransceiver,StatisticsGTULaneTransceiver
public abstract class AbstractTransceiver extends EventProducer implements org.opentrafficsim.imb.transceiver.EventTransceiver
Provide the basic implementation of a Transceiver from which targeted classes can extend.Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.- Version:
- $Revision$, $LastChangedDate$, by $Author$, initial version Sep 9, 2016
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.djutils.event.EventProducer
eventProducerImpl
-
Fields inherited from interface org.djutils.event.EventProducerInterface
FIRST_POSITION, LAST_POSITION
-
-
Constructor Summary
Constructors Constructor Description AbstractTransceiver(String id, org.opentrafficsim.imb.connector.Connector connector, DEVSSimulatorInterface.TimeDoubleUnit simulator)Construct a new AbstractTranceiver.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddIMBtoOTSChannel(String imbEventName, TimedEventType eventType, IMBToOTSTransformer imbToOTSTransformer)Register a new channel for sending an IMB message to an OTS EventListener.voidaddIMBtoOTSChannel(String imbEventName, org.opentrafficsim.imb.transceiver.IMBMessageHandler imbMessageHandler)Register that we are interested in an IMB payload, but do not register a listener or transformer.voidaddOTSToIMBChannel(EventProducerInterface producer, EventTypeInterface eventType, String imbEventName, Object[] imbNewPayload, OTSToIMBTransformer transformer)Make a connection from OTS to IMB, and and send a NEW message to IMB for the imbEventName with a corresponding payload.org.opentrafficsim.imb.connector.ConnectorgetConnector()StringgetId()DEVSSimulatorInterface.TimeDoubleUnitgetSimulator()Retrieve the simulator.voidhandleMessageFromIMB(String imbEventName, nl.tno.imb.TByteBuffer imbPayload)voidnotify(EventInterface event)voidremoveOTSToIMBChannel(EventProducerInterface producer, TimedEventType eventType, Object[] imbDeletePayload)Remove a connection from OTS to IMB, and and send a DELETE message to IMB for the imbEventName with a corresponding payload.StringtoString()-
Methods inherited from class org.djutils.event.EventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventTypesWithListeners, getListenerReferences, getSourceId, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.djutils.event.EventProducerInterface
addListener, addListener, addListener, addListener, getEventTypesWithListeners, getSourceId, hasListeners, numberOfListeners, removeListener
-
-
-
-
Constructor Detail
-
AbstractTransceiver
public AbstractTransceiver(String id, org.opentrafficsim.imb.connector.Connector connector, DEVSSimulatorInterface.TimeDoubleUnit simulator)
Construct a new AbstractTranceiver.- Parameters:
id- String; an id to identify the channel, e.g., "GTU" or "Simulator Control"connector- Connector; the IMB connector through which this transceiver communicatessimulator- DEVSSimulatorInterface.TimeDoubleUnit; the simulator to schedule the incoming notifications on- Throws:
NullPointerException- in case one of the arguments is null.
-
-
Method Detail
-
addOTSToIMBChannel
public final void addOTSToIMBChannel(EventProducerInterface producer, EventTypeInterface eventType, String imbEventName, Object[] imbNewPayload, OTSToIMBTransformer transformer) throws org.opentrafficsim.imb.IMBException
Make a connection from OTS to IMB, and and send a NEW message to IMB for the imbEventName with a corresponding payload. Store the transformer to use to create the CHANGE IMB messages. The Transceiver subscribes to the relevant information of the OTS EventProducer so it can send CHANGE messages from now on.- Parameters:
producer- EventProducerInterface; the OTS event producer that notifies this Transceiver about state changeseventType- TimedEventType; the event type that corresponds to the state change for this channelimbEventName- String; the IMB event name for the message to sendimbNewPayload- Object[]; the information to send to IMB with the IMB NEW messagetransformer- OTSToIMBTransformer; the transformer to use for create the IMB CHANGE events from an OTS Event content- Throws:
NullPointerException- in case one of the arguments is null.org.opentrafficsim.imb.IMBException- in case the mapping from a TimedEventType to an IMB event name is different from a previous time when a mapping was registered for the same TimedEventType (but for a different OTS EventProducer instance), when the transformer for a TimedEventType was changed a previous time when a mapping was registered, or when the subscription to the OTS EventProducer fails.
-
removeOTSToIMBChannel
public final void removeOTSToIMBChannel(EventProducerInterface producer, TimedEventType eventType, Object[] imbDeletePayload) throws org.opentrafficsim.imb.IMBException
Remove a connection from OTS to IMB, and and send a DELETE message to IMB for the imbEventName with a corresponding payload. The Transceiver subscription to the relevant information of the OTS EventProducer instance is removed.
Note that the mappings of TimedEventType to IMB Event name and of the TimedEventType to the transformer are not removed. There can be more instances of OTS EventProducer that use this channel. E.g., when all GTUs communicate through one channel using the same Transformer, the mappings should not be removed when one GTU leaves the model.- Parameters:
producer- EventProducerInterface; the OTS event producer to which we should stop listeningeventType- TimedEventType; the event type that corresponds for this channelimbDeletePayload- Object[]; the information to send to IMB with the IMB DELETE message- Throws:
NullPointerException- in case one of the arguments is null.org.opentrafficsim.imb.IMBException- when the cancellation of the subscription to the OTS EventProducer fails, or when the TimedEventType for the channel was not registered with an addOTSToIMBChannel call.
-
notify
public void notify(EventInterface event) throws RemoteException
- Specified by:
notifyin interfaceEventListenerInterface- Throws:
RemoteException
-
addIMBtoOTSChannel
public void addIMBtoOTSChannel(String imbEventName, TimedEventType eventType, IMBToOTSTransformer imbToOTSTransformer) throws org.opentrafficsim.imb.IMBException
Register a new channel for sending an IMB message to an OTS EventListener. Note that the listeners are not registered directly as an EventListener with the addListener method. Instead, we directly call the notify(event) method on the listeners.- Parameters:
imbEventName- String; the name of the IMB eventeventType- TimedEventType; the event type that the listener subscribes toimbToOTSTransformer- IMBToOTSTransformer; the transformer that creates the event content and identifies the exact listener on the basis of the IBM event payload, e.g., on the basis of an id within the payload- Throws:
org.opentrafficsim.imb.IMBException- in case the registration fails
-
addIMBtoOTSChannel
public void addIMBtoOTSChannel(String imbEventName, org.opentrafficsim.imb.transceiver.IMBMessageHandler imbMessageHandler) throws org.opentrafficsim.imb.IMBException
Register that we are interested in an IMB payload, but do not register a listener or transformer.- Parameters:
imbEventName- String; the name of the IMB eventimbMessageHandler- IMBMessageHandler; IMBMessageHandler the message handler that takes care of the IMB message- Throws:
org.opentrafficsim.imb.IMBException- in case registration fails
-
handleMessageFromIMB
public void handleMessageFromIMB(String imbEventName, nl.tno.imb.TByteBuffer imbPayload) throws org.opentrafficsim.imb.IMBException
- Specified by:
handleMessageFromIMBin interfaceorg.opentrafficsim.imb.transceiver.Transceiver- Throws:
org.opentrafficsim.imb.IMBException
-
getId
public String getId()
- Specified by:
getIdin interfaceIdentifiable- Specified by:
getIdin interfaceorg.opentrafficsim.imb.transceiver.Transceiver
-
getConnector
public final org.opentrafficsim.imb.connector.Connector getConnector()
- Specified by:
getConnectorin interfaceorg.opentrafficsim.imb.transceiver.Transceiver
-
getSimulator
public DEVSSimulatorInterface.TimeDoubleUnit getSimulator()
Retrieve the simulator.- Returns:
- DEVSSimulatorInterface.TimeDoubleUnit simulator
-
-