Class IMBConnector

  • All Implemented Interfaces:
    Connector

    public class IMBConnector
    extends java.lang.Object
    implements Connector
    Make a connection to the IMB bus, allow messages to be posted, and register callbacks from IMB to OTS.

    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 Aug 19, 2016
    Author:
    Alexander Verbraeck, Peter Knoppers, Wouter Schakel
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Map<java.lang.String,​Transceiver> imbTransceiverMap
      Registration of callback ids from IMB to OTS.
    • Constructor Summary

      Constructors 
      Constructor Description
      IMBConnector​(java.lang.String host, int port, java.lang.String modelName, int modelId, java.lang.String federation)
      Construct a new connection for sending events to IMB
      IMBConnector​(TConnection connection)
      Construct an IMBConnector that re-uses an existing TConnection.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getFederation()
      Return the federation name of the connection, e.g.
      java.lang.String getHost()
      Return the host of the connection, e.g.
      int getModelId()
      Return the model id (owner id) of the connection, e.g.
      java.lang.String getModelName()
      Return the model name (owner name) of the connection, e.g.
      int getPort()
      Return the port of the connection, e.g.
      boolean postIMBMessage​(java.lang.String eventName, Connector.IMBEventType imbEventType, java.lang.Object[] args)
      Compose a message containing the specified objects and send it to recipients.
      void register​(java.lang.String imbEventName, Transceiver transceiver)
      Register the transceiver as the interested party when an IMB message identified by the imbEventName is received.
      java.lang.String toString()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • imbTransceiverMap

        protected java.util.Map<java.lang.String,​Transceiver> imbTransceiverMap
        Registration of callback ids from IMB to OTS.
    • Constructor Detail

      • IMBConnector

        public IMBConnector​(java.lang.String host,
                            int port,
                            java.lang.String modelName,
                            int modelId,
                            java.lang.String federation)
                     throws IMBException
        Construct a new connection for sending events to IMB
        Parameters:
        host - String; name of the IMB hub
        port - int; port number of the IMB hub
        modelName - String; local model name
        modelId - int; model id
        federation - String; federation on the IMB hub
        Throws:
        IMBException - when a connection to the IMB hub could not be established
      • IMBConnector

        public IMBConnector​(TConnection connection)
                     throws IMBException
        Construct an IMBConnector that re-uses an existing TConnection.
        Parameters:
        connection - TConnection; the existing TConnection
        Throws:
        IMBException - when the connection is not connected to an IMB hub
    • Method Detail

      • register

        public void register​(java.lang.String imbEventName,
                             Transceiver transceiver)
                      throws IMBException
        Register the transceiver as the interested party when an IMB message identified by the imbEventName is received. When an IMB message with that imbEventName is received, the postOTSMessage method on the transceiver is called.
        Specified by:
        register in interface Connector
        Parameters:
        imbEventName - String; the IMB Event name including the federation prefix, e.g. OTS_RT.SIM_Start
        transceiver - Transceiver; the transceiver to handle the incoming event
        Throws:
        IMBException - in case the transceiver is switched to a new one for an event
      • postIMBMessage

        public final boolean postIMBMessage​(java.lang.String eventName,
                                            Connector.IMBEventType imbEventType,
                                            java.lang.Object[] args)
                                     throws IMBException
        Compose a message containing the specified objects and send it to recipients.
        Specified by:
        postIMBMessage in interface Connector
        Parameters:
        eventName - String; publication
        imbEventType - IMBEventType; one of NEW, CHANGE, or DELETE
        args - Object[]; the objects to send
        Returns:
        boolean; true on success, false on failure
        Throws:
        IMBException - when the event name is not a registered publication
      • getHost

        public final java.lang.String getHost()
        Return the host of the connection, e.g. localhost, or 192,168.1.11
        Specified by:
        getHost in interface Connector
        Returns:
        String; the host of the connection
      • getPort

        public final int getPort()
        Return the port of the connection, e.g. 4000
        Specified by:
        getPort in interface Connector
        Returns:
        int; the port of the connection
      • getModelName

        public final java.lang.String getModelName()
        Return the model name (owner name) of the connection, e.g. OTS
        Specified by:
        getModelName in interface Connector
        Returns:
        String; the model name (owner name) of the connection
      • getModelId

        public final int getModelId()
        Return the model id (owner id) of the connection, e.g. 1
        Specified by:
        getModelId in interface Connector
        Returns:
        String; the model id (owner id) of the connection
      • getFederation

        public final java.lang.String getFederation()
        Return the federation name of the connection, e.g. OTS_RT
        Specified by:
        getFederation in interface Connector
        Returns:
        String; the federation name of the connection
      • toString

        public final java.lang.String toString()
        Overrides:
        toString in class java.lang.Object