cn.nukkit.utils.ServerKiller Java Examples

The following examples show how to use cn.nukkit.utils.ServerKiller. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Server.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
/**
 * サーバーを終了させます。
 * @return void
 */
public void shutdown() {
    if (this.isRunning) {
        ServerKiller killer = new ServerKiller(90);
        killer.start();
    }
    this.isRunning = false;
}
 
Example #2
Source File: Nukkit.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public static void main(String[] args) {
	
    if(!(JAVA_VERSION.startsWith("1.8"))){
        System.out.println("[CRITICAL] This program runs on JRE(JRE) 1.8");
        System.out.println("[CRITICAL] You must use JRE(JDK) 1.8.");
        System.out.println("[CRITICAL] Java version: " + JAVA_VERSION);

        System.exit(0);
    }
    
    //Shorter title for windows 8/2012
    String osName = System.getProperty("os.name").toLowerCase();
    if (osName.contains("windows")) {
        if (osName.contains("windows 8") || osName.contains("2012")) {
            shortTitle = true;
        }
    }

    //启动参数
    for (String arg : args) {
        switch (arg) {
            case "disable-ansi":
                ANSI = false;
                break;
        }
    }

    MainLogger logger = new MainLogger(DATA_PATH + "server.log");

    System.out.println("Minecraft用 Jupiterサーバーを開始しています。");
    
    jobs.add(new Callable<Server>(){
        @Override
        public Server call() throws Exception {
            return new Server(logger, PATH, DATA_PATH, PLUGIN_PATH);
        }

    });

    try {
        threadpool.invokeAll(jobs);
        threadpool.shutdown();
        if(threadpool.awaitTermination(1L,TimeUnit.MINUTES)){// 1 minutes
            System.out.println("サーバーを停止しています...");
            logger.info("スレッドが停止しました。");

            for (Thread thread : java.lang.Thread.getAllStackTraces().keySet()) {
                if (!(thread instanceof InterruptibleThread)) {
                    continue;
                }
                logger.debug("Stopping " + thread.getClass().getSimpleName() + " thread");
                if (thread.isAlive()) {
                    thread.interrupt();
                }
            }

            ServerKiller killer = new ServerKiller(8);
            killer.start();

            logger.shutdown();
            logger.interrupt();

            CommandReader.getInstance().removePromptLine();

            System.out.println("サーバーが停止しました。");

            System.exit(0);
        }else{
            System.out.println("サーバーの停止に失敗しました。");
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
        threadpool.shutdown();
    }
}