KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > module > gui > html > PageProcess


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.module.gui.html;
11
12 import org.mmbase.util.*;
13 import org.mmbase.util.logging.*;
14
15 /**
16  * Support class for scanparser to calculate pages in the background.
17  * @application SCAN
18  * @author Rico Jansen
19  * @version $Id: PageProcess.java,v 1.6 2004/10/01 08:43:46 pierre Exp $
20  */

21 public class PageProcess implements Runnable JavaDoc {
22
23     private static Logger log = Logging.getLoggerInstance(PageProcess.class.getName());
24
25     String JavaDoc uri;
26     scanpage sp;
27     scanparser parser;
28
29     Thread JavaDoc kicker=null;
30
31     /**
32      * Create a thread and fire it up to calculate 1 page.
33      * After that die.
34      */

35     PageProcess(scanparser parser,scanpage sp,String JavaDoc uri) {
36         this.sp=sp;
37         this.uri=uri;
38         this.parser=parser;
39         this.start();
40     }
41
42     /**
43      * Starts the main Thread.
44      */

45     public void start() {
46         /* Start up the main thread */
47         if (kicker == null) {
48             kicker = new Thread JavaDoc(this,"pageProcess "+uri);
49             kicker.start();
50         }
51     }
52
53     /**
54      * Stops the main Thread.
55      */

56     public void stop() {
57         /* Stop thread */
58         kicker = null;
59     }
60
61     /**
62      * Main loop, exception protected
63      */

64     public void run () {
65         log.debug("Starting calc "+uri);
66         try {
67            doWork();
68         } catch(Exception JavaDoc e) {
69            log.error(e.getMessage());
70            log.error(Logging.stackTrace(e));
71         }
72         parser.removeProcess(uri);
73         log.debug("Done calc "+uri);
74     }
75
76     /**
77      * Calculate a page using scanparser
78      */

79     private void doWork() {
80         parser.calcPage(uri,sp,0);
81     }
82
83     public String JavaDoc toString() {
84         return uri;
85     }
86 }
87
Popular Tags