📄 workqueuefrontier.html
字号:
<a name="421" href="#421">421</a> <em> */</em><a name="422" href="#422">422</a> <strong>public</strong> <strong>void</strong> receive(<a href="../../../../org/archive/crawler/datamodel/CandidateURI.html">CandidateURI</a> caUri) {<a name="423" href="#423">423</a> <a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi = asCrawlUri(caUri);<a name="424" href="#424">424</a> applySpecialHandling(curi);<a name="425" href="#425">425</a> sendToQueue(curi);<a name="426" href="#426">426</a> <em class="comment">// Update recovery log.</em><a name="427" href="#427">427</a> doJournalAdded(curi);<a name="428" href="#428">428</a> }<a name="429" href="#429">429</a> <a name="430" href="#430">430</a> <em class="comment">/*<em class="comment"> (non-Javadoc)</em></em><a name="431" href="#431">431</a> <em class="comment"> * @see org.archive.crawler.frontier.AbstractFrontier#asCrawlUri(org.archive.crawler.datamodel.CandidateURI)</em><a name="432" href="#432">432</a> <em class="comment"> */</em><a name="433" href="#433">433</a> <strong>protected</strong> <a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> asCrawlUri(<a href="../../../../org/archive/crawler/datamodel/CandidateURI.html">CandidateURI</a> caUri) {<a name="434" href="#434">434</a> CrawlURI curi = <strong>super</strong>.asCrawlUri(caUri);<a name="435" href="#435">435</a> <em class="comment">// force cost to be calculated, pre-insert</em><a name="436" href="#436">436</a> getCost(curi);<a name="437" href="#437">437</a> <strong>return</strong> curi;<a name="438" href="#438">438</a> }<a name="439" href="#439">439</a> <a name="440" href="#440">440</a> <em>/**<em>*</em></em><a name="441" href="#441">441</a> <em> * Send a CrawlURI to the appropriate subqueue.</em><a name="442" href="#442">442</a> <em> * </em><a name="443" href="#443">443</a> <em> * @param curi</em><a name="444" href="#444">444</a> <em> */</em><a name="445" href="#445">445</a> <strong>protected</strong> <strong>void</strong> sendToQueue(<a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi) {<a name="446" href="#446">446</a> <a href="../../../../org/archive/crawler/frontier/WorkQueue.html">WorkQueue</a> wq = getQueueFor(curi);<a name="447" href="#447">447</a> <strong>synchronized</strong> (wq) {<a name="448" href="#448">448</a> wq.enqueue(<strong>this</strong>, curi);<a name="449" href="#449">449</a> <strong>if</strong>(!wq.isRetired()) {<a name="450" href="#450">450</a> incrementQueuedUriCount();<a name="451" href="#451">451</a> }<a name="452" href="#452">452</a> <strong>if</strong>(!wq.isHeld()) {<a name="453" href="#453">453</a> wq.setHeld();<a name="454" href="#454">454</a> <strong>if</strong>(holdQueues() && readyClassQueues.size()>=targetSizeForReadyQueues()) {<a name="455" href="#455">455</a> deactivateQueue(wq);<a name="456" href="#456">456</a> } <strong>else</strong> {<a name="457" href="#457">457</a> replenishSessionBalance(wq);<a name="458" href="#458">458</a> readyQueue(wq);<a name="459" href="#459">459</a> }<a name="460" href="#460">460</a> }<a name="461" href="#461">461</a> <a href="../../../../org/archive/crawler/frontier/WorkQueue.html">WorkQueue</a> laq = longestActiveQueue;<a name="462" href="#462">462</a> <strong>if</strong>(!wq.isRetired()&&((laq==<strong>null</strong>) || wq.getCount() > laq.getCount())) {<a name="463" href="#463">463</a> longestActiveQueue = wq; <a name="464" href="#464">464</a> }<a name="465" href="#465">465</a> }<a name="466" href="#466">466</a> }<a name="467" href="#467">467</a> <a name="468" href="#468">468</a> <em>/**<em>*</em></em><a name="469" href="#469">469</a> <em> * Whether queues should start inactive (only becoming active when needed</em><a name="470" href="#470">470</a> <em> * to keep the crawler busy), or if queues should start out ready.</em><a name="471" href="#471">471</a> <em> * </em><a name="472" href="#472">472</a> <em> * @return true if new queues should held inactive</em><a name="473" href="#473">473</a> <em> */</em><a name="474" href="#474">474</a> <strong>private</strong> <strong>boolean</strong> holdQueues() {<a name="475" href="#475">475</a> <strong>return</strong> ((Boolean) getUncheckedAttribute(<strong>null</strong>, ATTR_HOLD_QUEUES))<a name="476" href="#476">476</a> .booleanValue();<a name="477" href="#477">477</a> }<a name="478" href="#478">478</a> <a name="479" href="#479">479</a> <em>/**<em>*</em></em><a name="480" href="#480">480</a> <em> * Put the given queue on the readyClassQueues queue</em><a name="481" href="#481">481</a> <em> * @param wq</em><a name="482" href="#482">482</a> <em> */</em><a name="483" href="#483">483</a> <strong>private</strong> <strong>void</strong> readyQueue(<a href="../../../../org/archive/crawler/frontier/WorkQueue.html">WorkQueue</a> wq) {<a name="484" href="#484">484</a> <strong>try</strong> {<a name="485" href="#485">485</a> wq.setActive(<strong>this</strong>, <strong>true</strong>);<a name="486" href="#486">486</a> readyClassQueues.put(wq.getClassKey());<a name="487" href="#487">487</a> } <strong>catch</strong> (InterruptedException e) {<a name="488" href="#488">488</a> e.printStackTrace();<a name="489" href="#489">489</a> System.err.println(<span class="string">"unable to ready queue "</span>+wq);<a name="490" href="#490">490</a> <em class="comment">// propagate interrupt up </em><a name="491" href="#491">491</a> <strong>throw</strong> <strong>new</strong> RuntimeException(e);<a name="492" href="#492">492</a> }<a name="493" href="#493">493</a> }<a name="494" href="#494">494</a> <a name="495" href="#495">495</a> <em>/**<em>*</em></em><a name="496" href="#496">496</a> <em> * Put the given queue on the inactiveQueues queue</em><a name="497" href="#497">497</a> <em> * @param wq</em><a name="498" href="#498">498</a> <em> */</em><a name="499" href="#499">499</a> <strong>private</strong> <strong>void</strong> deactivateQueue(<a href="../../../../org/archive/crawler/frontier/WorkQueue.html">WorkQueue</a> wq) {<a name="500" href="#500">500</a> <strong>try</strong> {<a name="501" href="#501">501</a> wq.setSessionBalance(0); <em class="comment">// zero out session balance</em><a name="502" href="#502">502</a> inactiveQueues.put(wq.getClassKey());<a name="503" href="#503">503</a> wq.setActive(<strong>this</strong>, false);<a name="504" href="#504">504</a> } <strong>catch</strong> (InterruptedException e) {<a name="505" href="#505">505</a> e.printStackTrace();<a name="506" href="#506">506</a> System.err.println(<span class="string">"unable to deactivate queue "</span>+wq);<a name="507" href="#507">507</a> <em class="comment">// propagate interrupt up </em><a name="508" href="#508">508</a> <strong>throw</strong> <strong>new</strong> RuntimeException(e);<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>/**<em>*</em></em><a name="513" href="#513">513</a> <em> * Put the given queue on the retiredQueues queue</em><a name="514" href="#514">514</a> <em> * @param wq</em><a name="515" href="#515">515</a> <em> */</em><a name="516" href="#516">516</a> <strong>private</strong> <strong>void</strong> retireQueue(<a href="../../../../org/archive/crawler/frontier/WorkQueue.html">WorkQueue</a> wq) {<a name="517" href="#517">517</a> <strong>try</strong> {<a name="518" href="#518">518</a> retiredQueues.put(wq.getClassKey());<a name="519" href="#519">519</a> decrementQueuedCount(wq.getCount());<a name="520" href="#520">520</a> wq.setRetired(<strong>true</strong>);<a name="521" href="#521">521</a> wq.setActive(<strong>this</strong>, false);<a name="522" href="#522">522</a> } <strong>catch</strong> (InterruptedException e) {<a name="523" href="#523">523</a> e.printStackTrace();<a name="524" href="#524">524</a> System.err.println(<span class="string">"unable to retire queue "</span>+wq);<a name="525" href="#525">525</a> <em class="comment">// propagate interrupt up </em><a name="526" href="#526">526</a> <strong>throw</strong> <strong>new</strong> RuntimeException(e);<a name="527" href="#527">527</a> }<a name="528" href="#528">528</a> }<a name="529" href="#529">529</a> <a name="530" href="#530">530</a> <em>/**<em>* </em></em><a name="531" href="#531">531</a> <em> * Accomodate any changes in settings.</em><a name="532" href="#532">532</a> <em> * </em><a name="533" href="#533">533</a> <em> * @see org.archive.crawler.framework.Frontier#kickUpdate()</em><a name="534" href="#534">534</a> <em> */</em><a name="535" href="#535">535</a> <strong>public</strong> <strong>void</strong> kickUpdate() {<a name="536" href="#536">536</a> <strong>super</strong>.kickUpdate();<a name="537" href="#537">537</a> <strong>int</strong> target = (Integer)getUncheckedAttribute(<strong>null</strong>,<a name="538" href="#538">538</a> ATTR_TARGET_READY_QUEUES_BACKLOG);<a name="539" href="#539">539</a> <strong>if</strong> (target < 1) {<a name="540" href="#540">540</a> target = 1;<a name="541" href="#541">541</a> }<a name="542" href="#542">542</a> <strong>this</strong>.targetSizeForReadyQueues = target; <a name="543" href="#543">543</a> <strong>try</strong> {<a name="544" href="#544">544</a> initCostPolicy();<a name="545" href="#545">545</a> } <strong>catch</strong> (FatalConfigurationException fce) {<a name="546" href="#546">546</a> <strong>throw</strong> <strong>new</strong> RuntimeException(fce);<a name="547" href="#547">547</a> }<a name="548" href="#548">548</a> <em class="comment">// The rules for a 'retired' queue may have changed; so,</em><a name="549" href="#549">549</a> <em class="comment">// unretire all queues to 'inactive'. If they still qualify</em><a name="550" href="#550">550</a> <em class="comment">// as retired/overbudget next time they come up, they'll</em><a name="551" href="#551">551</a> <em class="comment">// be re-retired; if not, they'll get a chance to become</em><a name="552" href="#552">552</a> <em class="comment">// active under the new rules.</em><a name="553" href="#553">553</a> Object key = <strong>this</strong>.retiredQueues.poll();<a name="554" href="#554">554</a> <strong>while</strong> (key != <strong>null</strong>) {<a name="555" href="#555">555</a> <a href="../../../../org/archive/crawler/frontier/WorkQueue.html">WorkQueue</a> q = (WorkQueue)<strong>this</strong>.allQueues.get(key);<a name="556" href="#556">556</a> <strong>if</strong>(q != <strong>null</strong>) {<a name="557" href="#557">557</a> unretireQueue(q);<a name="558" href="#558">558</a> }<a name="559" href="#559">559</a> key = <strong>this</strong>.retiredQueues.poll();<a name="560" href="#560">560</a> }<a name="561" href="#561">561</a> }<a name="562" href="#562">562</a> <em>/**<em>*</em></em><a name="563" href="#563">563</a> <em> * Restore a retired queue to the 'inactive' state. </em>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -