Package it.polito.appeal.traci

## Class SumoTraciConnection

- java.lang.Object
- - it.polito.appeal.traci.SumoTraciConnection

-     public class SumoTraciConnection
      extends Object

  Models a TCP/IP connection to a local or remote SUMO server via the TraCI protocol.
  Author:
    Enrico Gueli <enrico.gueli@gmail.com>, Mario Krumnow

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `SumoTraciConnection​(int remotePort)` | Instantiates a new sumo traci connection.
    `SumoTraciConnection​(String sumo_bin)` | Instantiates a new sumo traci connection.
    `SumoTraciConnection​(String configFile, int randomSeed, boolean useGeoOffset)` | Instantiates a new sumo traci connection.
    `SumoTraciConnection​(String sumo_bin, String configFile)` | Instantiates a new sumo traci connection.
    `SumoTraciConnection​(String sumo_bin, String net_file, String route_file)` | Instantiates a new sumo traci connection.
    `SumoTraciConnection​(String sumo_bin, String net_file, String route_file, String additional_file)` | Instantiates a new sumo traci connection.
    `SumoTraciConnection​(String sumo_bin, String net_file, String route_file, String additional_file, String gui_settings)` | Instantiates a new sumo traci connection.
    `SumoTraciConnection​(SocketAddress sockAddr)` | Instantiates a new sumo traci connection.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `addObserver​(Observer o)` | Adds the observer.
    `void` | `addOption​(String option, String value)` | Adds a custom option to the SUMO command line before executing it.
    `void` | `close()` | Closes the connection, quits the simulator, frees any stale resource and makes all Vehicle instances inactive.
    `Object` | `do_job_get​(SumoCommand cmd)` | Do job get.
    `void` | `do_job_set​(SumoCommand cmd)` | Do job set.
    `void` | `do_subscription​(Subscription cs)` | Do subscription.
    `void` | `do_timestep()` | Do timestep.
    `void` | `do_timestep​(double targetTime)` | Do timestep.
    `boolean` | `isClosed()` | Returns `true` if the connection was closed by the user, or if an `IOException` was thrown after the connection was made.
    `void` | `printSumoError​(boolean b)` | Prints the sumo error.
    `void` | `printSumoOutput​(boolean b)` | Prints the sumo output.
    `void` | `runServer()` | Runs a SUMO instance and tries to connect at it.
    `void` | `runServer​(int _remotePort)` | Runs a SUMO instance and tries to connect at it.
    `void` | `setOrder​(int index)` | Sets the order.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### SumoTraciConnection

          public SumoTraciConnection​(String sumo_bin)

      Instantiates a new sumo traci connection.
      Parameters:
        `sumo_bin` - the sumo bin

    - #### SumoTraciConnection

          public SumoTraciConnection​(String sumo_bin,
                                     String net_file,
                                     String route_file)

      Instantiates a new sumo traci connection.
      Parameters:
        `sumo_bin` - the sumo bin
        `net_file` - the net file
        `route_file` - the route file

    - #### SumoTraciConnection

          public SumoTraciConnection​(String sumo_bin,
                                     String net_file,
                                     String route_file,
                                     String additional_file)

      Instantiates a new sumo traci connection.
      Parameters:
        `sumo_bin` - the sumo bin
        `net_file` - the net file
        `route_file` - the route file
        `additional_file` - the additional file

    - #### SumoTraciConnection

          public SumoTraciConnection​(String sumo_bin,
                                     String net_file,
                                     String route_file,
                                     String additional_file,
                                     String gui_settings)

      Instantiates a new sumo traci connection.
      Parameters:
        `sumo_bin` - the sumo bin
        `net_file` - the net file
        `route_file` - the route file
        `additional_file` - the additional file
        `gui_settings` - the gui settings

    - #### SumoTraciConnection

          public SumoTraciConnection​(String sumo_bin,
                                     String configFile)

      Instantiates a new sumo traci connection.
      Parameters:
        `sumo_bin` - the sumo bin
        `configFile` - the config file

    - #### SumoTraciConnection

          public SumoTraciConnection​(String configFile,
                                     int randomSeed,
                                     boolean useGeoOffset)

      Instantiates a new sumo traci connection.
      Parameters:
        `configFile` - the config file
        `randomSeed` - the random seed
        `useGeoOffset` - the use geo offset

    - #### SumoTraciConnection

          public SumoTraciConnection​(int remotePort)
                              throws IOException,
                                     InterruptedException

      Instantiates a new sumo traci connection.
      Parameters:
        `remotePort` - the remote port
      Throws:
        `IOException` - Signals that an I/O exception has occurred.
        `InterruptedException` - the interrupted exception

    - #### SumoTraciConnection

          public SumoTraciConnection​(SocketAddress sockAddr)
                              throws IOException,
                                     InterruptedException

      Instantiates a new sumo traci connection.
      Parameters:
        `sockAddr` - the sock addr
      Throws:
        `IOException` - Signals that an I/O exception has occurred.
        `InterruptedException` - the interrupted exception

  - ### Method Detail

    - #### addOption

          public void addOption​(String option,
                                String value)

      Adds a custom option to the SUMO command line before executing it.
      Parameters:
        `option` - the option name, in long form (e.g. "no-warnings" instead of "W") and without initial dashes
        `value` - the option value, or `null` if the option has no value

    - #### runServer

          public void runServer()
                         throws IOException

      Runs a SUMO instance and tries to connect at it.
      Throws:
        `IOException` - if something wrong occurs while starting SUMO or connecting at it.

    - #### runServer

          public void runServer​(int _remotePort)
                         throws IOException

      Runs a SUMO instance and tries to connect at it.
      Parameters:
        `_remotePort` - the remote port
      Throws:
        `IOException` - if something wrong occurs while starting SUMO or connecting at it.

    - #### close

          public void close()

      Closes the connection, quits the simulator, frees any stale resource and makes all Vehicle instances inactive.

    - #### isClosed

          public boolean isClosed()

      Returns `true` if the connection was closed by the user, or if an `IOException` was thrown after the connection was made.
      Returns:
        boolean
      See Also:
        `close()`

    - #### do_job_set

          public void do_job_set​(SumoCommand cmd)
                          throws Exception

      Do job set.
      Parameters:
        `cmd` - the cmd
      Throws:
        `Exception` - the exception

    - #### do_job_get

          public Object do_job_get​(SumoCommand cmd)
                            throws Exception

      Do job get.
      Parameters:
        `cmd` - the cmd
      Returns:
        the object
      Throws:
        `Exception` - the exception

    - #### setOrder

          public void setOrder​(int index)
                        throws Exception

      Sets the order.
      Parameters:
        `index` - the new order
      Throws:
        `Exception` - the exception

    - #### do_timestep

          public void do_timestep()
                           throws Exception

      Do timestep.
      Throws:
        `Exception` - the exception

    - #### do_timestep

          public void do_timestep​(double targetTime)
                           throws Exception

      Do timestep.
      Parameters:
        `targetTime` - the target time
      Throws:
        `Exception` - the exception

    - #### addObserver

          public void addObserver​(Observer o)

      Adds the observer.
      Parameters:
        `o` - the o

    - #### do_subscription

          public void do_subscription​(Subscription cs)
                               throws Exception

      Do subscription.
      Parameters:
        `cs` - the cs
      Throws:
        `Exception` - the exception

    - #### printSumoOutput

          public void printSumoOutput​(boolean b)

      Prints the sumo output.
      Parameters:
        `b` - the b

    - #### printSumoError

          public void printSumoError​(boolean b)

      Prints the sumo error.
      Parameters:
        `b` - the b