MCPcopy Create free account
hub / github.com/e2wugui/zeze / main

Method main

ZezeJava/ZezeJava/src/main/java/Zeze/Services/Token.java:844–894  ·  view source on GitHub ↗
(@NotNull String @NotNull [] args)

Source from the content-addressed store, hash-verified

842 }
843
844 public static void main(@NotNull String @NotNull [] args) throws Exception {
845 Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
846 //noinspection CallToPrintStackTrace
847 e.printStackTrace();
848 logger.error("uncaught exception in {}:", t, e);
849 });
850
851 String host = null;
852 int port = 0;
853 int netThreadCount = 0;
854 int workerThreadCount = 0;
855
856 for (int i = 0; i < args.length; ++i) {
857 switch (args[i]) {
858 case "-host":
859 host = args[++i];
860 if (host.isBlank())
861 host = null;
862 break;
863 case "-port":
864 port = Integer.parseInt(args[++i]);
865 break;
866 case "-net-threads":
867 netThreadCount = Integer.parseInt(args[++i]);
868 break;
869 case "-worker-threads":
870 workerThreadCount = Integer.parseInt(args[++i]);
871 break;
872 default:
873 throw new IllegalArgumentException("unknown argument: " + args[i]);
874 }
875 }
876
877 if (netThreadCount < 1)
878 netThreadCount = Runtime.getRuntime().availableProcessors();
879 if (workerThreadCount < 1)
880 workerThreadCount = Runtime.getRuntime().availableProcessors() * 2;
881 Task.initThreadPool(Task.newFixedThreadPool(workerThreadCount, "ZezeTaskPool"),
882 Executors.newSingleThreadScheduledExecutor(
883 new ThreadFactoryWithName("ZezeScheduledPool", Thread.NORM_PRIORITY + 2)));
884 if (Selectors.getInstance().getCount() < netThreadCount)
885 Selectors.getInstance().add(netThreadCount - Selectors.getInstance().getCount());
886
887 var token = new Token();
888 ShutdownHook.add(token::stop);
889
890 token.start(null, host, port);
891 synchronized (Thread.currentThread()) {
892 Thread.currentThread().wait();
893 }
894 }
895}

Callers

nothing calls this directly

Calls 8

initThreadPoolMethod · 0.95
newFixedThreadPoolMethod · 0.95
getInstanceMethod · 0.95
addMethod · 0.95
startMethod · 0.95
parseIntMethod · 0.80
getCountMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected