<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    linugb118--java space

    Java

    Netty 源碼研究

     

    org.jboss.netty.bootstrap
    本身 Netty 可以作為一個(gè)server存在的,因此他存在啟動(dòng)入口,他具有client啟動(dòng),server啟動(dòng)以及connectionless 啟動(dòng)(比如UDP)
    1.基類bootstrap:他包含ChannelFactory,ChannelPipeline,ChannelPipelineFactory。
    ClientBootstrap: 有connect()方法
    ConnectionlessBootstrap:有connect(),bind()方法
    ServerBootstrap:有bind()方法

    2.org.jboss.netty.buffer
    netty自己提供了buffer 來(lái)取代nio 中的java.nio.ByteBuffer,他與nio中的byteBuffer相比,有下面的幾個(gè)特點(diǎn)
    1>可以根據(jù)自己需要自己定義buffer type
    2>只是buffer type改變而不拷貝buffer的內(nèi)容,這樣可以減少開(kāi)銷(xiāo)
    3>動(dòng)態(tài)大小的buffer type 類似于stringbuffer
    4>不需要調(diào)用flip()方法
    5>更快的性能


    3.org.jboss.netty.channel
    channel的核心api,包括異步和事件驅(qū)動(dòng)等各種傳送接口
    org.jboss.netty.channel.group
    channel group,里面包含一系列open的channel

    org.jboss.netty.channel.local
    一種虛擬的運(yùn)輸方式,能允許同一個(gè)虛擬機(jī)上的兩個(gè)部分可以互相通信
    org.jboss.netty.channel.socket
    TCP,UDP端口接口,主要繼承channel

    org.jboss.netty.channel.socket.nio
    基于nio端口channel的具體實(shí)現(xiàn)

    org.jboss.netty.channel.socket.oio
    基于老的io端口的channel的具體實(shí)現(xiàn)

    org.jboss.netty.channel.socket.http
    基于http的客戶端和相應(yīng)的server端的實(shí)現(xiàn),可以在有防火墻的情況下進(jìn)行工作

    需要做的事情
    a. 將http tunnel 作為servlet進(jìn)行配置
    web.xml
    <servlet>
     *     <servlet-name>NettyTunnelingServlet</servlet-name>
     *      <servlet-class>org.jboss.netty.channel.socket.http.HttpTunnelingServlet</servlet-class>
     *     <!--
     *       The name of the channel, this should be a registered local channel.
     *       See LocalTransportRegister.
     *     -->
     *     <init-param>
     *       <param-name>endpoint</param-name>
     *       <param-value>local:myLocalServer</param-value>
     *     </init-param>
     *     <load-on-startup>1</load-on-startup>
     *   </servlet>
     *
     *   <servlet-mapping>
     *     <servlet-name>NettyTunnelingServlet</servlet-name>
     *     <url-pattern>/netty-tunnel</url-pattern>
     *   </servlet-mapping>
    接下來(lái)需要將你的基于netty的server app綁定到上面的http servlet
    你可以這樣寫(xiě)
     *
     * public class LocalEchoServerRegistration {
     *
     *     private final ChannelFactory factory = new DefaultLocalServerChannelFactory();
     *     private volatile Channel serverChannel;
     *
     *     public void start() {
     *         ServerBootstrap serverBootstrap = new ServerBootstrap(factory);
     *         EchoHandler handler = new EchoHandler();
     *         serverBootstrap.getPipeline().addLast("handler", handler);
     *
     *         // Note that "myLocalServer" is the endpoint which was specified in web.xml.
     *         serverChannel = serverBootstrap.bind(new LocalAddress("myLocalServer"));
     *     }
     *
     *     public void stop() {
     *         serverChannel.close();
     *     }
     * }

    然后在Ioc framework(JBoss Microcontainer,Guice,Spring)中定義bean
    <bean name="my-local-echo-server"
         class="org.jboss.netty.example.http.tunnel.LocalEchoServerRegistration" />

    這樣http servlet 就可以了

    b. 連接http tunnel
    構(gòu)造client
     * ClientBootstrap b = new ClientBootstrap(
     *         new HttpTunnelingClientSocketChannelFactory(
     *                 new NioClientSocketChannelFactory(...)));
     *
     * // Configure the pipeline (or pipeline factory) here.
     * ...
     *
     * // The host name of the HTTP server
     * b.setOption("serverName", "example.com");
     * // The path to the HTTP tunneling Servlet, which was specified in in web.xml
     * b.setOption("serverPath", "contextPath/netty-tunnel");
     * b.connect(new InetSocketAddress("example.com", 80);

    4.org.jboss.netty.container
    各種容器的兼容
    org.jboss.netty.container.microcontainer
    JBoss Microcontainer 整合接口

    org.jboss.netty.container.osgi
    OSGi framework 整合接口

    org.jboss.netty.container.spring
    Spring framework 整合接口

    5.org.jboss.netty.handler
    處理器
    org.jboss.netty.handler.codec.base64
    Base64 編碼

    org.jboss.netty.handler.codec.compression
    壓縮格式

    org.jboss.netty.handler.codec.embedder
    嵌入模式下編碼和解碼,即使沒(méi)有真正的io環(huán)境也能使用
    org.jboss.netty.handler.codec.frame
    可擴(kuò)展的接口,重新評(píng)估基于流的數(shù)據(jù)的排列和內(nèi)容
    org.jboss.netty.handler.codec.http.websocket
    websocket相關(guān)的編碼和解碼,
    參考
    http://en.wikipedia.org/wiki/Web_Sockets

    org.jboss.netty.handler.codec.http
    http的編碼解碼以及類型信息

    org.jboss.netty.handler.codec.oneone
    一個(gè)對(duì)象到另一對(duì)象的自定義抽象接口,如果有自己編碼需要繼承該抽象類

    org.jboss.netty.handler.codec.protobuf
    Google Protocol Buffers的編碼解碼
    Google Protocol Buffers參考下面
    http://code.google.com/p/protobuf/

    org.jboss.netty.handler.codec.replay

    org.jboss.netty.handler.codec.rtsp
    Real_Time_Streaming_Protocol的編碼解碼
    Real_Time_Streaming_Protocol 參考下面wiki
    http://en.wikipedia.org/wiki/Real_Time_Streaming_Protocol

    org.jboss.netty.handler.codec.serialization
    將序列化的對(duì)象轉(zhuǎn)換到byte buffer的相關(guān)實(shí)現(xiàn)

    org.jboss.netty.handler.codec.string
    字符串編碼解碼,比如utf8編碼等,繼承oneone包的接口

    org.jboss.netty.handler.execution
    基于java.util.concurrent.Executor的實(shí)現(xiàn)

    org.jboss.netty.handler.queue
    將event存入內(nèi)部隊(duì)列的處理

    org.jboss.netty.handler.ssl
    基于javax.net.ssl.SSLEngine的SSL以及TLS實(shí)現(xiàn)
    參考
    http://en.wikipedia.org/wiki/Transport_Layer_Security

    org.jboss.netty.handler.stream
    異步寫(xiě)入大數(shù)據(jù),不會(huì)產(chǎn)生outOfMemory 也不會(huì)花費(fèi)很多內(nèi)存

    org.jboss.netty.handler.timeout
    通過(guò)jboss.netty.util.Timer來(lái)對(duì)讀寫(xiě)超時(shí)或者閑置鏈接的通知

    6.org.jboss.netty.logging
    根據(jù)不同的log framework 實(shí)現(xiàn)的類

    7.org.jboss.netty.util
    nettyutil類

    org.jboss.netty.util.internal
    netty內(nèi)部util類,不被外部使用

    posted on 2010-11-09 15:08 linugb118 閱讀(4166) 評(píng)論(2)  編輯  收藏

    Feedback

    # re: Netty 源碼研究 2012-05-24 15:14

    http://m.tkk7.com/linugb118/archive/2010/11/09/Netty.html
    Netty 源碼研究:
    b.setOption("serverName", "example.com");
    // The path to the HTTP tunneling Servlet, which was specified in web.xml
    b.setOption("serverPath", "contextPath/netty-tunnel");
    b.connect(new InetSocketAddress("example.com", 80);
    請(qǐng)問(wèn)下博主那個(gè)example.com代表什么?
    netty配置成servlet,能正常處理請(qǐng)求嗎?  回復(fù)  更多評(píng)論   

    # re: Netty 源碼研究[未登錄](méi) 2012-05-24 17:22 linugb118

    example.com 代表網(wǎng)址,可以配置成servlet,只是他們之間io的請(qǐng)求變成nio方式,這是netty框架的本質(zhì)@胡
      回復(fù)  更多評(píng)論   



    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     

    My Links

    Blog Stats

    常用鏈接

    留言簿(1)

    隨筆檔案

    搜索

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 青青视频免费在线| 亚洲福利视频一区二区三区| 在线观看亚洲AV日韩A∨| 久久大香伊焦在人线免费| 亚洲人成影院在线无码观看| 免费精品国自产拍在线播放 | 亚洲男人第一无码aⅴ网站| 77777亚洲午夜久久多人| 亚洲成年轻人电影网站www| 免费日本一区二区| 亚洲黄色在线观看| 免费毛片a在线观看67194 | 国产亚洲人成A在线V网站| 一区二区三区免费视频观看 | 黄页网站免费在线观看| 亚洲精品一二三区| 国产免费小视频在线观看| 青娱乐在线免费观看视频| 色久悠悠婷婷综合在线亚洲| 国产一级淫片a免费播放口| 亚洲av无码成人黄网站在线观看| 亚洲成A人片在线播放器| 日韩视频免费在线| 国产aⅴ无码专区亚洲av麻豆| 久久国产乱子伦精品免费强| 亚洲色欲或者高潮影院| 成人免费视频一区| 一个人免费观看www视频| 亚洲AV日韩AV永久无码下载| 免费福利网站在线观看| 亚洲AV无码一区二区大桥未久| 亚洲女同成人AⅤ人片在线观看| 最近免费字幕中文大全| 日产国产精品亚洲系列| 亚洲成人激情小说| 亚洲一区二区三区乱码A| 在线a免费观看最新网站| 亚洲AV成人无码网天堂| 狠狠色伊人亚洲综合成人| 日韩av无码免费播放| 亚洲人成色7777在线观看不卡|