01: package vqwiki;
02:
03: import org.apache.log4j.Logger;
04:
05: /*
06: Very Quick Wiki - WikiWikiWeb clone
07: Copyright (C) 2001-2002 Gareth Cronin
08:
09: This program is free software; you can redistribute it and/or modify
10: it under the terms of the latest version of the GNU Lesser General
11: Public License as published by the Free Software Foundation;
12:
13: This program is distributed in the hope that it will be useful,
14: but WITHOUT ANY WARRANTY; without even the implied warranty of
15: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: GNU Lesser General Public License for more details.
17:
18: You should have received a copy of the GNU Lesser General Public License
19: along with this program (gpl.txt); if not, write to the Free Software
20: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21: */
22:
23: public class SearchRefreshThread extends Thread {
24:
25: private static SearchRefreshThread instance = null;
26: private boolean refreshNow = false;
27: private boolean endThread = false;
28: int millis;
29: private static final Logger logger = Logger
30: .getLogger(SearchRefreshThread.class);
31:
32: /**
33: *
34: */
35: public SearchRefreshThread(int interval) {
36: instance = this ;
37: if (interval <= 0) {
38: logger
39: .debug("Inappropriate refresh interval: setting to 10");
40: interval = 10;
41: }
42: this .millis = interval * 60 * 1000;
43: start();
44: }
45:
46: /**
47: *
48: */
49: public void run() {
50: while (!endThread) {
51: try {
52: sleep(this .millis);
53: } catch (InterruptedException e) {
54: logger.warn(e);
55: }
56: try {
57: WikiBase.getInstance().getSearchEngineInstance()
58: .refreshIndex();
59: refreshNow = false;
60: } catch (java.io.IOException err) {
61: logger.error(err);
62: } catch (Exception err) {
63: err.printStackTrace();
64: logger.error(err);
65: }
66: }
67: }
68:
69: /**
70: *
71: */
72: private static SearchRefreshThread getInstance() {
73: return instance;
74: }
75:
76: /**
77: *
78: */
79: public static void refreshNow() {
80: if (getInstance() == null)
81: return;
82: getInstance().refreshNow = true;
83: getInstance().interrupt();
84: }
85:
86: /**
87: *
88: */
89: public static void endThread() {
90: if (getInstance() == null)
91: return;
92: getInstance().endThread = true;
93: getInstance().interrupt();
94: }
95: }
|