From f3f001d72d5a1341f6631e7403ed663f3508c3f6 Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Mon, 5 Sep 2016 18:29:21 +0800 Subject: [PATCH] --- src/org/redkale/boot/Application.java | 24 ++++++++++++++++++++---- src/org/redkale/boot/RestDocs.java | 23 +++++++++++++++++++++++ 2 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 src/org/redkale/boot/RestDocs.java diff --git a/src/org/redkale/boot/Application.java b/src/org/redkale/boot/Application.java index f904a0133..6bbb77805 100644 --- a/src/org/redkale/boot/Application.java +++ b/src/org/redkale/boot/Application.java @@ -388,6 +388,19 @@ public final class Application { buffer.flip(); channel.send(buffer, address); } + } else if ("RESTDOC".equalsIgnoreCase(new String(bytes))) { + try { + new RestDocs(application).run(); + buffer.clear(); + buffer.put("RESTDOC OK".getBytes()); + buffer.flip(); + channel.send(buffer, address); + } catch (Exception ex) { + buffer.clear(); + buffer.put("RESTDOC FAIL".getBytes()); + buffer.flip(); + channel.send(buffer, address); + } } } } catch (Exception e) { @@ -398,12 +411,12 @@ public final class Application { }.start(); } - private void sendShutDown() throws Exception { + private void sendCommand(String command) throws Exception { final DatagramChannel channel = DatagramChannel.open(); channel.configureBlocking(true); channel.connect(new InetSocketAddress(config.getValue("host", "127.0.0.1"), config.getIntValue("port"))); ByteBuffer buffer = ByteBuffer.allocate(128); - buffer.put("SHUTDOWN".getBytes()); + buffer.put(command.getBytes()); buffer.flip(); channel.write(buffer); buffer.clear(); @@ -534,8 +547,11 @@ public final class Application { Utility.midnight(); //先初始化一下Utility //运行主程序 final Application application = Application.create(false); - if (System.getProperty("SHUTDOWN") != null) { - application.sendShutDown(); + if (System.getProperty("CMD") != null) { + application.sendCommand(System.getProperty("CMD")); + return; + } else if (System.getProperty("SHUTDOWN") != null) { //兼容旧接口 + application.sendCommand("SHUTDOWN"); return; } application.init(); diff --git a/src/org/redkale/boot/RestDocs.java b/src/org/redkale/boot/RestDocs.java new file mode 100644 index 000000000..572f4cd53 --- /dev/null +++ b/src/org/redkale/boot/RestDocs.java @@ -0,0 +1,23 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.redkale.boot; + +/** + * + * @author zhangjx + */ +public class RestDocs { + + private final Application app; + + public RestDocs(Application app) { + this.app = app; + } + + public void run() throws Exception { + + } +}