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

📄 workqueue.html

📁 用JAVA编写的,在做实验的时候留下来的,本来想删的,但是传上来,大家分享吧
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<a name="290" href="#290">290</a>         isHeld = false;<a name="291" href="#291">291</a>     }<a name="292" href="#292">292</a> <a name="293" href="#293">293</a>     <em>/**<em>*</em></em><a name="294" href="#294">294</a> <em>     * Whether the queue is already in a lifecycle stage --</em><a name="295" href="#295">295</a> <em>     * such as ready, in-progress, snoozed -- and thus should</em><a name="296" href="#296">296</a> <em>     * not be redundantly inserted to readyClassQueues</em><a name="297" href="#297">297</a> <em>     * </em><a name="298" href="#298">298</a> <em>     * @return isHeld</em><a name="299" href="#299">299</a> <em>     */</em><a name="300" href="#300">300</a>     <strong>public</strong> <strong>boolean</strong> isHeld() {<a name="301" href="#301">301</a>         <strong>return</strong> isHeld;<a name="302" href="#302">302</a>     }<a name="303" href="#303">303</a> <a name="304" href="#304">304</a>     <em>/**<em>*</em></em><a name="305" href="#305">305</a> <em>     * Set isHeld to true</em><a name="306" href="#306">306</a> <em>     */</em><a name="307" href="#307">307</a>     <strong>public</strong> <strong>void</strong> setHeld() {<a name="308" href="#308">308</a>         isHeld = <strong>true</strong>;<a name="309" href="#309">309</a>     }<a name="310" href="#310">310</a> <a name="311" href="#311">311</a>     <em>/**<em>*</em></em><a name="312" href="#312">312</a> <em>     * Forgive the peek, allowing a subsequent peek to </em><a name="313" href="#313">313</a> <em>     * return a different item. </em><a name="314" href="#314">314</a> <em>     * </em><a name="315" href="#315">315</a> <em>     */</em><a name="316" href="#316">316</a>     <strong>public</strong> <strong>void</strong> unpeek() {<a name="317" href="#317">317</a>         peekItem = <strong>null</strong>;<a name="318" href="#318">318</a>     }<a name="319" href="#319">319</a> <a name="320" href="#320">320</a>     <strong>public</strong> <strong>final</strong> <strong>int</strong> compareTo(Object obj) {<a name="321" href="#321">321</a>         <strong>if</strong>(<strong>this</strong> == obj) {<a name="322" href="#322">322</a>             <strong>return</strong> 0; <em class="comment">// for exact identity only</em><a name="323" href="#323">323</a>         }<a name="324" href="#324">324</a>         <a href="../../../../org/archive/crawler/frontier/WorkQueue.html">WorkQueue</a> other = (WorkQueue) obj;<a name="325" href="#325">325</a>         <strong>if</strong>(getWakeTime() > other.getWakeTime()) {<a name="326" href="#326">326</a>             <strong>return</strong> 1;<a name="327" href="#327">327</a>         }<a name="328" href="#328">328</a>         <strong>if</strong>(getWakeTime() &lt; other.getWakeTime()) {<a name="329" href="#329">329</a>             <strong>return</strong> -1;<a name="330" href="#330">330</a>         }<a name="331" href="#331">331</a>         <em class="comment">// at this point, the ordering is arbitrary, but still</em><a name="332" href="#332">332</a>         <em class="comment">// must be consistent/stable over time</em><a name="333" href="#333">333</a>         <strong>return</strong> <strong>this</strong>.classKey.compareTo(other.getClassKey());<a name="334" href="#334">334</a>     }<a name="335" href="#335">335</a> <a name="336" href="#336">336</a>     <em>/**<em>*</em></em><a name="337" href="#337">337</a> <em>     * Update the given CrawlURI, which should already be present. (This</em><a name="338" href="#338">338</a> <em>     * is not checked.) Equivalent to an enqueue without affecting the count.</em><a name="339" href="#339">339</a> <em>     * </em><a name="340" href="#340">340</a> <em>     * @param frontier Work queues manager.</em><a name="341" href="#341">341</a> <em>     * @param curi CrawlURI to update.</em><a name="342" href="#342">342</a> <em>     */</em><a name="343" href="#343">343</a>     <strong>public</strong> <strong>void</strong> update(<strong>final</strong> <a href="../../../../org/archive/crawler/frontier/WorkQueueFrontier.html">WorkQueueFrontier</a> frontier, <a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi) {<a name="344" href="#344">344</a>         <strong>try</strong> {<a name="345" href="#345">345</a>             insert(frontier, curi);<a name="346" href="#346">346</a>         } <strong>catch</strong> (IOException e) {<a name="347" href="#347">347</a>             <em class="comment">//FIXME better exception handling</em><a name="348" href="#348">348</a>             e.printStackTrace();<a name="349" href="#349">349</a>             <strong>throw</strong> <strong>new</strong> RuntimeException(e);<a name="350" href="#350">350</a>         }<a name="351" href="#351">351</a>     }<a name="352" href="#352">352</a> <a name="353" href="#353">353</a>     <em>/**<em>*</em></em><a name="354" href="#354">354</a> <em>     * @return Returns the count.</em><a name="355" href="#355">355</a> <em>     */</em><a name="356" href="#356">356</a>     <strong>public</strong> <strong>synchronized</strong> <strong>long</strong> getCount() {<a name="357" href="#357">357</a>         <strong>return</strong> <strong>this</strong>.count;<a name="358" href="#358">358</a>     }<a name="359" href="#359">359</a> <a name="360" href="#360">360</a>     <em>/**<em>*</em></em><a name="361" href="#361">361</a> <em>     * Insert the given curi, whether it is already present or not. </em><a name="362" href="#362">362</a> <em>     * @param frontier WorkQueueFrontier.</em><a name="363" href="#363">363</a> <em>     * @param curi CrawlURI to insert.</em><a name="364" href="#364">364</a> <em>     * @throws IOException</em><a name="365" href="#365">365</a> <em>     */</em><a name="366" href="#366">366</a>     <strong>private</strong> <strong>void</strong> insert(<strong>final</strong> <a href="../../../../org/archive/crawler/frontier/WorkQueueFrontier.html">WorkQueueFrontier</a> frontier, <a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi)<a name="367" href="#367">367</a>         throws IOException {<a name="368" href="#368">368</a>         insertItem(frontier, curi);<a name="369" href="#369">369</a>         lastQueued = curi.toString();<a name="370" href="#370">370</a>     }<a name="371" href="#371">371</a> <a name="372" href="#372">372</a>     <em>/**<em>*</em></em><a name="373" href="#373">373</a> <em>     * Insert the given curi, whether it is already present or not.</em><a name="374" href="#374">374</a> <em>     * Hook for subclasses. </em><a name="375" href="#375">375</a> <em>     * </em><a name="376" href="#376">376</a> <em>     * @param frontier WorkQueueFrontier.</em><a name="377" href="#377">377</a> <em>     * @param curi CrawlURI to insert.</em><a name="378" href="#378">378</a> <em>     * @throws IOException  if there was a problem while inserting the item</em><a name="379" href="#379">379</a> <em>     */</em><a name="380" href="#380">380</a>     <strong>protected</strong> <strong>abstract</strong> <strong>void</strong> insertItem(<strong>final</strong> <a href="../../../../org/archive/crawler/frontier/WorkQueueFrontier.html">WorkQueueFrontier</a> frontier,<a name="381" href="#381">381</a>         <a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi) throws IOException;<a name="382" href="#382">382</a> <a name="383" href="#383">383</a>     <em>/**<em>*</em></em><a name="384" href="#384">384</a> <em>     * Delete URIs matching the given pattern from this queue. </em><a name="385" href="#385">385</a> <em>     * @param frontier WorkQueues manager.</em><a name="386" href="#386">386</a> <em>     * @param match  the pattern to match</em><a name="387" href="#387">387</a> <em>     * @return count of deleted URIs</em><a name="388" href="#388">388</a> <em>     * @throws IOException  if there was a problem while deleting</em><a name="389" href="#389">389</a> <em>     */</em><a name="390" href="#390">390</a>     <strong>protected</strong> <strong>abstract</strong> <strong>long</strong> deleteMatchingFromQueue(<a name="391" href="#391">391</a>         <strong>final</strong> <a href="../../../../org/archive/crawler/frontier/WorkQueueFrontier.html">WorkQueueFrontier</a> frontier, <strong>final</strong> String match)<a name="392" href="#392">392</a>         throws IOException;<a name="393" href="#393">393</a> <a name="394" href="#394">394</a>     <em>/**<em>*</em></em><a name="395" href="#395">395</a> <em>     * Removes the given item from the queue.</em><a name="396" href="#396">396</a> <em>     * </em><a name="397" href="#397">397</a> <em>     * This is only used to remove the first item in the queue,</em><a name="398" href="#398">398</a> <em>     * so it is not necessary to implement a random-access queue.</em><a name="399" href="#399">399</a> <em>     * </em><a name="400" href="#400">400</a> <em>     * @param frontier  Work queues manager.</em><a name="401" href="#401">401</a> <em>     * @throws IOException  if there was a problem while deleting the item</em><a name="402" href="#402">402</a> <em>     */</em><a name="403" href="#403">403</a>     <strong>protected</strong> <strong>abstract</strong> <strong>void</strong> deleteItem(<strong>final</strong> <a href="../../../../org/archive/crawler/frontier/WorkQueueFrontier.html">WorkQueueFrontier</a> frontier,<a name="404" href="#404">404</a>         <strong>final</strong> <a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> item) throws IOException;<a name="405" href="#405">405</a> <a name="406" href="#406">406</a>     <em>/**<em>*</em></em><a name="407" href="#407">407</a> <em>     * Returns first item from queue (does not delete)</em><a name="408" href="#408">408</a> <em>     * </em><a name="409" href="#409">409</a> <em>     * @return The peeked item, or null</em><a name="410" href="#410">410</a> <em>     * @throws IOException  if there was a problem while peeking</em><a name="411" href="#411">411</a> <em>     */</em><a name="412" href="#412">412</a>     <strong>protected</strong> <strong>abstract</strong> <a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> peekItem(<strong>final</strong> <a href="../../../../org/archive/crawler/frontier/WorkQueueFrontier.html">WorkQueueFrontier</a> frontier)<a name="413" href="#413">413</a>         throws IOException;<a name="414" href="#414">414</a> <a name="415" href="#415">415</a>     <em>/**<em>*</em></em><a name="416" href="#416">416</a> <em>     * Suspends this WorkQueue. Closes all connections to resources etc.</em><a name="417" href="#417">417</a> <em>     * </em><a name="418" href="#418">418</a> <em>     * @param frontier</em><a name="419" href="#419">419</a> <em>     * @throws IOException</em><a name="420" href="#420">420</a> <em>     */</em><a name="421" href="#421">421</a>     <strong>protected</strong> <strong>void</strong> suspend(<strong>final</strong> <a href="../../../../org/archive/crawler/frontier/WorkQueueFrontier.html">WorkQueueFrontier</a> frontier) throws IOException {<a name="422" href="#422">422</a>     }<a name="423" href="#423">423</a> <a name="424" href="#424">424</a>     <em>/**<em>*</em></em><a name="425" href="#425">425</a> <em>     * Resumes this WorkQueue. Eventually opens connections to resources etc.</em><a name="426" href="#426">426</a> <em>     * </em><a name="427" href="#427">427</a> <em>     * @param frontier</em><a name="428" href="#428">428</a> <em>     * @throws IOException</em><a name="429" href="#429">429</a> <em>     */</em><a name="430" href="#430">430</a>     <strong>protected</strong> <strong>void</strong> resume(<strong>final</strong> <a href="../../../../org/archive/crawler/frontier/WorkQueueFrontier.html">WorkQueueFrontier</a> frontier) throws IOException {<a name="431" href="#431">431</a>     }<a name="432" href="#432">432</a> <a name="433" href="#433">433</a>     <strong>public</strong> <strong>void</strong> setActive(<strong>final</strong> <a href="../../../../org/archive/crawler/frontier/WorkQueueFrontier.html">WorkQueueFrontier</a> frontier, <strong>final</strong> <strong>boolean</strong> b) {<a name="434" href="#434">434</a>         <strong>if</strong>(active != b) {<a name="435" href="#435">435</a>             active = b;<a name="436" href="#436">436</a>             <strong>try</strong> {<a name="437" href="#437">437</a>                 <strong>if</strong>(active) {<a name="438" href="#438">438</a>                     resume(frontier);

⌨️ 快捷键说明

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