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
  • 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 communicates
      simulator - 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.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 changes
      eventType - EventType; the event type that corresponds to the state change for this channel
      imbEventName - String; the IMB event name for the message to send
      imbNewPayload - Object[]; the information to send to IMB with the IMB NEW message
      transformer - 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.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 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 listening
      eventType - EventType; the event type that corresponds for this channel
      imbDeletePayload - 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

      public void notify​(EventInterface event) throws RemoteException
      Specified by:
      notify in interface EventListenerInterface
      Throws:
      RemoteException
    • addIMBtoOTSChannel

      public void addIMBtoOTSChannel​(String imbEventName, EventType 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 event
      eventType - EventType; the event type that the listener subscribes to
      imbToOTSTransformer - 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 event
      imbMessageHandler - 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:
      handleMessageFromIMB in interface org.opentrafficsim.imb.transceiver.Transceiver
      Throws:
      org.opentrafficsim.imb.IMBException
    • getId

      public String getId()
      Specified by:
      getId in interface Identifiable
      Specified by:
      getId in interface org.opentrafficsim.imb.transceiver.Transceiver
    • getConnector

      public final org.opentrafficsim.imb.connector.Connector getConnector()
      Specified by:
      getConnector in interface org.opentrafficsim.imb.transceiver.Transceiver
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getSimulator

      Retrieve the simulator.
      Returns:
      DEVSSimulatorInterface.TimeDoubleUnit simulator