淘宝商城(天猫)高级技术专家.3年研发+3年性能测试调优/系统测试+4年团队管理与测试架构、研发系统实践. 新舞台新气象, 深化测试基础架构及研发架构,希望能在某个技术领域成为真正的技术大牛。欢迎荐才http://bbs.51testing.com/viewthread.php?tid=120496&extra=&page=1 .邮件: jianzhao.liangjz@alibaba-inc.com,MSN:liangjianzhao@163.com.微博:http://t.sina.com.cn/1674816524

Apache MINA2异步连接框架编译,运行

上一篇 / 下一篇  2008-12-27 19:10:00 / 个人分类:java性能监控与调优

http://mina.apache.org/mina-v20-quick-start-guide.html

样例代码有错误。IoAcceptorIdleStatus路径有问题

 

importjava.io.IOException;

importjava.net.InetSocketAddress;

importjava.nio.charset.Charset;

 

importorg.apache.mina.core.service.IoAcceptor;

importorg.apache.mina.core.session.IdleStatus;

 

importorg.apache.mina.filter.codec.ProtocolCodecFilter;

importorg.apache.mina.filter.codec.textline.TextLineCodecFactory;

importorg.apache.mina.filter.logging.LoggingFilter;

importorg.apache.mina.transport.socket.nio.NioSocketAcceptor;

 

publicclassMinaTimeServer {

   privatestaticfinalintPORT= 9123;

 

   publicstaticvoidmain(String[] args)throwsIOException {

      IoAcceptor acceptor =newNioSocketAcceptor();

 

      acceptor.getFilterChain().addLast("logger",newLoggingFilter());

      acceptor.getFilterChain().addLast(

             "codec",

             newProtocolCodecFilter(newTextLineCodecFactory(Charset

                    .forName("UTF-8"))));

 

      acceptor.setHandler(newTimeServerHandler());

      acceptor.getSessionConfig().setReadBufferSize(2048);

      acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);

      acceptor.bind(newInetSocketAddress(PORT));

   }

}

 

 

 

D:\eclipse-SDK-3.3.2-win32\project\mina-2.0.0-M4\src\mina-example>javac  -cp %cla

sspath%;D:\eclipse-SDK-3.3.2-win32\project\mina-2.0.0-M4\dist\mina-core-2.0.0-M4

.jar MinaTimeServer.java

 

运行时候,也费了很大周折,必须把log实现类也加载。看来文档未经测试:)

编译的时候需要把log4j.jar以及slf4j2个包放好。

 

D:\eclipse-SDK-3.3.2-win32\project\mina-2.0.0-M4\src\mina-example>java -cp %cla

sspath%;D:\eclipse-SDK-3.3.2-win32\project\mina-2.0.0-M4\dist\mina-core-2.0.0-M4

.jar;D:\eclipse-SDK-3.3.2-win32\project\mina-2.0.0-M4\lib\slf4j-api-1.5.6.jar;D:

\eclipse-SDK-3.3.2-win32\project\mina-2.0.0-M4\lib\slf4j-log4j12-1.5.6.jar;D:\ec

lipse-SDK-3.3.2-win32\project\mina-2.0.0-M4\lib\log4j.jar   MinaTimeServer


TAG: apache mina 编译 运行 java性能监控与调优

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar