<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 可以作為一個server存在的,因此他存在啟動入口,他具有client啟動,server啟動以及connectionless 啟動(比如UDP)
    1.基類bootstrap:他包含ChannelFactory,ChannelPipeline,ChannelPipelineFactory。
    ClientBootstrap: 有connect()方法
    ConnectionlessBootstrap:有connect(),bind()方法
    ServerBootstrap:有bind()方法

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


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

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

    org.jboss.netty.channel.socket.nio
    基于nio端口channel的具體實現

    org.jboss.netty.channel.socket.oio
    基于老的io端口的channel的具體實現

    org.jboss.netty.channel.socket.http
    基于http的客戶端和相應的server端的實現,可以在有防火墻的情況下進行工作

    需要做的事情
    a. 將http tunnel 作為servlet進行配置
    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>
    接下來需要將你的基于netty的server app綁定到上面的http servlet
    你可以這樣寫
     *
     * 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
    構造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
    嵌入模式下編碼和解碼,即使沒有真正的io環境也能使用
    org.jboss.netty.handler.codec.frame
    可擴展的接口,重新評估基于流的數據的排列和內容
    org.jboss.netty.handler.codec.http.websocket
    websocket相關的編碼和解碼,
    參考
    http://en.wikipedia.org/wiki/Web_Sockets

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

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

    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
    將序列化的對象轉換到byte buffer的相關實現

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

    org.jboss.netty.handler.execution
    基于java.util.concurrent.Executor的實現

    org.jboss.netty.handler.queue
    將event存入內部隊列的處理

    org.jboss.netty.handler.ssl
    基于javax.net.ssl.SSLEngine的SSL以及TLS實現
    參考
    http://en.wikipedia.org/wiki/Transport_Layer_Security

    org.jboss.netty.handler.stream
    異步寫入大數據,不會產生outOfMemory 也不會花費很多內存

    org.jboss.netty.handler.timeout
    通過jboss.netty.util.Timer來對讀寫超時或者閑置鏈接的通知

    6.org.jboss.netty.logging
    根據不同的log framework 實現的類

    7.org.jboss.netty.util
    nettyutil類

    org.jboss.netty.util.internal
    netty內部util類,不被外部使用

    posted on 2010-11-09 15:08 linugb118 閱讀(4157) 評論(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);
    請問下博主那個example.com代表什么?
    netty配置成servlet,能正常處理請求嗎?  回復  更多評論   

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

    example.com 代表網址,可以配置成servlet,只是他們之間io的請求變成nio方式,這是netty框架的本質@胡
      回復  更多評論   



    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    My Links

    Blog Stats

    常用鏈接

    留言簿(1)

    隨筆檔案

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲自偷自偷精品| 亚洲综合色自拍一区| 亚洲小说区图片区| 日韩内射激情视频在线播放免费| 亚洲色精品vr一区二区三区| 五月天国产成人AV免费观看| 亚洲精品国产精品国自产观看| 美女视频黄频a免费观看| 亚洲av片一区二区三区| 七次郎成人免费线路视频| www.亚洲色图.com| 你懂的免费在线观看| 亚洲第一中文字幕| 黄+色+性+人免费| yellow免费网站| 永久亚洲成a人片777777| 中文字幕一区二区免费| 久久久亚洲欧洲日产国码二区| 啦啦啦完整版免费视频在线观看 | 免费看成人AA片无码视频羞羞网| 久久久久亚洲AV无码观看| 18禁美女裸体免费网站| 亚洲熟女精品中文字幕| 亚洲精品456播放| 99久久久国产精品免费牛牛 | 国产在线观看免费视频播放器| 粉色视频成年免费人15次| 国产亚洲高清不卡在线观看| 久久不见久久见免费视频7| 亚洲人成www在线播放| 国产人妖ts在线观看免费视频| 国产黄片不卡免费| 亚洲精品电影在线| 国产男女猛烈无遮挡免费视频| a在线观看免费视频| 亚洲三级高清免费| 亚洲中文字幕久久精品无码APP | 久久免费国产精品一区二区| 亚洲毛片在线免费观看| 亚洲精品国产综合久久一线| 91精品免费观看|