All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zusmart.base.network.nio.NioChannelContextManager Maven / Gradle / Ivy

Go to download

提供基础的工具类及方法类,Logging,Scanner,Buffer,NetWork,Future,Thread

There is a newer version: 1.0.6
Show newest version
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 {

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy