Added "cancel processes" command, not hooked up yet.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@171 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-03-03 00:30:39 +00:00
parent 2741d54984
commit ad7671508f
3 changed files with 40 additions and 0 deletions

View File

@ -43,6 +43,7 @@ import com.metaweb.gridworks.commands.recon.ReconJudgeOneCellCommand;
import com.metaweb.gridworks.commands.recon.ReconJudgeSimilarCellsCommand;
import com.metaweb.gridworks.commands.recon.ReconMatchSpecificTopicCommand;
import com.metaweb.gridworks.commands.recon.ReconcileCommand;
import com.metaweb.gridworks.commands.util.CancelProcessesCommand;
import com.metaweb.gridworks.commands.util.GetExpressionLanguageInfoCommand;
import com.metaweb.gridworks.commands.util.GuessTypesOfColumnCommand;
import com.metaweb.gridworks.commands.util.PreviewExpressionCommand;
@ -68,6 +69,7 @@ public class GridworksServlet extends HttpServlet {
_commands.put("undo-redo", new UndoRedoCommand());
_commands.put("apply-operations", new ApplyOperationsCommand());
_commands.put("cancel-processes", new CancelProcessesCommand());
_commands.put("compute-facets", new ComputeFacetsCommand());
_commands.put("do-text-transform", new DoTextTransformCommand());

View File

@ -0,0 +1,29 @@
package com.metaweb.gridworks.commands.util;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.metaweb.gridworks.commands.Command;
import com.metaweb.gridworks.model.Project;
public class CancelProcessesCommand extends Command {
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
Project project = getProject(request);
project.processManager.cancelAll();
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json");
response.getWriter().write("{ \"code\" : \"ok\" }");
} catch (Exception e) {
respondException(response, e);
}
}
}

View File

@ -56,6 +56,15 @@ public class ProcessManager implements Jsonizable {
update();
}
public void cancelAll() {
for (Process p : _processes) {
if (!p.isImmediate() && p.isRunning()) {
p.cancel();
}
}
_processes.clear();
}
protected void update() {
while (_processes.size() > 0) {
Process p = _processes.get(0);