📄 profilertimerfilter.html
字号:
<a name="402" href="#402">402</a> <em class="jxr_javadoccomment">/**</em><a name="403" href="#403">403</a> <em class="jxr_javadoccomment"> * Add a new reading to this class. Total is updated</em><a name="404" href="#404">404</a> <em class="jxr_javadoccomment"> * and calls is incremented</em><a name="405" href="#405">405</a> <em class="jxr_javadoccomment"> *</em><a name="406" href="#406">406</a> <em class="jxr_javadoccomment"> * @param newReading</em><a name="407" href="#407">407</a> <em class="jxr_javadoccomment"> * The new reading</em><a name="408" href="#408">408</a> <em class="jxr_javadoccomment"> */</em><a name="409" href="#409">409</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> addNewReading(<strong class="jxr_keyword">long</strong> newReading) {<a name="410" href="#410">410</a> calls.incrementAndGet();<a name="411" href="#411">411</a> total.addAndGet(newReading);<a name="412" href="#412">412</a> <a name="413" href="#413">413</a> <strong class="jxr_keyword">synchronized</strong> (lock) {<a name="414" href="#414">414</a> <em class="jxr_comment">// this is not entirely thread-safe, must lock</em><a name="415" href="#415">415</a> <strong class="jxr_keyword">if</strong> (newReading < minimum.longValue()) {<a name="416" href="#416">416</a> minimum.set(newReading);<a name="417" href="#417">417</a> }<a name="418" href="#418">418</a> <a name="419" href="#419">419</a> <em class="jxr_comment">// this is not entirely thread-safe, must lock</em><a name="420" href="#420">420</a> <strong class="jxr_keyword">if</strong> (newReading > maximum.longValue()) {<a name="421" href="#421">421</a> maximum.set(newReading);<a name="422" href="#422">422</a> }<a name="423" href="#423">423</a> }<a name="424" href="#424">424</a> }<a name="425" href="#425">425</a> <a name="426" href="#426">426</a> <em class="jxr_javadoccomment">/**</em><a name="427" href="#427">427</a> <em class="jxr_javadoccomment"> * Gets the average reading for this event</em><a name="428" href="#428">428</a> <em class="jxr_javadoccomment"> *</em><a name="429" href="#429">429</a> <em class="jxr_javadoccomment"> * @return</em><a name="430" href="#430">430</a> <em class="jxr_javadoccomment"> * Gets the average reading for this event</em><a name="431" href="#431">431</a> <em class="jxr_javadoccomment"> */</em><a name="432" href="#432">432</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">double</strong> getAverage() {<a name="433" href="#433">433</a> <strong class="jxr_keyword">return</strong> total.longValue() / calls.longValue();<a name="434" href="#434">434</a> }<a name="435" href="#435">435</a> <a name="436" href="#436">436</a> <em class="jxr_javadoccomment">/**</em><a name="437" href="#437">437</a> <em class="jxr_javadoccomment"> * Returns the total number of readings</em><a name="438" href="#438">438</a> <em class="jxr_javadoccomment"> *</em><a name="439" href="#439">439</a> <em class="jxr_javadoccomment"> * @return</em><a name="440" href="#440">440</a> <em class="jxr_javadoccomment"> * total number of readings</em><a name="441" href="#441">441</a> <em class="jxr_javadoccomment"> */</em><a name="442" href="#442">442</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">long</strong> getCalls() {<a name="443" href="#443">443</a> <strong class="jxr_keyword">return</strong> calls.longValue();<a name="444" href="#444">444</a> }<a name="445" href="#445">445</a> <a name="446" href="#446">446</a> <em class="jxr_javadoccomment">/**</em><a name="447" href="#447">447</a> <em class="jxr_javadoccomment"> * Returns the total time</em><a name="448" href="#448">448</a> <em class="jxr_javadoccomment"> *</em><a name="449" href="#449">449</a> <em class="jxr_javadoccomment"> * @return</em><a name="450" href="#450">450</a> <em class="jxr_javadoccomment"> * the total time</em><a name="451" href="#451">451</a> <em class="jxr_javadoccomment"> */</em><a name="452" href="#452">452</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">long</strong> getTotal() {<a name="453" href="#453">453</a> <strong class="jxr_keyword">return</strong> total.longValue();<a name="454" href="#454">454</a> }<a name="455" href="#455">455</a> <a name="456" href="#456">456</a> <em class="jxr_javadoccomment">/**</em><a name="457" href="#457">457</a> <em class="jxr_javadoccomment"> * Returns the minimum value</em><a name="458" href="#458">458</a> <em class="jxr_javadoccomment"> *</em><a name="459" href="#459">459</a> <em class="jxr_javadoccomment"> * @return</em><a name="460" href="#460">460</a> <em class="jxr_javadoccomment"> * the minimum value</em><a name="461" href="#461">461</a> <em class="jxr_javadoccomment"> */</em><a name="462" href="#462">462</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">long</strong> getMinimum() {<a name="463" href="#463">463</a> <strong class="jxr_keyword">return</strong> minimum.longValue();<a name="464" href="#464">464</a> }<a name="465" href="#465">465</a> <a name="466" href="#466">466</a> <em class="jxr_javadoccomment">/**</em><a name="467" href="#467">467</a> <em class="jxr_javadoccomment"> * Returns the maximum value</em><a name="468" href="#468">468</a> <em class="jxr_javadoccomment"> *</em><a name="469" href="#469">469</a> <em class="jxr_javadoccomment"> * @return</em><a name="470" href="#470">470</a> <em class="jxr_javadoccomment"> * the maximum value</em><a name="471" href="#471">471</a> <em class="jxr_javadoccomment"> */</em><a name="472" href="#472">472</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">long</strong> getMaximum() {<a name="473" href="#473">473</a> <strong class="jxr_keyword">return</strong> maximum.longValue();<a name="474" href="#474">474</a> }<a name="475" href="#475">475</a> }<a name="476" href="#476">476</a> <a name="477" href="#477">477</a> <strong class="jxr_keyword">private</strong> enum <a href="../../../../../org/apache/mina/filter/statistic/ProfilerTimerFilter.html">ProfilerTimerUnit</a> {<a name="478" href="#478">478</a> SECONDS {<a name="479" href="#479">479</a> @Override<a name="480" href="#480">480</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">long</strong> timeNow() {<a name="481" href="#481">481</a> <strong class="jxr_keyword">return</strong> System.currentTimeMillis() / 1000;<a name="482" href="#482">482</a> }<a name="483" href="#483">483</a> <a name="484" href="#484">484</a> @Override<a name="485" href="#485">485</a> <strong class="jxr_keyword">public</strong> String getDescription() {<a name="486" href="#486">486</a> <strong class="jxr_keyword">return</strong> <span class="jxr_string">"seconds"</span>;<a name="487" href="#487">487</a> }<a name="488" href="#488">488</a> },<a name="489" href="#489">489</a> MILLISECONDS {<a name="490" href="#490">490</a> @Override<a name="491" href="#491">491</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">long</strong> timeNow() {<a name="492" href="#492">492</a> <strong class="jxr_keyword">return</strong> System.currentTimeMillis();<a name="493" href="#493">493</a> }<a name="494" href="#494">494</a> <a name="495" href="#495">495</a> @Override<a name="496" href="#496">496</a> <strong class="jxr_keyword">public</strong> String getDescription() {<a name="497" href="#497">497</a> <strong class="jxr_keyword">return</strong> <span class="jxr_string">"milliseconds"</span>;<a name="498" href="#498">498</a> }<a name="499" href="#499">499</a> },<a name="500" href="#500">500</a> NANOSECONDS {<a name="501" href="#501">501</a> @Override<a name="502" href="#502">502</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">long</strong> timeNow() {<a name="503" href="#503">503</a> <strong class="jxr_keyword">return</strong> System.nanoTime();<a name="504" href="#504">504</a> }<a name="505" href="#505">505</a> <a name="506" href="#506">506</a> @Override<a name="507" href="#507">507</a> <strong class="jxr_keyword">public</strong> String getDescription() {<a name="508" href="#508">508</a> <strong class="jxr_keyword">return</strong> <span class="jxr_string">"nanoseconds"</span>;<a name="509" href="#509">509</a> }<a name="510" href="#510">510</a> };<a name="511" href="#511">511</a> <a name="512" href="#512">512</a> <em class="jxr_comment">/*</em><a name="513" href="#513">513</a> <em class="jxr_comment"> * I was looking at possibly using the java.util.concurrent.TimeUnit</em><a name="514" href="#514">514</a> <em class="jxr_comment"> * and I found this construct for writing enums. Here is what the</em><a name="515" href="#515">515</a> <em class="jxr_comment"> * JDK developers say for why these methods below cannot be marked as</em><a name="516" href="#516">516</a> <em class="jxr_comment"> * abstract, but should act in an abstract way...</em><a name="517" href="#517">517</a> <em class="jxr_comment"> *</em><a name="518" href="#518">518</a> <em class="jxr_comment"> * To maintain full signature compatibility with 1.5, and to improve the</em><a name="519" href="#519">519</a> <em class="jxr_comment"> * clarity of the generated javadoc (see 6287639: Abstract methods in</em><a name="520" href="#520">520</a> <em class="jxr_comment"> * enum classes should not be listed as abstract), method convert</em><a name="521" href="#521">521</a> <em class="jxr_comment"> * etc. are not declared abstract but otherwise act as abstract methods.</em><a name="522" href="#522">522</a> <em class="jxr_comment"> */</em><a name="523" href="#523">523</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">long</strong> timeNow() {<a name="524" href="#524">524</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> AbstractMethodError();<a name="525" href="#525">525</a> }<a name="526" href="#526">526</a> <a name="527" href="#527">527</a> <strong class="jxr_keyword">public</strong> String getDescription() {<a name="528" href="#528">528</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> AbstractMethodError();<a name="529" href="#529">529</a> }<a name="530" href="#530">530</a> }<a name="531" href="#531">531</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 + -