This commit is contained in:
wentch
2016-01-20 17:11:26 +08:00
parent 88d22a4274
commit 4bc0934e5e
2 changed files with 7 additions and 5 deletions

View File

@@ -36,6 +36,7 @@ public final class HttpPrepareServlet extends PrepareServlet<HttpContext, HttpRe
@Override
public void init(HttpContext context, AnyValue config) {
this.servlets.stream().forEach(s -> {
if (s instanceof WebSocketServlet) ((WebSocketServlet) s).preInit(context, s._conf);
s.init(context, s._conf);
});
final WatchFactory watch = context.getWatchFactory();
@@ -131,6 +132,7 @@ public final class HttpPrepareServlet extends PrepareServlet<HttpContext, HttpRe
this.resourceHttpServlet.destroy(context, config);
this.servlets.stream().forEach(s -> {
s.destroy(context, s._conf);
if (s instanceof WebSocketServlet) ((WebSocketServlet) s).postDestroy(context, s._conf);
});
}

View File

@@ -33,7 +33,9 @@ import org.redkale.util.*;
*
* </pre></blockquote>
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
*/
public abstract class WebSocketServlet extends HttpServlet {
@@ -62,8 +64,7 @@ public abstract class WebSocketServlet extends HttpServlet {
protected WebSocketEngine engine;
@Override
public void init(HttpContext context, AnyValue conf) {
final void preInit(HttpContext context, AnyValue conf) {
InetSocketAddress addr = context.getServerAddress();
this.engine = new WebSocketEngine(addr.getHostString() + ":" + addr.getPort() + "-[" + name() + "]", this.node, logger);
this.node.putWebSocketEngine(engine);
@@ -71,8 +72,7 @@ public abstract class WebSocketServlet extends HttpServlet {
this.engine.init(conf);
}
@Override
public void destroy(HttpContext context, AnyValue conf) {
final void postDestroy(HttpContext context, AnyValue conf) {
this.node.destroy(conf);
super.destroy(context, conf);
engine.close();