This commit is contained in:
@@ -87,6 +87,7 @@
|
|||||||
responsePoolSize: Response池的大小,默认: CPU核数*256
|
responsePoolSize: Response池的大小,默认: CPU核数*256
|
||||||
readTimeoutSecond: 读操作超时秒数, 默认0, 表示永久不超时
|
readTimeoutSecond: 读操作超时秒数, 默认0, 表示永久不超时
|
||||||
writeTimeoutSecond: 写操作超时秒数, 默认0, 表示永久不超时
|
writeTimeoutSecond: 写操作超时秒数, 默认0, 表示永久不超时
|
||||||
|
nodeInterceptor: 启动/关闭NodeServer时被调用的拦截器实现类,必须是org.redkale.boot.NodeInterceptor的子类,默认为null
|
||||||
-->
|
-->
|
||||||
<server protocol="HTTP" host="127.0.0.1" port="6060" root="root" lib="">
|
<server protocol="HTTP" host="127.0.0.1" port="6060" root="root" lib="">
|
||||||
|
|
||||||
|
|||||||
21
src/org/redkale/boot/NodeInterceptor.java
Normal file
21
src/org/redkale/boot/NodeInterceptor.java
Normal 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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
package org.redkale.boot;
|
package org.redkale.boot;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import static java.lang.Class.forName;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
@@ -65,6 +66,8 @@ public abstract class NodeServer {
|
|||||||
|
|
||||||
protected AnyValue serverConf;
|
protected AnyValue serverConf;
|
||||||
|
|
||||||
|
protected NodeInterceptor interceptor;
|
||||||
|
|
||||||
protected final Set<ServiceWrapper> localServiceWrappers = new LinkedHashSet<>();
|
protected final Set<ServiceWrapper> localServiceWrappers = new LinkedHashSet<>();
|
||||||
|
|
||||||
protected final Set<ServiceWrapper> remoteServiceWrappers = new LinkedHashSet<>();
|
protected final Set<ServiceWrapper> remoteServiceWrappers = new LinkedHashSet<>();
|
||||||
@@ -139,7 +142,11 @@ public abstract class NodeServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
initResource(); //给 DataSource、CacheSource 注册依赖注入时的监听回调事件。
|
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<Servlet> servletFilter = createServletClassFilter();
|
||||||
ClassFilter<Service> serviceFilter = createServiceClassFilter();
|
ClassFilter<Service> serviceFilter = createServiceClassFilter();
|
||||||
long s = System.currentTimeMillis();
|
long s = System.currentTimeMillis();
|
||||||
@@ -473,10 +480,12 @@ public abstract class NodeServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void start() throws IOException {
|
public void start() throws IOException {
|
||||||
|
if (interceptor != null) interceptor.preStart(this);
|
||||||
server.start();
|
server.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() throws IOException {
|
public void shutdown() throws IOException {
|
||||||
|
if (interceptor != null) interceptor.preShutdown(this);
|
||||||
final StringBuilder sb = logger.isLoggable(Level.INFO) ? new StringBuilder() : null;
|
final StringBuilder sb = logger.isLoggable(Level.INFO) ? new StringBuilder() : null;
|
||||||
localServiceWrappers.forEach(y -> {
|
localServiceWrappers.forEach(y -> {
|
||||||
long s = System.currentTimeMillis();
|
long s = System.currentTimeMillis();
|
||||||
@@ -490,4 +499,16 @@ public abstract class NodeServer {
|
|||||||
server.shutdown();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user