KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > backoffice > indexation > IndexationServlet


1 package org.nextime.ion.backoffice.indexation;
2
3 import java.io.File JavaDoc;
4 import javax.servlet.ServletException JavaDoc;
5 import javax.servlet.http.HttpServlet JavaDoc;
6
7 import org.nextime.ion.framework.config.Config;
8 import org.nextime.ion.framework.helper.Indexer;
9 import org.nextime.ion.framework.mapping.Mapping;
10
11 public class IndexationServlet extends HttpServlet JavaDoc implements Runnable JavaDoc {
12
13     private int minuteDelay = 60;
14     private Thread JavaDoc thread;
15
16     /**
17      * @see javax.servlet.GenericServlet#init()
18      */

19     public void init() throws ServletException JavaDoc {
20         try {
21             minuteDelay =
22                 Integer.parseInt(getServletConfig().getInitParameter("delay"));
23         } catch (Exception JavaDoc e) {
24         }
25         thread = new Thread JavaDoc(this,"Indexation");
26         thread.setDaemon(true);
27         thread.start();
28     }
29
30     /**
31      * @see java.lang.Runnable#run()
32      */

33     public void run() {
34         while (true) {
35             String JavaDoc[] indexs = Config.getInstance().getIndexNames();
36             for( int i=0; i<indexs.length; i++ ) {
37                 File JavaDoc rep = new File JavaDoc( Config.getInstance().getIndexRoot(), indexs[i] );
38                 if( !rep.exists() ) {
39                     rep.mkdir();
40                 }
41             }
42             try {
43                 System.out.println("["+Thread.currentThread().getName()+"] ReIndexation");
44                 Mapping.begin();
45                     Indexer.reIndex();
46                 Mapping.rollback();
47                 Thread.sleep(minuteDelay * 60 * 1000);
48             } catch (Exception JavaDoc e) {
49                 e.printStackTrace();
50             }
51         }
52     }
53
54     /**
55      * Returns the minuteDelay.
56      * @return int
57      */

58     public int getMinuteDelay() {
59         return minuteDelay;
60     }
61
62     /**
63      * Sets the minuteDelay.
64      * @param minuteDelay The minuteDelay to set
65      */

66     public void setMinuteDelay(int minuteDelay) {
67         this.minuteDelay = minuteDelay;
68     }
69
70 }
71
Popular Tags