1 package org.nextime.ion.backoffice.indexation; 2 3 import java.io.File ; 4 import javax.servlet.ServletException ; 5 import javax.servlet.http.HttpServlet ; 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 implements Runnable { 12 13 private int minuteDelay = 60; 14 private Thread thread; 15 16 19 public void init() throws ServletException { 20 try { 21 minuteDelay = 22 Integer.parseInt(getServletConfig().getInitParameter("delay")); 23 } catch (Exception e) { 24 } 25 thread = new Thread (this,"Indexation"); 26 thread.setDaemon(true); 27 thread.start(); 28 } 29 30 33 public void run() { 34 while (true) { 35 String [] indexs = Config.getInstance().getIndexNames(); 36 for( int i=0; i<indexs.length; i++ ) { 37 File rep = new File ( 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 e) { 49 e.printStackTrace(); 50 } 51 } 52 } 53 54 58 public int getMinuteDelay() { 59 return minuteDelay; 60 } 61 62 66 public void setMinuteDelay(int minuteDelay) { 67 this.minuteDelay = minuteDelay; 68 } 69 70 } 71 | Popular Tags |