1 package org.tigris.scarab.actions.admin; 2 3 48 49 50 import org.apache.turbine.TemplateContext; 52 import org.apache.turbine.RunData; 53 54 import org.tigris.scarab.tools.ScarabRequestTool; 56 import org.tigris.scarab.tools.ScarabLocalizationTool; 57 import org.tigris.scarab.actions.base.RequireLoginFirstAction; 58 import org.tigris.scarab.util.word.SearchFactory; 59 import org.tigris.scarab.util.word.SearchIndex; 60 import org.tigris.scarab.util.Log; 61 62 72 public class UpdateSearchIndex extends RequireLoginFirstAction 73 { 74 private static ThreadGroup tg = null; 75 private static int seconds = 5; 76 private static int counter = 0; 77 78 private void reset() 79 { 80 seconds = 5; 81 counter = 0; 82 tg = null; 83 } 84 85 public void doPerform(RunData data, TemplateContext context) 86 throws Exception 87 { 88 ScarabRequestTool scarabR = getScarabRequestTool(context); 89 ScarabLocalizationTool l10n = getLocalizationTool(context); 90 91 synchronized (this) 92 { 93 Integer inttime = new Integer (seconds); 94 Object [] time = {inttime}; 95 if (tg == null) 96 { 97 try 98 { 99 tg = new ThreadGroup ("UpdateIndex"); 100 Thread updateThread = new Thread (tg, new UpdateThread()); 101 updateThread.start(); 102 context.put("updateFrequency", inttime.toString()); 103 scarabR.setConfirmMessage(l10n.format("SearchIndexDoNoteLeavePage",time)); 104 } 105 catch (Exception e) 106 { 107 reset(); 108 context.put("updateFrequency", ""); 109 scarabR.setAlertMessage(l10n.getMessage(e)); 110 } 111 } 112 else if (tg.activeCount() == 0) 113 { 114 reset(); 115 context.put("updateFrequency", ""); 116 scarabR.setConfirmMessage(l10n.get("SearchIndexUpdated")); 117 } 118 else 119 { 120 if (counter > 5) 121 { 122 seconds = 15; 123 } 124 else if (counter > 10) 125 { 126 seconds = 20; 127 } 128 context.put("updateFrequency", inttime.toString()); 129 scarabR.setConfirmMessage(l10n.format("SearchIndexDoNoteLeavePage",time)); 130 counter++; 131 } 132 } 133 134 String template = getCurrentTemplate(data, null); 135 String nextTemplate = getNextTemplate(data, template); 136 setTarget(data, nextTemplate); 137 } 138 139 public class UpdateThread implements Runnable 140 { 141 public UpdateThread() 142 { 143 } 144 145 public void run() 146 { 147 try 148 { 149 Log.get().info("Update index started!"); 150 SearchIndex indexer = SearchFactory.getInstance(); 151 indexer.updateIndex(); 152 Log.get().info("Update index completed!"); 153 } 154 catch (Exception e) 155 { 156 Log.get().error("Update index failed:", e); 157 } 158 } 159 } 160 } 161 | Popular Tags |