X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=eclipse%2Fplugins%2Forg.argeo.slc.client.ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fcontrollers%2FProcessController.java;h=cdeb01e27696aa98b29f42823aeb6efe13b282d9;hb=8908d07cc1fd6ac0a274c460bbd40652816ca054;hp=328282c54921bb094d29b7671c4954fc6cc6fb3b;hpb=0e2ff188c2e8ffac85739cccc3925e8bd82d7be9;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 328282c54..cdeb01e27 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 @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.argeo.slc.client.ui.controllers; import java.util.HashMap; @@ -6,6 +21,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; @@ -29,34 +45,10 @@ public class ProcessController { 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(); - - // process - SlcAgent slcAgent = agentFactory.getAgent(agentUuid); - slcAgent.process(process); - } + 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)) @@ -65,6 +57,50 @@ public class ProcessController { } } + 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); + throw new SlcException("Cannot execute " + processNode, e); + } + } + + 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);