?? recoveryjournal.html
字號:
<a name="121" href="#121">121</a> <strong>public</strong> <strong>void</strong> finishedFailure(<a href="../../../../org/archive/net/UURI.html">UURI</a> uuri) {<a name="122" href="#122">122</a> finishedFailure(uuri.toString());<a name="123" href="#123">123</a> }<a name="124" href="#124">124</a> <a name="125" href="#125">125</a> <strong>public</strong> <strong>void</strong> finishedFailure(String u) {<a name="126" href="#126">126</a> writeLine(F_FAILURE, u);<a name="127" href="#127">127</a> }<a name="128" href="#128">128</a> <a name="129" href="#129">129</a> <strong>public</strong> <strong>void</strong> rescheduled(<a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi) {<a name="130" href="#130">130</a> writeLine(F_RESCHEDULE, curi.toString());<a name="131" href="#131">131</a> }<a name="132" href="#132">132</a> <a name="133" href="#133">133</a> <em>/**<em>*</em></em><a name="134" href="#134">134</a> <em> * Utility method for scanning a recovery journal and applying it to</em><a name="135" href="#135">135</a> <em> * a Frontier.</em><a name="136" href="#136">136</a> <em> * </em><a name="137" href="#137">137</a> <em> * @param source Recover log path.</em><a name="138" href="#138">138</a> <em> * @param frontier Frontier reference.</em><a name="139" href="#139">139</a> <em> * @param retainFailures</em><a name="140" href="#140">140</a> <em> * @throws IOException</em><a name="141" href="#141">141</a> <em> * </em><a name="142" href="#142">142</a> <em> * @see org.archive.crawler.framework.Frontier#importRecoverLog(String, boolean)</em><a name="143" href="#143">143</a> <em> */</em><a name="144" href="#144">144</a> <strong>public</strong> <strong>static</strong> <strong>void</strong> importRecoverLog(<strong>final</strong> File source,<a name="145" href="#145">145</a> <strong>final</strong> <a href="../../../../org/archive/crawler/framework/Frontier.html">Frontier</a> frontier, <strong>final</strong> <strong>boolean</strong> retainFailures)<a name="146" href="#146">146</a> throws IOException {<a name="147" href="#147">147</a> <strong>if</strong> (source == <strong>null</strong>) {<a name="148" href="#148">148</a> <strong>throw</strong> <strong>new</strong> IllegalArgumentException(<span class="string">"Passed source file is null."</span>);<a name="149" href="#149">149</a> }<a name="150" href="#150">150</a> LOGGER.info(<span class="string">"recovering frontier completion state from "</span>+source);<a name="151" href="#151">151</a> <a name="152" href="#152">152</a> <em class="comment">// first, fill alreadyIncluded with successes (and possibly failures),</em><a name="153" href="#153">153</a> <em class="comment">// and count the total lines</em><a name="154" href="#154">154</a> <strong>final</strong> <strong>int</strong> lines =<a name="155" href="#155">155</a> importCompletionInfoFromLog(source, frontier, retainFailures);<a name="156" href="#156">156</a> <a name="157" href="#157">157</a> LOGGER.info(<span class="string">"finished completion state; recovering queues from "</span> +<a name="158" href="#158">158</a> source);<a name="159" href="#159">159</a> <a name="160" href="#160">160</a> <em class="comment">// now, re-add anything that was in old frontier and not already</em><a name="161" href="#161">161</a> <em class="comment">// registered as finished. Do this in a separate thread that signals</em><a name="162" href="#162">162</a> <em class="comment">// this thread once ENOUGH_TO_START_CRAWLING URIs have been queued. </em><a name="163" href="#163">163</a> <strong>final</strong> CountDownLatch recoveredEnough = <strong>new</strong> CountDownLatch(1);<a name="164" href="#164">164</a> <strong>new</strong> Thread(<strong>new</strong> Runnable() {<a name="165" href="#165">165</a> <strong>public</strong> <strong>void</strong> run() {<a name="166" href="#166">166</a> importQueuesFromLog(source, frontier, lines, recoveredEnough);<a name="167" href="#167">167</a> }<a name="168" href="#168">168</a> }, <span class="string">"queuesRecoveryThread"</span>).start();<a name="169" href="#169">169</a> <a name="170" href="#170">170</a> <strong>try</strong> {<a name="171" href="#171">171</a> <em class="comment">// wait until at least ENOUGH_TO_START_CRAWLING URIs queued</em><a name="172" href="#172">172</a> recoveredEnough.await();<a name="173" href="#173">173</a> } <strong>catch</strong> (InterruptedException e) {<a name="174" href="#174">174</a> <em class="comment">// TODO Auto-generated catch block</em><a name="175" href="#175">175</a> e.printStackTrace();<a name="176" href="#176">176</a> }<a name="177" href="#177">177</a> }<a name="178" href="#178">178</a> <a name="179" href="#179">179</a> <em>/**<em>*</em></em><a name="180" href="#180">180</a> <em> * Import just the SUCCESS (and possibly FAILURE) URIs from the given</em><a name="181" href="#181">181</a> <em> * recovery log into the frontier as considered included. </em><a name="182" href="#182">182</a> <em> * </em><a name="183" href="#183">183</a> <em> * @param source recovery log file to use</em><a name="184" href="#184">184</a> <em> * @param frontier frontier to update</em><a name="185" href="#185">185</a> <em> * @param retainFailures whether failure ('Ff') URIs should count as done</em><a name="186" href="#186">186</a> <em> * @return number of lines in recovery log (for reference)</em><a name="187" href="#187">187</a> <em> * @throws IOException</em><a name="188" href="#188">188</a> <em> */</em><a name="189" href="#189">189</a> <strong>private</strong> <strong>static</strong> <strong>int</strong> importCompletionInfoFromLog(File source, <a name="190" href="#190">190</a> <a href="../../../../org/archive/crawler/framework/Frontier.html">Frontier</a> frontier, <strong>boolean</strong> retainFailures) throws IOException {<a name="191" href="#191">191</a> <em class="comment">// Scan log for all 'Fs' lines: add as 'alreadyIncluded'</em><a name="192" href="#192">192</a> BufferedInputStream is = getBufferedInput(source);<a name="193" href="#193">193</a> <em class="comment">// create MutableString of good starting size (will grow if necessary)</em><a name="194" href="#194">194</a> MutableString read = <strong>new</strong> MutableString(UURI.MAX_URL_LENGTH); <a name="195" href="#195">195</a> <strong>int</strong> lines = 0; <a name="196" href="#196">196</a> <strong>try</strong> {<a name="197" href="#197">197</a> <strong>while</strong> (readLine(is,read)) {<a name="198" href="#198">198</a> lines++;<a name="199" href="#199">199</a> <strong>boolean</strong> wasSuccess = read.startsWith(F_SUCCESS);<a name="200" href="#200">200</a> <strong>if</strong> (wasSuccess<a name="201" href="#201">201</a> || (retainFailures && read.startsWith(F_FAILURE))) {<a name="202" href="#202">202</a> <em class="comment">// retrieve first (only) URL on line </em><a name="203" href="#203">203</a> String s = read.subSequence(3,read.length()).toString();<a name="204" href="#204">204</a> <strong>try</strong> {<a name="205" href="#205">205</a> <a href="../../../../org/archive/net/UURI.html">UURI</a> u = UURIFactory.getInstance(s);<a name="206" href="#206">206</a> frontier.considerIncluded(u);<a name="207" href="#207">207</a> <strong>if</strong>(wasSuccess) {<a name="208" href="#208">208</a> <strong>if</strong> (frontier.getFrontierJournal() != <strong>null</strong>) {<a name="209" href="#209">209</a> frontier.getFrontierJournal().<a name="210" href="#210">210</a> finishedSuccess(u);<a name="211" href="#211">211</a> }<a name="212" href="#212">212</a> } <strong>else</strong> {<a name="213" href="#213">213</a> <em class="comment">// carryforward failure, in case future recovery</em><a name="214" href="#214">214</a> <em class="comment">// wants to no retain them as finished </em><a name="215" href="#215">215</a> <strong>if</strong> (frontier.getFrontierJournal() != <strong>null</strong>) {<a name="216" href="#216">216</a> frontier.getFrontierJournal().<a name="217" href="#217">217</a> finishedFailure(u);<a name="218" href="#218">218</a> }<a name="219" href="#219">219</a> }<a name="220" href="#220">220</a> } <strong>catch</strong> (URIException e) {<a name="221" href="#221">221</a> e.printStackTrace();<a name="222" href="#222">222</a> }<a name="223" href="#223">223</a> }<a name="224" href="#224">224</a> <strong>if</strong>((lines%PROGRESS_INTERVAL)==0) {<a name="225" href="#225">225</a> <em class="comment">// every 1 million lines, print progress</em><a name="226" href="#226">226</a> LOGGER.info(<a name="227" href="#227">227</a> <span class="string">"at line "</span> + lines <a name="228" href="#228">228</a> + <span class="string">" alreadyIncluded count = "</span> +<a name="229" href="#229">229</a> frontier.discoveredUriCount());<a name="230" href="#230">230</a> }<a name="231" href="#231">231</a> }<a name="232" href="#232">232</a> } <strong>catch</strong> (EOFException e) {<a name="233" href="#233">233</a> <em class="comment">// expected in some uncleanly-closed recovery logs; ignore</em><a name="234" href="#234">234</a> } <strong>finally</strong> {<a name="235" href="#235">235</a> is.close();<a name="236" href="#236">236</a> }<a name="237" href="#237">237</a> <strong>return</strong> lines;<a name="238" href="#238">238</a> }<a name="239" href="#239">239</a> <a name="240" href="#240">240</a> <em>/**<em>*</em></em><a name="241" href="#241">241</a> <em> * Read a line from the given bufferedinputstream into the MutableString.</em><a name="242" href="#242">242</a> <em> * Return true if a line was read; false if EOF. </em><a name="243" href="#243">243</a> <em> * </em><a name="244" href="#244">244</a> <em> * @param is</em><a name="245" href="#245">245</a> <em> * @param read</em><a name="246" href="#246">246</a> <em> * @return True if we read a line.</em><a name="247" href="#247">247</a> <em> * @throws IOException</em><a name="248" href="#248">248</a> <em> */</em><a name="249" href="#249">249</a> <strong>private</strong> <strong>static</strong> <strong>boolean</strong> readLine(BufferedInputStream is, MutableString read)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -