com.zusmart.base.network.nio.NioChannelContextManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zusmart-base Show documentation
Show all versions of zusmart-base Show documentation
提供基础的工具类及方法类,Logging,Scanner,Buffer,NetWork,Future,Thread
package com.zusmart.base.network.nio;
import java.nio.channels.SocketChannel;
import com.zusmart.base.network.ChannelAdapter;
import com.zusmart.base.network.ChannelContext;
import com.zusmart.base.network.handler.support.DefaultRecognizeHandler;
import com.zusmart.base.network.message.MessageProtocol;
import com.zusmart.base.network.support.AbstractChannelContextManager;
public class NioChannelContextManager extends AbstractChannelContextManager {
private final ChannelAdapter channelAdapter;
private final NioChannelEventLoopGroup channelEventLoopGroup;
public NioChannelContextManager(ChannelAdapter channelAdapter, NioChannelEventLoopGroup channelEventLoopGroup) {
this.channelAdapter = channelAdapter;
this.channelEventLoopGroup = channelEventLoopGroup;
}
@Override
public NioChannelContext createChannelContext(SocketChannel socketChannel) {
return (NioChannelContext) super.createChannelContext(socketChannel);
}
@Override
protected ChannelContext doCreateChannelContext(String contextCode, SocketChannel socketChannel) {
MessageProtocol messageProtocol = this.channelAdapter.createMessageProtocol();
NioChannelEventLoop channelEventLoop = this.channelEventLoopGroup.getEventLoop();
NioChannelContext channelContext = new NioChannelContext(true, contextCode, socketChannel, messageProtocol, channelEventLoop);
this.channelAdapter.initChannelContextHandlerChain(channelContext.getChannelContextHandlerChain());
channelContext.getChannelContextHandlerChain().addLast(DefaultRecognizeHandler.NAME, new DefaultRecognizeHandler(messageProtocol));
return channelContext;
}
@Override
protected void doStart() throws Exception {
}
@Override
protected void doClose() throws Exception {
}
}