| 14 | import org.jetbrains.annotations.NotNull; |
| 15 | |
| 16 | public class LinksInfo extends AbstractLinksInfo { |
| 17 | private final Netty netty = new Netty(); |
| 18 | private final @NotNull HttpServer httpServer; |
| 19 | private final AbstractAgent agent; |
| 20 | private String defaultLinkServiceName; |
| 21 | |
| 22 | public LinksInfo() throws Exception { |
| 23 | var conf = Config.load(); |
| 24 | agent = Application.createServiceManager(conf, "LinksInfo"); |
| 25 | if (agent == null) |
| 26 | throw new IllegalStateException("agent is null. check your config for ServiceManager."); |
| 27 | httpServer = new HttpServer(); |
| 28 | RegisterHttpServlet(httpServer); |
| 29 | } |
| 30 | |
| 31 | public void start() throws Exception { |
| 32 | agent.start(); |
| 33 | agent.waitReady(); |
| 34 | httpServer.start(netty, 80); |
| 35 | } |
| 36 | |
| 37 | public void stop() throws Exception { |
| 38 | agent.close(); |
| 39 | httpServer.close(); |
| 40 | netty.close(); |
| 41 | } |
| 42 | |
| 43 | public void subscribeLinkService(@NotNull String linkServiceName) { |
| 44 | if (defaultLinkServiceName == null) |
| 45 | defaultLinkServiceName = linkServiceName; |
| 46 | agent.subscribeService(new BSubscribeInfo(linkServiceName)); |
| 47 | } |
| 48 | |
| 49 | public static void main(String @NotNull [] args) throws Exception { |
| 50 | var linksInfo = new LinksInfo(); |
| 51 | linksInfo.start(); |
| 52 | for (var i = 0; i < args.length; ++i) { |
| 53 | switch (args[i]) { |
| 54 | case "-link": |
| 55 | linksInfo.subscribeLinkService(args[++i]); |
| 56 | break; |
| 57 | case "-default": |
| 58 | linksInfo.defaultLinkServiceName = args[++i]; |
| 59 | break; |
| 60 | } |
| 61 | } |
| 62 | try { |
| 63 | if (linksInfo.defaultLinkServiceName == null) |
| 64 | throw new IllegalArgumentException("no link service present."); |
| 65 | synchronized (Thread.currentThread()) { |
| 66 | Thread.currentThread().wait(); |
| 67 | } |
| 68 | } finally { |
| 69 | linksInfo.stop(); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | private void send(HttpExchange x, String sep) { |
nothing calls this directly
no outgoing calls
no test coverage detected