📄 crawlcontroller.html
字号:
<a name="276" href="#276">276</a> <em>/**<em>*</em></em><a name="277" href="#277">277</a> <em> * List of crawl status listeners.</em><a name="278" href="#278">278</a> <em> *</em><a name="279" href="#279">279</a> <em> * All iterations need to synchronize on this object if they're to avoid</em><a name="280" href="#280">280</a> <em> * concurrent modification exceptions.</em><a name="281" href="#281">281</a> <em> * See {@link java.util.Collections#synchronizedList(List)}.</em><a name="282" href="#282">282</a> <em> */</em><a name="283" href="#283">283</a> <strong>private</strong> <strong>transient</strong> List registeredCrawlStatusListeners =<a name="284" href="#284">284</a> Collections.synchronizedList(<strong>new</strong> ArrayList());<a name="285" href="#285">285</a> <a name="286" href="#286">286</a> <em class="comment">// Since there is a high probability that there will only ever by one</em><a name="287" href="#287">287</a> <em class="comment">// CrawlURIDispositionListner we will use this while there is only one:</em><a name="288" href="#288">288</a> <strong>private</strong> <strong>transient</strong> <a href="../../../../org/archive/crawler/event/CrawlURIDispositionListener.html">CrawlURIDispositionListener</a><a name="289" href="#289">289</a> registeredCrawlURIDispositionListener;<a name="290" href="#290">290</a> <a name="291" href="#291">291</a> <em class="comment">// And then switch to the array once there is more then one.</em><a name="292" href="#292">292</a> <strong>protected</strong> <strong>transient</strong> ArrayList registeredCrawlURIDispositionListeners;<a name="293" href="#293">293</a> <a name="294" href="#294">294</a> <em>/**<em>* Shared bdb Environment for <a href="../../../../org/archive/crawler/framework/Frontier.html">Frontier</a> subcomponents */</em></em><a name="295" href="#295">295</a> <em class="comment">// TODO: investigate using multiple environments to split disk accesses</em><a name="296" href="#296">296</a> <em class="comment">// across separate physical disks</em><a name="297" href="#297">297</a> <strong>private</strong> <strong>transient</strong> Environment bdbEnvironment = <strong>null</strong>;<a name="298" href="#298">298</a> <a name="299" href="#299">299</a> <em>/**<em>*</em></em><a name="300" href="#300">300</a> <em> * Shared class catalog database. Used by the</em><a name="301" href="#301">301</a> <em> * {@link #classCatalog}.</em><a name="302" href="#302">302</a> <em> */</em><a name="303" href="#303">303</a> <strong>private</strong> <strong>transient</strong> Database classCatalogDB = <strong>null</strong>;<a name="304" href="#304">304</a> <a name="305" href="#305">305</a> <em>/**<em>*</em></em><a name="306" href="#306">306</a> <em> * Class catalog instance.</em><a name="307" href="#307">307</a> <em> * Used by bdb serialization.</em><a name="308" href="#308">308</a> <em> */</em><a name="309" href="#309">309</a> <strong>private</strong> <strong>transient</strong> StoredClassCatalog classCatalog = <strong>null</strong>;<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> * Keep a list of all BigMap instance made -- shouldn't be many -- so that</em><a name="313" href="#313">313</a> <em> * we can checkpoint.</em><a name="314" href="#314">314</a> <em> */</em><a name="315" href="#315">315</a> <strong>private</strong> <strong>transient</strong> Map bigmaps = <strong>null</strong>;<a name="316" href="#316">316</a> <a name="317" href="#317">317</a> <em>/**<em>*</em></em><a name="318" href="#318">318</a> <em> * Default constructor</em><a name="319" href="#319">319</a> <em> */</em><a name="320" href="#320">320</a> <strong>public</strong> <a href="../../../../org/archive/crawler/framework/CrawlController.html">CrawlController</a>() {<a name="321" href="#321">321</a> <strong>super</strong>();<a name="322" href="#322">322</a> <em class="comment">// Defer most setup to initialize methods</em><a name="323" href="#323">323</a> }<a name="324" href="#324">324</a> <a name="325" href="#325">325</a> <em>/**<em>*</em></em><a name="326" href="#326">326</a> <em> * Starting from nothing, set up CrawlController and associated</em><a name="327" href="#327">327</a> <em> * classes to be ready for a first crawl.</em><a name="328" href="#328">328</a> <em> *</em><a name="329" href="#329">329</a> <em> * @param sH Settings handler.</em><a name="330" href="#330">330</a> <em> * @throws InitializationException</em><a name="331" href="#331">331</a> <em> */</em><a name="332" href="#332">332</a> <strong>public</strong> <strong>void</strong> initialize(<a href="../../../../org/archive/crawler/settings/SettingsHandler.html">SettingsHandler</a> sH)<a name="333" href="#333">333</a> throws <a href="../../../../org/archive/crawler/framework/exceptions/InitializationException.html">InitializationException</a> {<a name="334" href="#334">334</a> sendCrawlStateChangeEvent(PREPARING, CrawlJob.STATUS_PREPARING);<a name="335" href="#335">335</a> <a name="336" href="#336">336</a> <strong>this</strong>.singleThreadLock = <strong>new</strong> ReentrantLock();<a name="337" href="#337">337</a> <strong>this</strong>.settingsHandler = sH;<a name="338" href="#338">338</a> <strong>this</strong>.order = settingsHandler.getOrder();<a name="339" href="#339">339</a> <strong>this</strong>.order.setController(<strong>this</strong>);<a name="340" href="#340">340</a> <strong>this</strong>.bigmaps = <strong>new</strong> Hashtable();<a name="341" href="#341">341</a> sExit = <span class="string">""</span>;<a name="342" href="#342">342</a> <strong>this</strong>.manifest = <strong>new</strong> StringBuffer();<a name="343" href="#343">343</a> String onFailMessage = <span class="string">""</span>;<a name="344" href="#344">344</a> <strong>try</strong> {<a name="345" href="#345">345</a> onFailMessage = <span class="string">"You must set the User-Agent and From HTTP"</span> +<a name="346" href="#346">346</a> <span class="string">" header values to acceptable strings. \n"</span> +<a name="347" href="#347">347</a> <span class="string">" User-Agent: [software-name](+[info-url])[misc]\n"</span> +<a name="348" href="#348">348</a> <span class="string">" From: [email-address]\n"</span>;<a name="349" href="#349">349</a> order.checkUserAgentAndFrom();<a name="350" href="#350">350</a> <a name="351" href="#351">351</a> onFailMessage = <span class="string">"Unable to setup disk"</span>;<a name="352" href="#352">352</a> <strong>if</strong> (disk == <strong>null</strong>) {<a name="353" href="#353">353</a> setupDisk();<a name="354" href="#354">354</a> }<a name="355" href="#355">355</a> <a name="356" href="#356">356</a> onFailMessage = <span class="string">"Unable to create log file(s)"</span>;<a name="357" href="#357">357</a> setupLogs();<a name="358" href="#358">358</a> <a name="359" href="#359">359</a> <em class="comment">// Figure if we're to do a checkpoint restore. If so, get the</em><a name="360" href="#360">360</a> <em class="comment">// checkpointRecover instance and then put into place the old bdb</em><a name="361" href="#361">361</a> <em class="comment">// log files. If any of the log files already exist in target state</em><a name="362" href="#362">362</a> <em class="comment">// diretory, WE DO NOT OVERWRITE (Makes for faster recovery).</em><a name="363" href="#363">363</a> <em class="comment">// CrawlController checkpoint recovery code manages restoration of</em><a name="364" href="#364">364</a> <em class="comment">// the old StatisticsTracker, any BigMaps used by the Crawler and</em><a name="365" href="#365">365</a> <em class="comment">// the moving of bdb log files into place only. Other objects</em><a name="366" href="#366">366</a> <em class="comment">// interested in recovery need to ask if</em><a name="367" href="#367">367</a> <em class="comment">// CrawlController#isCheckpointRecover is set to figure if in</em><a name="368" href="#368">368</a> <em class="comment">// recovery and then take appropriate recovery action</em><a name="369" href="#369">369</a> <em class="comment">// (These objects can call CrawlController#getCheckpointRecover</em><a name="370" href="#370">370</a> <em class="comment">// to get the directory that might hold files/objects dropped</em><a name="371" href="#371">371</a> <em class="comment">// checkpointing). Such objects will need to use a technique other</em><a name="372" href="#372">372</a> <em class="comment">// than object serialization restoring settings because they'll</em><a name="373" href="#373">373</a> <em class="comment">// have already been constructed when comes time for object to ask</em><a name="374" href="#374">374</a> <em class="comment">// if its to recover itself. See ARCWriterProcessor for example.</em><a name="375" href="#375">375</a> onFailMessage = <span class="string">"Unable to test/run checkpoint recover"</span>;<a name="376" href="#376">376</a> <strong>this</strong>.checkpointRecover = getCheckpointRecover();<a name="377" href="#377">377</a> <strong>if</strong> (<strong>this</strong>.checkpointRecover == <strong>null</strong>) {<a name="378" href="#378">378</a> <strong>this</strong>.checkpointer =<a name="379" href="#379">379</a> <strong>new</strong> <a href="../../../../org/archive/crawler/framework/Checkpointer.html">Checkpointer</a>(<strong>this</strong>, <strong>this</strong>.checkpointsDisk);<a name="380" href="#380">380</a> } <strong>else</strong> {<a name="381" href="#381">381</a> setupCheckpointRecover();<a name="382" href="#382">382</a> }<a name="383" href="#383">383</a> <a name="384" href="#384">384</a> onFailMessage = <span class="string">"Unable to setup bdb environment."</span>;<a name="385" href="#385">385</a> setupBdb();<a name="386" href="#386">386</a> <a name="387" href="#387">387</a> onFailMessage = <span class="string">"Unable to setup statistics"</span>;<a name="388" href="#388">388</a> setupStatTracking();<a name="389" href="#389">389</a> <a name="390" href="#390">390</a> onFailMessage = <span class="string">"Unable to setup crawl modules"</span>;<a name="391" href="#391">391</a> setupCrawlModules();<a name="392" href="#392">392</a> } <strong>catch</strong> (Exception e) {<a name="393" href="#393">393</a> String tmp = <span class="string">"On crawl: "</span><a name="394" href="#394">394</a> + settingsHandler.getSettingsObject(<strong>null</strong>).getName() + <span class="string">" "</span> +<a name="395" href="#395">395</a> onFailMessage;<a name="396" href="#396">396</a> LOGGER.log(Level.SEVERE, tmp, e);<a name="397" href="#397">397</a> <strong>throw</strong> <strong>new</strong> <a href="../../../../org/archive/crawler/framework/exceptions/InitializationException.html">InitializationException</a>(tmp, e);<a name="398" href="#398">398</a> }<a name="399" href="#399">399</a> <a name="400" href="#400">400</a> <em class="comment">// force creation of DNS Cache now -- avoids CacheCleaner in toe-threads group</em><a name="401" href="#401">401</a> dns.getRecords(<span class="string">"localhost"</span>, Type.A, DClass.IN);<a name="402" href="#402">402</a> <a name="403" href="#403">403</a> setupToePool();<a name="404" href="#404">404</a> setThresholds();<a name="405" href="#405">405</a> <a name="406" href="#406">406</a> reserveMemory = <strong>new</strong> LinkedList();<a name="407" href="#407">407</a> <strong>for</strong>(<strong>int</strong> i = 1; i < RESERVE_BLOCKS; i++) {<a name="408" href="#408">408</a> reserveMemory.add(<strong>new</strong> <strong>char</strong>[RESERVE_BLOCK_SIZE]);<a name="409" href="#409">409</a> }<a name="410" href="#410">410</a> }<a name="411" href="#411">411</a> <a name="412" href="#412">412</a> <em>/**<em>*</em></em><a name="413" href="#413">413</a> <em> * Does setup of checkpoint recover.</em><a name="414" href="#414">414</a> <em> * Copies bdb log files into state dir.</em><a name="415" href="#415">415</a> <em> * @throws IOException</em><a name="416" href="#416">416</a> <em> */</em><a name="417" href="#417">417</a> <strong>protected</strong> <strong>void</strong> setupCheckpointRecover()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -