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

📄 crawljobhandler.html

📁 用JAVA编写的,在做实验的时候留下来的,本来想删的,但是传上来,大家分享吧
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<a name="442" href="#442">442</a>     <em>/**<em>*</em></em><a name="443" href="#443">443</a> <em>     * Returns the default profile. If no default profile has been set it will</em><a name="444" href="#444">444</a> <em>     * return the first profile that was set/loaded and still exists. If no</em><a name="445" href="#445">445</a> <em>     * profiles exist it will return null</em><a name="446" href="#446">446</a> <em>     * @return the default profile.</em><a name="447" href="#447">447</a> <em>     */</em><a name="448" href="#448">448</a>     <strong>public</strong> <strong>synchronized</strong> <a href="../../../../org/archive/crawler/admin/CrawlJob.html">CrawlJob</a> getDefaultProfile() {<a name="449" href="#449">449</a>         <strong>if</strong>(defaultProfile != <strong>null</strong>){<a name="450" href="#450">450</a>             <strong>for</strong>(Iterator it = profileJobs.iterator(); it.hasNext();) {<a name="451" href="#451">451</a>                 <a href="../../../../org/archive/crawler/admin/CrawlJob.html">CrawlJob</a> item = (CrawlJob)it.next();<a name="452" href="#452">452</a>                 <strong>if</strong>(item.getJobName().equals(defaultProfile)){<a name="453" href="#453">453</a>                     <em class="comment">// Found it.</em><a name="454" href="#454">454</a>                     <strong>return</strong> item;<a name="455" href="#455">455</a>                 }<a name="456" href="#456">456</a>             }<a name="457" href="#457">457</a>         }<a name="458" href="#458">458</a>         <strong>if</strong>(profileJobs.size() > 0){<a name="459" href="#459">459</a>             <strong>return</strong> (CrawlJob)profileJobs.first();<a name="460" href="#460">460</a>         }<a name="461" href="#461">461</a>         <strong>return</strong> <strong>null</strong>;<a name="462" href="#462">462</a>     }<a name="463" href="#463">463</a> <a name="464" href="#464">464</a>     <em>/**<em>*</em></em><a name="465" href="#465">465</a> <em>     * Set the default profile.</em><a name="466" href="#466">466</a> <em>     * @param profile The new default profile. The following must apply to it.</em><a name="467" href="#467">467</a> <em>     *                profile.isProfile() should return true and</em><a name="468" href="#468">468</a> <em>     *                this.getProfiles() should contain it.</em><a name="469" href="#469">469</a> <em>     */</em><a name="470" href="#470">470</a>     <strong>public</strong> <strong>void</strong> setDefaultProfile(<a href="../../../../org/archive/crawler/admin/CrawlJob.html">CrawlJob</a> profile) {<a name="471" href="#471">471</a>         defaultProfile = profile.getJobName();<a name="472" href="#472">472</a>         <em class="comment">// TODO: Make changes to default profile durable across restarts.</em><a name="473" href="#473">473</a>     }<a name="474" href="#474">474</a> <a name="475" href="#475">475</a>     <em>/**<em>*</em></em><a name="476" href="#476">476</a> <em>     * A List of all pending jobs</em><a name="477" href="#477">477</a> <em>     *</em><a name="478" href="#478">478</a> <em>     * @return A List of all pending jobs.</em><a name="479" href="#479">479</a> <em>     * No promises are made about the order of the list</em><a name="480" href="#480">480</a> <em>     */</em><a name="481" href="#481">481</a>     <strong>public</strong> List getPendingJobs() {<a name="482" href="#482">482</a>         ArrayList tmp = <strong>new</strong> ArrayList(pendingCrawlJobs.size());<a name="483" href="#483">483</a>         tmp.addAll(pendingCrawlJobs);<a name="484" href="#484">484</a>         <strong>return</strong> tmp;<a name="485" href="#485">485</a>     }<a name="486" href="#486">486</a> <a name="487" href="#487">487</a>     <em>/**<em>*</em></em><a name="488" href="#488">488</a> <em>     * @return The job currently being crawled.</em><a name="489" href="#489">489</a> <em>     */</em><a name="490" href="#490">490</a>     <strong>public</strong> <a href="../../../../org/archive/crawler/admin/CrawlJob.html">CrawlJob</a> getCurrentJob() {<a name="491" href="#491">491</a>         <strong>return</strong> currentJob;<a name="492" href="#492">492</a>     }<a name="493" href="#493">493</a> <a name="494" href="#494">494</a>     <em>/**<em>*</em></em><a name="495" href="#495">495</a> <em>     * @return A List of all finished jobs.</em><a name="496" href="#496">496</a> <em>     */</em><a name="497" href="#497">497</a>     <strong>public</strong> List getCompletedJobs() {<a name="498" href="#498">498</a>         ArrayList tmp = <strong>new</strong> ArrayList(completedCrawlJobs.size());<a name="499" href="#499">499</a>         tmp.addAll(completedCrawlJobs);<a name="500" href="#500">500</a>         <strong>return</strong> tmp;<a name="501" href="#501">501</a>     }<a name="502" href="#502">502</a> <a name="503" href="#503">503</a>     <em>/**<em>*</em></em><a name="504" href="#504">504</a> <em>     * Return a job with the given UID.</em><a name="505" href="#505">505</a> <em>     * Doesn't matter if it's pending, currently running, has finished running</em><a name="506" href="#506">506</a> <em>     * is new or a profile.</em><a name="507" href="#507">507</a> <em>     *</em><a name="508" href="#508">508</a> <em>     * @param jobUID The unique ID of the job.</em><a name="509" href="#509">509</a> <em>     * @return The job with the UID or null if no such job is found</em><a name="510" href="#510">510</a> <em>     */</em><a name="511" href="#511">511</a>     <strong>public</strong> <a href="../../../../org/archive/crawler/admin/CrawlJob.html">CrawlJob</a> getJob(String jobUID) {<a name="512" href="#512">512</a>         <strong>if</strong> (jobUID == <strong>null</strong>){<a name="513" href="#513">513</a>             <strong>return</strong> <strong>null</strong>; <em class="comment">// UID can't be null</em><a name="514" href="#514">514</a>         }<a name="515" href="#515">515</a>         <em class="comment">// First check currently running job</em><a name="516" href="#516">516</a>         <strong>if</strong> (currentJob != <strong>null</strong> &amp;&amp; currentJob.getUID().equals(jobUID)) {<a name="517" href="#517">517</a>             <strong>return</strong> currentJob;<a name="518" href="#518">518</a>         } <strong>else</strong> <strong>if</strong> (newJob != <strong>null</strong> &amp;&amp; newJob.getUID().equals(jobUID)) {<a name="519" href="#519">519</a>             <em class="comment">// Then check the 'new job'</em><a name="520" href="#520">520</a>             <strong>return</strong> newJob;<a name="521" href="#521">521</a>         } <strong>else</strong> {<a name="522" href="#522">522</a>             <em class="comment">// Then check pending jobs.</em><a name="523" href="#523">523</a>             Iterator itPend = pendingCrawlJobs.iterator();<a name="524" href="#524">524</a>             <strong>while</strong> (itPend.hasNext()) {<a name="525" href="#525">525</a>                 <a href="../../../../org/archive/crawler/admin/CrawlJob.html">CrawlJob</a> cj = (CrawlJob) itPend.next();<a name="526" href="#526">526</a>                 <strong>if</strong> (cj.getUID().equals(jobUID)) {<a name="527" href="#527">527</a>                     <strong>return</strong> cj;<a name="528" href="#528">528</a>                 }<a name="529" href="#529">529</a>             }<a name="530" href="#530">530</a> <a name="531" href="#531">531</a>             <em class="comment">// Next check completed jobs.</em><a name="532" href="#532">532</a>             Iterator itComp = completedCrawlJobs.iterator();<a name="533" href="#533">533</a>             <strong>while</strong> (itComp.hasNext()) {<a name="534" href="#534">534</a>                 <a href="../../../../org/archive/crawler/admin/CrawlJob.html">CrawlJob</a> cj = (CrawlJob) itComp.next();<a name="535" href="#535">535</a>                 <strong>if</strong> (cj.getUID().equals(jobUID)) {<a name="536" href="#536">536</a>                     <strong>return</strong> cj;<a name="537" href="#537">537</a>                 }<a name="538" href="#538">538</a>             }<a name="539" href="#539">539</a> <a name="540" href="#540">540</a>             <em class="comment">// And finally check the profiles.</em><a name="541" href="#541">541</a>             <strong>for</strong> (Iterator i = getProfiles().iterator(); i.hasNext();) {<a name="542" href="#542">542</a>                 <a href="../../../../org/archive/crawler/admin/CrawlJob.html">CrawlJob</a> cj = (CrawlJob) i.next();<a name="543" href="#543">543</a>                 <strong>if</strong> (cj.getUID().equals(jobUID)) {<a name="544" href="#544">544</a>                     <strong>return</strong> cj;<a name="545" href="#545">545</a>                 }<a name="546" href="#546">546</a>             }<a name="547" href="#547">547</a>         }<a name="548" href="#548">548</a>         <strong>return</strong> <strong>null</strong>; <em class="comment">// Nothing found, return null</em><a name="549" href="#549">549</a>     }<a name="550" href="#550">550</a>     <a name="551" href="#551">551</a>     <em>/**<em>*</em></em><a name="552" href="#552">552</a> <em>     * @return True if we terminated a current job (False if no job to</em><a name="553" href="#553">553</a> <em>     * terminate)</em><a name="554" href="#554">554</a> <em>     */</em><a name="555" href="#555">555</a>     <strong>public</strong> <strong>boolean</strong> terminateCurrentJob() {<a name="556" href="#556">556</a>         <strong>if</strong> (<strong>this</strong>.currentJob == <strong>null</strong>) {<a name="557" href="#557">557</a>             <strong>return</strong> false;<a name="558" href="#558">558</a>         }<a name="559" href="#559">559</a>         <em class="comment">// requestCrawlStop will cause crawlEnding to be invoked.</em><a name="560" href="#560">560</a>         <em class="comment">// It will handle the clean up.</em><a name="561" href="#561">561</a>         <strong>this</strong>.currentJob.stopCrawling();<a name="562" href="#562">562</a>         <strong>synchronized</strong> (<strong>this</strong>) {<a name="563" href="#563">563</a>             <strong>try</strong> {<a name="564" href="#564">564</a>                 <em class="comment">// Take a few moments so that the controller can change</em><a name="565" href="#565">565</a>                 <em class="comment">// states before the UI updates. The CrawlEnding event</em><a name="566" href="#566">566</a>                 <em class="comment">// will wake us if it occurs sooner than this.</em><a name="567" href="#567">567</a>                 wait(3000);<a name="568" href="#568">568</a>             } <strong>catch</strong> (InterruptedException e) {<a name="569" href="#569">569</a>                 <em class="comment">// Ignore.</em><a name="570" href="#570">570</a>             }<a name="571" href="#571">571</a>         }<a name="572" href="#572">572</a>         <strong>return</strong> <strong>true</strong>;<a name="573" href="#573">573</a>     }<a name="574" href="#574">574</a> <a name="575" href="#575">575</a>     <em>/**<em>*</em></em><a name="576" href="#576">576</a> <em>     * The specified job will be removed from the pending queue or aborted if</em><a name="577" href="#577">577</a> <em>     * currently running.  It will be placed in the list of completed jobs with</em><a name="578" href="#578">578</a> <em>     * appropriate status info. If the job is already in the completed list or</em><a name="579" href="#579">579</a> <em>     * no job with the given UID is found, no action will be taken.</em><a name="580" href="#580">580</a> <em>     *</em><a name="581" href="#581">581</a> <em>     * @param jobUID The UID (unique ID) of the job that is to be deleted.</em><a name="582" href="#582">582</a> <em>     *</em><a name="583" href="#583">583</a> <em>     */</em><a name="584" href="#584">584</a>     <strong>public</strong> <strong>void</strong> deleteJob(String jobUID) {<a name="585" href="#585">585</a>         <em class="comment">// First check to see if we are deleting the current job.</em><a name="586" href="#586">586</a>         <strong>if</strong> (currentJob != <strong>null</strong> &amp;&amp; jobUID.equals(currentJob.getUID())) {<a name="587" href="#587">587</a>             terminateCurrentJob();<a name="588" href="#588">588</a>             <strong>return</strong>; <em class="comment">// We're not going to find another job with the same UID</em><a name="589" href="#589">589</a>         }<a name="590" href="#590">590</a>         <a name="591" href="#591">591</a>         <em class="comment">// Ok, it isn't the current job, let's check the pending jobs.</em>

⌨️ 快捷键说明

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