X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=plugins%2Forg.argeo.slc.client.ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fcontrollers%2FProcessController.java;h=8b66bd89a49d9fb74803f09a4e08a3e183228cce;hb=fd6362dda19f29ca746ecefae779694e6cb43dd4;hp=cdeb01e27696aa98b29f42823aeb6efe13b282d9;hpb=651d33e13bfa9a7b46464be412023ee747e612e8;p=gpl%2Fargeo-slc.git diff --git a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/controllers/ProcessController.java b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/controllers/ProcessController.java index cdeb01e27..8b66bd89a 100644 --- a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/controllers/ProcessController.java +++ b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/controllers/ProcessController.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2012 Mathieu Baudier + * Copyright (C) 2007-2012 Argeo GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,32 +15,25 @@ */ package org.argeo.slc.client.ui.controllers; -import java.util.HashMap; -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; import org.argeo.slc.SlcException; import org.argeo.slc.execution.ExecutionProcess; -import org.argeo.slc.jcr.SlcJcrConstants; -import org.argeo.slc.jcr.SlcJcrUtils; -import org.argeo.slc.jcr.SlcNames; +import org.argeo.slc.execution.SlcAgent; import org.argeo.slc.jcr.execution.JcrExecutionProcess; -import org.argeo.slc.runtime.SlcAgent; -import org.argeo.slc.runtime.SlcAgentFactory; /** * We use a separate class (not in UI components) so that it can be a singleton * in an application context. */ public class ProcessController { - private final static Log log = LogFactory.getLog(ProcessController.class); - private Map agentFactories = new HashMap(); + // private final static Log log = + // LogFactory.getLog(ProcessController.class); + // private Map agentFactories = new HashMap(); + + private SlcAgent agent; public ExecutionProcess process(Node processNode) { JcrExecutionProcess process = new JcrExecutionProcess(processNode); @@ -63,7 +56,7 @@ public class ProcessController { SlcAgent slcAgent = findAgent(processNode); if (slcAgent == null) throw new SlcException("Cannot find agent for " + processNode); - slcAgent.kill(process); + slcAgent.kill(process.getUuid()); } catch (Exception e) { if (!process.getStatus().equals(ExecutionProcess.ERROR)) process.setStatus(ExecutionProcess.ERROR); @@ -71,49 +64,55 @@ public class ProcessController { } } + /** Always return the default runtime agent */ 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(); + // 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); + // } - // process - return agentFactory.getAgent(agentUuid); - } - return null; + return agent; } - public synchronized void register(SlcAgentFactory agentFactory, - Map properties) { - String path = properties.get(SlcJcrConstants.PROPERTY_PATH); - if (log.isDebugEnabled()) - log.debug("Agent factory registered under " + path); - agentFactories.put(path, agentFactory); + public void setAgent(SlcAgent agent) { + this.agent = agent; } - public synchronized void unregister(SlcAgentFactory agentFactory, - Map properties) { - String path = properties.get(SlcJcrConstants.PROPERTY_PATH); - if (log.isDebugEnabled()) - log.debug("Agent factory unregistered from " + path); - agentFactories.remove(path); - } + // public synchronized void register(SlcAgentFactory agentFactory, + // Map properties) { + // String path = properties.get(SlcJcrConstants.PROPERTY_PATH); + // if (log.isDebugEnabled()) + // log.debug("Agent factory registered under " + path); + // agentFactories.put(path, agentFactory); + // } + // + // public synchronized void unregister(SlcAgentFactory agentFactory, + // Map properties) { + // String path = properties.get(SlcJcrConstants.PROPERTY_PATH); + // if (log.isDebugEnabled()) + // log.debug("Agent factory unregistered from " + path); + // agentFactories.remove(path); + // } }