⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 protocolhandleradapter.java

📁 Mina框架http协议简单实现。Mina框架效率与c程序比较接近
💻 JAVA
字号:
package com.eshore.pubservice.nio.handle;

import org.apache.log4j.Logger;
import org.apache.mina.common.IoHandlerAdapter;
import org.apache.mina.common.IoSession;

import com.eshore.pubservice.nio.msg.IMsg;
import com.eshore.pubservice.nio.util.IThreadPool;
import com.eshore.pubservice.nio.util.ThreadPoolImpl;
import com.eshore.pubservice.nio.util.Worker;

/**
 * 
 * @author lishuisheng
 *
 */
public class ProtocolHandlerAdapter extends IoHandlerAdapter {
	
	private static Logger log=Logger.getLogger(ProtocolHandlerAdapter.class);
	
	private IHandlerFactory handlerFactory;
	
	private IThreadPool threadPool;
	
	public ProtocolHandlerAdapter(IHandlerFactory handlerFactory){
		this.handlerFactory=handlerFactory;
		threadPool=new ThreadPoolImpl();
		threadPool.initThread();
	}
	
	public void messageReceived(IoSession session, Object message)throws Exception{
		log.info("...receive a/an message...");
		IMsg msg=(IMsg)message;
		if(handlerFactory==null){
			log.debug("not have handlerFactory!");
		}else{
			IHandler handler=handlerFactory.getHandler(msg);
			if(handler==null){
				log.debug("not have handler!");
			}else{
				Worker worker=new Worker(session,handler,msg);
				threadPool.addWorker(worker);
			}
		}
		
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -