Search in sources :

Example 1 with StreamFragmentBean

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);
}
Also used : StreamFragmentBean(info.xiancloud.core.stream.StreamFragmentBean) UnitResponse(info.xiancloud.core.message.UnitResponse) NotifyHandler(info.xiancloud.core.NotifyHandler) Stream(info.xiancloud.core.stream.Stream) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

NotifyHandler (info.xiancloud.core.NotifyHandler)1 UnitResponse (info.xiancloud.core.message.UnitResponse)1 Stream (info.xiancloud.core.stream.Stream)1 StreamFragmentBean (info.xiancloud.core.stream.StreamFragmentBean)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1