View Javadoc
1   package org.opentrafficsim.imb.connector;
2   
3   import org.opentrafficsim.imb.IMBException;
4   import org.opentrafficsim.imb.transceiver.Transceiver;
5   
6   import nl.tno.imb.TEventEntry;
7   
8   /**
9    * IMB listener and publisher.
10   * <p>
11   * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12   * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
13   * <p>
14   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Aug 19, 2016 <br>
15   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
16   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
17   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
18   */
19  public interface Connector
20  {
21      /**
22       * Compose a message containing the specified objects and send it to recipients.
23       * @param IMBEventName String; publication
24       * @param imbEventType IMBEventType; one of NEW, CHANGE, or DELETE
25       * @param args Object[]; the objects to send
26       * @return boolean; true on success, false on failure
27       * @throws IMBException when the event name is not a registered publication
28       */
29      boolean postIMBMessage(String IMBEventName, IMBEventType imbEventType, Object[] args) throws IMBException;
30  
31      /**
32       * Register the transceiver as the interested party when an IMB message identified by the imbEventName is received. When an
33       * IMB message with that imbEventName is received, the postOTSMessage method on the transceiver is called.
34       * @param fullIMBEventName the IMB Event name including the federation prefix, e.g. OTS_RT.SIM_Start
35       * @param transceiver the transceiver to handle the incoming event
36       * @throws IMBException in case the transceiver is switched to a new one for an event
37       */
38      void register(String fullIMBEventName, Transceiver transceiver) throws IMBException;
39  
40      /**
41       * Return the host of the connection, e.g. localhost, or 192,168.1.11
42       * @return String; the host of the connection
43       */
44      String getHost();
45  
46      /**
47       * Return the port of the connection, e.g. 4000
48       * @return int; the port of the connection
49       */
50      int getPort();
51  
52      /**
53       * Return the model name (owner name) of the connection, e.g. OTS
54       * @return String; the model name (owner name) of the connection
55       */
56      String getModelName();
57  
58      /**
59       * Return the model id (owner id) of the connection, e.g. 1
60       * @return String; the model id (owner id) of the connection
61       */
62      int getModelId();
63  
64      /**
65       * Return the federation name of the connection, e.g. OTS_RT
66       * @return String; the federation name of the connection
67       */
68      String getFederation();
69  
70      /**
71       * Enum for IMB event types.
72       * <p>
73       * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
74       * <br>
75       * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
76       * <p>
77       * @version $Revision$, $LastChangedDate$, by $Author$, initial version Sep 9, 2016 <br>
78       * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
79       * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
80       * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
81       */
82      public enum IMBEventType
83      {
84          /** Corresponds to TEventEntry.ACTION_NEW. */
85          NEW(TEventEntry.ACTION_NEW),
86  
87          /** Corresponds to TEventEntry.ACTION_CHANGE. */
88          CHANGE(TEventEntry.ACTION_CHANGE),
89  
90          /** Corresponds to TEventEntry.ACTION_DELETE. */
91          DELETE(TEventEntry.ACTION_DELETE);
92  
93          /** Equivalent TEventEntry value. */
94          private final int eventEntry;
95  
96          /**
97           * Construct a
98           * @param eventEntry
99           */
100         IMBEventType(final int eventEntry)
101         {
102             this.eventEntry = eventEntry;
103         }
104 
105         /**
106          * Return the corresponding integer IMB type.
107          * @return int; the IMB event type
108          */
109         public int getEventEntry()
110         {
111             return this.eventEntry;
112         }
113 
114     }
115 
116 }