可定制DispatcherServlet
This commit is contained in:
@@ -26,14 +26,7 @@
|
||||
lib: 加上额外的lib路径,多个路径用分号;隔开; 默认为空。 例如: ${APP_HOME}/lib/a.jar;${APP_HOME}/lib2/b.jar;
|
||||
-->
|
||||
<application nodeid="1000" port="6560" lib="">
|
||||
|
||||
<!--
|
||||
【已废弃,不再需要此节点】
|
||||
所有服务所需的资源
|
||||
-->
|
||||
<resources>
|
||||
</resources>
|
||||
|
||||
|
||||
<!--
|
||||
【节点全局唯一】 @since 2.3.0
|
||||
全局Serivce执行的线程池, Application.workExecutor, 没配置该节点将自动创建一个。
|
||||
@@ -159,7 +152,6 @@
|
||||
lib: server额外的class目录, 默认为${APP_HOME}/libs/*;
|
||||
charset: 文本编码, 默认: UTF-8
|
||||
backlog: 默认10K
|
||||
threads【已废弃】: 线程数, 默认: CPU核数*2,最小8个【已废弃 @since 2.3.0】
|
||||
maxconns: 最大连接数, 小于1表示无限制, 默认: 0
|
||||
maxbody: request.body最大值, 默认: 256K
|
||||
bufferCapacity: ByteBuffer的初始化大小, TCP默认: 32K; (HTTP 2.0、WebSocket,必须要16k以上); UDP默认: 8K
|
||||
@@ -168,6 +160,7 @@
|
||||
aliveTimeoutSeconds: KeepAlive读操作超时秒数, 默认30, 0表示永久不超时; -1表示禁止KeepAlive
|
||||
readTimeoutSeconds: 读操作超时秒数, 默认0, 0表示永久不超时
|
||||
writeTimeoutSeconds: 写操作超时秒数, 默认0, 0表示永久不超时
|
||||
dispatcher: DispatcherServlet的自定义实现类,若是HttpServer,则实现类必须是HttpDispatcherServlet的子类
|
||||
interceptor: 启动/关闭NodeServer时被调用的拦截器实现类,必须是org.redkale.boot.NodeInterceptor的子类,默认为null
|
||||
-->
|
||||
<server protocol="HTTP" host="127.0.0.1" port="6060" root="root" lib="">
|
||||
|
||||
@@ -57,7 +57,7 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
|
||||
protected final ResourceFactory resourceFactory;
|
||||
|
||||
//服务的根Servlet
|
||||
protected final DispatcherServlet<K, C, R, P, S> dispatcher;
|
||||
protected DispatcherServlet<K, C, R, P, S> dispatcher;
|
||||
|
||||
//ClassLoader
|
||||
protected RedkaleClassLoader serverClassLoader;
|
||||
@@ -138,6 +138,14 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
|
||||
if (!this.name.matches("^[a-zA-Z][\\w_-]{1,64}$")) {
|
||||
throw new RedkaleException("server.name (" + this.name + ") is illegal");
|
||||
}
|
||||
String dispatcherImpl = config.getValue("dispatcher");
|
||||
if (Utility.isNotBlank(dispatcherImpl)) {
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
Class dispatcherImplClass = classLoader.loadClass(dispatcherImpl);
|
||||
RedkaleClassLoader.putReflectionDeclaredConstructors(dispatcherImplClass, dispatcherImplClass.getName());
|
||||
this.dispatcher = (DispatcherServlet) dispatcherImplClass.getConstructors()[0].newInstance();
|
||||
this.dispatcher.application = application;
|
||||
}
|
||||
AnyValue sslConf = config.getAnyValue("ssl");
|
||||
if (sslConf != null) {
|
||||
String builderClass = sslConf.getValue("builder", SSLBuilder.class.getName());
|
||||
|
||||
@@ -113,14 +113,14 @@ public class HttpDispatcherServlet extends DispatcherServlet<String, HttpContext
|
||||
}
|
||||
|
||||
public HttpServlet removeHttpServlet(final HttpServlet servlet) {
|
||||
Predicate<MappingEntry> predicateEntry = (t) -> t.servlet == servlet;
|
||||
Predicate<Map.Entry<String, WebSocketServlet>> predicateFilter = (t) -> t.getValue() == servlet;
|
||||
Predicate<MappingEntry> predicateEntry = t -> t.servlet == servlet;
|
||||
Predicate<Map.Entry<String, WebSocketServlet>> predicateFilter = t -> t.getValue() == servlet;
|
||||
removeHttpServlet(predicateEntry, predicateFilter);
|
||||
return servlet;
|
||||
}
|
||||
|
||||
public <T extends HttpServlet> HttpServlet removeHttpServlet(Service service) {
|
||||
Predicate<MappingEntry> predicateEntry = (t) -> {
|
||||
public HttpServlet removeHttpServlet(Service service) {
|
||||
Predicate<MappingEntry> predicateEntry = t -> {
|
||||
if (!Rest.isRestDyn(t.servlet)) {
|
||||
return false;
|
||||
}
|
||||
@@ -161,7 +161,7 @@ public class HttpDispatcherServlet extends DispatcherServlet<String, HttpContext
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends WebSocket> HttpServlet removeHttpServlet(Class<T> websocketOrServletType) {
|
||||
Predicate<MappingEntry> predicateEntry = (t) -> {
|
||||
Predicate<MappingEntry> predicateEntry = t -> {
|
||||
Class type = t.servlet.getClass();
|
||||
if (type == websocketOrServletType) {
|
||||
return true;
|
||||
@@ -169,7 +169,7 @@ public class HttpDispatcherServlet extends DispatcherServlet<String, HttpContext
|
||||
RestDynSourceType rdt = (RestDynSourceType) type.getAnnotation(RestDynSourceType.class);
|
||||
return (rdt != null && rdt.value() == websocketOrServletType);
|
||||
};
|
||||
Predicate<Map.Entry<String, WebSocketServlet>> predicateFilter = (t) -> {
|
||||
Predicate<Map.Entry<String, WebSocketServlet>> predicateFilter = t -> {
|
||||
Class type = t.getValue().getClass();
|
||||
if (type == websocketOrServletType) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user