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
26
27
28
29
30
31
32
33
34
35 public final class Sim0MQControlledOTSNew
36 {
37
38
39
40 private Sim0MQControlledOTSNew()
41 {
42
43 }
44
45
46
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
53 @Option(names = { "-p", "--port" }, description = "Internet port to use", defaultValue = "8888")
54 private int port;
55
56
57
58
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
77
78
79
80
81
82
83
84
85
86
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);
95 int port = options.getPort();
96 System.out.println("Creating OTS server listening on port " + port + " on all interfaces");
97 new Sim0MQPublisher(port);
98 System.out.println("Sim0MQControlledOTSNew exits");
99 }
100
101 }