HttpServlet增加postStart方法
This commit is contained in:
@@ -283,11 +283,15 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
|
|||||||
serverChannel.bind(address, backlog);
|
serverChannel.bind(address, backlog);
|
||||||
serverChannel.accept(this);
|
serverChannel.accept(this);
|
||||||
final String threadName = "[" + Thread.currentThread().getName() + "] ";
|
final String threadName = "[" + Thread.currentThread().getName() + "] ";
|
||||||
|
postStart();
|
||||||
logger.info(threadName + this.getClass().getSimpleName() + ("TCP".equalsIgnoreCase(protocol) ? "" : ("." + protocol)) + " listen: " + address
|
logger.info(threadName + this.getClass().getSimpleName() + ("TCP".equalsIgnoreCase(protocol) ? "" : ("." + protocol)) + " listen: " + address
|
||||||
+ ", threads: " + threads + ", maxbody: " + formatLenth(context.maxbody) + ", bufferCapacity: " + formatLenth(bufferCapacity) + ", bufferPoolSize: " + bufferPoolSize + ", responsePoolSize: " + responsePoolSize
|
+ ", threads: " + threads + ", maxbody: " + formatLenth(context.maxbody) + ", bufferCapacity: " + formatLenth(bufferCapacity) + ", bufferPoolSize: " + bufferPoolSize + ", responsePoolSize: " + responsePoolSize
|
||||||
+ ", started in " + (System.currentTimeMillis() - context.getServerStartTime()) + " ms");
|
+ ", started in " + (System.currentTimeMillis() - context.getServerStartTime()) + " ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void postStart() {
|
||||||
|
}
|
||||||
|
|
||||||
public void changeAddress(final InetSocketAddress addr) throws IOException {
|
public void changeAddress(final InetSocketAddress addr) throws IOException {
|
||||||
long s = System.currentTimeMillis();
|
long s = System.currentTimeMillis();
|
||||||
Objects.requireNonNull(addr);
|
Objects.requireNonNull(addr);
|
||||||
|
|||||||
@@ -23,11 +23,13 @@ public abstract class Servlet<C extends Context, R extends Request<C>, P extends
|
|||||||
|
|
||||||
AnyValue _conf; //当前Servlet的配置
|
AnyValue _conf; //当前Servlet的配置
|
||||||
|
|
||||||
|
//Server执行start时运行此方法
|
||||||
public void init(C context, AnyValue config) {
|
public void init(C context, AnyValue config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void execute(R request, P response) throws IOException;
|
public abstract void execute(R request, P response) throws IOException;
|
||||||
|
|
||||||
|
//Server执行shutdown后运行此方法
|
||||||
public void destroy(C context, AnyValue config) {
|
public void destroy(C context, AnyValue config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
package org.redkale.net.http;
|
package org.redkale.net.http;
|
||||||
|
|
||||||
import org.redkale.net.Filter;
|
import org.redkale.net.Filter;
|
||||||
|
import org.redkale.util.AnyValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTTP 过滤器 <br>
|
* HTTP 过滤器 <br>
|
||||||
@@ -17,4 +18,7 @@ import org.redkale.net.Filter;
|
|||||||
*/
|
*/
|
||||||
public abstract class HttpFilter extends Filter<HttpContext, HttpRequest, HttpResponse> {
|
public abstract class HttpFilter extends Filter<HttpContext, HttpRequest, HttpResponse> {
|
||||||
|
|
||||||
|
//Server执行start后运行此方法
|
||||||
|
public void postStart(HttpContext context, AnyValue config) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -402,6 +402,21 @@ public class HttpPrepareServlet extends PrepareServlet<String, HttpContext, Http
|
|||||||
return this.resourceHttpServlet;
|
return this.resourceHttpServlet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void postStart(HttpContext context, AnyValue config) {
|
||||||
|
List filters = getFilters();
|
||||||
|
synchronized (filters) {
|
||||||
|
if (!filters.isEmpty()) {
|
||||||
|
for (Object filter : filters) {
|
||||||
|
((HttpFilter) filter).postStart(context, config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.resourceHttpServlet.postStart(context, config);
|
||||||
|
getServlets().forEach(s -> {
|
||||||
|
s.postStart(context, getServletConf(s));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy(HttpContext context, AnyValue config) {
|
public void destroy(HttpContext context, AnyValue config) {
|
||||||
super.destroy(context, config); //必须要执行
|
super.destroy(context, config); //必须要执行
|
||||||
|
|||||||
@@ -56,6 +56,11 @@ public class HttpServer extends Server<String, HttpContext, HttpRequest, HttpRes
|
|||||||
super.init(config);
|
super.init(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void postStart() {
|
||||||
|
((HttpPrepareServlet) this.prepare).postStart(this.context, config);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy(final AnyValue config) throws Exception {
|
public void destroy(final AnyValue config) throws Exception {
|
||||||
super.destroy(config);
|
super.destroy(config);
|
||||||
|
|||||||
@@ -105,6 +105,10 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
|
|||||||
void postDestroy(HttpContext context, AnyValue config) {
|
void postDestroy(HttpContext context, AnyValue config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Server执行start后运行此方法
|
||||||
|
public void postStart(HttpContext context, AnyValue config) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 预执行方法,在execute方法之前运行,设置当前用户信息,或者加入常规统计和基础检测,例如 : <br>
|
* 预执行方法,在execute方法之前运行,设置当前用户信息,或者加入常规统计和基础检测,例如 : <br>
|
||||||
|
|||||||
Reference in New Issue
Block a user