Package org.opentrafficsim.imb.connector
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
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.opentrafficsim.imb.connector.Connector
Connector.IMBEventType -
Field Summary
Fields Modifier and Type Field Description protected Map<String,Transceiver>imbTransceiverMapRegistration of callback ids from IMB to OTS. -
Constructor Summary
Constructors Constructor Description IMBConnector(String host, int port, String modelName, int modelId, String federation)Construct a new connection for sending events to IMBIMBConnector(TConnection connection)Construct an IMBConnector that re-uses an existing TConnection. -
Method Summary
Modifier and Type Method Description StringgetFederation()Return the federation name of the connection, e.g.StringgetHost()Return the host of the connection, e.g.intgetModelId()Return the model id (owner id) of the connection, e.g.StringgetModelName()Return the model name (owner name) of the connection, e.g.intgetPort()Return the port of the connection, e.g.booleanpostIMBMessage(String eventName, Connector.IMBEventType imbEventType, Object[] args)Compose a message containing the specified objects and send it to recipients.voidregister(String imbEventName, Transceiver transceiver)Register the transceiver as the interested party when an IMB message identified by the imbEventName is received.StringtoString()
-
Field Details
-
imbTransceiverMap
Registration of callback ids from IMB to OTS.
-
-
Constructor Details
-
IMBConnector
public IMBConnector(String host, int port, String modelName, int modelId, String federation) throws IMBExceptionConstruct a new connection for sending events to IMB- Parameters:
host- String; name of the IMB hubport- int; port number of the IMB hubmodelName- String; local model namemodelId- int; model idfederation- String; federation on the IMB hub- Throws:
IMBException- when a connection to the IMB hub could not be established
-
IMBConnector
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
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:
registerin interfaceConnector- Parameters:
imbEventName- String; the IMB Event name including the federation prefix, e.g. OTS_RT.SIM_Starttransceiver- 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 IMBExceptionCompose a message containing the specified objects and send it to recipients.- Specified by:
postIMBMessagein interfaceConnector- Parameters:
eventName- String; publicationimbEventType- IMBEventType; one of NEW, CHANGE, or DELETEargs- 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
Return the host of the connection, e.g. localhost, or 192,168.1.11 -
getPort
public final int getPort()Return the port of the connection, e.g. 4000 -
getModelName
Return the model name (owner name) of the connection, e.g. OTS- Specified by:
getModelNamein interfaceConnector- 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:
getModelIdin interfaceConnector- Returns:
- String; the model id (owner id) of the connection
-
getFederation
Return the federation name of the connection, e.g. OTS_RT- Specified by:
getFederationin interfaceConnector- Returns:
- String; the federation name of the connection
-
toString
-