This commit is contained in:
Redkale
2016-09-05 18:29:21 +08:00
parent b49a4d2c83
commit f3f001d72d
2 changed files with 43 additions and 4 deletions

View File

@@ -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();

View File

@@ -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 {
}
}