Class IMBConnector

java.lang.Object
org.opentrafficsim.imb.connector.IMBConnector
All Implemented Interfaces:
Connector

public class IMBConnector
extends 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 Details

  • Constructor Details

    • IMBConnector

      public IMBConnector​(String host, int port, String modelName, int modelId, 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 Details

    • register

      public void register​(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​(String eventName, Connector.IMBEventType imbEventType, 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 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 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 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 String toString()
      Overrides:
      toString in class Object