📄 protocolhandleradapter.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 + -