From ad7671508f33d33c59e6971a7bb269559d38f50c Mon Sep 17 00:00:00 2001 From: David Huynh Date: Wed, 3 Mar 2010 00:30:39 +0000 Subject: [PATCH] Added "cancel processes" command, not hooked up yet. git-svn-id: http://google-refine.googlecode.com/svn/trunk@171 7d457c2a-affb-35e4-300a-418c747d4874 --- .../metaweb/gridworks/GridworksServlet.java | 2 ++ .../commands/util/CancelProcessesCommand.java | 29 +++++++++++++++++++ .../gridworks/process/ProcessManager.java | 9 ++++++ 3 files changed, 40 insertions(+) create mode 100644 src/main/java/com/metaweb/gridworks/commands/util/CancelProcessesCommand.java diff --git a/src/main/java/com/metaweb/gridworks/GridworksServlet.java b/src/main/java/com/metaweb/gridworks/GridworksServlet.java index f8ab11e48..d22480330 100644 --- a/src/main/java/com/metaweb/gridworks/GridworksServlet.java +++ b/src/main/java/com/metaweb/gridworks/GridworksServlet.java @@ -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()); diff --git a/src/main/java/com/metaweb/gridworks/commands/util/CancelProcessesCommand.java b/src/main/java/com/metaweb/gridworks/commands/util/CancelProcessesCommand.java new file mode 100644 index 000000000..f1906c63e --- /dev/null +++ b/src/main/java/com/metaweb/gridworks/commands/util/CancelProcessesCommand.java @@ -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); + } + } +} diff --git a/src/main/java/com/metaweb/gridworks/process/ProcessManager.java b/src/main/java/com/metaweb/gridworks/process/ProcessManager.java index 209c795da..e090601eb 100644 --- a/src/main/java/com/metaweb/gridworks/process/ProcessManager.java +++ b/src/main/java/com/metaweb/gridworks/process/ProcessManager.java @@ -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);