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

📄 abstractioservice.html

📁 MINA+API 关于MINA的API
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<a name="247" href="#247">247</a> <a name="248" href="#248">248</a>         <strong class="jxr_keyword">if</strong> (isActive()) {<a name="249" href="#249">249</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> IllegalStateException(<span class="jxr_string">"handler cannot be set while the service is active."</span>);<a name="250" href="#250">250</a>         }<a name="251" href="#251">251</a> <a name="252" href="#252">252</a>         <strong class="jxr_keyword">this</strong>.handler = handler;<a name="253" href="#253">253</a>     }<a name="254" href="#254">254</a> <a name="255" href="#255">255</a>     <strong class="jxr_keyword">public</strong> <a href="../../../../org/apache/mina/common/IoSessionConfig.html">IoSessionConfig</a> getSessionConfig() {<a name="256" href="#256">256</a>         <strong class="jxr_keyword">return</strong> sessionConfig;<a name="257" href="#257">257</a>     }<a name="258" href="#258">258</a> <a name="259" href="#259">259</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> <a href="../../../../org/apache/mina/common/IoSessionDataStructureFactory.html">IoSessionDataStructureFactory</a> getSessionDataStructureFactory() {<a name="260" href="#260">260</a>         <strong class="jxr_keyword">return</strong> sessionDataStructureFactory;<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> <strong class="jxr_keyword">void</strong> setSessionDataStructureFactory(<a href="../../../../org/apache/mina/common/IoSessionDataStructureFactory.html">IoSessionDataStructureFactory</a> sessionDataStructureFactory) {<a name="264" href="#264">264</a>         <strong class="jxr_keyword">if</strong> (sessionDataStructureFactory == <strong class="jxr_keyword">null</strong>) {<a name="265" href="#265">265</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> NullPointerException(<span class="jxr_string">"sessionDataStructureFactory"</span>);<a name="266" href="#266">266</a>         }<a name="267" href="#267">267</a> <a name="268" href="#268">268</a>         <strong class="jxr_keyword">if</strong> (isActive()) {<a name="269" href="#269">269</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> IllegalStateException(<a name="270" href="#270">270</a>                     <span class="jxr_string">"sessionDataStructureFactory cannot be set while the service is active."</span>);<a name="271" href="#271">271</a>         }<a name="272" href="#272">272</a> <a name="273" href="#273">273</a>         <strong class="jxr_keyword">this</strong>.sessionDataStructureFactory = sessionDataStructureFactory;<a name="274" href="#274">274</a>     }<a name="275" href="#275">275</a> <a name="276" href="#276">276</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">long</strong> getReadBytes() {<a name="277" href="#277">277</a>         <strong class="jxr_keyword">return</strong> readBytes.get();<a name="278" href="#278">278</a>     }<a name="279" href="#279">279</a> <a name="280" href="#280">280</a>     <strong class="jxr_keyword">protected</strong> <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">void</strong> increaseReadBytes(<strong class="jxr_keyword">long</strong> increment, <strong class="jxr_keyword">long</strong> currentTime) {<a name="281" href="#281">281</a>         readBytes.addAndGet(increment);<a name="282" href="#282">282</a>         lastReadTime = currentTime;<a name="283" href="#283">283</a>         idleCountForBoth = 0;<a name="284" href="#284">284</a>         idleCountForRead = 0;<a name="285" href="#285">285</a>     }<a name="286" href="#286">286</a> <a name="287" href="#287">287</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">long</strong> getReadMessages() {<a name="288" href="#288">288</a>         <strong class="jxr_keyword">return</strong> readMessages.get();<a name="289" href="#289">289</a>     }<a name="290" href="#290">290</a> <a name="291" href="#291">291</a>     <strong class="jxr_keyword">protected</strong> <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">void</strong> increaseReadMessages(<strong class="jxr_keyword">long</strong> currentTime) {<a name="292" href="#292">292</a>         readMessages.incrementAndGet();<a name="293" href="#293">293</a>         lastReadTime = currentTime;<a name="294" href="#294">294</a>         idleCountForBoth = 0;<a name="295" href="#295">295</a>         idleCountForRead = 0;<a name="296" href="#296">296</a>     }<a name="297" href="#297">297</a> <a name="298" href="#298">298</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">int</strong> getThroughputCalculationInterval() {<a name="299" href="#299">299</a>         <strong class="jxr_keyword">return</strong> throughputCalculationInterval;<a name="300" href="#300">300</a>     }<a name="301" href="#301">301</a> <a name="302" href="#302">302</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">void</strong> setThroughputCalculationInterval(<strong class="jxr_keyword">int</strong> throughputCalculationInterval) {<a name="303" href="#303">303</a>         <strong class="jxr_keyword">if</strong> (throughputCalculationInterval &lt; 0) {<a name="304" href="#304">304</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> IllegalArgumentException(<a name="305" href="#305">305</a>                     <span class="jxr_string">"throughputCalculationInterval: "</span> + throughputCalculationInterval);<a name="306" href="#306">306</a>         }<a name="307" href="#307">307</a> <a name="308" href="#308">308</a>         <strong class="jxr_keyword">this</strong>.throughputCalculationInterval = throughputCalculationInterval;<a name="309" href="#309">309</a>     }<a name="310" href="#310">310</a>     <a name="311" href="#311">311</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">long</strong> getThroughputCalculationIntervalInMillis() {<a name="312" href="#312">312</a>         <strong class="jxr_keyword">return</strong> throughputCalculationInterval * 1000L;<a name="313" href="#313">313</a>     }<a name="314" href="#314">314</a>     <a name="315" href="#315">315</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> getReadBytesThroughput() {<a name="316" href="#316">316</a>         resetThroughput();<a name="317" href="#317">317</a>         <strong class="jxr_keyword">return</strong> readBytesThroughput;<a name="318" href="#318">318</a>     }<a name="319" href="#319">319</a> <a name="320" href="#320">320</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> getWrittenBytesThroughput() {<a name="321" href="#321">321</a>         resetThroughput();<a name="322" href="#322">322</a>         <strong class="jxr_keyword">return</strong> writtenBytesThroughput;<a name="323" href="#323">323</a>     }<a name="324" href="#324">324</a> <a name="325" href="#325">325</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> getReadMessagesThroughput() {<a name="326" href="#326">326</a>         resetThroughput();<a name="327" href="#327">327</a>         <strong class="jxr_keyword">return</strong> readMessagesThroughput;<a name="328" href="#328">328</a>     }<a name="329" href="#329">329</a> <a name="330" href="#330">330</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> getWrittenMessagesThroughput() {<a name="331" href="#331">331</a>         resetThroughput();<a name="332" href="#332">332</a>         <strong class="jxr_keyword">return</strong> writtenMessagesThroughput;<a name="333" href="#333">333</a>     }<a name="334" href="#334">334</a>     <a name="335" href="#335">335</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> getLargestReadBytesThroughput() {<a name="336" href="#336">336</a>         <strong class="jxr_keyword">return</strong> largestReadBytesThroughput;<a name="337" href="#337">337</a>     }<a name="338" href="#338">338</a>     <a name="339" href="#339">339</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> getLargestWrittenBytesThroughput() {<a name="340" href="#340">340</a>         <strong class="jxr_keyword">return</strong> largestWrittenBytesThroughput;<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">public</strong> <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> getLargestReadMessagesThroughput() {<a name="344" href="#344">344</a>         <strong class="jxr_keyword">return</strong> largestReadMessagesThroughput;<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">public</strong> <strong class="jxr_keyword">final</strong> <strong class="jxr_keyword">double</strong> getLargestWrittenMessagesThroughput() {<a name="348" href="#348">348</a>         <strong class="jxr_keyword">return</strong> largestWrittenMessagesThroughput;<a name="349" href="#349">349</a>     }<a name="350" href="#350">350</a>     <a name="351" href="#351">351</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> resetThroughput() {<a name="352" href="#352">352</a>         <strong class="jxr_keyword">if</strong> (getManagedSessionCount() == 0) {<a name="353" href="#353">353</a>             readBytesThroughput = 0;<a name="354" href="#354">354</a>             writtenBytesThroughput = 0;<a name="355" href="#355">355</a>             readMessagesThroughput = 0;<a name="356" href="#356">356</a>             writtenMessagesThroughput = 0;<a name="357" href="#357">357</a>         }<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">private</strong> <strong class="jxr_keyword">void</strong> updateThroughput(<strong class="jxr_keyword">long</strong> currentTime) {<a name="361" href="#361">361</a>         <strong class="jxr_keyword">synchronized</strong> (throughputCalculationLock) {<a name="362" href="#362">362</a>             <strong class="jxr_keyword">int</strong> interval = (<strong class="jxr_keyword">int</strong>) (currentTime - lastThroughputCalculationTime);<a name="363" href="#363">363</a>             <strong class="jxr_keyword">long</strong> minInterval = getThroughputCalculationIntervalInMillis();<a name="364" href="#364">364</a>             <strong class="jxr_keyword">if</strong> (minInterval == 0 || interval &lt; minInterval) {<a name="365" href="#365">365</a>                 <strong class="jxr_keyword">return</strong>;<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">long</strong> readBytes = <strong class="jxr_keyword">this</strong>.readBytes.get();<a name="369" href="#369">369</a>             <strong class="jxr_keyword">long</strong> writtenBytes = <strong class="jxr_keyword">this</strong>.writtenBytes.get();<a name="370" href="#370">370</a>             <strong class="jxr_keyword">long</strong> readMessages = <strong class="jxr_keyword">this</strong>.readMessages.get();<a name="371" href="#371">371</a>             <strong class="jxr_keyword">long</strong> writtenMessages = <strong class="jxr_keyword">this</strong>.writtenMessages.get();<a name="372" href="#372">372</a>             <a name="373" href="#373">373</a>             readBytesThroughput = (readBytes - lastReadBytes) * 1000.0 / interval;<a name="374" href="#374">374</a>             writtenBytesThroughput = (writtenBytes - lastWrittenBytes) * 1000.0 / interval;

⌨️ 快捷键说明

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