X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=eclipse%2Fplugins%2Forg.argeo.slc.client.ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fcontrollers%2FProcessController.java;h=d6719dce0c10975b4922015d4a7ee0a59d4d2500;hb=24d560ee846fda5d7954d44f83cb22ab449dbe61;hp=7d0a76ad552d40c05ac539935481e0a1961d2ce3;hpb=da80480f09f8efc5e0278ed992e17e586b0a0e62;p=gpl%2Fargeo-slc.git diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/controllers/ProcessController.java b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/controllers/ProcessController.java index 7d0a76ad5..d6719dce0 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/controllers/ProcessController.java +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/controllers/ProcessController.java @@ -6,6 +6,7 @@ import java.util.Map; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.Property; +import javax.jcr.RepositoryException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -26,37 +27,28 @@ public class ProcessController { private final static Log log = LogFactory.getLog(ProcessController.class); private Map agentFactories = new HashMap(); - public void process(Node processNode) { + public ExecutionProcess process(Node processNode) { JcrExecutionProcess process = new JcrExecutionProcess(processNode); try { - // we currently only deal with single agents - Node realizedFlowNode = processNode.getNode(SlcNames.SLC_FLOW); - NodeIterator nit = realizedFlowNode.getNodes(); - if (nit.hasNext()) { - // TODO find a better way to determine which agent to use - // currently we check the agent of the first registered flow - Node firstRealizedFlow = nit.nextNode(); - // we assume there is an nt:address - String firstFlowPath = firstRealizedFlow - .getNode(SlcNames.SLC_ADDRESS) - .getProperty(Property.JCR_PATH).getString(); - Node flowNode = processNode.getSession().getNode(firstFlowPath); - String agentFactoryPath = SlcJcrUtils - .flowAgentFactoryPath(firstFlowPath); - if (!agentFactories.containsKey(agentFactoryPath)) - throw new SlcException("No agent factory registered under " - + agentFactoryPath); - SlcAgentFactory agentFactory = agentFactories - .get(agentFactoryPath); - Node agentNode = ((Node) flowNode - .getAncestor(SlcJcrUtils.AGENT_FACTORY_DEPTH + 1)); - String agentUuid = agentNode.getProperty(SlcNames.SLC_UUID) - .getString(); + SlcAgent slcAgent = findAgent(processNode); + if (slcAgent == null) + throw new SlcException("Cannot find agent for " + processNode); + slcAgent.process(process); + return process; + } catch (Exception e) { + if (!process.getStatus().equals(ExecutionProcess.ERROR)) + process.setStatus(ExecutionProcess.ERROR); + throw new SlcException("Cannot execute " + processNode, e); + } + } - // process - SlcAgent slcAgent = agentFactory.getAgent(agentUuid); - slcAgent.process(process); - } + public void kill(Node processNode) { + JcrExecutionProcess process = new JcrExecutionProcess(processNode); + try { + SlcAgent slcAgent = findAgent(processNode); + if (slcAgent == null) + throw new SlcException("Cannot find agent for " + processNode); + slcAgent.kill(process); } catch (Exception e) { if (!process.getStatus().equals(ExecutionProcess.ERROR)) process.setStatus(ExecutionProcess.ERROR); @@ -64,6 +56,36 @@ public class ProcessController { } } + protected SlcAgent findAgent(Node processNode) throws RepositoryException { + // we currently only deal with single agents + Node realizedFlowNode = processNode.getNode(SlcNames.SLC_FLOW); + NodeIterator nit = realizedFlowNode.getNodes(); + if (nit.hasNext()) { + // TODO find a better way to determine which agent to use + // currently we check the agent of the first registered flow + Node firstRealizedFlow = nit.nextNode(); + // we assume there is an nt:address + String firstFlowPath = firstRealizedFlow + .getNode(SlcNames.SLC_ADDRESS) + .getProperty(Property.JCR_PATH).getString(); + Node flowNode = processNode.getSession().getNode(firstFlowPath); + String agentFactoryPath = SlcJcrUtils + .flowAgentFactoryPath(firstFlowPath); + if (!agentFactories.containsKey(agentFactoryPath)) + throw new SlcException("No agent factory registered under " + + agentFactoryPath); + SlcAgentFactory agentFactory = agentFactories.get(agentFactoryPath); + Node agentNode = ((Node) flowNode + .getAncestor(SlcJcrUtils.AGENT_FACTORY_DEPTH + 1)); + String agentUuid = agentNode.getProperty(SlcNames.SLC_UUID) + .getString(); + + // process + return agentFactory.getAgent(agentUuid); + } + return null; + } + public synchronized void register(SlcAgentFactory agentFactory, Map properties) { String path = properties.get(SlcJcrConstants.PROPERTY_PATH);