?? adaptiverevisithostqueue.html
字號:
<a name="136" href="#136">136</a> <em>/**<em>* Logger */</em></em><a name="137" href="#137">137</a> <strong>private</strong> <strong>static</strong> <strong>final</strong> Logger logger = <a name="138" href="#138">138</a> Logger.getLogger(AdaptiveRevisitHostQueue.<strong>class</strong>.getName());<a name="139" href="#139">139</a> <a name="140" href="#140">140</a> <strong>protected</strong> <a href="../../../../org/archive/crawler/datamodel/CrawlSubstats.html">CrawlSubstats</a> substats = <strong>new</strong> <a href="../../../../org/archive/crawler/datamodel/CrawlSubstats.html">CrawlSubstats</a>(); <a name="141" href="#141">141</a> <a name="142" href="#142">142</a> <em class="comment">// Berkeley DB - All class member variables related to BDB JE</em><a name="143" href="#143">143</a> <em class="comment">// Databases</em><a name="144" href="#144">144</a> <em>/**<em>* Database containing the URI priority queue, indexed by the the </em></em><a name="145" href="#145">145</a> <em> * URI string. */</em><a name="146" href="#146">146</a> <strong>protected</strong> Database primaryUriDB;<a name="147" href="#147">147</a> <em>/**<em>* Secondary index into {@link #primaryUriDB the primary DB}, URIs indexed</em></em><a name="148" href="#148">148</a> <em> * by the time when they can next be processed again. */</em><a name="149" href="#149">149</a> <strong>protected</strong> SecondaryDatabase secondaryUriDB;<a name="150" href="#150">150</a> <em>/**<em>* A database containing those URIs that are currently being processed. */</em></em><a name="151" href="#151">151</a> <strong>protected</strong> Database processingUriDB;<a name="152" href="#152">152</a> <em class="comment">// Serialization support</em><a name="153" href="#153">153</a> <em>/**<em>* For BDB serialization of objects */</em></em><a name="154" href="#154">154</a> <strong>protected</strong> StoredClassCatalog classCatalog;<a name="155" href="#155">155</a> <em>/**<em>* A binding for the serialization of the primary key (URI string) */</em></em><a name="156" href="#156">156</a> <strong>protected</strong> EntryBinding primaryKeyBinding;<a name="157" href="#157">157</a> <em>/**<em>* A binding for the CrawlURIARWrapper object */</em></em><a name="158" href="#158">158</a> <strong>protected</strong> EntryBinding crawlURIBinding;<a name="159" href="#159">159</a> <em class="comment">// Cursors into databases</em><a name="160" href="#160">160</a> <a name="161" href="#161">161</a> <a name="162" href="#162">162</a> <a name="163" href="#163">163</a> <em>/**<em>*</em></em><a name="164" href="#164">164</a> <em> * Constructor</em><a name="165" href="#165">165</a> <em> * </em><a name="166" href="#166">166</a> <em> * @param hostName Name of the host this queue represents. This name must</em><a name="167" href="#167">167</a> <em> * be unique for all HQs in the same Environment.</em><a name="168" href="#168">168</a> <em> * @param env Berkeley DB Environment. All BDB databases created will use </em><a name="169" href="#169">169</a> <em> * it.</em><a name="170" href="#170">170</a> <em> * @param catalog Db for bdb class serialization.</em><a name="171" href="#171">171</a> <em> * @param valence The total number of simultanous URIs that the HQ can issue</em><a name="172" href="#172">172</a> <em> * for processing. Once this many URIs have been issued for</em><a name="173" href="#173">173</a> <em> * processing, the HQ will go into {@link #HQSTATE_BUSY busy}</em><a name="174" href="#174">174</a> <em> * state until at least one of the URI is </em><a name="175" href="#175">175</a> <em> * {@link #update(CrawlURI, boolean, long) updated}.</em><a name="176" href="#176">176</a> <em> * Value should be larger then zero. Zero and negative values</em><a name="177" href="#177">177</a> <em> * will be treated same as 1.</em><a name="178" href="#178">178</a> <em> * </em><a name="179" href="#179">179</a> <em> * @throws IOException if an error occurs opening/creating the </em><a name="180" href="#180">180</a> <em> * database</em><a name="181" href="#181">181</a> <em> */</em><a name="182" href="#182">182</a> <strong>public</strong> <a href="../../../../org/archive/crawler/frontier/AdaptiveRevisitHostQueue.html">AdaptiveRevisitHostQueue</a>(String hostName, Environment env,<a name="183" href="#183">183</a> StoredClassCatalog catalog, <strong>int</strong> valence)<a name="184" href="#184">184</a> throws IOException {<a name="185" href="#185">185</a> <strong>try</strong>{<a name="186" href="#186">186</a> <strong>if</strong>(valence < 1) {<a name="187" href="#187">187</a> <strong>this</strong>.valence = 1;<a name="188" href="#188">188</a> } <strong>else</strong> {<a name="189" href="#189">189</a> <strong>this</strong>.valence = valence;<a name="190" href="#190">190</a> }<a name="191" href="#191">191</a> wakeUpTime = <strong>new</strong> <strong>long</strong>[valence];<a name="192" href="#192">192</a> <strong>for</strong>(<strong>int</strong> i = 0 ; i < valence ; i++){<a name="193" href="#193">193</a> wakeUpTime[i]=0; <em class="comment">// 0 means open slot.</em><a name="194" href="#194">194</a> }<a name="195" href="#195">195</a> <a name="196" href="#196">196</a> inProcessing = 0;<a name="197" href="#197">197</a> <a name="198" href="#198">198</a> <strong>this</strong>.hostName = hostName;<a name="199" href="#199">199</a> <a name="200" href="#200">200</a> state = HQSTATE_EMPTY; <em class="comment">//HQ is initially empty.</em><a name="201" href="#201">201</a> nextReadyTime = Long.MAX_VALUE; <em class="comment">//Empty and busy HQ get this value.</em><a name="202" href="#202">202</a> <a name="203" href="#203">203</a> <em class="comment">// Set up the primary URI database, it is indexed by URI names </em><a name="204" href="#204">204</a> DatabaseConfig dbConfig = <strong>new</strong> DatabaseConfig();<a name="205" href="#205">205</a> dbConfig.setTransactional(false); <a name="206" href="#206">206</a> dbConfig.setAllowCreate(<strong>true</strong>);<a name="207" href="#207">207</a> primaryUriDB = env.openDatabase(<strong>null</strong>, hostName, dbConfig);<a name="208" href="#208">208</a> <a name="209" href="#209">209</a> <strong>this</strong>.classCatalog = catalog;<a name="210" href="#210">210</a> <a name="211" href="#211">211</a> <em class="comment">// Set up a DB for storing URIs being processed</em><a name="212" href="#212">212</a> DatabaseConfig dbConfig2 = <strong>new</strong> DatabaseConfig();<a name="213" href="#213">213</a> dbConfig2.setTransactional(false); <a name="214" href="#214">214</a> dbConfig2.setAllowCreate(<strong>true</strong>);<a name="215" href="#215">215</a> processingUriDB = env.openDatabase(<strong>null</strong>, <a name="216" href="#216">216</a> hostName + <span class="string">"/processing"</span>, dbConfig2);<a name="217" href="#217">217</a> <a name="218" href="#218">218</a> <em class="comment">// Create a primitive binding for the primary key (URI string) </em><a name="219" href="#219">219</a> primaryKeyBinding = TupleBinding.getPrimitiveBinding(String.<strong>class</strong>);<a name="220" href="#220">220</a> <em class="comment">// Create a serial binding for the CrawlURI object </em><a name="221" href="#221">221</a> crawlURIBinding = <strong>new</strong> SerialBinding(<strong>class</strong>Catalog, CrawlURI.<strong>class</strong>);<a name="222" href="#222">222</a> <a name="223" href="#223">223</a> <em class="comment">// Open a secondary database to allow accessing the primary</em><a name="224" href="#224">224</a> <em class="comment">// database by the secondary key value.</em><a name="225" href="#225">225</a> SecondaryConfig secConfig = <strong>new</strong> SecondaryConfig();<a name="226" href="#226">226</a> secConfig.setAllowCreate(<strong>true</strong>);<a name="227" href="#227">227</a> secConfig.setSortedDuplicates(<strong>true</strong>);<a name="228" href="#228">228</a> secConfig.setKeyCreator(<a name="229" href="#229">229</a> <strong>new</strong> OrderOfProcessingKeyCreator(<strong>class</strong>Catalog,CrawlURI.<strong>class</strong>));<a name="230" href="#230">230</a> secondaryUriDB = env.openSecondaryDatabase(<strong>null</strong>, <a name="231" href="#231">231</a> hostName+<span class="string">"/timeOfProcessing"</span>, primaryUriDB, secConfig);<a name="232" href="#232">232</a> <a name="233" href="#233">233</a> <em class="comment">// Check if we are opening an existing DB...</em><a name="234" href="#234">234</a> size = countCrawlURIs();<a name="235" href="#235">235</a> <strong>if</strong> (size > 0) {<a name="236" href="#236">236</a> <em class="comment">// If size > 0 then we just opened an existing DB.</em><a name="237" href="#237">237</a> <em class="comment">// Set nextReadyTime;</em><a name="238" href="#238">238</a> nextReadyTime = peek().getLong(<a name="239" href="#239">239</a> A_TIME_OF_NEXT_PROCESSING);<a name="240" href="#240">240</a> <em class="comment">// Move any items in processingUriDB into the primariUriDB, ensure</em><a name="241" href="#241">241</a> <em class="comment">// that they wind up on top!</em><a name="242" href="#242">242</a> flushProcessingURIs();<a name="243" href="#243">243</a> state = HQSTATE_READY;<a name="244" href="#244">244</a> } <a name="245" href="#245">245</a> } <strong>catch</strong> (DatabaseException e) {<a name="246" href="#246">246</a> <em class="comment">// Blanket catch all DBExceptions and convert to IOExceptions.</em><a name="247" href="#247">247</a> IOException e2 = <strong>new</strong> IOException(e.getMessage());<a name="248" href="#248">248</a> e2.setStackTrace(e.getStackTrace());<a name="249" href="#249">249</a> <strong>throw</strong> e2; <a name="250" href="#250">250</a> }<a name="251" href="#251">251</a> }<a name="252" href="#252">252</a> <a name="253" href="#253">253</a> <em>/**<em>*</em></em><a name="254" href="#254">254</a> <em> * Returns the HQ's name</em><a name="255" href="#255">255</a> <em> * @return the HQ's name</em><a name="256" href="#256">256</a> <em> */</em><a name="257" href="#257">257</a> <strong>public</strong> String getHostName() {<a name="258" href="#258">258</a> <strong>return</strong> hostName;<a name="259" href="#259">259</a> }<a name="260" href="#260">260</a> <a name="261" href="#261">261</a> <em>/**<em>*</em></em><a name="262" href="#262">262</a> <em> * Add a CrawlURI to this host queue.</em><a name="263" href="#263">263</a> <em> * <p></em><a name="264" href="#264">264</a> <em> * Calls can optionally chose to have the time of next processing value </em><a name="265" href="#265">265</a> <em> * override existing values for the URI if the existing values are 'later'</em><a name="266" href="#266">266</a> <em> * then the new ones. </em><a name="267" href="#267">267</a> <em> * </em><a name="268" href="#268">268</a> <em> * @param curi The CrawlURI to add.</em><a name="269" href="#269">269</a> <em> * @param overrideSetTimeOnDups If true then the time of next processing for</em><a name="270" href="#270">270</a> <em> * the supplied URI will override the any</em><a name="271" href="#271">271</a> <em> * existing time for it already stored in the HQ.</em><a name="272" href="#272">272</a> <em> * If false, then no changes will be made to any</em><a name="273" href="#273">273</a> <em> * existing values of the URI. Note: Will never</em><a name="274" href="#274">274</a> <em> * override with a later time.</em><a name="275" href="#275">275</a> <em> * @throws IOException When an error occurs accessing the database</em><a name="276" href="#276">276</a> <em> */</em><a name="277" href="#277">277</a> <strong>public</strong> <strong>void</strong> add(<a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi, <strong>boolean</strong> overrideSetTimeOnDups) <a name="278" href="#278">278</a> throws IOException{<a name="279" href="#279">279</a> <strong>if</strong>(logger.isLoggable(Level.FINER)){
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -