use of info.xiancloud.core.stream.StreamFragmentBean in project xian by happyyangyuan.
the class StreamRpcClientHandler method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext ctx, JSONObject msg) throws Exception {
LOG.warn("已关闭此功能");
if (MessageType.isStream(msg)) {
try {
StreamFragmentBean streamFragmentBean = msg.toJavaObject(StreamFragmentBean.class);
MsgIdHolder.set(streamFragmentBean.getHeader().getMsgId());
String ssid = streamFragmentBean.getHeader().getId();
NotifyHandler handler = LocalNodeManager.handleMap.getIfPresent(ssid);
LocalNodeManager.handleMap.invalidate(ssid);
// 以下写出不会阻塞
Stream stream = StreamManager.singleton.add(streamFragmentBean);
if (streamFragmentBean.getHeader().isFirst()) {
UnitResponse responseUnitResponse = UnitResponse.success(stream);
try {
ThreadPoolManager.execute(() -> handler.callback(responseUnitResponse));
} catch (RejectedExecutionException threadPoolAlreadyShutdown) {
LOG.info("线程池已关闭,这里使用临时线程执行任务,针对停服务时线程池已关闭的情况。");
new Thread(() -> handler.callback(responseUnitResponse)).start();
}
}
} catch (Throwable e) {
LOG.error(e);
} finally {
MsgIdHolder.clear();
}
} else
ctx.fireChannelRead(msg);
}
Aggregations