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

📄 heritrix.html

📁 一个开源的网页爬虫一个开源的网页爬虫一个开源的网页爬虫一个开源的网页爬虫一个开源的网页爬虫一个开源的网页爬虫
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<a name="439" href="#439">439</a>                 sinkHandler.remove(Long.parseLong(alertID));<a name="440" href="#440">440</a>             }<a name="441" href="#441">441</a> <a name="442" href="#442">442</a>             <strong>public</strong> <strong>void</strong> read(String alertID) {<a name="443" href="#443">443</a>                 sinkHandler.read(Long.parseLong(alertID));<a name="444" href="#444">444</a>             }<a name="445" href="#445">445</a>         };<a name="446" href="#446">446</a>         <a name="447" href="#447">447</a>         <strong>try</strong> {<a name="448" href="#448">448</a>             Heritrix.registerHeritrix(<strong>this</strong>, name, jmxregister);<a name="449" href="#449">449</a>         } <strong>catch</strong> (InstanceAlreadyExistsException e) {<a name="450" href="#450">450</a>             <strong>throw</strong> <strong>new</strong> RuntimeException(e);<a name="451" href="#451">451</a>         } <strong>catch</strong> (MBeanRegistrationException e) {<a name="452" href="#452">452</a>             <strong>throw</strong> <strong>new</strong> RuntimeException(e);<a name="453" href="#453">453</a>         } <strong>catch</strong> (NotCompliantMBeanException e) {<a name="454" href="#454">454</a>             <strong>throw</strong> <strong>new</strong> RuntimeException(e);<a name="455" href="#455">455</a>         } <strong>catch</strong> (MalformedObjectNameException e) {<a name="456" href="#456">456</a>             <strong>throw</strong> <strong>new</strong> RuntimeException(e);<a name="457" href="#457">457</a>         }<a name="458" href="#458">458</a>     }<a name="459" href="#459">459</a>     <a name="460" href="#460">460</a>     <em>/**<em>*</em></em><a name="461" href="#461">461</a> <em>     * Run setup tasks for this 'container'. Idempotent.</em><a name="462" href="#462">462</a> <em>     * </em><a name="463" href="#463">463</a> <em>     * @throws IOException</em><a name="464" href="#464">464</a> <em>     */</em><a name="465" href="#465">465</a>     <strong>protected</strong> <strong>static</strong> <strong>void</strong> containerInitialization() throws IOException {<a name="466" href="#466">466</a>         <strong>if</strong> (Heritrix.containerInitialized) {<a name="467" href="#467">467</a>             <strong>return</strong>;<a name="468" href="#468">468</a>         }<a name="469" href="#469">469</a>         Heritrix.containerInitialized = <strong>true</strong>;<a name="470" href="#470">470</a>         <em class="comment">// Load up the properties.  This invocation adds heritrix properties</em><a name="471" href="#471">471</a>         <em class="comment">// to system properties so all available via System.getProperty.</em><a name="472" href="#472">472</a>         <em class="comment">// Note, loadProperties and patchLogging have global effects.  May be an</em><a name="473" href="#473">473</a>         <em class="comment">// issue if we're running inside a container such as tomcat or jboss.</em><a name="474" href="#474">474</a>         Heritrix.loadProperties();<a name="475" href="#475">475</a>         Heritrix.patchLogging();<a name="476" href="#476">476</a>         Heritrix.configureTrustStore();<a name="477" href="#477">477</a>         <em class="comment">// Will run on SIGTERM but not on SIGKILL, unfortunately.</em><a name="478" href="#478">478</a>         <em class="comment">// Otherwise, ensures we cleanup after ourselves (Deregister from</em><a name="479" href="#479">479</a>         <em class="comment">// JMX and JNDI).</em><a name="480" href="#480">480</a>         Runtime.getRuntime().addShutdownHook(<a name="481" href="#481">481</a>             Heritrix.getShutdownThread(false, 0, <span class="string">"Heritrix shutdown hook"</span>));<a name="482" href="#482">482</a>         <em class="comment">// Register this heritrix 'container' though we may be inside another</em><a name="483" href="#483">483</a>         <em class="comment">// tomcat or jboss container.</em><a name="484" href="#484">484</a>         <strong>try</strong> {<a name="485" href="#485">485</a>             registerContainerJndi();<a name="486" href="#486">486</a>         } <strong>catch</strong> (Exception e) {<a name="487" href="#487">487</a>             logger.log(Level.WARNING, <span class="string">"Failed jndi container registration."</span>, e);<a name="488" href="#488">488</a>         }<a name="489" href="#489">489</a>     }<a name="490" href="#490">490</a>     <a name="491" href="#491">491</a>     <em>/**<em>*</em></em><a name="492" href="#492">492</a> <em>     * Do inverse of construction. Used by anyone who does a 'new Heritrix' when</em><a name="493" href="#493">493</a> <em>     * they want to cleanup the instance.</em><a name="494" href="#494">494</a> <em>     * Of note, there may be Heritrix threads still hanging around after the</em><a name="495" href="#495">495</a> <em>     * call to destroy completes.  They'll eventually go down after they've</em><a name="496" href="#496">496</a> <em>     * finished their cleanup routines.  In particular, if you are watching</em><a name="497" href="#497">497</a> <em>     * Heritrix via JMX, you can see the Heritrix instance JMX bean unregister</em><a name="498" href="#498">498</a> <em>     * ahead of the CrawlJob JMX bean that its hosting.</em><a name="499" href="#499">499</a> <em>     */</em><a name="500" href="#500">500</a>     <strong>public</strong> <strong>void</strong> destroy() {<a name="501" href="#501">501</a>         stop();<a name="502" href="#502">502</a>         <strong>try</strong> {<a name="503" href="#503">503</a>             Heritrix.unregisterHeritrix(<strong>this</strong>);<a name="504" href="#504">504</a>         } <strong>catch</strong> (InstanceNotFoundException e) {<a name="505" href="#505">505</a>             e.printStackTrace();<a name="506" href="#506">506</a>         } <strong>catch</strong> (MBeanRegistrationException e) {<a name="507" href="#507">507</a>             e.printStackTrace();<a name="508" href="#508">508</a>         } <strong>catch</strong> (NullPointerException e) {<a name="509" href="#509">509</a>             e.printStackTrace();<a name="510" href="#510">510</a>         }<a name="511" href="#511">511</a>         <strong>this</strong>.jobHandler = <strong>null</strong>;<a name="512" href="#512">512</a>         <strong>this</strong>.openMBeanInfo = <strong>null</strong>;<a name="513" href="#513">513</a>     }<a name="514" href="#514">514</a>     <a name="515" href="#515">515</a>     <em>/**<em>*</em></em><a name="516" href="#516">516</a> <em>     * Launch program.</em><a name="517" href="#517">517</a> <em>     * Optionally will launch a web server to host UI.  Will also register</em><a name="518" href="#518">518</a> <em>     * Heritrix MBean with first found JMX Agent (Usually the 1.5.0 JVM</em><a name="519" href="#519">519</a> <em>     * Agent).</em><a name="520" href="#520">520</a> <em>     * </em><a name="521" href="#521">521</a> <em>     * @param args Command line arguments.</em><a name="522" href="#522">522</a> <em>     * @throws Exception</em><a name="523" href="#523">523</a> <em>     */</em><a name="524" href="#524">524</a>     <strong>public</strong> <strong>static</strong> <strong>void</strong> main(String[] args)<a name="525" href="#525">525</a>     throws Exception {<a name="526" href="#526">526</a>         Heritrix.commandLine = <strong>true</strong>;<a name="527" href="#527">527</a>         <a name="528" href="#528">528</a>         <em class="comment">// Set timezone here.  Would be problematic doing it if we're running</em><a name="529" href="#529">529</a>         <em class="comment">// inside in a container.</em><a name="530" href="#530">530</a>         TimeZone.setDefault(TimeZone.getTimeZone(<span class="string">"GMT"</span>));<a name="531" href="#531">531</a>         <a name="532" href="#532">532</a>         File startLog = <strong>new</strong> File(getHeritrixHome(), STARTLOG);<a name="533" href="#533">533</a>         Heritrix.out = <strong>new</strong> PrintWriter(isDevelopment()? <a name="534" href="#534">534</a>             System.out: <strong>new</strong> PrintStream(<strong>new</strong> FileOutputStream(startLog)));<a name="535" href="#535">535</a>         <a name="536" href="#536">536</a>         <strong>try</strong> {<a name="537" href="#537">537</a>             containerInitialization();<a name="538" href="#538">538</a>             String status = doCmdLineArgs(args);<a name="539" href="#539">539</a>             <strong>if</strong> (status != <strong>null</strong>) {<a name="540" href="#540">540</a>                 Heritrix.out.println(status);<a name="541" href="#541">541</a>             }<a name="542" href="#542">542</a>         }<a name="543" href="#543">543</a> <a name="544" href="#544">544</a>         <strong>catch</strong>(Exception e) {<a name="545" href="#545">545</a>             <em class="comment">// Show any exceptions in STARTLOG.</em><a name="546" href="#546">546</a>             e.printStackTrace(Heritrix.out);<a name="547" href="#547">547</a>             <strong>throw</strong> e;<a name="548" href="#548">548</a>         }<a name="549" href="#549">549</a> <a name="550" href="#550">550</a>         <strong>finally</strong> {<a name="551" href="#551">551</a>             <em class="comment">// If not development, close the file that signals the wrapper</em><a name="552" href="#552">552</a>             <em class="comment">// script that we've started.  Otherwise, just flush it; if in</em><a name="553" href="#553">553</a>             <em class="comment">// development, the output is probably a console.</em><a name="554" href="#554">554</a>             <strong>if</strong> (!isDevelopment()) {<a name="555" href="#555">555</a>                 <strong>if</strong> (Heritrix.out != <strong>null</strong>) {<a name="556" href="#556">556</a>                     Heritrix.out.close();<a name="557" href="#557">557</a>                 }<a name="558" href="#558">558</a>                 System.out.println(<span class="string">"Heritrix version: "</span> +<a name="559" href="#559">559</a>                         Heritrix.getVersion());<a name="560" href="#560">560</a>             } <strong>else</strong> {<a name="561" href="#561">561</a>                 <strong>if</strong> (Heritrix.out != <strong>null</strong>) {<a name="562" href="#562">562</a>                     Heritrix.out.flush();<a name="563" href="#563">563</a>                 }<a name="564" href="#564">564</a>             }<a name="565" href="#565">565</a>         }<a name="566" href="#566">566</a>     }<a name="567" href="#567">567</a>     <a name="568" href="#568">568</a>     <strong>protected</strong> <strong>static</strong> String doCmdLineArgs(<strong>final</strong> String [] args)<a name="569" href="#569">569</a>     throws Exception {<a name="570" href="#570">570</a>         <em class="comment">// Get defaults for commandline arguments from the properties file.</em><a name="571" href="#571">571</a>         String tmpStr = PropertyUtils.<a name="572" href="#572">572</a>             getPropertyOrNull(<span class="string">"heritrix.context"</span>);<a name="573" href="#573">573</a>         <strong>if</strong> (tmpStr != <strong>null</strong>)  {<a name="574" href="#574">574</a>             Heritrix.adminContext = tmpStr;<a name="575" href="#575">575</a>         }<a name="576" href="#576">576</a>         tmpStr = PropertyUtils.getPropertyOrNull(<span class="string">"heritrix.cmdline.port"</span>);<a name="577" href="#577">577</a>         <strong>if</strong> (tmpStr != <strong>null</strong>) {<a name="578" href="#578">578</a>             Heritrix.guiPort = Integer.parseInt(tmpStr);<a name="579" href="#579">579</a>         }<a name="580" href="#580">580</a>         tmpStr = PropertyUtils.getPropertyOrNull(<span class="string">"heritrix.cmdline.admin"</span>);<a name="581" href="#581">581</a>         String adminLoginPassword = (tmpStr == <strong>null</strong>)? <span class="string">""</span>: tmpStr;<a name="582" href="#582">582</a>         String crawlOrderFile =<a name="583" href="#583">583</a>             PropertyUtils.getPropertyOrNull(<span class="string">"heritrix.cmdline.order"</span>);<a name="584" href="#584">584</a>         tmpStr = PropertyUtils.getPropertyOrNull(<span class="string">"heritrix.cmdline.run"</span>);<a name="585" href="#585">585</a>         <strong>boolean</strong> runMode =<a name="586" href="#586">586</a>             PropertyUtils.getBooleanProperty(<span class="string">"heritrix.cmdline.run"</span>);<a name="587" href="#587">587</a>         <strong>boolean</strong> selfTest = false;

⌨️ 快捷键说明

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