protocolhandleradapter.java
来自「Mina框架http协议简单实现。Mina框架效率与c程序比较接近」· Java 代码 · 共 49 行
JAVA
49 行
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 + =
减小字号Ctrl + -
显示快捷键?