锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲国产精品综合久久20,亚洲成AV人片在线观看,亚洲精品视频免费观看http://m.tkk7.com/alex-zheng/category/47156.html---on my wayzh-cnThu, 31 Mar 2011 01:36:58 GMTThu, 31 Mar 2011 01:36:58 GMT60姝e垯琛ㄨ揪寮忓尮閰嶅涓瓧絎︿覆涓竴涓垨澶氫釜http://m.tkk7.com/alex-zheng/articles/347257.htmlalex_zhengalex_zhengWed, 30 Mar 2011 02:22:00 GMThttp://m.tkk7.com/alex-zheng/articles/347257.htmlhttp://m.tkk7.com/alex-zheng/comments/347257.htmlhttp://m.tkk7.com/alex-zheng/articles/347257.html#Feedback0http://m.tkk7.com/alex-zheng/comments/commentRss/347257.htmlhttp://m.tkk7.com/alex-zheng/services/trackbacks/347257.html ^(((width|height)\s*:\s*\d+(px|%)[;]?)|\s|(float:(left|right)[;]?))+$
榪欓噷娌℃湁瀵歸噸澶嶅畾涔夊仛澶勭悊

alex_zheng 2011-03-30 10:22 鍙戣〃璇勮
]]>
宸х敤浣嶈繍綆楄〃紺哄睘鎬у垎綾?/title><link>http://m.tkk7.com/alex-zheng/articles/344806.html</link><dc:creator>alex_zheng</dc:creator><author>alex_zheng</author><pubDate>Tue, 22 Feb 2011 03:07:00 GMT</pubDate><guid>http://m.tkk7.com/alex-zheng/articles/344806.html</guid><wfw:comment>http://m.tkk7.com/alex-zheng/comments/344806.html</wfw:comment><comments>http://m.tkk7.com/alex-zheng/articles/344806.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/alex-zheng/comments/commentRss/344806.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/alex-zheng/services/trackbacks/344806.html</trackback:ping><description><![CDATA[鏈夋椂鍊欙紝鎴戜滑甯屾湜鐢ㄤ竴涓瓧孌典繚瀛樺璞$殑鎵灞炵姸鎬佹垨鍒嗙被錛屽綋榪欎釜鍊煎瓨鍦ㄥ縐嶇粍鍚堢殑鏃跺欙紝鎴戜滑灝卞彲浠ヤ嬌鐢ㄤ綅榪愮畻鏉ヨ〃紺虹粍鍚堝悗鐨勫箋?br /> 鍏堝畾涔夌被鍨婣=1,B=2,C=4,D=8,E=16絳?鐨勫嶆暟,<br /> 閭d箞objectA鍗沖睘浜嶢鍙堝睘浜嶤,鍏跺間負A|C,娣誨姞綾誨瀷浣跨敤|錛堟垨錛夎繍綆楋紝縐婚櫎綾誨瀷浣跨敤^(寮傛垨)榪愮畻錛屽垽鏂槸鍚﹀睘浜庢煇涓被鍨嬩嬌鐢?amp;榪愮畻銆?br /> A=00000001<br /> B=00000010<br /> C=00000100<br /> D=00001000<br /> E=00010000<br /> <br /> objectA = (A|B|C = 00000111)<br /> 鍘婚櫎B綾誨瀷 00000111<br />               ^00000010<br /> -------------------------<br />                  00000101=(A|C)<br /> <br /> 鍒ゆ柇鏄惁鏄疉,00000101&00000001 = 00000001<br /> <br /> <br /> <br /> <img src ="http://m.tkk7.com/alex-zheng/aggbug/344806.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/alex-zheng/" target="_blank">alex_zheng</a> 2011-02-22 11:07 <a href="http://m.tkk7.com/alex-zheng/articles/344806.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>eclipse涓瓁ml鐨勮嚜鍔ㄦ彁紺洪厤緗?杞?http://m.tkk7.com/alex-zheng/articles/343078.htmlalex_zhengalex_zhengMon, 17 Jan 2011 01:31:00 GMThttp://m.tkk7.com/alex-zheng/articles/343078.htmlhttp://m.tkk7.com/alex-zheng/comments/343078.htmlhttp://m.tkk7.com/alex-zheng/articles/343078.html#Feedback0http://m.tkk7.com/alex-zheng/comments/commentRss/343078.htmlhttp://m.tkk7.com/alex-zheng/services/trackbacks/343078.htmlhttp://hi.baidu.com/2wiki/blog/item/2cc40a3f2b7ef2c97c1e7127.html
DTD 綾誨瀷綰︽潫鏂囦歡
    1. Window->Preferences->XML->XML Catalog->User Specified Entries紿楀彛涓?閫夋嫨Add 鎸夌航
       
    2.鍦ˋdd XML Catalog Entry 瀵硅瘽妗嗕腑閫夋嫨鎴栬緭鍏ヤ互涓嬪唴瀹?
        Location: F:\soft\programmingSoft\Framework\Ibatis\sql-map-config-2.dtd
        Key Type: URI
        KEY: http://ibatis.apache.org/dtd/sql-map-config-2.dtd
       
XSD 綾誨瀷綰︽潫鏂囦歡

    1. Window->Preferences->XML->XML Catalog->User Specified Entries紿楀彛涓?閫夋嫨Add 鎸夌航
       
    2.鍦ˋdd XML Catalog Entry 瀵硅瘽妗嗕腑閫夋嫨鎴栬緭鍏ヤ互涓嬪唴瀹?
        Location: F:\soft\programmingSoft\Framework\Spring\spring-framework-2.5.6.SEC01-with-dependencies\spring-framework-2.5.6.SEC01\dist\resources\spring-beans-2.5.xsd
        Key Type: Schema Location
        KEY: http://www.springframework.org/schema/beans/spring-beans-2.5.xsd



alex_zheng 2011-01-17 09:31 鍙戣〃璇勮
]]>
hibernate婧愮爜org.hibernate.hql.antlr鍖呬負絀虹殑瑙e喅鏂規硶http://m.tkk7.com/alex-zheng/articles/340639.htmlalex_zhengalex_zhengTue, 14 Dec 2010 06:23:00 GMThttp://m.tkk7.com/alex-zheng/articles/340639.htmlhttp://m.tkk7.com/alex-zheng/comments/340639.htmlhttp://m.tkk7.com/alex-zheng/articles/340639.html#Feedback0http://m.tkk7.com/alex-zheng/comments/commentRss/340639.htmlhttp://m.tkk7.com/alex-zheng/services/trackbacks/340639.html 棣栧厛灝哸ntlr.jar鍖呭鍒跺埌hibernate-distribution-3.5.6-Final/project/core/src/main/antlr,榪欓噷hibernate-distribution-3.5.6-Final鏄綘鐨勮В鍘嬭礬寰?br /> 鐒跺悗渚濇鎵цjava -classpath antlr-2.7.6.jar antlr.Tool hql.g絳夛紝鏈鍚庡皢鐢熸垚鐨刯ava鏂囦歡澶嶅埗鍒扮浉搴斿寘



alex_zheng 2010-12-14 14:23 鍙戣〃璇勮
]]>
netty婧愮爜鍒嗘瀽灝忕粨http://m.tkk7.com/alex-zheng/articles/340157.htmlalex_zhengalex_zhengThu, 09 Dec 2010 08:46:00 GMThttp://m.tkk7.com/alex-zheng/articles/340157.htmlhttp://m.tkk7.com/alex-zheng/comments/340157.htmlhttp://m.tkk7.com/alex-zheng/articles/340157.html#Feedback0http://m.tkk7.com/alex-zheng/comments/commentRss/340157.htmlhttp://m.tkk7.com/alex-zheng/services/trackbacks/340157.html channelfuture璐熻矗channel鐨勬墍澶勭姸鎬侊紝涓涓猚hannle涓叧鑱旀潵channelpipeline錛宑hannelpipeline鍒欑敱pipelinefactory鍒涘緩錛?br /> 鍦╟hannelpipeline涓湁鍐呴儴綾籧hannelhandlercontext錛屼繚瀛榗hannelhandler鐨勯摼寮忕粨鏋勶紝鐢眂hannelhandler鏉ヤ紶閫抍hannelevent錛?br /> channelevent鍒嗗埆鏈塷pen錛宐ind錛宑onnected錛宑lose錛宮essagereceived絳夈?br />


alex_zheng 2010-12-09 16:46 鍙戣〃璇勮
]]>
netty3.2.3婧愮爜鍒嗘瀽-ClientBootstrap鍚姩鍒嗘瀽http://m.tkk7.com/alex-zheng/articles/339908.htmlalex_zhengalex_zhengMon, 06 Dec 2010 08:59:00 GMThttp://m.tkk7.com/alex-zheng/articles/339908.htmlhttp://m.tkk7.com/alex-zheng/comments/339908.htmlhttp://m.tkk7.com/alex-zheng/articles/339908.html#Feedback0http://m.tkk7.com/alex-zheng/comments/commentRss/339908.htmlhttp://m.tkk7.com/alex-zheng/services/trackbacks/339908.html
public class TelnetClient {

    
public static void main(String[] args) throws Exception {
        
        ClientBootstrap bootstrap 
= new ClientBootstrap(
                
new NioClientSocketChannelFactory(
                        Executors.newCachedThreadPool(),
                        Executors.newCachedThreadPool()));

        
// Configure the pipeline factory.
        bootstrap.setPipelineFactory(new TelnetClientPipelineFactory());

        
// Start the connection attempt.
        ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));

        
// Wait until the connection attempt succeeds or fails.
        Channel channel = future.awaitUninterruptibly().getChannel();
        
if (!future.isSuccess()) {
            future.getCause().printStackTrace();
            bootstrap.releaseExternalResources();
            
return;
        }

        
    }
}
鐩存帴鐪媍onnect鏂規硶
public ChannelFuture connect(final SocketAddress remoteAddress, final SocketAddress localAddress) {

        
if (remoteAddress == null) {
            
throw new NullPointerException("remoteAddress");
        }

        ChannelPipeline pipeline;
        
try {
            pipeline 
= getPipelineFactory().getPipeline();
        } 
catch (Exception e) {
            
throw new ChannelPipelineException("Failed to initialize a pipeline.", e);
        }

        
// Set the options.
        
//NioClientSocketChannel鏋勯犲嚱鏁頒腑浼氳Е鍙慶hannelopen
        
//TelnetClientPipelineFactory涓殑upstreamhandler娌℃湁閲嶅啓channelOpen錛岃繖閲屽彧鏄竴鐩村線涓嬩紶閫掕浜嬩歡
        Channel ch = getFactory().newChannel(pipeline);
        ch.getConfig().setOptions(getOptions());

        
// Bind.
        if (localAddress != null) {
            ch.bind(localAddress);
        }

        
// Connect.
        return ch.connect(remoteAddress);
    }
鐒跺悗鎵цch.connect(remoteAddress);
榪欓噷鏄疦ioClientSocketChannel-->NioSocketChannel-->AbstractChannel
public ChannelFuture connect(SocketAddress remoteAddress) {
       
return Channels.connect(this, remoteAddress);
}

public static ChannelFuture connect(Channel channel, SocketAddress remoteAddress) {
        
if (remoteAddress == null) {
            
throw new NullPointerException("remoteAddress");
        }
        ChannelFuture future 
= future(channel, true);
        channel.getPipeline().sendDownstream(
new DownstreamChannelStateEvent(
                channel, future, ChannelState.CONNECTED, remoteAddress));
        
return future;
}

浠嶵elnetClientPipelineFactory鐨刾ipeline涓敱涓嬪線涓婁紶閫扖ONNECTED浜嬩歡錛岃繖閲屽彧鏈変竴涓猄tringEncoder-->OneToOneEncoder,鍏?br /> handleDownstream鏂規硶瀵硅浜嬩歡涓嶅仛澶勭悊,寰涓婁紶閫掕浜嬩歡,鎵цDefaultChannelHandlerContext.sendDownstream
public void sendDownstream(ChannelEvent e) {
            
//鍦⊿tringEncoder涔嬪墠鍐嶆病鏈塪ownstreamhandler
            DefaultChannelHandlerContext prev = getActualDownstreamContext(this.prev);
            
if (prev == null) {
                
try {
                    getSink().eventSunk(DefaultChannelPipeline.
this, e);
                } 
catch (Throwable t) {
                    notifyHandlerException(e, t);
                }
            } 
else {
                DefaultChannelPipeline.
this.sendDownstream(prev, e);
            }
        }
鎵цNioClientSocketPipelineSink.eventSunk,鍏朵腑浼氭墽琛?br />
 private void connect(
            
final NioClientSocketChannel channel, final ChannelFuture cf,
            SocketAddress remoteAddress) {
        
try {
            
//濡傛灉榪斿洖true錛岃皟鐢╪ioworker.register,寮濮嬪惎鍔╪ioworker綰跨▼澶勭悊璇hannel鐨勮鍐?br />             //鍚﹀垯錛屼氦緇檅oss.register鏂規硶錛屽湪boss綰跨▼涓畬鎴愯繛鎺?/span>
            if (channel.socket.connect(remoteAddress)) {
                channel.worker.register(channel, cf);
            } 
else {
                
//涓哄綋鍓峜lientsocketchannel娣誨姞closed鐨刲istener
                channel.getCloseFuture().addListener(new ChannelFutureListener() {
                    
public void operationComplete(ChannelFuture f)
                            
throws Exception {
                        
if (!cf.isDone()) {
                            cf.setFailure(
new ClosedChannelException());
                        }
                    }
                });
                cf.addListener(ChannelFutureListener.CLOSE_ON_FAILURE);
                channel.connectFuture 
= cf;
                
                boss.register(channel);
            }

        } 
catch (Throwable t) {
            cf.setFailure(t);
            fireExceptionCaught(channel, t);
            channel.worker.close(channel, succeededFuture(channel));
        }
    }

鎵цboss.register錛屽湪boss綰跨▼涓‘淇濊channel榪炴帴鎴愬姛錛岃繖閲屼細鍚姩boss綰跨▼
void register(NioClientSocketChannel channel) {
            
//鍦≧egisterTask鐨剅un鏂規硶閲屾敞鍐孲electionKey.OP_CONNECT
            Runnable registerTask = new RegisterTask(this, channel);
            
                
boolean offered = registerTaskQueue.offer(registerTask);
                
assert offered;
            }

            
if (wakenUp.compareAndSet(falsetrue)) {
                selector.wakeup();
            }
        }
鏈鍚庡惎鍔╞oss.run錛屽叾涓璸rocessSelectedKeys閲屾墽琛宑onnect
private void connect(SelectionKey k) {
            NioClientSocketChannel ch 
= (NioClientSocketChannel) k.attachment();
            
try {
                
if (ch.socket.finishConnect()) {
                    k.cancel();
                    
//榪炴帴鎴愬姛錛屾墠鍦╪ioworker涓惎鍔ㄤ竴涓柊綰跨▼鏉ュ鐞嗚socketchannel鐨勮鍐?/span>
                    ch.worker.register(ch, ch.connectFuture);
                }
            } 
catch (Throwable t) {
                ch.connectFuture.setFailure(t);
                fireExceptionCaught(ch, t);
                ch.worker.close(ch, succeededFuture(ch));
            }
        }

涔嬪悗灝辨槸浜ょ粰nioworker綰跨▼鏉ヨ繘琛屾暟鎹殑鍙戦佸拰鎺ユ敹浜嗐?br />

alex_zheng 2010-12-06 16:59 鍙戣〃璇勮
]]>
java-string綾誨瀷鍙傛暟浼犻掑垎鏋?/title><link>http://m.tkk7.com/alex-zheng/articles/339846.html</link><dc:creator>alex_zheng</dc:creator><author>alex_zheng</author><pubDate>Sun, 05 Dec 2010 08:27:00 GMT</pubDate><guid>http://m.tkk7.com/alex-zheng/articles/339846.html</guid><wfw:comment>http://m.tkk7.com/alex-zheng/comments/339846.html</wfw:comment><comments>http://m.tkk7.com/alex-zheng/articles/339846.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/alex-zheng/comments/commentRss/339846.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/alex-zheng/services/trackbacks/339846.html</trackback:ping><description><![CDATA[     鎽樿: 涓婂懆鍘諱竴瀹跺叕鍙擱潰璇曪紝鍏朵腑涓涓潰璇曢鏄繖鏍風殑錛屽垽鏂笅闈㈢▼搴忚緭鍑猴紝鏈漢寰堟澂鍏風殑鍐欎簡"changed" Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->public class StringArgTest ...  <a href='http://m.tkk7.com/alex-zheng/articles/339846.html'>闃呰鍏ㄦ枃</a><img src ="http://m.tkk7.com/alex-zheng/aggbug/339846.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/alex-zheng/" target="_blank">alex_zheng</a> 2010-12-05 16:27 <a href="http://m.tkk7.com/alex-zheng/articles/339846.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>netty3.2.3婧愮爜鍒嗘瀽--鏈嶅姟鍣ㄧ鍙戦佹暟鎹垎鏋?/title><link>http://m.tkk7.com/alex-zheng/articles/339795.html</link><dc:creator>alex_zheng</dc:creator><author>alex_zheng</author><pubDate>Sat, 04 Dec 2010 06:54:00 GMT</pubDate><guid>http://m.tkk7.com/alex-zheng/articles/339795.html</guid><wfw:comment>http://m.tkk7.com/alex-zheng/comments/339795.html</wfw:comment><comments>http://m.tkk7.com/alex-zheng/articles/339795.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/alex-zheng/comments/commentRss/339795.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/alex-zheng/services/trackbacks/339795.html</trackback:ping><description><![CDATA[涓婁竴綃囧垎鏋愪簡鏈嶅姟鍣ㄧ璇誨彇瀹㈡埛鍙戦佺殑鏁版嵁錛岃繖綃囨潵鐪嬫湇鍔″櫒绔浣曞彂閫佹暟鎹粰瀹㈡埛绔紝鏈嶅姟鍣ㄥ線澶栧彂閫佹暟鎹槸閫氳繃downstreamhandler浠庝笅鍒頒笂鎵ц<br /> 鍙戦佷粠ChannelFuture future = e.getChannel().write(response)寮濮嬫墽琛孋hannels涓嬬殑<br /> <div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> ChannelFuture write(Channel channel, Object message, SocketAddress remoteAddress) {<br />         ChannelFuture future </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> future(channel);<br />         channel.getPipeline().sendDownstream(<br />                 </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> DownstreamMessageEvent(channel, future, message, remoteAddress));<br />         </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> future;<br />  }<br /> <br /> </span></div> telentpipeline涓渶涓嬮潰涓涓猟ownstreamhandler鏄痵tringencoder錛屾渶鍚庢墽琛孫neToOneEncoder鐨刪andleDownstream<br /> <div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> handleDownstream(<br />             ChannelHandlerContext ctx, ChannelEvent evt) </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception {<br />         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 0);">!</span><span style="color: rgb(0, 0, 0);">(evt </span><span style="color: rgb(0, 0, 255);">instanceof</span><span style="color: rgb(0, 0, 0);"> MessageEvent)) {<br />             ctx.sendDownstream(evt);<br />             </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">;<br />         }<br /> <br />         MessageEvent e </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (MessageEvent) evt;<br />         Object originalMessage </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> e.getMessage();<br />         Object encodedMessage </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> encode(ctx, e.getChannel(), originalMessage);<br />         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (originalMessage </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> encodedMessage) {<br />             ctx.sendDownstream(evt);<br />         } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (encodedMessage </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">) {<br />             </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">榪欓噷鍐檈ncode鏁版嵁錛孌efaultChannelPipeline鐨剆endDownstream</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">            write(ctx, e.getFuture(), encodedMessage, e.getRemoteAddress());<br />         }<br />     }</span></div> DefaultChannelPipeline鐨剆endDownstream鏂規硶<br /> <div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> sendDownstream(ChannelEvent e) {<br />             DefaultChannelHandlerContext prev </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> getActualDownstreamContext(</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.prev);<br />             </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (prev </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">) {<br />                 </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {<br />                     </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">鍥犱負stringencoder鏄敮涓涓涓猟ownstreamhandler錛岃繖閲屾墽琛孨ioServerSocketPipelineSink.eventSunk</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">                    getSink().eventSunk(DefaultChannelPipeline.</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">, e);<br />                 } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (Throwable t) {<br />                     notifyHandlerException(e, t);<br />                 }<br />             } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> {<br />                 DefaultChannelPipeline.</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.sendDownstream(prev, e);<br />             }<br />         }</span></div> eventSunk鏂規硶浼氭墽琛?br /> <div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> handleAcceptedSocket(ChannelEvent e) {<br />         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (e </span><span style="color: rgb(0, 0, 255);">instanceof</span><span style="color: rgb(0, 0, 0);"> ChannelStateEvent) {<br />             ChannelStateEvent event </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (ChannelStateEvent) e;<br />             NioSocketChannel channel </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (NioSocketChannel) event.getChannel();<br />             ChannelFuture future </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> event.getFuture();<br />             ChannelState state </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> event.getState();<br />             Object value </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> event.getValue();<br /> <br />             </span><span style="color: rgb(0, 0, 255);">switch</span><span style="color: rgb(0, 0, 0);"> (state) {<br />             </span><span style="color: rgb(0, 0, 255);">case</span><span style="color: rgb(0, 0, 0);"> OPEN:<br />                 </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (Boolean.FALSE.equals(value)) {<br />                     channel.worker.close(channel, future);<br />                 }<br />                 </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br />             </span><span style="color: rgb(0, 0, 255);">case</span><span style="color: rgb(0, 0, 0);"> BOUND:<br />             </span><span style="color: rgb(0, 0, 255);">case</span><span style="color: rgb(0, 0, 0);"> CONNECTED:<br />                 </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (value </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">) {<br />                     channel.worker.close(channel, future);<br />                 }<br />                 </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br />             </span><span style="color: rgb(0, 0, 255);">case</span><span style="color: rgb(0, 0, 0);"> INTEREST_OPS:<br />                 channel.worker.setInterestOps(channel, future, ((Integer) value).intValue());<br />                 </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br />             }<br />         } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (e </span><span style="color: rgb(0, 0, 255);">instanceof</span><span style="color: rgb(0, 0, 0);"> MessageEvent) {<br />             MessageEvent event </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (MessageEvent) e;<br />             NioSocketChannel channel </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (NioSocketChannel) event.getChannel();<br />             </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">鏀懼叆writerequestqueue闃熷垪</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">boolean</span><span style="color: rgb(0, 0, 0);"> offered </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> channel.writeBuffer.offer(event);<br />             </span><span style="color: rgb(0, 0, 255);">assert</span><span style="color: rgb(0, 0, 0);"> offered;<br />             </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">鎵цnioworker鐨剋riteFromUserCode,涔嬪悗鎵цwrite0鏂規硶</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">            channel.worker.writeFromUserCode(channel);<br />         }<br />     }</span></div> <br /> <div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> write0(NioSocketChannel channel) {<br />         </span><span style="color: rgb(0, 0, 255);">boolean</span><span style="color: rgb(0, 0, 0);"> open </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">;<br />         </span><span style="color: rgb(0, 0, 255);">boolean</span><span style="color: rgb(0, 0, 0);"> addOpWrite </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">;<br />         </span><span style="color: rgb(0, 0, 255);">boolean</span><span style="color: rgb(0, 0, 0);"> removeOpWrite </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">;<br /> <br />         </span><span style="color: rgb(0, 0, 255);">long</span><span style="color: rgb(0, 0, 0);"> writtenBytes </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br /> <br />         </span><span style="color: rgb(0, 0, 255);">final</span><span style="color: rgb(0, 0, 0);"> SocketSendBufferPool sendBufferPool </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.sendBufferPool;<br />         </span><span style="color: rgb(0, 0, 255);">final</span><span style="color: rgb(0, 0, 0);"> SocketChannel ch </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> channel.socket;<br />         </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">涔嬪墠灝哻hannel鏀懼埌浜嗚闃熷垪</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">final</span><span style="color: rgb(0, 0, 0);"> Queue</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">MessageEvent</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"> writeBuffer </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> channel.writeBuffer;<br />         //<span style="color: rgb(80, 255, 90);"><span style="color: rgb(0, 134, 33);"><span style="color: rgb(80, 255, 90);"><span style="color: rgb(0, 134, 33);">榛樿灝濊瘯16嬈″啓</span></span></span></span><br />         </span><span style="color: rgb(0, 0, 255);">final</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> writeSpinCount </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> channel.getConfig().getWriteSpinCount();<br />         </span><span style="color: rgb(0, 0, 255);">synchronized</span><span style="color: rgb(0, 0, 0);"> (channel.writeLock) {<br />             channel.inWriteNowLoop </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">;<br />             </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> (;;) {<br />                 MessageEvent evt </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> channel.currentWriteEvent;<br />                 SendBuffer buf;<br />                 </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (evt </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">) {<br />             </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">浠巜ritebuffer涓幏寰椾竴涓獁riteevent</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">                    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> ((channel.currentWriteEvent </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> evt </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> writeBuffer.poll()) </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">) {<br />                         removeOpWrite </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">;<br />                         channel.writeSuspended </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">;<br />                         </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br />                     }<br />                     <br />                     channel.currentWriteBuffer </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> buf </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> sendBufferPool.acquire(evt.getMessage());<br />                 } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> {<br />                     buf </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> channel.currentWriteBuffer;<br />                 }<br /> <br />                 ChannelFuture future </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> evt.getFuture();<br />                 </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {<br />                     </span><span style="color: rgb(0, 0, 255);">long</span><span style="color: rgb(0, 0, 0);"> localWrittenBytes </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />                     </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> i </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> writeSpinCount; i </span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">; i </span><span style="color: rgb(0, 0, 0);">--</span><span style="color: rgb(0, 0, 0);">) {<br />                         </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">鍙戦佹暟鎹粰瀹㈡埛绔?鎵цPooledSendBuffer.transferTo</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">                        localWrittenBytes </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> buf.transferTo(ch);<br />                         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (localWrittenBytes </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">) {<br />                             writtenBytes </span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);"> localWrittenBytes;<br />                             </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br />                         }<br />                         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (buf.finished()) {<br />                             </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br />                         }<br />                     }<br /> <br />                     </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (buf.finished()) {<br />                         </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Successful write - proceed to the next message.</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">                        buf.release();<br />                         channel.currentWriteEvent </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />                         channel.currentWriteBuffer </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />                         evt </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />                         buf </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />                         future.setSuccess();<br />                     } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> {<br />                         </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Not written fully - perhaps the kernel buffer is full.</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">                        addOpWrite </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">;<br />                         channel.writeSuspended </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">;<br /> <br />                         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (localWrittenBytes </span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">) {<br />                             </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Notify progress listeners if necessary.</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">                            future.setProgress(<br />                                     localWrittenBytes,<br />                                     buf.writtenBytes(), buf.totalBytes());<br />                         }<br />                         </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br />                     }<br />                 } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (AsynchronousCloseException e) {<br />                     </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Doesn't need a user attention - ignore.</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">                } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (Throwable t) {<br />                     buf.release();<br />                     channel.currentWriteEvent </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />                     channel.currentWriteBuffer </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />                     buf </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />                     evt </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />                     future.setFailure(t);<br />                     fireExceptionCaught(channel, t);<br />                     </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (t </span><span style="color: rgb(0, 0, 255);">instanceof</span><span style="color: rgb(0, 0, 0);"> IOException) {<br />                         open </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">;<br />                         close(channel, succeededFuture(channel));<br />                     }<br />                 }<br />             }<br />             channel.inWriteNowLoop </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">;<br />         }<br />         </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">瑙﹀彂鍐欏畬鎴愪簨浠訛紝鎵ц鐨勬槸DefaultChannelPipeline鐨剆endUpstream錛屾渶鍚庤皟鐢⊿impleChannelUpstreamHandler.writeComplete<br />         </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">pipeline涓殑upstreamhandler鐨剋riteComplete閮芥湭閲嶅啓錛屾墍浠ュ彧鏄畝鍗曠殑浼犻掕浜嬩歡</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">        fireWriteComplete(channel, writtenBytes);<br /> <br />         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (open) {<br />             </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (addOpWrite) {<br />                 setOpWrite(channel);<br />             } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (removeOpWrite) {<br />                 clearOpWrite(channel);<br />             }<br />         }<br />     }<br /> </span></div> <img src ="http://m.tkk7.com/alex-zheng/aggbug/339795.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/alex-zheng/" target="_blank">alex_zheng</a> 2010-12-04 14:54 <a href="http://m.tkk7.com/alex-zheng/articles/339795.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>netty3.2.3婧愮爜鍒嗘瀽--鏈嶅姟鍣ㄧ璇繪暟鎹垎鏋?/title><link>http://m.tkk7.com/alex-zheng/articles/339751.html</link><dc:creator>alex_zheng</dc:creator><author>alex_zheng</author><pubDate>Fri, 03 Dec 2010 13:26:00 GMT</pubDate><guid>http://m.tkk7.com/alex-zheng/articles/339751.html</guid><wfw:comment>http://m.tkk7.com/alex-zheng/comments/339751.html</wfw:comment><comments>http://m.tkk7.com/alex-zheng/articles/339751.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/alex-zheng/comments/commentRss/339751.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/alex-zheng/services/trackbacks/339751.html</trackback:ping><description><![CDATA[涓婁竴綃囧垎鏋愪簡serverboostrap鐨勫惎鍔紝鎺ヤ笅鏉ュ垎鏋恘etty鐨勬暟鎹鍙栥?br /> 鍦╪ioworker鐨勶紝璐熻矗璇誨彇鎿嶄綔鏄敱錛屽湪璇ユ柟娉曚腑錛屽鏋滃綋鍓峜hannel鐨?readyOps & SelectionKey.OP_READ) != 0 || readyOps == 0錛屼笖姝ゆ椂<br /> ch.read(buff)<0,鍒欏垽鏂鎴風宸茬粡鏂紑榪炴帴<span style="color: rgb(0, 0, 0);"><br /> </span> <div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">boolean</span><span style="color: rgb(0, 0, 0);"> read(SelectionKey k) {<br />         </span><span style="color: rgb(0, 0, 255);">final</span><span style="color: rgb(0, 0, 0);"> SocketChannel ch </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (SocketChannel) k.channel();<br />         </span><span style="color: rgb(0, 0, 255);">final</span><span style="color: rgb(0, 0, 0);"> NioSocketChannel channel </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (NioSocketChannel) k.attachment();<br /> <br />         </span><span style="color: rgb(0, 0, 255);">final</span><span style="color: rgb(0, 0, 0);"> ReceiveBufferSizePredictor predictor </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"><br />             channel.getConfig().getReceiveBufferSizePredictor();<br />         </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">榛樿1024涓瓧鑺傜┖闂?/span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">final</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> predictedRecvBufSize </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> predictor.nextReceiveBufferSize();<br /> <br />         </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> ret </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />         </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> readBytes </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />         </span><span style="color: rgb(0, 0, 255);">boolean</span><span style="color: rgb(0, 0, 0);"> failure </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">;<br />         </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">鍒嗛厤榪炵畫鐨?024涓猙yte絀洪棿</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">        ByteBuffer bb </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> recvBufferPool.acquire(predictedRecvBufSize);<br />         </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {<br />             </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);"> ((ret </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ch.read(bb)) </span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">) {<br />                 readBytes </span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);"> ret;<br />                 </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 0);">!</span><span style="color: rgb(0, 0, 0);">bb.hasRemaining()) {<br />                     </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br />                 }<br />             }<br />             failure </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">;<br />         } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (ClosedChannelException e) {<br />             </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Can happen, and does not need a user attention.</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">        } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (Throwable t) {<br />             fireExceptionCaught(channel, t);<br />         }<br /> <br />         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (readBytes </span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">) {<br />             bb.flip();<br /> <br />             </span><span style="color: rgb(0, 0, 255);">final</span><span style="color: rgb(0, 0, 0);"> ChannelBufferFactory bufferFactory </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"><br />                 channel.getConfig().getBufferFactory();<br />             </span><span style="color: rgb(0, 0, 255);">final</span><span style="color: rgb(0, 0, 0);"> ChannelBuffer buffer </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> bufferFactory.getBuffer(readBytes);<br />             buffer.setBytes(</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, bb);<br />             buffer.writerIndex(readBytes);<br /> <br />             recvBufferPool.release(bb);<br /> <br />             </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Update the predictor.</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">            predictor.previousReceiveBufferSize(readBytes);<br /> <br />             </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">瑙﹀彂娑堟伅鎺ユ敹浜嬩歡錛屾牴鎹畃ipeline涓璾pstreamhandler鐢變笂鍒頒笅鐨勯『搴忥紝璋冪敤messageReceived鏂規硶</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">            fireMessageReceived(channel, buffer);<br />         } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> {<br />             recvBufferPool.release(bb);<br />         }<br /> <br />         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (ret </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 0);"> failure) {<br />             close(channel, succeededFuture(channel));<br />             </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">;<br />         }<br /> <br />         </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">;<br />     }</span></div> <span style="color: rgb(0, 0, 0);">     </span><span style="color: rgb(0, 0, 0);"><br /> </span> <br /> 鍦╬ipelinefactory涓殑絎竴涓猽pstreamhandler涓篋elimiterBasedFrameDecoder錛岀戶鎵胯嚜FrameDecoder <div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> ChannelPipeline getPipeline() </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception {<br />         </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Create a default pipeline implementation.</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">        ChannelPipeline pipeline </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> pipeline();<br /> <br />         </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Add the text line codec combination first,</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">        pipeline.addLast(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">framer</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> DelimiterBasedFrameDecoder(<br />                 </span><span style="color: rgb(0, 0, 0);">8192</span><span style="color: rgb(0, 0, 0);">, Delimiters.lineDelimiter()));<br />         pipeline.addLast(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">decoder</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> StringDecoder());<br />         pipeline.addLast(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">encoder</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> StringEncoder());<br /> <br />         </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> and then business logic.</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">        pipeline.addLast(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">handler</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> TelnetServerHandler());<br /> <br />         </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> pipeline;<br />     }</span></div> 浼氳皟鐢‵rameDecoder鐨刴essageReceived<br />  <br /> <div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> messageReceived(<br />             ChannelHandlerContext ctx, MessageEvent e) </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception {<br /> <br />         Object m </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> e.getMessage();<br />         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 0);">!</span><span style="color: rgb(0, 0, 0);">(m </span><span style="color: rgb(0, 0, 255);">instanceof</span><span style="color: rgb(0, 0, 0);"> ChannelBuffer)) {<br />             ctx.sendUpstream(e);<br />             </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">;<br />         }<br /> <br />         ChannelBuffer input </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (ChannelBuffer) m;<br />         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 0);">!</span><span style="color: rgb(0, 0, 0);">input.readable()) {<br />             </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">;<br />         }<br /> <br />         ChannelBuffer cumulation </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> cumulation(ctx);<br />         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (cumulation.readable()) {<br />             cumulation.discardReadBytes();<br />             cumulation.writeBytes(input);<br />             callDecode(ctx, e.getChannel(), cumulation, e.getRemoteAddress());<br />         } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> {<br />             </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">榪欓噷璋冪敤瀛愮被鐨刣ecode鏂規硶</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">            callDecode(ctx, e.getChannel(), input, e.getRemoteAddress());<br />             </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (input.readable()) {<br />                 cumulation.writeBytes(input);<br />             }<br />         }<br />     }</span></div> <br />  //鍦ㄨ繖涓猽pstreamhandler涓紝浼氫竴鐩磋鍙栨暟鎹紝鐩村埌閬囧埌鍗忚綰﹀畾鐨勭粨鏉熸爣蹇楁墠灝唌essagereceived浜嬩歡浼犵粰涓嬩竴涓?br />  <br /> <div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> callDecode(<br />             ChannelHandlerContext context, Channel channel,<br />             ChannelBuffer cumulation, SocketAddress remoteAddress) </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception {<br /> <br />         </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);"> (cumulation.readable()) {<br />             </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> oldReaderIndex </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> cumulation.readerIndex();<br />             Object frame </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> decode(context, channel, cumulation);<br />             </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (frame </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">) {<br />                 </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (oldReaderIndex </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> cumulation.readerIndex()) {<br />                     </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Seems like more data is required.<br />                     </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Let us wait for the next notification.</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">                    </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br />                 } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> {<br />                     </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Previous data has been discarded.<br />                     </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Probably it is reading on.</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">                    </span><span style="color: rgb(0, 0, 255);">continue</span><span style="color: rgb(0, 0, 0);">;<br />                 }<br />             } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (oldReaderIndex </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> cumulation.readerIndex()) {<br />                 </span><span style="color: rgb(0, 0, 255);">throw</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> IllegalStateException(<br />                         </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">decode() method must read at least one byte </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"><br />                         </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">if it returned a frame (caused by: </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> getClass() </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />             }<br />             </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">灝唌essagereceive浜嬩歡浼犵粰涓嬩釜upstreamhandler</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">            unfoldAndFireMessageReceived(context, remoteAddress, frame);<br />         }<br />     }</span></div> 鐪嬪瓙綾葷殑decode鏄浣曞垽鏂暟鎹鍙栧畬姣?br /> <div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 255);">protected</span><span style="color: rgb(0, 0, 0);"> Object decode(<br />             ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception {<br />         </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Try all delimiters and choose the delimiter which yields the shortest frame.</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> minFrameLength </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> Integer.MAX_VALUE;<br />         ChannelBuffer minDelim </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />         </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">鑾峰彇\r\n鐨勪綅緗?/span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> (ChannelBuffer delim: delimiters) {<br />             </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> frameLength </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> indexOf(buffer, delim);<br />             </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (frameLength </span><span style="color: rgb(0, 0, 0);">>=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">&&</span><span style="color: rgb(0, 0, 0);"> frameLength </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);"> minFrameLength) {<br />                 minFrameLength </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> frameLength;<br />                 minDelim </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> delim;<br />             }<br />         }<br />         </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">濡傛灉鎵懼埌\r\n錛岃〃鏄庡鎴風鏁版嵁鍙戦佸畬姣?/span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (minDelim </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">) {<br />             </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> minDelimLength </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> minDelim.capacity();<br />             ChannelBuffer frame;<br /> <br />             </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (discardingTooLongFrame) {<br />                 </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> We've just finished discarding a very large frame.<br />                 </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Go back to the initial state.</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">                discardingTooLongFrame </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">;<br />                 buffer.skipBytes(minFrameLength </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> minDelimLength);<br /> <br />                 </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> TODO Let user choose when the exception should be raised - early or late?<br />                 </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">      If early, fail() should be called when discardingTooLongFrame is set to true.</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> tooLongFrameLength </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.tooLongFrameLength;<br />                 </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.tooLongFrameLength </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />                 fail(ctx, tooLongFrameLength);<br />                 </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />             }<br /> <br />             </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (minFrameLength </span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"> maxFrameLength) {<br />                 </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Discard read frame.</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">                buffer.skipBytes(minFrameLength </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> minDelimLength);<br />                 fail(ctx, minFrameLength);<br />                 </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />             }<br /> <br />             </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (stripDelimiter) {<br />                 </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">榪欓噷璇誨彇鍏ㄩ儴鏁版嵁</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">                frame </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> buffer.readBytes(minFrameLength);<br />                 buffer.skipBytes(minDelimLength);<br />             } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> {<br />                 frame </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> buffer.readBytes(minFrameLength </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> minDelimLength);<br />             }<br /> <br />             </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> frame;<br />         } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> {<br />             </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 0);">!</span><span style="color: rgb(0, 0, 0);">discardingTooLongFrame) {<br />                 </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (buffer.readableBytes() </span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"> maxFrameLength) {<br />                     </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Discard the content of the buffer until a delimiter is found.</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">                    tooLongFrameLength </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> buffer.readableBytes();<br />                     buffer.skipBytes(buffer.readableBytes());<br />                     discardingTooLongFrame </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">;<br />                 }<br />             } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> {<br />                 </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Still discarding the buffer since a delimiter is not found.</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">                tooLongFrameLength </span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);"> buffer.readableBytes();<br />                 buffer.skipBytes(buffer.readableBytes());<br />             }<br />             </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />         }<br />     }</span></div> 鍥犱負unfold榛樿鏄痜alse錛屼細鎵ц錛岃皟鐢ㄤ笅涓涓猽pstreamhandler錛岃繖閲屾槸stringdecoder錛岄氳繃stringdecoder錛屽皢channelbuffer涓殑鏁版嵁杞負string<br /> 鐒跺悗鍐嶈Е鍙戜笅涓涓猽pstreamhandler鐨刴essagereceive錛岃繖閲屾槸TelnetServerHandler<br /> <div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> messageReceived(<br />             ChannelHandlerContext ctx, MessageEvent e) {<br /> <br />         </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Cast to a String first.<br />         </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> We know it is a String because we put some codec in TelnetPipelineFactory.</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">        String request </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (String) e.getMessage();<br /> <br />         </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Generate and write a response.</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">        String response;<br />         </span><span style="color: rgb(0, 0, 255);">boolean</span><span style="color: rgb(0, 0, 0);"> close </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">;<br />         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (request.length() </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">) {<br />             response </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Please type something.</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">r</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />         } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (request.toLowerCase().equals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">bye</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)) {<br />             response </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Have a good day!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">r</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />             close </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">;<br />         } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> {<br />             response </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Did you say '</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> request </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">'?</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">r</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />         }<br /> <br />         </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> We do not need to write a ChannelBuffer here.<br />         </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> We know the encoder inserted at TelnetPipelineFactory will do the conversion.</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">        ChannelFuture future </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> e.getChannel().write(response);<br /> <br />         </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Close the connection after sending 'Have a good day!'<br />         </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> if the client has sent 'bye'.</span><span style="color: rgb(0, 128, 0);"><br /> </span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (close) {<br />             future.addListener(ChannelFutureListener.CLOSE);<br />         }<br />     }</span></div> <br /> 鏁版嵁璇誨彇鍒嗘瀽瀹屾瘯錛屾帴鐫緇х畫鍒嗘瀽鏈嶅姟鍣ㄧ鏁版嵁鐨勫彂閫?br /> <br /> <br /> <img src ="http://m.tkk7.com/alex-zheng/aggbug/339751.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/alex-zheng/" target="_blank">alex_zheng</a> 2010-12-03 21:26 <a href="http://m.tkk7.com/alex-zheng/articles/339751.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>netty3.2.3婧愮爜鍒嗘瀽--ServerBootstrap鍚姩鍒嗘瀽http://m.tkk7.com/alex-zheng/articles/339552.htmlalex_zhengalex_zhengWed, 01 Dec 2010 13:37:00 GMThttp://m.tkk7.com/alex-zheng/articles/339552.htmlhttp://m.tkk7.com/alex-zheng/comments/339552.htmlhttp://m.tkk7.com/alex-zheng/articles/339552.html#Feedback0http://m.tkk7.com/alex-zheng/comments/commentRss/339552.htmlhttp://m.tkk7.com/alex-zheng/services/trackbacks/339552.html闃呰鍏ㄦ枃

alex_zheng 2010-12-01 21:37 鍙戣〃璇勮
]]>
jboss5.1+mysql5+spring3鏁版嵁搴搄ndi閰嶇疆http://m.tkk7.com/alex-zheng/articles/339204.htmlalex_zhengalex_zhengSat, 27 Nov 2010 08:58:00 GMThttp://m.tkk7.com/alex-zheng/articles/339204.htmlhttp://m.tkk7.com/alex-zheng/comments/339204.htmlhttp://m.tkk7.com/alex-zheng/articles/339204.html#Feedback0http://m.tkk7.com/alex-zheng/comments/commentRss/339204.htmlhttp://m.tkk7.com/alex-zheng/services/trackbacks/339204.html

1.灝唌ysql鐨凧DBC椹卞姩鏀懼埌鐨凧BOSS_HOME\server\default\lib 涓?wbr>

2.鎶奐BOSS_HOME\docs\examples\jca\mysql-ds.xml澶嶅埗鍒癑BOSS_HOME\server\default\deploy鐩綍涓嬨備慨鏀筸ysql- ds.xml鏂囦歡
 <local-tx-datasource>
    
<jndi-name>mysql</jndi-name>
    
<connection-url>jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=utf-8</connection-url>
    
<driver-class>com.mysql.jdbc.Driver</driver-class>
    
<user-name>alex</user-name>
    
<password>alex</password>
    <use-java-context>false</use-java-context> 
    
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
   

    
<!--pooling parameters-->
    
<min-pool-size>5</min-pool-size>
    
<max-pool-size>100</max-pool-size>
    
<blocking-timeout-millis>5000</blocking-timeout-millis>
    
<idle-timeout-minutes>15</idle-timeout-minutes>
    
<set-tx-query-timeout/>
    
<query-timeout>60</query-timeout> <!-- maximum of 1 minutes for queries -->

    
<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
    
<metadata>
       
<type-mapping>mySQL</type-mapping>
    
</metadata>

3.spring閰嶇疆鏂囦歡涓?br />
    <!--鍦╩ysql-ds.xml涓緗?/span>use-java-context涓篺alse鍚?娉ㄦ剰娌℃湁鍓嶇紑java錛?->
    <
jee:jndi-lookup id="dataSource" jndi-name="mysql" />
    
<bean id="txManager"
        class
="org.springframework.transaction.jta.JtaTransactionManager">
       <!--鎵嬪姩娉ㄥ叆錛屽惁鍒欎細鎶ransactionmanager not bound-->
        
<property name="transactionManagerName" value="java:/TransactionManager"/>
    
</bean>
鑷蟲錛宻pring3浣跨敤jboss鐨刯ta浜嬪姟綆$悊宸茬粡閰嶇疆瀹屾瘯銆?br />
閬楃暀闂錛?br /> 濡傛灉浣跨敤榛樿璁劇疆use-java-context涓簍rue錛岀劧鍚庝嬌鐢╦ndi name涓簀ava:mysql,鎻愮ずmysql not bound錛屽緢濂囨紝鍦╦boss鍚姩鐨勬椂鍊欏彲浠ョ湅鍒板皢mysql緇戝畾
鍒板懡鍚嶇┖闂磈ava:mysql




alex_zheng 2010-11-27 16:58 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 亚洲AV无码乱码国产麻豆| 国产亚洲精品VA片在线播放| 国产成人午夜精品免费视频| 亚洲AV色无码乱码在线观看 | 亚洲人成人伊人成综合网无码| 亚洲AV无码成人精品区狼人影院| 久久亚洲免费视频| 亚洲自偷自拍另类图片二区| 日韩高清在线高清免费| 免费无码又爽又刺激网站| 国产精品高清视亚洲一区二区| 免费在线观看h片| 免费一级毛片在线播放视频免费观看永久| free哆啪啪免费永久| WWW亚洲色大成网络.COM | 亚洲人成电影网站国产精品| 日韩精品在线免费观看| 亚洲国产欧洲综合997久久| 久久精品国产亚洲av成人| 免费一看一级毛片全播放| h片在线免费观看| igao激情在线视频免费| 亚洲中文字幕久久精品无码VA| 成人免费无毒在线观看网站| 成人爽a毛片免费| 免费无遮挡无遮羞在线看| 亚洲最新在线视频| 国产亚洲一区二区手机在线观看| 青青操在线免费观看| 亚洲av日韩综合一区久热| 色婷婷六月亚洲婷婷丁香| 亚洲国产综合久久天堂| 最新免费jlzzjlzz在线播放| 久久久久免费精品国产小说| sss在线观看免费高清| jzzijzzij在线观看亚洲熟妇| 亚洲欧洲久久久精品| 日韩高清在线免费看| 国产精品视频免费| 午夜精品射精入后重之免费观看| 亚洲精品免费在线视频|