This commit is contained in:
RedKale
2016-04-13 14:34:48 +08:00
parent 43ef1fb22f
commit 04098f976b
3 changed files with 54 additions and 11 deletions

View File

@@ -87,6 +87,7 @@
responsePoolSize Response池的大小默认: CPU核数*256
readTimeoutSecond: 读操作超时秒数, 默认0 表示永久不超时
writeTimeoutSecond: 写操作超时秒数, 默认0 表示永久不超时
nodeInterceptor: 启动/关闭NodeServer时被调用的拦截器实现类必须是org.redkale.boot.NodeInterceptor的子类默认为null
-->
<server protocol="HTTP" host="127.0.0.1" port="6060" root="root" lib="">

View File

@@ -0,0 +1,21 @@
/*
* 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 NodeInterceptor {
public void preStart(NodeServer server) {
}
public void preShutdown(NodeServer server) {
}
}

View File

@@ -6,6 +6,7 @@
package org.redkale.boot;
import java.io.*;
import static java.lang.Class.forName;
import java.lang.annotation.Annotation;
import java.lang.reflect.*;
import java.net.InetSocketAddress;
@@ -65,6 +66,8 @@ public abstract class NodeServer {
protected AnyValue serverConf;
protected NodeInterceptor interceptor;
protected final Set<ServiceWrapper> localServiceWrappers = new LinkedHashSet<>();
protected final Set<ServiceWrapper> remoteServiceWrappers = new LinkedHashSet<>();
@@ -139,7 +142,11 @@ public abstract class NodeServer {
}
initResource(); //给 DataSource、CacheSource 注册依赖注入时的监听回调事件。
String interceptorClass = config.getValue("nodeInterceptor", "");
if (!interceptorClass.isEmpty()) {
Class clazz = forName(interceptorClass);
this.interceptor = (NodeInterceptor) clazz.newInstance();
}
ClassFilter<Servlet> servletFilter = createServletClassFilter();
ClassFilter<Service> serviceFilter = createServiceClassFilter();
long s = System.currentTimeMillis();
@@ -473,10 +480,12 @@ public abstract class NodeServer {
}
public void start() throws IOException {
if (interceptor != null) interceptor.preStart(this);
server.start();
}
public void shutdown() throws IOException {
if (interceptor != null) interceptor.preShutdown(this);
final StringBuilder sb = logger.isLoggable(Level.INFO) ? new StringBuilder() : null;
localServiceWrappers.forEach(y -> {
long s = System.currentTimeMillis();
@@ -490,4 +499,16 @@ public abstract class NodeServer {
server.shutdown();
}
public <T extends Server> T getServer() {
return (T) server;
}
public Set<ServiceWrapper> getLocalServiceWrappers() {
return new LinkedHashSet<>(localServiceWrappers);
}
public Set<ServiceWrapper> getRemoteServiceWrappers() {
return new LinkedHashSet<>(remoteServiceWrappers);
}
}