锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久久久亚洲AV成人网,yy6080久久亚洲精品,亚洲色图在线播放http://www.tkk7.com/czihong/category/53023.htmlzh-cnThu, 24 Jan 2013 09:28:21 GMTThu, 24 Jan 2013 09:28:21 GMT60Netty 4.0 婧愮爜鍒嗘瀽錛堝叓錛夛細Netty 4.0涓殑io.netty.buffer鍖?/title><link>http://www.tkk7.com/czihong/articles/392059.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Tue, 27 Nov 2012 03:34:00 GMT</pubDate><guid>http://www.tkk7.com/czihong/articles/392059.html</guid><wfw:comment>http://www.tkk7.com/czihong/comments/392059.html</wfw:comment><comments>http://www.tkk7.com/czihong/articles/392059.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.tkk7.com/czihong/comments/commentRss/392059.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/czihong/services/trackbacks/392059.html</trackback:ping><description><![CDATA[     鎽樿: Netty 4.0鐨勬簮鐮佺粨鏋勪笌涔嬪墠鐨?.X鐗堟湰鍙戠敓浜嗚緝澶х殑鍙樺寲錛屼互涓嬫槸Netty 4.0婧愮爜鐨勫眰嬈$粨鏋? netty/    common/     - utility and logging    buffer/     - buffer API   ...  <a href='http://www.tkk7.com/czihong/articles/392059.html'>闃呰鍏ㄦ枃</a><img src ="http://www.tkk7.com/czihong/aggbug/392059.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/czihong/" target="_blank">Chan Chen</a> 2012-11-27 11:34 <a href="http://www.tkk7.com/czihong/articles/392059.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Netty 4.0 婧愮爜鍒嗘瀽錛堜竷錛夛細AbstractBootstrap鎶借薄綾?/title><link>http://www.tkk7.com/czihong/articles/391953.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Mon, 26 Nov 2012 02:57:00 GMT</pubDate><guid>http://www.tkk7.com/czihong/articles/391953.html</guid><wfw:comment>http://www.tkk7.com/czihong/comments/391953.html</wfw:comment><comments>http://www.tkk7.com/czihong/articles/391953.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/czihong/comments/commentRss/391953.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/czihong/services/trackbacks/391953.html</trackback:ping><description><![CDATA[<p><span style="font-size:6.5pt;font-family:"Courier New"">AbstractBootstrap</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">鏄竴涓府鍔╃被錛岄氳繃鏂規硶閾撅紙</span><span style="font-size:6.5pt;font-family:"Courier New"">method chaining</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">錛夌殑鏂瑰紡錛屾彁渚涗簡涓涓畝鍗曟槗鐢ㄧ殑鏂瑰紡鏉ラ厤緗?/span><span style="font-size:6.5pt;font-family:"Courier New"">Bootstrap</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">錛岀劧鍚庡惎鍔ㄤ竴涓?/span><span style="font-size:6.5pt;font-family:"Courier New"">Channel</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">銆傚湪鐞嗚В</span><span style="font-size:6.5pt;font-family:"Courier New"">Netty</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">婧愮爜涓殑</span><span style="font-size:6.5pt;font-family:"Courier New"">AbstractBootstrap</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">錛?/span><span style="font-size:6.5pt;font-family:"Courier New""> ServerBootstrap</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">鍜?/span><span style="font-size:6.5pt;font-family:"Courier New"">Bootstrap</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">涔嬪墠錛屽簲璇ュ厛浜嗚В涓涓嬩粈涔堟槸</span><span style="font-size:6.5pt;font-family:"Courier New"">method chaining</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">銆?br /></span></p> <p><span style="font-size:6.5pt;font-family:"Courier New""><br />Wiki</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">涓婇潰瀵逛簬</span><span style="font-size:6.5pt;font-family:"Courier New"">method chaining</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">鐨勫畾涔夊涓嬶細</span></p> <p><strong><span style="font-size: 6.5pt; font-family: 'Courier New'; background-color: white; background-position: initial initial; background-repeat: initial initial;">Method chaining</span></strong><span style="font-size: 6.5pt; font-family: 'Courier New'; background-color: white; background-position: initial initial; background-repeat: initial initial;">, is a common technique for invoking multiple method calls in object-oriented programming languages</span><span style="font-size:6.5pt;font-family:"Courier New""><span style="background-color: white; background-position: initial initial; background-repeat: initial initial;">. Each method returns an object (possibly the current object itself), allowing the calls to be chained together in a single statement.</span></span></p> <p><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">鍦ㄩ潰鍚戝璞$殑緙栫▼璇█涓紝</span><span style="font-size:6.5pt;font-family:"Courier New"">method chaining</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">鏄竴縐嶇敤浜庤皟鐢ㄥ涓柟娉曠殑甯哥敤鎶鏈傛瘡涓柟娉曢兘浼氳繑鍥炰竴涓璞★紙鍙兘鏄綋鍓嶅璞℃湰韜級錛岃繖鏍峰仛鐨勫ソ澶勫氨鏄紝閫氳繃涓鏉¤鍙ワ紝灝卞彲浠ヨ鎵鏈夌殑鏂規硶璋冪敤閾炬帴鍦ㄤ竴璧楓?/span> </p> <p><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New""><br />瀹氫箟鏈変竴浜涙娊璞★紝閭d箞鍙互閫氳繃瀹為檯鐨勪緥瀛愭潵榪涜鐞嗚В鍜屾秷鍖栥?/span></p> <p><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">鍋囪鏈変竴涓?/span><span style="font-size:6.5pt;font-family:"Courier New"">StringBuffer</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">鐨勭被錛岀被涓湁涓涓?/span><span style="font-size:6.5pt;font-family:"Courier New"">append()</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">鏂規硶</span></p> <p align="left"></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">class</span> StringBuffer {<br />  <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">void</span> append(String str) {<br />    <span style="color: #008000; ">//</span><span style="color: #008000; "> <img src="http://www.tkk7.com/Images/dot.gif" alt="" /> useful code <img src="http://www.tkk7.com/Images/dot.gif" alt="" /></span><span style="color: #008000; "><br /></span>  }<br />}</div><p> </p> <p><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">榪欎釜綾繪湁緙虹偣灝辨槸璇達紝鍦ㄥ悜</span><span style="font-size:6.5pt;font-family:"Courier New"">StringBuffer</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">瀵硅薄榪藉姞鏂扮殑瀛楃涓茬殑鏃跺欙紝闇瑕佸湪澶氭潯璇彞涓紝涓嶆柇鐨勮皟鐢?/span><span style="font-size:6.5pt;font-family:"Courier New"">append()</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">鏂規硶銆?/span></p> <pre><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->StringBuffer sb = <span style="color: #0000FF; ">new</span> StringBuffer();<br />sb.append("Hello ");<br />sb.append(name);<br />sb.append("! Welcome!");</div></pre> <p><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">鑰?/span><span style="font-size:6.5pt;font-family:"Courier New"">method chaining</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">鐨勫疄鐜幫紝灝卞彲浠ラ伩鍏嶈繖涓己闄楓?/span></p> <pre><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">class</span> StringBuffer {<br />  <span style="color: #0000FF; ">public</span> StringBuffer append(String str) {<br />    <span style="color: #008000; ">//</span><span style="color: #008000; "> <img src="http://www.tkk7.com/Images/dot.gif" alt="" /> useful code <img src="http://www.tkk7.com/Images/dot.gif" alt="" /></span><span style="color: #008000; "><br /></span>    <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">this</span>;<br />  }<br />}</div></pre> <p><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">鐜板湪鎴戜滑灝卞彲浠ュ啀涓鏉¤鍙ヤ腑瀹炵幇絎竴涓緥瀛愮殑鍔熻兘浜嗐?/span></p> <pre><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->StringBuffer sb = <span style="color: #0000FF; ">new</span> StringBuffer();<br />sb.append("Hello ").append(name).append("! Welcome!");</div></pre> <p><span style="font-size:6.5pt;font-family:"Courier New""><br />AbstractBootstrap</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">鎶借薄綾?/span> <span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New"">錛堥儴鍒嗕唬鐮侊級</span></p> <p align="left"></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">package</span> io.netty.bootstrap;<br /> <br /><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">abstract</span> <span style="color: #0000FF; ">class</span> AbstractBootstrap<B <span style="color: #0000FF; ">extends</span> AbstractBootstrap<?>> {<br />    <span style="color: #0000FF; ">private</span> EventLoopGroup group;<br />    <span style="color: #0000FF; ">private</span> ChannelFactory factory;<br />    <span style="color: #0000FF; ">private</span> SocketAddress localAddress;<br />    <span style="color: #0000FF; ">private</span> <span style="color: #0000FF; ">final</span> Map<ChannelOption<?>, Object> options = <span style="color: #0000FF; ">new</span> LinkedHashMap<ChannelOption<?>, Object>();<br />    <span style="color: #0000FF; ">private</span> <span style="color: #0000FF; ">final</span> Map<AttributeKey<?>, Object> attrs = <span style="color: #0000FF; ">new</span> LinkedHashMap<AttributeKey<?>, Object>();<br /><span style="color: #0000FF; ">private</span> ChannelHandler handler;<br /> <br />    @SuppressWarnings("unchecked")<br />    <span style="color: #0000FF; ">public</span> B group(EventLoopGroup group) {<br />        <span style="color: #0000FF; ">if</span> (group == <span style="color: #0000FF; ">null</span>) {<br />            <span style="color: #0000FF; ">throw</span> <span style="color: #0000FF; ">new</span> NullPointerException("group");<br />        }<br />        <span style="color: #0000FF; ">if</span> (<span style="color: #0000FF; ">this</span>.group != <span style="color: #0000FF; ">null</span>) {<br />            <span style="color: #0000FF; ">throw</span> <span style="color: #0000FF; ">new</span> IllegalStateException("group set already");<br />        }<br />        <span style="color: #0000FF; ">this</span>.group = group;<br />        <span style="color: #0000FF; ">return</span> (B) <span style="color: #0000FF; ">this</span>;<br />    }<br />    <span style="color: #0000FF; ">public</span> B channel(Class<? <span style="color: #0000FF; ">extends</span> Channel> channelClass) {<br />        <span style="color: #0000FF; ">if</span> (channelClass == <span style="color: #0000FF; ">null</span>) {<br />            <span style="color: #0000FF; ">throw</span> <span style="color: #0000FF; ">new</span> NullPointerException("channelClass");<br />        }<br />        <span style="color: #0000FF; ">return</span> channelFactory(<span style="color: #0000FF; ">new</span> BootstrapChannelFactory(channelClass));<br />    }<br />    @SuppressWarnings("unchecked")<br />    <span style="color: #0000FF; ">public</span> B channelFactory(ChannelFactory factory) {<br />        <span style="color: #0000FF; ">if</span> (factory == <span style="color: #0000FF; ">null</span>) {<br />            <span style="color: #0000FF; ">throw</span> <span style="color: #0000FF; ">new</span> NullPointerException("factory");<br />        }<br />        <span style="color: #0000FF; ">if</span> (<span style="color: #0000FF; ">this</span>.factory != <span style="color: #0000FF; ">null</span>) {<br />            <span style="color: #0000FF; ">throw</span> <span style="color: #0000FF; ">new</span> IllegalStateException("factory set already");<br />        }<br />        <span style="color: #0000FF; ">this</span>.factory = factory;<br />        <span style="color: #0000FF; ">return</span> (B) <span style="color: #0000FF; ">this</span>;<br />    }<br />    @SuppressWarnings("unchecked")<br />    <span style="color: #0000FF; ">public</span> B localAddress(SocketAddress localAddress) {<br />        <span style="color: #0000FF; ">this</span>.localAddress = localAddress;<br />        <span style="color: #0000FF; ">return</span> (B) <span style="color: #0000FF; ">this</span>;<br />    }<br />    @SuppressWarnings("unchecked")<br />    <span style="color: #0000FF; ">public</span> <T> B option(ChannelOption<T> option, T value) {<br />        <span style="color: #0000FF; ">if</span> (option == <span style="color: #0000FF; ">null</span>) {<br />            <span style="color: #0000FF; ">throw</span> <span style="color: #0000FF; ">new</span> NullPointerException("option");<br />        }<br />        <span style="color: #0000FF; ">if</span> (value == <span style="color: #0000FF; ">null</span>) {<br />            options.remove(option);<br />        } <span style="color: #0000FF; ">else</span> {<br />            options.put(option, value);<br />        }<br />        <span style="color: #0000FF; ">return</span> (B) <span style="color: #0000FF; ">this</span>;<br />    }<br />    <span style="color: #0000FF; ">public</span> <T> B attr(AttributeKey<T> key, T value) {<br />        <span style="color: #0000FF; ">if</span> (key == <span style="color: #0000FF; ">null</span>) {<br />            <span style="color: #0000FF; ">throw</span> <span style="color: #0000FF; ">new</span> NullPointerException("key");<br />        }<br />        <span style="color: #0000FF; ">if</span> (value == <span style="color: #0000FF; ">null</span>) {<br />            attrs.remove(key);<br />        } <span style="color: #0000FF; ">else</span> {<br />            attrs.put(key, value);<br />        }<br />        <span style="color: #0000FF; ">return</span> (B) <span style="color: #0000FF; ">this</span>;<br />    }<br />    @SuppressWarnings("unchecked")<br />    <span style="color: #0000FF; ">public</span> B handler(ChannelHandler handler) {<br />        <span style="color: #0000FF; ">if</span> (handler == <span style="color: #0000FF; ">null</span>) {<br />            <span style="color: #0000FF; ">throw</span> <span style="color: #0000FF; ">new</span> NullPointerException("handler");<br />        }<br />        <span style="color: #0000FF; ">this</span>.handler = handler;<br />        <span style="color: #0000FF; ">return</span> (B) <span style="color: #0000FF; ">this</span>;<br />    }<br />}</div><p> </p> <p align="left"> </p> <p align="left"><span style="font-size:6.5pt;font-family: "Courier New";">AbstractBootstrap</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">澹版槑浜嗗叚涓鏈夌殑鎴愬憳鍙橀噺錛?/span><span style="font-size:6.5pt;font-family:"Courier New";">EventLoopGroup</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">瀵硅薄錛?/span><span style="font-size:6.5pt; font-family:"Courier New";">ChannelFacotry</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">瀵硅薄錛?/span><span style="font-size:6.5pt;font-family:"Courier New";">SockteAddress</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">瀵硅薄錛?/span><span style="font-size:6.5pt; font-family:"Courier New";">Map<ChannelOption<?>,Object></span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">瀵硅薄錛?/span><span style="font-size:6.5pt;font-family:"Courier New";">Map<Attribute<?>,Object></span><span style="font-size:6.5pt; font-family:瀹嬩綋;Courier New";Courier New";Courier New";">瀵硅薄錛?/span><span style="font-size:6.5pt;font-family:"Courier New";">ChannelHandler</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">瀵硅薄銆傚茍涓旀湁鐩稿搴旂殑鏂規硶錛屾潵璁劇疆榪欎簺瀵硅薄錛屽</span></p> <p align="left"></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">public</span> B group(EventLoopGroup group) {<br />        <span style="color: #0000FF; ">if</span> (group == <span style="color: #0000FF; ">null</span>) {<br />            <span style="color: #0000FF; ">throw</span> <span style="color: #0000FF; ">new</span> NullPointerException("group");<br />        }<br />        <span style="color: #0000FF; ">if</span> (<span style="color: #0000FF; ">this</span>.group != <span style="color: #0000FF; ">null</span>) {<br />            <span style="color: #0000FF; ">throw</span> <span style="color: #0000FF; ">new</span> IllegalStateException("group set already");<br />        }<br />        <span style="color: #0000FF; ">this</span>.group = group;<br />        <span style="color: #0000FF; ">return</span> (B) <span style="color: #0000FF; ">this</span>;<br />}</div><p> </p> <p align="left"><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">閫氳繃浼犺繘鏉ョ殑</span><span style="font-size:6.5pt; font-family:"Courier New";">group</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">瀵硅薄錛岀劧鍚庡皢</span><span style="font-size:6.5pt;font-family:"Courier New";">AbstractBootstrap</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">涓殑</span><span style="font-size:6.5pt; font-family:"Courier New";">group</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">鎸囧悜浼犺繘鏉ョ殑</span><span style="font-size:6.5pt;font-family:"Courier New";">group</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">銆傛渶緇堣繑鍥炵殑榪樻槸</span><span style="font-size:6.5pt; font-family:"Courier New";">AbstractBootstrap</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">榪欎釜褰撳墠瀵硅薄銆?/span></p> <p align="left"> </p> <p align="left"><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">鍏釜瀵硅薄鐨勪綔鐢?/span></p> <table border="1" cellspacing="0" cellpadding="0" style="border-collapse: collapse; border: none;"> <tbody><tr> <td width="284" valign="top" style="width: 213.05pt; border: 1pt solid black; padding: 0cm 5.4pt;"> <p align="left"><span style="font-size:6.5pt;font-family: "Courier New";">EventLoopGroup group</span></p> </td> <td width="284" valign="top" style="width: 213.05pt; border-style: solid solid solid none; border-top-color: black; border-right-color: black; border-bottom-color: black; border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; padding: 0cm 5.4pt;"> <p align="left"><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">鐢ㄤ簬澶勭悊灝嗚琚垱寤虹殑鎵鏈?/span><span style="font-size: 6.5pt;font-family:"Courier New";">event</span></p> </td> </tr> <tr> <td width="284" valign="top" style="width: 213.05pt; border-style: none solid solid; border-right-color: black; border-bottom-color: black; border-left-color: black; border-right-width: 1pt; border-bottom-width: 1pt; border-left-width: 1pt; padding: 0cm 5.4pt;"> <p align="left"><span style="font-size:6.5pt;font-family: "Courier New";">ChannelFactory factory</span></p> </td> <td width="284" valign="top" style="width:213.05pt;border-top:none;border-left: none;border-bottom:solid black 1.0pt; border-right:solid black 1.0pt;padding:0cm 5.4pt 0cm 5.4pt"> <p align="left"><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">寤虹珛涓涓伐鍘傦紝鐢ㄤ簬浠ュ悗鐨?/span><span style="font-size: 6.5pt;font-family:"Courier New";">Channel</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">鍒涘緩</span></p> </td> </tr> <tr> <td width="284" valign="top" style="width: 213.05pt; border-style: none solid solid; border-right-color: black; border-bottom-color: black; border-left-color: black; border-right-width: 1pt; border-bottom-width: 1pt; border-left-width: 1pt; padding: 0cm 5.4pt;"> <p align="left"><span style="font-size:6.5pt;font-family: "Courier New";">SocketAddress localAddress;</span></p> </td> <td width="284" valign="top" style="width:213.05pt;border-top:none;border-left: none;border-bottom:solid black 1.0pt; border-right:solid black 1.0pt;padding:0cm 5.4pt 0cm 5.4pt"> <p align="left"><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">鐢ㄤ簬緇戝畾鏈湴鐨勭綉緇滃湴鍧</span></p> </td> </tr> <tr> <td width="284" valign="top" style="width: 213.05pt; border-style: none solid solid; border-right-color: black; border-bottom-color: black; border-left-color: black; border-right-width: 1pt; border-bottom-width: 1pt; border-left-width: 1pt; padding: 0cm 5.4pt;"> <p align="left"><span style="font-size:6.5pt;font-family: "Courier New";">Map<ChannelOption<?>, Object> options</span></p> </td> <td width="284" valign="top" style="width:213.05pt;border-top:none;border-left: none;border-bottom:solid black 1.0pt; border-right:solid black 1.0pt;padding:0cm 5.4pt 0cm 5.4pt"> <p align="left"><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">鎸囧畾鎵鍒涘緩</span><span style="font-size:6.5pt; font-family:"Courier New";">Channel</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">鐨勯夐」錛屽</span><span style="font-size:6.5pt;font-family:"Courier New";">TCP_NODELAY</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">錛?/span><span style="font-size:6.5pt; font-family:"Courier New";">AIO_READ_TIMEOUT</span></p> </td> </tr> <tr> <td width="284" valign="top" style="width: 213.05pt; border-style: none solid solid; border-right-color: black; border-bottom-color: black; border-left-color: black; border-right-width: 1pt; border-bottom-width: 1pt; border-left-width: 1pt; padding: 0cm 5.4pt;"> <p align="left"><span style="font-size:6.5pt;font-family: "Courier New";">Map<AttributeKey<?>, Object> attrs</span></p> </td> <td width="284" valign="top" style="width:213.05pt;border-top:none;border-left: none;border-bottom:solid black 1.0pt; border-right:solid black 1.0pt;padding:0cm 5.4pt 0cm 5.4pt"> <p align="left"><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">鎸囧畾鎵鍒涘緩</span><span style="font-size:6.5pt; font-family:"Courier New";">Channel</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">鐨勫睘鎬?/span></p> </td> </tr> <tr> <td width="284" valign="top" style="width: 213.05pt; border-style: none solid solid; border-right-color: black; border-bottom-color: black; border-left-color: black; border-right-width: 1pt; border-bottom-width: 1pt; border-left-width: 1pt; padding: 0cm 5.4pt;"> <p align="left"><span style="font-size:6.5pt;font-family: "Courier New";">ChannelHandler handler</span></p> </td> <td width="284" valign="top" style="width:213.05pt;border-top:none;border-left: none;border-bottom:solid black 1.0pt; border-right:solid black 1.0pt;padding:0cm 5.4pt 0cm 5.4pt"> <p align="left"><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">鐢ㄤ簬澶勭悊鍚勭被璇鋒眰</span></p> </td> </tr> </tbody></table> <p align="left"> </p> <p align="left"><span style="font-size:6.5pt;font-family: "Courier New";">AbstractBootstrap</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">鎶借薄綾葷殑鎺ュ彛<br /></span></p><p> </p> <p align="center" style="text-align:center;text-autospace:none"><img src="http://www.tkk7.com/images/blogjava_net/czihong/AbstractBootstrap鎶借薄綾籙ML鍥?JPG" border="0" alt="" /><br /></p> <p align="center" style="text-align:center;text-autospace:none"><span style="font-size:6.5pt;font-family: "Courier New";">AbstractBootstrap</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">鎶借薄綾?/span><span style="font-size:6.5pt;font-family:"Courier New";">UML</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">鍥?/span></p> <p align="left"> </p> <p align="left"><span style="font-size:6.5pt;font-family: "Courier New";">ServerBootstrap</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">鍜?/span><span style="font-size:6.5pt;font-family:"Courier New";">Bootstrap</span></p> <p align="left"><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">鍦?/span><span style="font-size:6.5pt; font-family:"Courier New";">Netty 4.0</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">涓紝</span><span style="font-size:6.5pt;font-family:"Courier New";">ServerBootstrap</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">鐢ㄤ簬涓烘湇鍔″櫒鍚姩</span><span style="font-size:6.5pt; font-family:"Courier New";">ServerChannel</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">錛?/span><span style="font-size:6.5pt;font-family:"Courier New";">Bootstrap</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">鐢ㄤ簬涓哄鏈嶇鍚姩</span><span style="font-size:6.5pt; font-family:"Courier New";">Channel</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">銆傝繖涓や釜綾繪槸</span><span style="font-size:6.5pt;font-family:"Courier New";">AbstractBootstrap</span><span style="font-size:6.5pt;font-family:瀹嬩綋;Courier New";Courier New";Courier New";">鐨勫叿浣撳疄鐜般?br /><br /></span></p><div>澶囨敞:鍥犱負絎旇呭紑濮嬪啓Netty婧愮爜鍒嗘瀽鐨勬椂鍊欙紝Netty 4.0榪樻槸澶勪簬Alpha闃舵錛屼箣鍚庣殑API鍙兘榪樹細鏈夋敼鍔紝絎旇呭皢浼氬強鏃舵洿鏀廣備嬌鐢ㄥ紑婧愬凡緇忔湁濂藉嚑騫寸殑鏃墮棿浜嗭紝涓鐩存病鏈夋椂闂村拰綺懼姏鏉ュ叿浣撶爺絀舵煇涓紑婧愰」鐩殑鍏蜂綋瀹炵幇錛岃繖嬈℃槸絎竴嬈″啓寮婧愰」鐩殑婧愮爜鍒嗘瀽錛屽鏋滄枃涓湁閿欒鐨勫湴鏂癸紝嬈㈣繋璇昏呭彲浠ョ暀璦鎸囧嚭銆傚浜庤漿杞界殑璇昏咃紝璇鋒敞鏄庢枃绔犵殑鍑哄銆?/div><div>甯屾湜鍜屽箍澶х殑寮鍙戣?寮婧愮埍濂借呰繘琛屼氦嫻侊紝嬈㈣繋澶у鐨勭暀璦鍜岃璁恒?/div><p> </p><img src ="http://www.tkk7.com/czihong/aggbug/391953.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/czihong/" target="_blank">Chan Chen</a> 2012-11-26 10:57 <a href="http://www.tkk7.com/czihong/articles/391953.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Netty 4.0 婧愮爜鍒嗘瀽錛堝叚錛夛細EventLoop鍜孍ventLoopGrouphttp://www.tkk7.com/czihong/articles/391939.htmlChan ChenChan ChenSun, 25 Nov 2012 13:49:00 GMThttp://www.tkk7.com/czihong/articles/391939.htmlhttp://www.tkk7.com/czihong/comments/391939.htmlhttp://www.tkk7.com/czihong/articles/391939.html#Feedback0http://www.tkk7.com/czihong/comments/commentRss/391939.htmlhttp://www.tkk7.com/czihong/services/trackbacks/391939.htmlEventLoop鐩稿綋浜庝竴涓?/span>Thread綰跨▼錛岃?/span>EventLoopGroup鍒欐槸綆$悊榪欎簺EventLoop鐨?/span>Thread綰跨▼姹?/span>

EventLoop鎺ュ彛

package io.netty.channel;

public interface EventLoop extends EventExecutor, EventLoopGroup {
    @Override
    EventLoopGroup parent();
}


EventLoop鎺ュ彛UML鍥?/span>

parent()鏂規硶

榪斿洖綆$悊榪欎釜EventLoop鐨?/span>EventLoopGroup銆?/span>


EventLoopGroup鎺ュ彛

package io.netty.channel;
public interface EventLoopGroup extends EventExecutorGroup {
    @Override
    EventLoop next();
    ChannelFuture register(Channel channel);
    ChannelFuture register(Channel channel, ChannelFuture future);
}


EventLoopGroup鎺ュ彛UML鍥?/span>

 

next()

榪斿洖涓嬩竴涓?/span>EventLoop

register(Channel channel)

鎸囧畾涓涓?/span>EventLoopGroup鏉ユ敞鍐屾煇涓?/span>Channel銆?br />

澶囨敞:鍥犱負絎旇呭紑濮嬪啓Netty婧愮爜鍒嗘瀽鐨勬椂鍊欙紝Netty 4.0榪樻槸澶勪簬Alpha闃舵錛屼箣鍚庣殑API鍙兘榪樹細鏈夋敼鍔紝絎旇呭皢浼氬強鏃舵洿鏀廣備嬌鐢ㄥ紑婧愬凡緇忔湁濂藉嚑騫寸殑鏃墮棿浜嗭紝涓鐩存病鏈夋椂闂村拰綺懼姏鏉ュ叿浣撶爺絀舵煇涓紑婧愰」鐩殑鍏蜂綋瀹炵幇錛岃繖嬈℃槸絎竴嬈″啓寮婧愰」鐩殑婧愮爜鍒嗘瀽錛屽鏋滄枃涓湁閿欒鐨勫湴鏂癸紝嬈㈣繋璇昏呭彲浠ョ暀璦鎸囧嚭銆傚浜庤漿杞界殑璇昏咃紝璇鋒敞鏄庢枃绔犵殑鍑哄銆?/div>
甯屾湜鍜屽箍澶х殑寮鍙戣?寮婧愮埍濂借呰繘琛屼氦嫻侊紝嬈㈣繋澶у鐨勭暀璦鍜岃璁恒?/div>



Chan Chen 2012-11-25 21:49 鍙戣〃璇勮
]]>Netty 4.0 婧愮爜鍒嗘瀽錛堝洓錛夛細ByteBufhttp://www.tkk7.com/czihong/articles/391937.htmlChan ChenChan ChenSun, 25 Nov 2012 12:44:00 GMThttp://www.tkk7.com/czihong/articles/391937.htmlhttp://www.tkk7.com/czihong/comments/391937.htmlhttp://www.tkk7.com/czihong/articles/391937.html#Feedback0http://www.tkk7.com/czihong/comments/commentRss/391937.htmlhttp://www.tkk7.com/czihong/services/trackbacks/391937.htmlNetty鏄熀浜庢祦鐨勬秷鎭紶閫掓満鍒躲?/span>Netty妗嗘灦涓紝鎵鏈夋秷鎭殑浼犺緭閮戒緷璧栦簬ByteBuf鎺ュ彛錛?/span>ByteBuf鏄?/span>Netty NIO妗嗘灦涓殑緙撳啿鍖恒?/span>ByteBuf鎺ュ彛鍙互鐞嗚В涓轟竴鑸殑Byte鏁扮粍錛屼笉榪?/span>Netty瀵?/span>Byte榪涜浜嗗皝瑁咃紝澧炲姞浜嗕竴浜涘疄鐢ㄧ殑鏂規硶銆?/span>


ChannelBuf鎺ュ彛

package io.netty.buffer;
public interface ChannelBuf {
    ChannelBufType type();
    boolean isPooled();
}


ByteBuf鎺ュ彛 

package io.netty.buffer;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.GatheringByteChannel;
import java.nio.channels.ScatteringByteChannel;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
public interface ByteBuf extends ChannelBuf, Comparable<ByteBuf> {
    int capacity();
    ByteBuf capacity(int newCapacity);
    int maxCapacity();
    ByteOrder order();
    ByteBuf order(ByteOrder endianness);
    boolean isDirect();
    int readerIndex();
    ByteBuf readerIndex(int readerIndex);
    int writerIndex();
    ByteBuf writerIndex(int writerIndex);
    ByteBuf setIndex(int readerIndex, int writerIndex);
    int readableBytes();
    int writableBytes();
    boolean readable();
    boolean writable();
    ByteBuf clear();
    ByteBuf markReaderIndex();
    ByteBuf resetReaderIndex();
    ByteBuf markWriterIndex();
    ByteBuf resetWriterIndex();
    ByteBuf discardReadBytes();
    ByteBuf ensureWritableBytes(int minWritableBytes);
    int ensureWritableBytes(int minWritableBytes, boolean force);
    boolean getBoolean(int index);
    byte  getByte(int index);
    short getUnsignedByte(int index);
    short getShort(int index);
    int getUnsignedShort(int index);
    int   getMedium(int index);
    int   getUnsignedMedium(int index);
    int   getInt(int index);
    long  getUnsignedInt(int index);
    long  getLong(int index);
    char  getChar(int index);
    float getFloat(int index);
    double getDouble(int index);
    ByteBuf getBytes(int index, ByteBuf dst);
    ByteBuf getBytes(int index, ByteBuf dst, int length);
    ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length);
    ByteBuf getBytes(int index, byte[] dst);
    ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length);
    ByteBuf getBytes(int index, ByteBuffer dst);
    ByteBuf getBytes(int index, OutputStream out, int length) throws IOException;
    int getBytes(int index, GatheringByteChannel out, int length) throws IOException;
    ByteBuf setBoolean(int index, boolean value);
    ByteBuf setByte(int index, int value);
    ByteBuf setShort(int index, int value);
    ByteBuf setMedium(int index, int   value);
    ByteBuf setInt(int index, int   value);
    ByteBuf setLong(int index, long  value);
    ByteBuf setChar(int index, int value);
    ByteBuf setFloat(int index, float value);
    ByteBuf setDouble(int index, double value);
    ByteBuf setBytes(int index, ByteBuf src);
    ByteBuf setBytes(int index, ByteBuf src, int length);
    ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length);
    ByteBuf setBytes(int index, byte[] src);
    ByteBuf setBytes(int index, byte[] src, int srcIndex, int length);
    ByteBuf setBytes(int index, ByteBuffer src);
    int setBytes(int index, InputStream in, int length) throws IOException;
    int  setBytes(int index, ScatteringByteChannel in, int length) throws IOException;
    ByteBuf setZero(int index, int length);
     boolean readBoolean();
    byte  readByte();
    short readUnsignedByte();
    short readShort();
    int   readUnsignedShort();
    int   readMedium();
    int   readUnsignedMedium();
    int   readInt();
    long  readUnsignedInt();
    long  readLong();
    char  readChar();
    float readFloat();
    double readDouble();
    ByteBuf readBytes(int length);
    ByteBuf readSlice(int length);
    ByteBuf readBytes(ByteBuf dst);
    ByteBuf readBytes(ByteBuf dst, int length);
    ByteBuf readBytes(ByteBuf dst, int dstIndex, int length);
    ByteBuf readBytes(byte[] dst);
    ByteBuf readBytes(byte[] dst, int dstIndex, int length);
    ByteBuf readBytes(ByteBuffer dst);
    ByteBuf readBytes(OutputStream out, int length) throws IOException;
    int  readBytes(GatheringByteChannel out, int length) throws IOException;
    ByteBuf skipBytes(int length);
    ByteBuf writeBoolean(boolean value);
    ByteBuf writeByte(int value);
    ByteBuf writeShort(int value);
    ByteBuf writeMedium(int   value);
    ByteBuf writeInt(int   value);
    ByteBuf writeLong(long  value);
    ByteBuf writeChar(int value);
    ByteBuf writeFloat(float value);
    ByteBuf writeDouble(double value);
    ByteBuf writeBytes(ByteBuf src);
    ByteBuf writeBytes(ByteBuf src, int length);
    ByteBuf writeBytes(ByteBuf src, int srcIndex, int length);
    ByteBuf writeBytes(byte[] src);
    ByteBuf writeBytes(byte[] src, int srcIndex, int length);
    ByteBuf writeBytes(ByteBuffer src);
    int  writeBytes(InputStream in, int length) throws IOException;
    int  writeBytes(ScatteringByteChannel in, int length) throws IOException;
    ByteBuf writeZero(int length);
    int indexOf(int fromIndex, int toIndex, byte value);
    int indexOf(int fromIndex, int toIndex, ByteBufIndexFinder indexFinder);
    int bytesBefore(byte value);
    int bytesBefore(ByteBufIndexFinder indexFinder);
    int bytesBefore(int length, byte value);
    int bytesBefore(int length, ByteBufIndexFinder indexFinder);
    int bytesBefore(int index, int length, byte value);
    int bytesBefore(int index, int length, ByteBufIndexFinder indexFinder);
    ByteBuf copy();
    ByteBuf copy(int index, int length);
    ByteBuf slice();
    ByteBuf slice(int index, int length);
    ByteBuf duplicate();
    boolean hasNioBuffer();
    ByteBuffer nioBuffer();
    ByteBuffer nioBuffer(int index, int length);
    boolean hasNioBuffers();
    ByteBuffer[] nioBuffers();
    ByteBuffer[] nioBuffers(int offset, int length);
    boolean hasArray();
    byte[] array();
    int arrayOffset();
    String toString(Charset charset);
    String toString(int index, int length, Charset charset);
    @Override
    int hashCode();
    @Override
    boolean equals(Object obj);
    @Override
    int compareTo(ByteBuf buffer);
    @Override
    String toString();
    Unsafe unsafe();
    interface Unsafe {
        ByteBuffer nioBuffer();
        ByteBuffer[] nioBuffers();
        ByteBuf newBuffer(int initialCapacity);
        void discardSomeReadBytes();
        void acquire();
        void release();
    }
}

 

 


ByteBuf Index

 

ByteBuf閫氳繃涓や釜鎸囬拡鏉ュ崗鍔?/span>I/O鐨勮鍐欐搷浣滐紝璇繪搷浣滅殑readIndex鍜屽啓鎿嶄綔鐨?/span>writeIndex

readerIndex鍜?/span>writerIndex閮芥槸涓寮濮嬮兘鏄?/span>0錛岄殢鐫鏁版嵁鐨勫啓鍏?/span>writerIndex浼氬鍔狅紝璇誨彇鏁版嵁浼氫嬌readerIndex澧炲姞錛屼絾鏄粬涓嶄細瓚呰繃writerIndx錛屽湪璇誨彇涔嬪悗錛?/span>0-readerIndex鐨勫氨琚涓?/span>discard鐨?/span>.璋冪敤discardReadBytes鏂規硶,鍙互閲婃斁榪欓儴鍒嗙┖闂?/span>,浠栫殑浣滅敤綾諱技ByeBuffer鐨?/span>compact鏂規硶;

璇誨拰鍐欑殑鏃跺?/span>Index鏄垎寮鐨勶紝鍥犳涔熷氨娌″繀瑕佸啀姣忔璇誨畬浠ュ悗璋冪敤flip鏂規硶錛屽彟澶栬繕鏈?/span>indexOf銆?/span>bytesBefore絳変竴浜涙柟渚跨殑鏂規硶錛?/span>

 

ByteBuf鐨勫嚑涓噸瑕佹柟娉?/span>

discardReadBytes()
涓㈠純宸茶鐨勫唴瀹廣傚叾鎵ц榪囩▼濡備笅錛?/span>
璋冪敤discardReadBytes()涔嬪墠錛?/span>


璋冪敤 discardReadBytes()鏂規硶鍚?/span>


clear()
涓㈠純鎵鏈夌殑鏁版嵁錛屽茍灝?span style="font-size: 6.5pt; font-family: 'Courier New'; background-position: initial initial; background-repeat: initial initial;">readerIndex鍜?/span>writerIndex閲嶇疆涓?/span>0銆?/span>


璋冪敤clear()涔嬪墠


璋冪敤clear()涔嬪悗


 

 
澶囨敞:鍥犱負絎旇呭紑濮嬪啓Netty婧愮爜鍒嗘瀽鐨勬椂鍊欙紝Netty 4.0榪樻槸澶勪簬Alpha闃舵錛屼箣鍚庣殑API鍙兘榪樹細鏈夋敼鍔紝絎旇呭皢浼氬強鏃舵洿鏀廣備嬌鐢ㄥ紑婧愬凡緇忔湁濂藉嚑騫寸殑鏃墮棿浜嗭紝涓鐩存病鏈夋椂闂村拰綺懼姏鏉ュ叿浣撶爺絀舵煇涓紑婧愰」鐩殑鍏蜂綋瀹炵幇錛岃繖嬈℃槸絎竴嬈″啓寮婧愰」鐩殑婧愮爜鍒嗘瀽錛屽鏋滄枃涓湁閿欒鐨勫湴鏂癸紝嬈㈣繋璇昏呭彲浠ョ暀璦鎸囧嚭銆傚浜庤漿杞界殑璇昏咃紝璇鋒敞鏄庢枃绔犵殑鍑哄銆?/p>

甯屾湜鍜屽箍澶х殑寮鍙戣?寮婧愮埍濂借呰繘琛屼氦嫻侊紝嬈㈣繋澶у鐨勭暀璦鍜岃璁恒?/div>

Chan Chen 2012-11-25 20:44 鍙戣〃璇勮
]]>Netty 4.0 婧愮爜鍒嗘瀽錛堜簲錛夛細ChannelHandlerContext鍜孋hannelHandlerhttp://www.tkk7.com/czihong/articles/391932.htmlChan ChenChan ChenSun, 25 Nov 2012 08:51:00 GMThttp://www.tkk7.com/czihong/articles/391932.htmlhttp://www.tkk7.com/czihong/comments/391932.htmlhttp://www.tkk7.com/czihong/articles/391932.html#Feedback3http://www.tkk7.com/czihong/comments/commentRss/391932.htmlhttp://www.tkk7.com/czihong/services/trackbacks/391932.htmlChannelHandlerContext鎺ュ彛

 1 package io.netty.channel;
 2 import io.netty.buffer.ByteBuf;
 3 import io.netty.buffer.MessageBuf;
 4 import io.netty.util.AttributeMap;
 5 import java.nio.channels.Channels;
 6 import java.util.Set;
 7 public interface ChannelHandlerContext
 8          extends AttributeMap, ChannelFutureFactory,
 9                  ChannelInboundInvoker, ChannelOutboundInvoker {
10     Channel channel();
11     ChannelPipeline pipeline();
12     EventExecutor executor();
13     String name();
14     ChannelHandler handler();
15     Set<ChannelHandlerType> types();
16     boolean hasInboundByteBuffer();
17     boolean hasInboundMessageBuffer();
18     ByteBuf inboundByteBuffer();
19     <T> MessageBuf<T> inboundMessageBuffer();
20     boolean hasOutboundByteBuffer();
21     boolean hasOutboundMessageBuffer();
22     ByteBuf outboundByteBuffer();
23     <T> MessageBuf<T> outboundMessageBuffer();
24     ByteBuf replaceInboundByteBuffer(ByteBuf newInboundByteBuf);
25     <T> MessageBuf<T> replaceInboundMessageBuffer(MessageBuf<T> newInboundMsgBuf);
26     ByteBuf replaceOutboundByteBuffer(ByteBuf newOutboundByteBuf);
27     <T> MessageBuf<T> replaceOutboundMessageBuffer(MessageBuf<T> newOutboundMsgBuf);
28     boolean hasNextInboundByteBuffer();
29     boolean hasNextInboundMessageBuffer();
30     ByteBuf nextInboundByteBuffer();
31     MessageBuf<Object> nextInboundMessageBuffer();
32     boolean hasNextOutboundByteBuffer();
33     boolean hasNextOutboundMessageBuffer();
34     ByteBuf nextOutboundByteBuffer();
35     MessageBuf<Object> nextOutboundMessageBuffer();
36     boolean isReadable();
37     void readable(boolean readable);
38 }

 

ChannelHandlerContext鎺ュ彛UML綾?/span>

 

ChannelHandlerContext鎺ュ彛鐨勫嚑涓噸瑕佹柟娉?/span>

ChannelPipeline pipeline();

榪斿洖灞炰簬褰撳墠ChannelHandlerContext鐨?/span>ChannelPipeline銆?/span>

 

EventExecutor executor();

EnventExcutor鐢ㄤ簬璋冨害EventLoop涓殑event錛岃繖涓柟娉曡繑鍥炲綋鍓嶇殑EventExecutor銆?/span>

 

涓涓?/span>Handler鍙互鏈夊涓?/span>Context

涓涓?/span>Handler鍙互琚坊鍔犲埌澶氫釜ChannelPipeline銆傝繖灝辨剰鍛崇潃涓涓?/span>ChannelHandler鍙互鏈夊涓?/span>ChannelHandlerContext銆?/span>

 

 

ChannelHandler鎺ュ彛

 1 package io.netty.channel;
 2  
 3 import io.netty.channel.group.ChannelGroup; 
 4 import java.lang.annotation.Documented;
 5 import java.lang.annotation.ElementType;
 6 import java.lang.annotation.Inherited;
 7 import java.lang.annotation.Retention;
 8 import java.lang.annotation.RetentionPolicy;
 9 import java.lang.annotation.Target;
10 import java.nio.channels.Channels;
11  
12 public interface ChannelHandler {
13     void beforeAdd(ChannelHandlerContext ctx) throws Exception;
14     void afterAdd(ChannelHandlerContext ctx) throws Exception;
15     void beforeRemove(ChannelHandlerContext ctx) throws Exception;
16     void afterRemove(ChannelHandlerContext ctx) throws Exception;
17     void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception;
18     void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception;
19     @Inherited
20     @Documented
21     @Target(ElementType.TYPE)
22     @Retention(RetentionPolicy.RUNTIME)
23     @interface Sharable {
24         // no value
25     }
26 }


 

ChannelHandler綾?/span>UML鍥?/span>

 

ChannelHandler涓殑鍑犱釜閲嶈鏂規硶

ChannelHandler鏈変袱涓瓙鎺ュ彛錛?/span>ChannelUpstreamHandler鍜?/span>ChannelDownstreamHandler銆?/span>

1.    ChannelUpstreamHandler鐢ㄤ簬澶勭悊鍜屾嫤鎴?/span>upstream涓殑ChannelEvent

2.    ChannelDownstreamHandler鐢ㄤ簬澶勭悊鍜屾嫤鎴?/span>downstream涓殑ChannelEvent

 

鐘舵佷俊鎭?/span>

ChannelHandler涓鑸渶瑕佸瓨鍌ㄤ竴浜涚姸鎬佷俊鎭紝浠ヤ笅鏄愬畼鏂規帹鑽愩戠殑鏂規硶錛屼嬌鐢ㄦ垚鍛樺彉閲忋?/span>

public class DataServerHandler extends SimpleChannelHandler {
     private boolean loggedIn;
     @Override
     public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
         Channel ch = e.getChannel();
         Object o = e.getMessage();
         if (o instanceof LoginMessage) {
             authenticate((LoginMessage) o);
             loggedIn = true;
         } else (o instanceof GetDataMessage) {
             if (loggedIn) {
                 ch.write(fetchSecret((GetDataMessage) o));
             } else {
                 fail();
             }
         }
     }
     
 }
 
// Create a new handler instance per channel.
 
// See ClientBootstrap#setPipelineFactory(ChannelPipelineFactory).
 public class DataServerPipelineFactory implements ChannelPipelineFactory {
     public ChannelPipeline getPipeline() {
         return Channels.pipeline(new DataServerHandler());
     }
 }

 

 

鎴栬呬嬌鐢?/span>ChannelLocal錛屼唬鐮佸涓?/span>

public final class DataServerState {      public static final ChannelLocal<Boolean> loggedIn = new ChannelLocal<>() {          protected Boolean initialValue(Channel channel) {              return false;          }      }      
}
 @Sharable  public class DataServerHandler extends SimpleChannelHandler {      @Override      public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {          Channel ch = e.getChannel();          Object o = e.getMessage();          if (o instanceof LoginMessage) {              authenticate((LoginMessage) o);              DataServerState.loggedIn.set(ch, true);          } else (o instanceof GetDataMessage) {              if (DataServerState.loggedIn.get(ch)) {                  ctx.getChannel().write(fetchSecret((GetDataMessage) o));              } else {                  fail();              }          }      }      
}

 // Print the remote addresses of the authenticated clients:  ChannelGroup allClientChannels = ;  for (Channel ch: allClientChannels) {      if (DataServerState.loggedIn.get(ch)) {          System.out.println(ch.getRemoteAddress());      }  }


澶囨敞:鍥犱負絎旇呭紑濮嬪啓Netty婧愮爜鍒嗘瀽鐨勬椂鍊欙紝Netty 4.0榪樻槸澶勪簬Alpha闃舵錛屼箣鍚庣殑API鍙兘榪樹細鏈夋敼鍔紝絎旇呭皢浼氬強鏃舵洿鏀廣備嬌鐢ㄥ紑婧愬凡緇忔湁濂藉嚑騫寸殑鏃墮棿浜嗭紝涓鐩存病鏈夋椂闂村拰綺懼姏鏉ュ叿浣撶爺絀舵煇涓紑婧愰」鐩殑鍏蜂綋瀹炵幇錛岃繖嬈℃槸絎竴嬈″啓寮婧愰」鐩殑婧愮爜鍒嗘瀽錛屽鏋滄枃涓湁閿欒鐨勫湴鏂癸紝嬈㈣繋璇昏呭彲浠ョ暀璦鎸囧嚭銆傚浜庤漿杞界殑璇昏咃紝璇鋒敞鏄庢枃绔犵殑鍑哄銆?甯屾湜鍜屽箍澶х殑寮鍙戣?寮婧愮埍濂借呰繘琛屼氦嫻侊紝嬈㈣繋澶у鐨勭暀璦鍜岃璁恒?/div>


Chan Chen 2012-11-25 16:51 鍙戣〃璇勮
]]>
Netty 4.0 婧愮爜鍒嗘瀽錛堜笁錛夛細Channel鍜孋hannelPipelinehttp://www.tkk7.com/czihong/articles/391927.htmlChan ChenChan ChenSun, 25 Nov 2012 06:53:00 GMThttp://www.tkk7.com/czihong/articles/391927.htmlhttp://www.tkk7.com/czihong/comments/391927.htmlhttp://www.tkk7.com/czihong/articles/391927.html#Feedback0http://www.tkk7.com/czihong/comments/commentRss/391927.htmlhttp://www.tkk7.com/czihong/services/trackbacks/391927.html闃呰鍏ㄦ枃

Chan Chen 2012-11-25 14:53 鍙戣〃璇勮
]]>
Netty 4.0 婧愮爜鍒嗘瀽錛堜簩錛夛細Echo Serverhttp://www.tkk7.com/czihong/articles/391899.htmlChan ChenChan ChenSat, 24 Nov 2012 04:38:00 GMThttp://www.tkk7.com/czihong/articles/391899.htmlhttp://www.tkk7.com/czihong/comments/391899.htmlhttp://www.tkk7.com/czihong/articles/391899.html#Feedback1http://www.tkk7.com/czihong/comments/commentRss/391899.htmlhttp://www.tkk7.com/czihong/services/trackbacks/391899.htmlNetty欏圭洰涓紝鑷甫浜嗗緢澶氫嬌鐢ㄧ殑渚嬪瓙錛屽浜庡垰鍒氬紑濮嬫帴瑙﹀拰瀛︿範Netty婧愮爜鐨勫紑鍙戣呮潵璇達紝鍙互閫氳繃渚嬪瓙鏉ユ洿濂界殑鐞嗚ВNetty鐨勫叿浣撳疄鐜般傛簮鐮佸彲浠ュ啀netty 4.0鐨別xample鎵懼埌銆?/span>

 

 1 public class EchoServerHandler extends ChannelInboundByteHandlerAdapter {            
 2     private static final Logger logger = Logger.getLogger(
 3             EchoServerHandler.class.getName());
 4 
 5     @Override
 6     public void inboundBufferUpdated(ChannelHandlerContext ctx, ByteBuf in) {
 7         ByteBuf out = ctx.nextOutboundByteBuffer();
 8         out.discardReadBytes();
 9         out.writeBytes(in);
10         ctx.flush();
11     }
12  
13     @Override
14     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
15         // Close the connection when an exception is raised.
16         logger.log(Level.WARNING, "Unexpected exception from downstream.", cause);
17         ctx.close();
18     }
19 }

Line 1: 澹版槑涓涓?/span>EchoServerHandler, 騫朵笖緇ф壙浜?/span>ChannelInboundByteHandlerAdapter銆?/span> 榪欐牱EchoServerHandler灝卞彲浠ュ鐞?/span>client鍙戦佽繃鏉ョ殑request銆?/span>

Line 6: 閲嶅啓inboundBufferUpdated鏂規硶錛屽client鍙戦佽繃鏉ョ殑request榪涜瀵?/span>ByteBuffer瀵硅薄鐨勬搷浣溿傚叧浜?/span>ByteBuffer鐨勬蹇靛皢鍦ㄤ互鍚庣珷鑺傝璁恒?/span>

Line 7: ctx.nextOutboundByteBuffer()灝嗚繑鍥炰竴涓?/span>ByteBuffer瀵硅薄銆傚鏋滆瀵硅薄涓嶅瓨鍦紝閭d箞鎶涘嚭UnsupportedOperationException寮傚父銆?/span>

Line 14: 閲嶅啓exceptionCaught鍦?/span>server绔崟鑾峰紓甯搞?/span>

 

 1 public class EchoServer {
 2  
 3     private final int port;
 4  
 5     public EchoServer(int port) {
 6         this.port = port;
 7     }
 8  
 9     public void run() throws Exception {
10         // Configure the server.
11         ServerBootstrap b = new ServerBootstrap();
12         try {
13             b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
14              .channel(NioServerSocketChannel.class)
15              .option(ChannelOption.SO_BACKLOG, 100)
16              .localAddress(new InetSocketAddress(port))
17              .childOption(ChannelOption.TCP_NODELAY, true)
18              .handler(new LoggingHandler(LogLevel.INFO))
19              .childHandler(new ChannelInitializer<SocketChannel>() {
20                  @Override
21                  public void initChannel(SocketChannel ch) throws Exception {
22                      ch.pipeline().addLast(
23                              new LoggingHandler(LogLevel.INFO),
24                              new EchoServerHandler());
25                  }
26              });
27  
28             // Start the server.
29             ChannelFuture f = b.bind().sync();
30  
31             // Wait until the server socket is closed.
32             f.channel().closeFuture().sync();
33         } finally {
34             // Shut down all event loops to terminate all threads.
35             b.shutdown();
36         }
37     }
38  
39     public static void main(String[] args) throws Exception {
40         int port;
41         if (args.length > 0) {
42             port = Integer.parseInt(args[0]);
43         } else {
44             port = 8080;
45         }
46         new EchoServer(port).run();
47     }
48 }

 

 

Line 11: 閫氳繃ServerBootStrap瀵硅薄錛屾潵鍚姩鏈嶅姟鍣?/span>

Line 13:  閫氳繃group鏂規硶錛屾潵緇戝畾EventLoopGroup錛?/span>EventLoopGroup鐢ㄦ潵澶勭悊SocketChannel鍜?/span>Channel涓婇潰鐨勬墍鏈夋椂闂村拰IO銆?/span>

Line 16: localAddress鏂規硶鐢ㄤ簬緇戝畾鏈嶅姟鍣ㄥ湴鍧鍜岀鍙c?/span>

Line 18,19: handler鏂規硶鍜?/span>childhandler鏂規硶鐢ㄤ簬鎸囧畾鍚勭ChannelHandler瀵硅薄錛屾寚瀹氱殑ChannelHandler瀵硅薄灝嗙敤浜庡鐞?/span>client绔潵鐨?/span>request銆?/span>

Line 21: 鍒濆鍖栦竴涓?/span>Channel瀵硅薄錛屽茍涓旂粦瀹氫箣鍓嶅畾涔夌殑EchoServerHandler綾匯?/span>

Line 22:  灝?/span>EchoServerHandler娣誨姞鍒?/span>Pipeline涓?/span>

Line 29: ServerBootstrap瀵硅薄鍑嗗灝辯華錛屽惎鍔?/span>server錛?/span>

Line 32: 絳夊緟鐩村埌server socket鍏抽棴

 

public class EchoClientHandler extends ChannelInboundByteHandlerAdapter {
 
    private static final Logger logger = Logger.getLogger(
            EchoClientHandler.class.getName());
 
    private final ByteBuf firstMessage;
 
    /**
     * Creates a client-side handler.
     
*/
    public EchoClientHandler(int firstMessageSize) {
        if (firstMessageSize <= 0) {
            throw new IllegalArgumentException("firstMessageSize: " + firstMessageSize);
        }
        firstMessage = Unpooled.buffer(firstMessageSize);
        for (int i = 0; i < firstMessage.capacity(); i ++) {
            firstMessage.writeByte((byte) i);
        }
    }
 
    @Override
    public void channelActive(ChannelHandlerContext ctx) {
        ctx.write(firstMessage);
    }
 
    @Override
    public void inboundBufferUpdated(ChannelHandlerContext ctx, ByteBuf in) {
        ByteBuf out = ctx.nextOutboundByteBuffer();
        out.discardReadBytes();
        out.writeBytes(in);
        ctx.flush();
    }
 
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        // Close the connection when an exception is raised.
        logger.log(Level.WARNING, "Unexpected exception from downstream.", cause);
        ctx.close();
    }
}

 

EchoClientHandler綾葷殑瀹炵幇涓?/span>EchoServerHandler綾諱技錛屼篃閮界戶鎵夸簡ChannelInboundByteHandlerAdapter銆備笉鍚屽湪浜庨噸鍐欎簡channelActive()鏂規硶銆?/span>

 

 1 public class EchoClient {
 2  
 3     private final String host;
 4     private final int port;
 5     private final int firstMessageSize;
 6  
 7     public EchoClient(String host, int port, int firstMessageSize) {
 8         this.host = host;
 9         this.port = port;
10         this.firstMessageSize = firstMessageSize;
11     }
12  
13     public void run() throws Exception {
14         // Configure the client.
15         Bootstrap b = new Bootstrap();
16         try {
17             b.group(new NioEventLoopGroup())
18              .channel(NioSocketChannel.class)
19              .option(ChannelOption.TCP_NODELAY, true)
20              .remoteAddress(new InetSocketAddress(host, port))
21              .handler(new ChannelInitializer<SocketChannel>() {
22                  @Override
23                  public void initChannel(SocketChannel ch) throws Exception {
24                      ch.pipeline().addLast(
25                              new LoggingHandler(LogLevel.INFO),
26                              new EchoClientHandler(firstMessageSize));
27                  }
28              });
29  
30             // Start the client.
31             ChannelFuture f = b.connect().sync();
32  
33             // Wait until the connection is closed.
34             f.channel().closeFuture().sync();
35         } finally {
36             // Shut down the event loop to terminate all threads.
37             b.shutdown();
38         }
39     }
40  
41     public static void main(String[] args) throws Exception {
42         // Print usage if no argument is specified.
43         if (args.length < 2 || args.length > 3) {
44             System.err.println(
45                     "Usage: " + EchoClient.class.getSimpleName() +
46                     " <host> <port> [<first message size>]");
47             return;
48         }
49  
50         // Parse options.
51         final String host = args[0];
52         final int port = Integer.parseInt(args[1]);
53         final int firstMessageSize;
54         if (args.length == 3) {
55             firstMessageSize = Integer.parseInt(args[2]);
56         } else {
57             firstMessageSize = 256;
58         }
59  
60         new EchoClient(host, port, firstMessageSize).run();
61     }
62 }

 

Line 20: 鎸囧畾榪滅▼鏈嶅姟鍣ㄧ殑鍦板潃鍜岀鍙o紙localhost:8080錛?br />

澶囨敞:鍥犱負絎旇呭紑濮嬪啓Netty婧愮爜鍒嗘瀽鐨勬椂鍊欙紝Netty 4.0榪樻槸澶勪簬Alpha闃舵錛屼箣鍚庣殑API鍙兘榪樹細鏈夋敼鍔紝絎旇呭皢浼氬強鏃舵洿鏀廣備嬌鐢ㄥ紑婧愬凡緇忔湁濂藉嚑騫寸殑鏃墮棿浜嗭紝涓鐩存病鏈夋椂闂村拰綺懼姏鏉ュ叿浣撶爺絀舵煇涓紑婧愰」鐩殑鍏蜂綋瀹炵幇錛岃繖嬈℃槸絎竴嬈″啓寮婧愰」鐩殑婧愮爜鍒嗘瀽錛屽鏋滄枃涓湁閿欒鐨勫湴鏂癸紝嬈㈣繋璇昏呭彲浠ョ暀璦鎸囧嚭銆傚浜庤漿杞界殑璇昏咃紝璇鋒敞鏄庢枃绔犵殑鍑哄銆?/div>
甯屾湜鍜屽箍澶х殑寮鍙戣?寮婧愮埍濂借呰繘琛屼氦嫻侊紝嬈㈣繋澶у鐨勭暀璦鍜岃璁恒?/div>



Chan Chen 2012-11-24 12:38 鍙戣〃璇勮
]]>Netty 4.0 婧愮爜鍒嗘瀽錛堜竴錛夛細閰嶇疆鐜http://www.tkk7.com/czihong/articles/391784.htmlChan ChenChan ChenThu, 22 Nov 2012 13:21:00 GMThttp://www.tkk7.com/czihong/articles/391784.htmlhttp://www.tkk7.com/czihong/comments/391784.htmlhttp://www.tkk7.com/czihong/articles/391784.html#Feedback0http://www.tkk7.com/czihong/comments/commentRss/391784.htmlhttp://www.tkk7.com/czihong/services/trackbacks/391784.htmlNetty 婧愮爜鍒嗘瀽錛堜竴錛夛細閰嶇疆鐜
1. 涓嬭澆jdk + elipse + egit
2. 鐩稿叧jar鍖呬笅杞?br />3. cynwin + telnet/ssh (setup.exe keywork:inetutils / ssh )
3. 浠巈xample鍖呭紑濮嬮槄璇?br />

澶囨敞:鍥犱負絎旇呭紑濮嬪啓Netty婧愮爜鍒嗘瀽鐨勬椂鍊欙紝Netty 4.0榪樻槸澶勪簬Alpha闃舵錛屼箣鍚庣殑API鍙兘榪樹細鏈夋敼鍔紝絎旇呭皢浼氬強鏃舵洿鏀廣備嬌鐢ㄥ紑婧愬凡緇忔湁濂藉嚑騫寸殑鏃墮棿浜嗭紝涓鐩存病鏈夋椂闂村拰綺懼姏鏉ュ叿浣撶爺絀舵煇涓紑婧愰」鐩殑鍏蜂綋瀹炵幇錛岃繖嬈℃槸絎竴嬈″啓寮婧愰」鐩殑婧愮爜鍒嗘瀽錛屽鏋滄枃涓湁閿欒鐨勫湴鏂癸紝嬈㈣繋璇昏呭彲浠ョ暀璦鎸囧嚭銆傚浜庤漿杞界殑璇昏咃紝璇鋒敞鏄庢枃绔犵殑鍑哄銆?/div>
甯屾湜鍜屽箍澶х殑寮鍙戣?寮婧愮埍濂借呰繘琛屼氦嫻侊紝嬈㈣繋澶у鐨勭暀璦鍜岃璁恒?/div>


Chan Chen 2012-11-22 21:21 鍙戣〃璇勮
]]> 主站蜘蛛池模板: 久久精品国产亚洲AV| 婷婷亚洲天堂影院| 成人影片一区免费观看| 亚洲国产欧洲综合997久久| 亚洲国产精品嫩草影院在线观看| 免费国内精品久久久久影院| 成年人网站在线免费观看| 色欲A∨无码蜜臀AV免费播| 国产裸体美女永久免费无遮挡| 国产精品成人亚洲| 2020亚洲男人天堂精品| 亚洲的天堂av无码| 亚洲一区二区三区首页| 亚洲成av人在线视| 亚洲中文久久精品无码ww16| 亚洲av区一区二区三| 国产jizzjizz免费视频| 韩国18福利视频免费观看| 91在线品视觉盛宴免费| 久热中文字幕在线精品免费| 99re免费视频| 国产亚洲色视频在线| 免费大黄网站在线观| 免费看国产曰批40分钟| 免费一级特黄特色大片在线| 国产成人精品123区免费视频| 免费看www视频| 四虎影永久在线高清免费| 爽爽日本在线视频免费| 国产一级淫片视频免费看| 国产裸模视频免费区无码| 国产成人精品免费直播| 免费一级毛片在线播放不收费| 亚洲成AV人网址| 中文字幕无码播放免费| 久久不见久久见免费视频7| 久久久免费精品re6| h视频在线观看免费完整版| 国产一卡2卡3卡4卡2021免费观看| 国产精品成人免费福利| 免费精品国产自产拍在|