⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractiosession.html

📁 MINA+API 关于MINA的API
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<a name="245" href="#245">245</a>                         READY_READ_FUTURES, readyReadFutures);<a name="246" href="#246">246</a>             <strong class="jxr_keyword">if</strong> (oldReadyReadFutures != <strong class="jxr_keyword">null</strong>) {<a name="247" href="#247">247</a>                 readyReadFutures = oldReadyReadFutures;<a name="248" href="#248">248</a>             }<a name="249" href="#249">249</a>             <a name="250" href="#250">250</a>             <em class="jxr_comment">// Initialize waitingReadFutures together.</em><a name="251" href="#251">251</a>             Queue&lt;ReadFuture&gt; waitingReadFutures = <a name="252" href="#252">252</a>                 <strong class="jxr_keyword">new</strong> CircularQueue&lt;ReadFuture&gt;();<a name="253" href="#253">253</a>             setAttributeIfAbsent(WAITING_READ_FUTURES, waitingReadFutures);<a name="254" href="#254">254</a>         }<a name="255" href="#255">255</a>         <strong class="jxr_keyword">return</strong> readyReadFutures;<a name="256" href="#256">256</a>     }<a name="257" href="#257">257</a> <a name="258" href="#258">258</a>     @SuppressWarnings(<span class="jxr_string">"unchecked"</span>)<a name="259" href="#259">259</a>     <strong class="jxr_keyword">private</strong> Queue&lt;ReadFuture&gt; getWaitingReadFutures() {<a name="260" href="#260">260</a>         <strong class="jxr_keyword">return</strong> (Queue&lt;ReadFuture&gt;) getAttribute(WAITING_READ_FUTURES);<a name="261" href="#261">261</a>     }<a name="262" href="#262">262</a> <a name="263" href="#263">263</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> <a href="../../../../org/apache/mina/common/WriteFuture.html">WriteFuture</a> write(Object message) {<a name="264" href="#264">264</a>         <strong class="jxr_keyword">return</strong> write(message, <strong class="jxr_keyword">null</strong>);<a name="265" href="#265">265</a>     }<a name="266" href="#266">266</a> <a name="267" href="#267">267</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> <a href="../../../../org/apache/mina/common/WriteFuture.html">WriteFuture</a> write(Object message, SocketAddress remoteAddress) {<a name="268" href="#268">268</a>         <strong class="jxr_keyword">if</strong> (message == <strong class="jxr_keyword">null</strong>) {<a name="269" href="#269">269</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> NullPointerException(<span class="jxr_string">"message"</span>);<a name="270" href="#270">270</a>         }<a name="271" href="#271">271</a> <a name="272" href="#272">272</a>         <strong class="jxr_keyword">if</strong> (!getTransportMetadata().isConnectionless() &amp;&amp;<a name="273" href="#273">273</a>                 remoteAddress != <strong class="jxr_keyword">null</strong>) {<a name="274" href="#274">274</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> UnsupportedOperationException();<a name="275" href="#275">275</a>         }<a name="276" href="#276">276</a> <a name="277" href="#277">277</a>         <strong class="jxr_keyword">if</strong> (isClosing() || !isConnected()) {<a name="278" href="#278">278</a>             <a href="../../../../org/apache/mina/common/WriteFuture.html">WriteFuture</a> future = <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/mina/common/DefaultWriteFuture.html">DefaultWriteFuture</a>(<strong class="jxr_keyword">this</strong>);<a name="279" href="#279">279</a>             <a href="../../../../org/apache/mina/common/WriteRequest.html">WriteRequest</a> request = <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/mina/common/DefaultWriteRequest.html">DefaultWriteRequest</a>(message, future, remoteAddress);<a name="280" href="#280">280</a>             future.setException(<strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/mina/common/WriteToClosedSessionException.html">WriteToClosedSessionException</a>(request));<a name="281" href="#281">281</a>             <strong class="jxr_keyword">return</strong> future;<a name="282" href="#282">282</a>         }<a name="283" href="#283">283</a> <a name="284" href="#284">284</a>         FileChannel openedFileChannel = <strong class="jxr_keyword">null</strong>;<a name="285" href="#285">285</a>         <strong class="jxr_keyword">try</strong> {<a name="286" href="#286">286</a>             <strong class="jxr_keyword">if</strong> (message instanceof IoBuffer<a name="287" href="#287">287</a>                     &amp;&amp; !((IoBuffer) message).hasRemaining()) {<a name="288" href="#288">288</a>                 <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> IllegalArgumentException(<a name="289" href="#289">289</a>                 <span class="jxr_string">"message is empty. Forgot to call flip()?"</span>);<a name="290" href="#290">290</a>             } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (message instanceof FileChannel) {<a name="291" href="#291">291</a>                 FileChannel fileChannel = (FileChannel) message;<a name="292" href="#292">292</a>                 message = <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/mina/common/DefaultFileRegion.html">DefaultFileRegion</a>(fileChannel, 0, fileChannel.size());<a name="293" href="#293">293</a>             } <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (message instanceof File) {<a name="294" href="#294">294</a>                 File file = (File) message;<a name="295" href="#295">295</a>                 openedFileChannel = <strong class="jxr_keyword">new</strong> FileInputStream(file).getChannel();<a name="296" href="#296">296</a>                 message = <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/mina/common/DefaultFileRegion.html">DefaultFileRegion</a>(openedFileChannel, 0, openedFileChannel.size());<a name="297" href="#297">297</a>             }<a name="298" href="#298">298</a>         } <strong class="jxr_keyword">catch</strong> (IOException e) {<a name="299" href="#299">299</a>             ExceptionMonitor.getInstance().exceptionCaught(e);<a name="300" href="#300">300</a>             <strong class="jxr_keyword">return</strong> DefaultWriteFuture.newNotWrittenFuture(<strong class="jxr_keyword">this</strong>, e);<a name="301" href="#301">301</a>         }<a name="302" href="#302">302</a> <a name="303" href="#303">303</a>         <a href="../../../../org/apache/mina/common/WriteFuture.html">WriteFuture</a> future = <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/mina/common/DefaultWriteFuture.html">DefaultWriteFuture</a>(<strong class="jxr_keyword">this</strong>);<a name="304" href="#304">304</a>         getFilterChain().fireFilterWrite(<a name="305" href="#305">305</a>                 <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/mina/common/DefaultWriteRequest.html">DefaultWriteRequest</a>(message, future, remoteAddress));<a name="306" href="#306">306</a> <a name="307" href="#307">307</a>         <strong class="jxr_keyword">if</strong> (openedFileChannel != <strong class="jxr_keyword">null</strong>) {<a name="308" href="#308">308</a>             <em class="jxr_comment">// If we opened a FileChannel, it needs to be closed when the write has completed</em><a name="309" href="#309">309</a>             <strong class="jxr_keyword">final</strong> FileChannel finalChannel = openedFileChannel;<a name="310" href="#310">310</a>             future.addListener(<strong class="jxr_keyword">new</strong> IoFutureListener&lt;WriteFuture&gt;() {<a name="311" href="#311">311</a>                 <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> operationComplete(<a href="../../../../org/apache/mina/common/WriteFuture.html">WriteFuture</a> future) {<a name="312" href="#312">312</a>                     <strong class="jxr_keyword">try</strong> {<a name="313" href="#313">313</a>                         finalChannel.close();<a name="314" href="#314">314</a>                     } <strong class="jxr_keyword">catch</strong> (IOException e) {<a name="315" href="#315">315</a>                         ExceptionMonitor.getInstance().exceptionCaught(e);<a name="316" href="#316">316</a>                     }<a name="317" href="#317">317</a>                 }<a name="318" href="#318">318</a>             });<a name="319" href="#319">319</a>         }<a name="320" href="#320">320</a> <a name="321" href="#321">321</a>         <strong class="jxr_keyword">return</strong> future;<a name="322" href="#322">322</a>     }<a name="323" href="#323">323</a> <a name="324" href="#324">324</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> Object getAttachment() {<a name="325" href="#325">325</a>         <strong class="jxr_keyword">return</strong> getAttribute(<span class="jxr_string">""</span>);<a name="326" href="#326">326</a>     }<a name="327" href="#327">327</a> <a name="328" href="#328">328</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> Object setAttachment(Object attachment) {<a name="329" href="#329">329</a>         <strong class="jxr_keyword">return</strong> setAttribute(<span class="jxr_string">""</span>, attachment);<a name="330" href="#330">330</a>     }<a name="331" href="#331">331</a> <a name="332" href="#332">332</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> Object getAttribute(Object key) {<a name="333" href="#333">333</a>         <strong class="jxr_keyword">return</strong> getAttribute(key, <strong class="jxr_keyword">null</strong>);<a name="334" href="#334">334</a>     }<a name="335" href="#335">335</a> <a name="336" href="#336">336</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> Object getAttribute(Object key, Object defaultValue) {<a name="337" href="#337">337</a>         <strong class="jxr_keyword">return</strong> attributes.getAttribute(<strong class="jxr_keyword">this</strong>, key, defaultValue);<a name="338" href="#338">338</a>     }<a name="339" href="#339">339</a> <a name="340" href="#340">340</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> Object setAttribute(Object key, Object value) {<a name="341" href="#341">341</a>         <strong class="jxr_keyword">return</strong> attributes.setAttribute(<strong class="jxr_keyword">this</strong>, key, value);<a name="342" href="#342">342</a>     }<a name="343" href="#343">343</a> <a name="344" href="#344">344</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> Object setAttribute(Object key) {<a name="345" href="#345">345</a>         <strong class="jxr_keyword">return</strong> setAttribute(key, Boolean.TRUE);<a name="346" href="#346">346</a>     }<a name="347" href="#347">347</a> <a name="348" href="#348">348</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> Object setAttributeIfAbsent(Object key, Object value) {<a name="349" href="#349">349</a>         <strong class="jxr_keyword">return</strong> attributes.setAttributeIfAbsent(<strong class="jxr_keyword">this</strong>, key, value);<a name="350" href="#350">350</a>     }<a name="351" href="#351">351</a> <a name="352" href="#352">352</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> Object setAttributeIfAbsent(Object key) {<a name="353" href="#353">353</a>         <strong class="jxr_keyword">return</strong> setAttributeIfAbsent(key, Boolean.TRUE);<a name="354" href="#354">354</a>     }<a name="355" href="#355">355</a> <a name="356" href="#356">356</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> Object removeAttribute(Object key) {<a name="357" href="#357">357</a>         <strong class="jxr_keyword">return</strong> attributes.removeAttribute(<strong class="jxr_keyword">this</strong>, key);<a name="358" href="#358">358</a>     }<a name="359" href="#359">359</a> <a name="360" href="#360">360</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">boolean</strong> removeAttribute(Object key, Object value) {<a name="361" href="#361">361</a>         <strong class="jxr_keyword">return</strong> attributes.removeAttribute(<strong class="jxr_keyword">this</strong>, key, value);<a name="362" href="#362">362</a>     }<a name="363" href="#363">363</a> <a name="364" href="#364">364</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">boolean</strong> replaceAttribute(Object key, Object oldValue, Object newValue) {<a name="365" href="#365">365</a>         <strong class="jxr_keyword">return</strong> attributes.replaceAttribute(<strong class="jxr_keyword">this</strong>, key, oldValue, newValue);<a name="366" href="#366">366</a>     }<a name="367" href="#367">367</a> <a name="368" href="#368">368</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">boolean</strong> containsAttribute(Object key) {<a name="369" href="#369">369</a>         <strong class="jxr_keyword">return</strong> attributes.containsAttribute(<strong class="jxr_keyword">this</strong>, key);<a name="370" href="#370">370</a>     }<a name="371" href="#371">371</a> 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -