1 26 package org.snipsnap.net.admin; 27 28 import org.snipsnap.app.Application; 29 import org.snipsnap.config.Configuration; 30 import org.snipsnap.container.Components; 31 import org.snipsnap.snip.SnipSpace; 32 33 import javax.servlet.http.HttpServletRequest ; 34 import javax.servlet.http.HttpServletResponse ; 35 import java.util.HashMap ; 36 import java.util.Map ; 37 38 public class ManageSearchEngine implements SetupHandler { 39 public String getName() { 40 return "search"; 41 } 42 43 private Map indexerThreads = new HashMap (); 44 45 public Map setup(HttpServletRequest request, HttpServletResponse response, Configuration config, Map errors) { 46 if (request.getParameter("reset") != null) { 47 final String appOid = (String ) Application.get().getObject(Application.OID); 48 Thread indexerThread = (Thread ) indexerThreads.get(appOid); 49 if (indexerThread != null && indexerThread.isAlive()) { 50 if (request.getSession().getAttribute("running") == null) { 51 request.getSession().setAttribute("running", new HashMap ()); 52 } 53 return errors; 54 } else if (indexerThread != null) { 55 request.getSession().removeAttribute("running"); 56 indexerThreads.remove(appOid); 57 indexerThread = null; 58 } 59 indexerThread = new Thread () { 60 public void run() { 61 Application.get().storeObject(Application.OID, appOid); 62 ((SnipSpace) Components.getComponent(SnipSpace.class)).reIndex(); 63 } 64 }; 65 indexerThread.start(); 66 request.getSession().setAttribute("indexerThread", indexerThread); 67 request.getSession().setAttribute("running", new HashMap ()); 68 } 69 70 return errors; 71 } 72 } 73 | Popular Tags |