📄 protocolcodecfilter.html
字号:
<a name="336" href="#336">336</a> decoder.dispose(session);<a name="337" href="#337">337</a> } <strong class="jxr_keyword">catch</strong> (Throwable t) {<a name="338" href="#338">338</a> logger.warn(<a name="339" href="#339">339</a> <span class="jxr_string">"Falied to dispose: "</span> + decoder.getClass().getName() + <span class="jxr_string">" ("</span> + decoder + ')');<a name="340" href="#340">340</a> }<a name="341" href="#341">341</a> }<a name="342" href="#342">342</a> <a name="343" href="#343">343</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> disposeDecoderOut(<a href="../../../../../org/apache/mina/common/IoSession.html">IoSession</a> session) {<a name="344" href="#344">344</a> session.removeAttribute(DECODER_OUT);<a name="345" href="#345">345</a> }<a name="346" href="#346">346</a> <a name="347" href="#347">347</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">class</strong> <a href="../../../../../org/apache/mina/filter/codec/ProtocolCodecFilter.html">EncodedWriteRequest</a> <strong class="jxr_keyword">extends</strong> <a href="../../../../../org/apache/mina/common/DefaultWriteRequest.html">DefaultWriteRequest</a> {<a name="348" href="#348">348</a> <strong class="jxr_keyword">private</strong> <a href="../../../../../org/apache/mina/filter/codec/ProtocolCodecFilter.html">EncodedWriteRequest</a>(Object encodedMessage,<a name="349" href="#349">349</a> <a href="../../../../../org/apache/mina/common/WriteFuture.html">WriteFuture</a> future, SocketAddress destination) {<a name="350" href="#350">350</a> <strong class="jxr_keyword">super</strong>(encodedMessage, future, destination);<a name="351" href="#351">351</a> }<a name="352" href="#352">352</a> }<a name="353" href="#353">353</a> <a name="354" href="#354">354</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">class</strong> <a href="../../../../../org/apache/mina/filter/codec/ProtocolCodecFilter.html">MessageWriteRequest</a> <strong class="jxr_keyword">extends</strong> <a href="../../../../../org/apache/mina/common/WriteRequestWrapper.html">WriteRequestWrapper</a> {<a name="355" href="#355">355</a> <strong class="jxr_keyword">private</strong> <a href="../../../../../org/apache/mina/filter/codec/ProtocolCodecFilter.html">MessageWriteRequest</a>(<a href="../../../../../org/apache/mina/common/WriteRequest.html">WriteRequest</a> writeRequest) {<a name="356" href="#356">356</a> <strong class="jxr_keyword">super</strong>(writeRequest);<a name="357" href="#357">357</a> }<a name="358" href="#358">358</a> <a name="359" href="#359">359</a> @Override<a name="360" href="#360">360</a> <strong class="jxr_keyword">public</strong> Object getMessage() {<a name="361" href="#361">361</a> <strong class="jxr_keyword">return</strong> EMPTY_BUFFER;<a name="362" href="#362">362</a> }<a name="363" href="#363">363</a> }<a name="364" href="#364">364</a> <a name="365" href="#365">365</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">class</strong> <a href="../../../../../org/apache/mina/filter/codec/ProtocolCodecFilter.html">ProtocolDecoderOutputImpl</a> <strong class="jxr_keyword">extends</strong><a name="366" href="#366">366</a> <a href="../../../../../org/apache/mina/filter/codec/AbstractProtocolDecoderOutput.html">AbstractProtocolDecoderOutput</a> {<a name="367" href="#367">367</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">final</strong> <a href="../../../../../org/apache/mina/common/IoSession.html">IoSession</a> session;<a name="368" href="#368">368</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">final</strong> <a href="../../../../../org/apache/mina/common/IoFilter.html">NextFilter</a> nextFilter;<a name="369" href="#369">369</a> <a name="370" href="#370">370</a> <strong class="jxr_keyword">public</strong> <a href="../../../../../org/apache/mina/filter/codec/ProtocolCodecFilter.html">ProtocolDecoderOutputImpl</a>(<a name="371" href="#371">371</a> <a href="../../../../../org/apache/mina/common/IoSession.html">IoSession</a> session, <a href="../../../../../org/apache/mina/common/IoFilter.html">NextFilter</a> nextFilter) {<a name="372" href="#372">372</a> <strong class="jxr_keyword">this</strong>.session = session;<a name="373" href="#373">373</a> <strong class="jxr_keyword">this</strong>.nextFilter = nextFilter;<a name="374" href="#374">374</a> }<a name="375" href="#375">375</a> <a name="376" href="#376">376</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> flush() {<a name="377" href="#377">377</a> Queue<Object> messageQueue = getMessageQueue();<a name="378" href="#378">378</a> <strong class="jxr_keyword">while</strong> (!messageQueue.isEmpty()) {<a name="379" href="#379">379</a> nextFilter.messageReceived(session, messageQueue.poll());<a name="380" href="#380">380</a> }<a name="381" href="#381">381</a> }<a name="382" href="#382">382</a> }<a name="383" href="#383">383</a> <a name="384" href="#384">384</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">class</strong> <a href="../../../../../org/apache/mina/filter/codec/ProtocolCodecFilter.html">ProtocolEncoderOutputImpl</a> <strong class="jxr_keyword">extends</strong><a name="385" href="#385">385</a> <a href="../../../../../org/apache/mina/filter/codec/AbstractProtocolEncoderOutput.html">AbstractProtocolEncoderOutput</a> {<a name="386" href="#386">386</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">final</strong> <a href="../../../../../org/apache/mina/common/IoSession.html">IoSession</a> session;<a name="387" href="#387">387</a> <a name="388" href="#388">388</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">final</strong> <a href="../../../../../org/apache/mina/common/IoFilter.html">NextFilter</a> nextFilter;<a name="389" href="#389">389</a> <a name="390" href="#390">390</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">final</strong> <a href="../../../../../org/apache/mina/common/WriteRequest.html">WriteRequest</a> writeRequest;<a name="391" href="#391">391</a> <a name="392" href="#392">392</a> <strong class="jxr_keyword">public</strong> <a href="../../../../../org/apache/mina/filter/codec/ProtocolCodecFilter.html">ProtocolEncoderOutputImpl</a>(<a href="../../../../../org/apache/mina/common/IoSession.html">IoSession</a> session,<a name="393" href="#393">393</a> <a href="../../../../../org/apache/mina/common/IoFilter.html">NextFilter</a> nextFilter, <a href="../../../../../org/apache/mina/common/WriteRequest.html">WriteRequest</a> writeRequest) {<a name="394" href="#394">394</a> <strong class="jxr_keyword">this</strong>.session = session;<a name="395" href="#395">395</a> <strong class="jxr_keyword">this</strong>.nextFilter = nextFilter;<a name="396" href="#396">396</a> <strong class="jxr_keyword">this</strong>.writeRequest = writeRequest;<a name="397" href="#397">397</a> }<a name="398" href="#398">398</a> <a name="399" href="#399">399</a> <strong class="jxr_keyword">public</strong> <a href="../../../../../org/apache/mina/common/WriteFuture.html">WriteFuture</a> flush() {<a name="400" href="#400">400</a> Queue<Object> bufferQueue = getMessageQueue();<a name="401" href="#401">401</a> <a href="../../../../../org/apache/mina/common/WriteFuture.html">WriteFuture</a> future = <strong class="jxr_keyword">null</strong>;<a name="402" href="#402">402</a> <strong class="jxr_keyword">for</strong> (;;) {<a name="403" href="#403">403</a> Object encodedMessage = bufferQueue.poll();<a name="404" href="#404">404</a> <strong class="jxr_keyword">if</strong> (encodedMessage == <strong class="jxr_keyword">null</strong>) {<a name="405" href="#405">405</a> <strong class="jxr_keyword">break</strong>;<a name="406" href="#406">406</a> }<a name="407" href="#407">407</a> <a name="408" href="#408">408</a> <em class="jxr_comment">// Flush only when the buffer has remaining.</em><a name="409" href="#409">409</a> <strong class="jxr_keyword">if</strong> (!(encodedMessage instanceof IoBuffer) ||<a name="410" href="#410">410</a> ((<a href="../../../../../org/apache/mina/common/IoBuffer.html">IoBuffer</a>) encodedMessage).hasRemaining()) {<a name="411" href="#411">411</a> future = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/mina/common/DefaultWriteFuture.html">DefaultWriteFuture</a>(session);<a name="412" href="#412">412</a> nextFilter.filterWrite(session, <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/mina/filter/codec/ProtocolCodecFilter.html">EncodedWriteRequest</a>(encodedMessage,<a name="413" href="#413">413</a> future, writeRequest.getDestination()));<a name="414" href="#414">414</a> }<a name="415" href="#415">415</a> }<a name="416" href="#416">416</a> <a name="417" href="#417">417</a> <strong class="jxr_keyword">if</strong> (future == <strong class="jxr_keyword">null</strong>) {<a name="418" href="#418">418</a> future = DefaultWriteFuture.newNotWrittenFuture(<a name="419" href="#419">419</a> session, <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/mina/common/NothingWrittenException.html">NothingWrittenException</a>(writeRequest));<a name="420" href="#420">420</a> }<a name="421" href="#421">421</a> <a name="422" href="#422">422</a> <strong class="jxr_keyword">return</strong> future;<a name="423" href="#423">423</a> }<a name="424" href="#424">424</a> <a name="425" href="#425">425</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> flushWithoutFuture() {<a name="426" href="#426">426</a> Queue<Object> bufferQueue = getMessageQueue();<a name="427" href="#427">427</a> <strong class="jxr_keyword">for</strong> (;;) {<a name="428" href="#428">428</a> Object encodedMessage = bufferQueue.poll();<a name="429" href="#429">429</a> <strong class="jxr_keyword">if</strong> (encodedMessage == <strong class="jxr_keyword">null</strong>) {<a name="430" href="#430">430</a> <strong class="jxr_keyword">break</strong>;<a name="431" href="#431">431</a> }<a name="432" href="#432">432</a> <a name="433" href="#433">433</a> <em class="jxr_comment">// Flush only when the buffer has remaining.</em><a name="434" href="#434">434</a> <strong class="jxr_keyword">if</strong> (!(encodedMessage instanceof IoBuffer) ||<a name="435" href="#435">435</a> ((<a href="../../../../../org/apache/mina/common/IoBuffer.html">IoBuffer</a>) encodedMessage).hasRemaining()) {<a name="436" href="#436">436</a> nextFilter.filterWrite(<a name="437" href="#437">437</a> session, <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/mina/filter/codec/ProtocolCodecFilter.html">EncodedWriteRequest</a>(<a name="438" href="#438">438</a> encodedMessage, <strong class="jxr_keyword">null</strong>, writeRequest.getDestination()));<a name="439" href="#439">439</a> }<a name="440" href="#440">440</a> }<a name="441" href="#441">441</a> }<a name="442" href="#442">442</a> }<a name="443" href="#443">443</a> }</pre><hr/><div id="footer">This page was automatically generated by <a href="http://maven.apache.org/">Maven</a></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -