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

📄 readthrottlefilter.html

📁 MINA+API 关于MINA的API
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<a name="483" href="#483">483</a> <a name="484" href="#484">484</a>         <strong class="jxr_keyword">int</strong> maxGlobalBufferSize = <strong class="jxr_keyword">this</strong>.maxGlobalBufferSize;<a name="485" href="#485">485</a>         <strong class="jxr_keyword">int</strong> maxServiceBufferSize = <strong class="jxr_keyword">this</strong>.maxServiceBufferSize;<a name="486" href="#486">486</a>         <strong class="jxr_keyword">int</strong> maxSessionBufferSize = <strong class="jxr_keyword">this</strong>.maxSessionBufferSize;<a name="487" href="#487">487</a>         <a name="488" href="#488">488</a>         <strong class="jxr_keyword">int</strong> sessionBufferSize;<a name="489" href="#489">489</a>         <a name="490" href="#490">490</a>         <strong class="jxr_keyword">boolean</strong> enforcePolicy = false;<a name="491" href="#491">491</a>         <strong class="jxr_keyword">synchronized</strong> (state) {<a name="492" href="#492">492</a>             sessionBufferSize = (state.sessionBufferSize -= size);<a name="493" href="#493">493</a>             <strong class="jxr_keyword">if</strong> (sessionBufferSize &lt; 0) {<a name="494" href="#494">494</a>                 <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> IllegalStateException(<span class="jxr_string">"sessionBufferSize: "</span> + sessionBufferSize);<a name="495" href="#495">495</a>             }<a name="496" href="#496">496</a>             <strong class="jxr_keyword">if</strong> ((maxGlobalBufferSize == 0 || globalBufferSize &lt; maxGlobalBufferSize) &amp;&amp;<a name="497" href="#497">497</a>                 (maxServiceBufferSize == 0 || serviceBufferSize &lt; maxServiceBufferSize) &amp;&amp;<a name="498" href="#498">498</a>                 (maxSessionBufferSize == 0 || sessionBufferSize &lt; maxSessionBufferSize)) {<a name="499" href="#499">499</a>                 state.suspendedRead = false;<a name="500" href="#500">500</a>                 enforcePolicy = <strong class="jxr_keyword">true</strong>;<a name="501" href="#501">501</a>             }<a name="502" href="#502">502</a>         }<a name="503" href="#503">503</a>         <a name="504" href="#504">504</a>         <strong class="jxr_keyword">if</strong> (logger.isDebugEnabled()) {<a name="505" href="#505">505</a>             logger.debug(getMessage(session, <span class="jxr_string">"   Exited - "</span>));<a name="506" href="#506">506</a>         }<a name="507" href="#507">507</a>         <a name="508" href="#508">508</a>         <strong class="jxr_keyword">if</strong> (enforcePolicy) {<a name="509" href="#509">509</a>             session.resumeRead();<a name="510" href="#510">510</a>             <strong class="jxr_keyword">if</strong> (logger.isDebugEnabled()) {<a name="511" href="#511">511</a>                 logger.debug(getMessage(session, <span class="jxr_string">"  Resumed - "</span>));<a name="512" href="#512">512</a>             }<a name="513" href="#513">513</a>         }<a name="514" href="#514">514</a>         <a name="515" href="#515">515</a>         resumeOthers();<a name="516" href="#516">516</a>     }<a name="517" href="#517">517</a>     <a name="518" href="#518">518</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> resumeOthers() {<a name="519" href="#519">519</a>         <strong class="jxr_keyword">long</strong> currentTime = System.currentTimeMillis();<a name="520" href="#520">520</a>         <a name="521" href="#521">521</a>         <em class="jxr_comment">// Try to resume other sessions every other second.</em><a name="522" href="#522">522</a>         <strong class="jxr_keyword">boolean</strong> resumeOthers;<a name="523" href="#523">523</a>         <strong class="jxr_keyword">synchronized</strong> (globalResumeLock) {<a name="524" href="#524">524</a>             <strong class="jxr_keyword">if</strong> (currentTime - lastGlobalResumeTime &gt; 1000) {<a name="525" href="#525">525</a>                 lastGlobalResumeTime = currentTime;<a name="526" href="#526">526</a>                 resumeOthers = <strong class="jxr_keyword">true</strong>;<a name="527" href="#527">527</a>             } <strong class="jxr_keyword">else</strong> {<a name="528" href="#528">528</a>                 resumeOthers = false;<a name="529" href="#529">529</a>             }<a name="530" href="#530">530</a>         }<a name="531" href="#531">531</a>         <a name="532" href="#532">532</a>         <strong class="jxr_keyword">if</strong> (resumeOthers) {<a name="533" href="#533">533</a>             <strong class="jxr_keyword">int</strong> maxGlobalBufferSize = <strong class="jxr_keyword">this</strong>.maxGlobalBufferSize;<a name="534" href="#534">534</a>             <strong class="jxr_keyword">if</strong> (maxGlobalBufferSize == 0 || globalBufferSize.get() &lt; maxGlobalBufferSize) {<a name="535" href="#535">535</a>                 List&lt;IoService&gt; inactiveServices = <strong class="jxr_keyword">null</strong>;<a name="536" href="#536">536</a>                 <strong class="jxr_keyword">for</strong> (IoService service: serviceBufferSizes.keySet()) {<a name="537" href="#537">537</a>                     resumeService(service);<a name="538" href="#538">538</a>                     <a name="539" href="#539">539</a>                     <strong class="jxr_keyword">if</strong> (!service.isActive()) {<a name="540" href="#540">540</a>                         <strong class="jxr_keyword">if</strong> (inactiveServices == <strong class="jxr_keyword">null</strong>) {<a name="541" href="#541">541</a>                             inactiveServices = <strong class="jxr_keyword">new</strong> ArrayList&lt;IoService&gt;();<a name="542" href="#542">542</a>                         }<a name="543" href="#543">543</a>                         inactiveServices.add(service);<a name="544" href="#544">544</a>                     }<a name="545" href="#545">545</a>                     <a name="546" href="#546">546</a>                     <em class="jxr_comment">// Remove inactive services from the map.</em><a name="547" href="#547">547</a>                     <strong class="jxr_keyword">if</strong> (inactiveServices != <strong class="jxr_keyword">null</strong>) {<a name="548" href="#548">548</a>                         <strong class="jxr_keyword">for</strong> (IoService s: inactiveServices) {<a name="549" href="#549">549</a>                             serviceBufferSizes.remove(s);<a name="550" href="#550">550</a>                         }<a name="551" href="#551">551</a>                     }<a name="552" href="#552">552</a> <a name="553" href="#553">553</a>                     <strong class="jxr_keyword">synchronized</strong> (globalResumeLock) {<a name="554" href="#554">554</a>                         lastGlobalResumeTime = System.currentTimeMillis();<a name="555" href="#555">555</a>                     }<a name="556" href="#556">556</a>                 }<a name="557" href="#557">557</a>             }<a name="558" href="#558">558</a>         }<a name="559" href="#559">559</a>     }<a name="560" href="#560">560</a>     <a name="561" href="#561">561</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> resumeService(<a href="../../../../../org/apache/mina/common/IoService.html">IoService</a> service) {<a name="562" href="#562">562</a>         <strong class="jxr_keyword">int</strong> maxServiceBufferSize = <strong class="jxr_keyword">this</strong>.maxServiceBufferSize;<a name="563" href="#563">563</a>         <strong class="jxr_keyword">if</strong> (maxServiceBufferSize == 0 || getServiceBufferSize(service) &lt; maxServiceBufferSize) {<a name="564" href="#564">564</a>             <strong class="jxr_keyword">for</strong> (IoSession session: service.getManagedSessions()) {<a name="565" href="#565">565</a>                 resume(session);<a name="566" href="#566">566</a>             }<a name="567" href="#567">567</a>         }<a name="568" href="#568">568</a>     }<a name="569" href="#569">569</a>     <a name="570" href="#570">570</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> resume(<a href="../../../../../org/apache/mina/common/IoSession.html">IoSession</a> session) {<a name="571" href="#571">571</a>         <a href="../../../../../org/apache/mina/filter/traffic/ReadThrottleFilter.html">State</a> state = (State) session.getAttribute(STATE);<a name="572" href="#572">572</a>         <strong class="jxr_keyword">if</strong> (state == <strong class="jxr_keyword">null</strong>) {<a name="573" href="#573">573</a>             <strong class="jxr_keyword">return</strong>;<a name="574" href="#574">574</a>         }<a name="575" href="#575">575</a>         <a name="576" href="#576">576</a>         <strong class="jxr_keyword">int</strong> maxSessionBufferSize = <strong class="jxr_keyword">this</strong>.maxSessionBufferSize;<a name="577" href="#577">577</a>         <strong class="jxr_keyword">boolean</strong> resume = false;<a name="578" href="#578">578</a>         <strong class="jxr_keyword">synchronized</strong> (state) {<a name="579" href="#579">579</a>             <strong class="jxr_keyword">if</strong> ((maxSessionBufferSize == 0 || state.sessionBufferSize &lt; maxSessionBufferSize)) {<a name="580" href="#580">580</a>                 state.suspendedRead = false;<a name="581" href="#581">581</a>                 resume = <strong class="jxr_keyword">true</strong>;<a name="582" href="#582">582</a>             }<a name="583" href="#583">583</a>         }<a name="584" href="#584">584</a> <a name="585" href="#585">585</a>         <strong class="jxr_keyword">if</strong> (resume) {<a name="586" href="#586">586</a>             session.resumeRead();<a name="587" href="#587">587</a>             <strong class="jxr_keyword">if</strong> (logger.isDebugEnabled()) {<a name="588" href="#588">588</a>                 logger.debug(getMessage(session, <span class="jxr_string">"  Resumed - "</span>));<a name="589" href="#589">589</a>             }<a name="590" href="#590">590</a>         }<a name="591" href="#591">591</a>     }<a name="592" href="#592">592</a> <a name="593" href="#593">593</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> log(<a href="../../../../../org/apache/mina/common/IoSession.html">IoSession</a> session, <a href="../../../../../org/apache/mina/filter/traffic/ReadThrottleFilter.html">State</a> state) {<a name="594" href="#594">594</a>         <strong class="jxr_keyword">long</strong> currentTime = System.currentTimeMillis();<a name="595" href="#595">595</a>         <a name="596" href="#596">596</a>         <em class="jxr_comment">// Prevent log flood by logging every 3 seconds.</em><a name="597" href="#597">597</a>         <strong class="jxr_keyword">boolean</strong> log;<a name="598" href="#598">598</a>         <strong class="jxr_keyword">synchronized</strong> (state.logLock) {<a name="599" href="#599">599</a>             <strong class="jxr_keyword">if</strong> (currentTime - state.lastLogTime &gt; 3000) {<a name="600" href="#600">600</a>                 state.lastLogTime = currentTime;<a name="601" href="#601">601</a>                 log = <strong class="jxr_keyword">true</strong>;<a name="602" href="#602">602</a>             } <stro

⌨️ 快捷键说明

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