(@NotNull String @NotNull [] args)
| 585 | } |
| 586 | |
| 587 | public static void main(@NotNull String @NotNull [] args) throws Exception { |
| 588 | Thread.setDefaultUncaughtExceptionHandler((t, e) -> { |
| 589 | //noinspection CallToPrintStackTrace |
| 590 | e.printStackTrace(); |
| 591 | logger.error("uncaught exception in {}:", t, e); |
| 592 | }); |
| 593 | |
| 594 | String host = null; |
| 595 | int port = 0; |
| 596 | int threadCount = 0; |
| 597 | String path = "binlog"; |
| 598 | |
| 599 | for (int i = 0; i < args.length; ++i) { |
| 600 | switch (args[i]) { |
| 601 | case "-host": // 指定监听的IP,不指定则监听所有IP,如果当前目录存在zeze.xml且定义了BinLoggerService,则默认以配置为准 |
| 602 | host = args[++i]; |
| 603 | if (host.isBlank()) |
| 604 | host = null; |
| 605 | break; |
| 606 | case "-port": // 指定监听端口号,默认DEFAULT_PORT常量,如果当前目录存在zeze.xml且定义了BinLoggerService,则默认以配置为准 |
| 607 | port = Integer.parseInt(args[++i]); |
| 608 | break; |
| 609 | case "-threads": // 网络IO线程数,默认0表示CPU核数 |
| 610 | threadCount = Integer.parseInt(args[++i]); |
| 611 | break; |
| 612 | case "-path": // 输出二进制日志的相对路径,默认"binlog" |
| 613 | path = args[++i].trim(); |
| 614 | break; |
| 615 | default: |
| 616 | throw new IllegalArgumentException("unknown argument: '" + args[i] + '\''); |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | if (threadCount < 1) |
| 621 | threadCount = Runtime.getRuntime().availableProcessors(); |
| 622 | Task.initThreadPool(Task.newCriticalThreadPool("ZezeTaskPool"), |
| 623 | Executors.newSingleThreadScheduledExecutor( |
| 624 | new ThreadFactoryWithName("ZezeScheduledPool", Thread.NORM_PRIORITY + 2))); |
| 625 | if (Selectors.getInstance().getCount() < threadCount) |
| 626 | Selectors.getInstance().add(threadCount - Selectors.getInstance().getCount()); |
| 627 | ZezeCounter.tryInit(); |
| 628 | |
| 629 | new BinLoggerService(path).start(host, port); |
| 630 | synchronized (Thread.currentThread()) { |
| 631 | Thread.currentThread().wait(); |
| 632 | } |
| 633 | } |
| 634 | } |
nothing calls this directly
no test coverage detected