View Javadoc
1   package org.opentrafficsim.remotecontrol;
2   
3   import java.io.IOException;
4   
5   import javax.naming.NamingException;
6   
7   import org.djunits.value.ValueRuntimeException;
8   import org.djutils.cli.Checkable;
9   import org.djutils.cli.CliUtil;
10  import org.djutils.logger.CategoryLogger;
11  import org.djutils.logger.LogCategory;
12  import org.djutils.serialization.SerializationException;
13  import org.opentrafficsim.base.parameters.ParameterException;
14  import org.opentrafficsim.core.geometry.OTSGeometryException;
15  import org.opentrafficsim.core.network.NetworkException;
16  import org.opentrafficsim.sim0mq.swing.Sim0MQPublisher;
17  import org.pmw.tinylog.Level;
18  import org.sim0mq.Sim0MQException;
19  
20  import nl.tudelft.simulation.dsol.SimRuntimeException;
21  import picocli.CommandLine.Command;
22  import picocli.CommandLine.Option;
23  
24  /**
25   * Sim0MQ controlled OTS
26   * <p>
27   * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
28   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
29   * <p>
30   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Apr 18, 2017 <br>
31   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
32   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
33   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
34   */
35  public final class Sim0MQControlledOTSNew
36  {
37      /**
38       * Do not instantiate.
39       */
40      private Sim0MQControlledOTSNew()
41      {
42          // Do not instantiate
43      }
44      
45      /**
46       * The command line options.
47       */
48      @Command(description = "Sim0MQ Remotely Controlled OTS", name = "Sim0MQOTS", mixinStandardHelpOptions = true,
49              version = "1.0")
50      public static class Options implements Checkable
51      {
52          /** The IP port. */
53          @Option(names = { "-p", "--port" }, description = "Internet port to use", defaultValue = "8888")
54          private int port;
55  
56          /**
57           * Retrieve the port.
58           * @return int; the port
59           */
60          public final int getPort()
61          {
62              return this.port;
63          }
64  
65          @Override
66          public final void check() throws Exception
67          {
68              if (this.port <= 0 || this.port > 65535)
69              {
70                  throw new Exception("Port should be between 1 and 65535");
71              }
72          }
73      }
74  
75      /**
76       * Program entry point.
77       * @param args String[]; the command line arguments
78       * @throws OTSGeometryException on error
79       * @throws NetworkException on error
80       * @throws NamingException on error
81       * @throws ValueRuntimeException on error
82       * @throws SimRuntimeException on error
83       * @throws ParameterException on error
84       * @throws SerializationException on error
85       * @throws Sim0MQException on error
86       * @throws IOException on error
87       */
88      public static void main(final String[] args) throws NetworkException, OTSGeometryException, NamingException,
89              ValueRuntimeException, ParameterException, SimRuntimeException, Sim0MQException, SerializationException, IOException
90      {
91          CategoryLogger.setAllLogLevel(Level.WARNING);
92          CategoryLogger.setLogCategories(LogCategory.ALL);
93          Options options = new Options();
94          CliUtil.execute(options, args); // register Unit converters, parse the command line, etc..
95          int port = options.getPort();
96          System.out.println("Creating OTS server listening on port " + port + " on all interfaces");
97          new Sim0MQPublisher(port); // Should not return until it receives a DIE command, or the connection is closed
98          System.out.println("Sim0MQControlledOTSNew exits");
99      }
100 
101 }