feat: channelRead0 处理逻辑移动到业务线程

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-02-19 19:46:50 +08:00
parent 93c83cac94
commit d9e2b50953

View File

@ -159,6 +159,7 @@ const WebSocketServerProtocolHandler = Java.type('io.netty.handler.codec.http.we
const SimpleChannelInboundHandler = Java.type('io.netty.channel.SimpleChannelInboundHandler')
const FullHttpRequestMatcher = TypeParameterMatcher.get(base.getClass('io.netty.handler.codec.http.FullHttpRequest'))
const File = Java.type('java.io.File')
const Runnable = Java.type('java.lang.Runnable')
const RandomAccessFile = Java.type('java.io.RandomAccessFile')
const DefaultFileRegion = Java.type('io.netty.channel.DefaultFileRegion')
const ChannelFutureListener = Java.type('io.netty.channel.ChannelFutureListener')
@ -170,11 +171,13 @@ const HttpRequestHandler = Java.extend(SimpleChannelInboundHandler, {
if ('/ws' == request.getUri()) {
ctx.fireChannelRead(request.retain())
} else {
ctx.executor().execute(new Runnable({
run: () => {
if (HttpHeaders.is100ContinueExpected(request)) {
ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE))
}
let filename = request.getUri().split('?')[0].substr(1)
let file = new File('/home/project/TSWorkSpace/ms/packages/plugins/public', filename || 'index.html')
let file = new File('/home/project/WebWorkSpace/MiaoConsole', filename || 'index.html')
if (!file.exists() || !file.isFile()) {
ctx.write(new DefaultHttpResponse(request.getProtocolVersion(), HttpResponseStatus.NOT_FOUND))
ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT).addListener(ChannelFutureListener.CLOSE)
@ -195,6 +198,8 @@ const HttpRequestHandler = Java.extend(SimpleChannelInboundHandler, {
future.addListener(ChannelFutureListener.CLOSE)
}
}
}))
}
}
})
const TextWebSocketFrameMatcher = TypeParameterMatcher.get(base.getClass('io.netty.handler.codec.http.websocketx.TextWebSocketFrame'))