Class AbstractTransceiver

    • Constructor Detail

      • AbstractTransceiver

        public AbstractTransceiver​(java.lang.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:
        java.lang.NullPointerException - in case one of the arguments is null.
    • Method Detail

      • addOTSToIMBChannel

        public final void addOTSToIMBChannel​(EventProducerInterface producer,
                                             EventTypeInterface eventType,
                                             java.lang.String imbEventName,
                                             java.lang.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 - TimedEventType; 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:
        java.lang.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,
                                                java.lang.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 listening
        eventType - TimedEventType; the event type that corresponds for this channel
        imbDeletePayload - Object[]; the information to send to IMB with the IMB DELETE message
        Throws:
        java.lang.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.
      • addIMBtoOTSChannel

        public void addIMBtoOTSChannel​(java.lang.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 event
        eventType - TimedEventType; 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​(java.lang.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​(java.lang.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 java.lang.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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object