1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package com.xley.lfosc;
22
23 import com.xley.lfosc.util.LogUtil;
24 import joptsimple.OptionParser;
25 import joptsimple.OptionSet;
26 import org.apache.log4j.Level;
27
28 import java.io.IOException;
29 import java.util.Locale;
30 import java.util.ResourceBundle;
31
32
33
34
35 public class OSCProxy {
36
37
38
39
40 public static final ResourceBundle resources = ResourceBundle.getBundle(OSCProxy.class.getSimpleName(),
41 Locale.getDefault());
42
43
44
45
46 public OSCProxy() {
47 }
48
49
50
51
52
53
54 public static void main(final String[] args) {
55 System.exit(new OSCProxy().execute(args));
56 }
57
58
59
60
61
62
63
64 public final int execute(final String[] args) {
65 OptionParser parser = new OptionParser() {
66 {
67 accepts("p").withOptionalArg().ofType(Integer.class)
68 .describedAs(resources.getString("option.lf.port.desc"))
69 .defaultsTo(Integer.parseInt(resources.getString("option.lf.port.default")));
70 accepts("l").withOptionalArg().ofType(Integer.class)
71 .describedAs(resources.getString("option.osc.port.desc"))
72 .defaultsTo(Integer.parseInt(resources.getString("option.osc.port.default")));
73 accepts("m").withOptionalArg().ofType(String.class)
74 .describedAs(resources.getString("option.mode.desc"))
75 .defaultsTo(resources.getString("option.mode.default"));
76 accepts("b").withOptionalArg().ofType(String.class)
77 .describedAs(resources.getString("option.bind.address.desc"))
78 .defaultsTo(resources.getString("option.bind.address.default"));
79 accepts("t").withOptionalArg().ofType(Integer.class)
80 .describedAs(resources.getString("option.socket.threads.desc"))
81 .defaultsTo(Integer.parseInt(resources.getString("option.socket.threads.default")));
82 accepts("d").withOptionalArg().ofType(String.class)
83 .describedAs(resources.getString("option.verbosity.desc"));
84 accepts("?").withOptionalArg().describedAs(resources.getString("option.help.desc"));
85 }
86 };
87 OptionSet options = parser.parse(args);
88 if (options.has("?")) {
89 System.out.println(resources.getString("console.header.1"));
90 try {
91 parser.printHelpOn(System.out);
92 } catch (IOException e) {
93 LogUtil.error(e);
94 }
95 return 0;
96 }
97
98 System.out.println(resources.getString("console.header.1"));
99 System.out.println(resources.getString("console.header.2"));
100
101 if (options.has("d")) {
102 LogUtil.setLevel(Level.toLevel(((String) options.valueOf("d")).toUpperCase()));
103 }
104
105
106 ProxyDaemon daemon = new ProxyDaemon(options);
107 Thread mainThread = new Thread(daemon, "OSCProxy - Daemon");
108 mainThread.setDaemon(true);
109 mainThread.start();
110
111 while (mainThread.isAlive()) {
112 if (Thread.interrupted()) {
113 daemon.shutdown();
114 break;
115 }
116 }
117
118 LogUtil.info(resources.getString("shutdown.complete"));
119 return daemon.errorcode();
120 }
121
122 }