Class AbstractTransceiver
java.lang.Object
nl.tudelft.simulation.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-2019 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 interface nl.tudelft.simulation.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
Modifier and Type Method Description voidaddIMBtoOTSChannel(String imbEventName, EventType 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, EventType 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, EventType 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 nl.tudelft.simulation.event.EventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, removeAllListeners, removeAllListeners, removeListenerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface nl.tudelft.simulation.event.EventProducerInterface
addListener, addListener, addListener, addListener, removeListener
-
Constructor Details
-
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 Details
-
addOTSToIMBChannel
public final void addOTSToIMBChannel(EventProducerInterface producer, EventType eventType, String imbEventName, Object[] imbNewPayload, OTSToIMBTransformer transformer) throws org.opentrafficsim.imb.IMBExceptionMake 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- EventType; 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 an EventType to an IMB event name is different from a previous time when a mapping was registered for the same EventType (but for a different OTS EventProducer instance), when the transformer for an EventType 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, EventType eventType, Object[] imbDeletePayload) throws org.opentrafficsim.imb.IMBExceptionRemove 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 EventType to IMB Event name and of the EventType 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- EventType; 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 EventType for the channel was not registered with an addOTSToIMBChannel call.
-
notify
- Specified by:
notifyin interfaceEventListenerInterface- Throws:
RemoteException
-
addIMBtoOTSChannel
public void addIMBtoOTSChannel(String imbEventName, EventType eventType, IMBToOTSTransformer imbToOTSTransformer) throws org.opentrafficsim.imb.IMBExceptionRegister 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- EventType; 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.IMBExceptionRegister 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
- 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
-
toString
-
getSimulator
Retrieve the simulator.- Returns:
- DEVSSimulatorInterface.TimeDoubleUnit simulator
-