1 package org
.argeo
.slc
.client
.ui
.controllers
;
4 import javax
.jcr
.RepositoryException
;
6 import org
.argeo
.slc
.SlcException
;
7 import org
.argeo
.slc
.execution
.ExecutionProcess
;
8 import org
.argeo
.slc
.execution
.SlcAgent
;
9 import org
.argeo
.slc
.jcr
.execution
.JcrExecutionProcess
;
12 * We use a separate class (not in UI components) so that it can be a singleton
13 * in an application context.
15 public class ProcessController
{
16 // private final static Log log =
17 // LogFactory.getLog(ProcessController.class);
18 // private Map<String, SlcAgentFactory> agentFactories = new HashMap<String,
19 // SlcAgentFactory>();
21 private SlcAgent agent
;
23 public ExecutionProcess
process(Node processNode
) {
24 JcrExecutionProcess process
= new JcrExecutionProcess(processNode
);
26 SlcAgent slcAgent
= findAgent(processNode
);
28 throw new SlcException("Cannot find agent for " + processNode
);
29 slcAgent
.process(process
);
31 } catch (Exception e
) {
32 if (!process
.getStatus().equals(ExecutionProcess
.ERROR
))
33 process
.setStatus(ExecutionProcess
.ERROR
);
34 throw new SlcException("Cannot execute " + processNode
, e
);
38 public void kill(Node processNode
) {
39 JcrExecutionProcess process
= new JcrExecutionProcess(processNode
);
41 SlcAgent slcAgent
= findAgent(processNode
);
43 throw new SlcException("Cannot find agent for " + processNode
);
44 slcAgent
.kill(process
.getUuid());
45 } catch (Exception e
) {
46 if (!process
.getStatus().equals(ExecutionProcess
.ERROR
))
47 process
.setStatus(ExecutionProcess
.ERROR
);
48 throw new SlcException("Cannot execute " + processNode
, e
);
52 /** Always return the default runtime agent */
53 protected SlcAgent
findAgent(Node processNode
) throws RepositoryException
{
54 // we currently only deal with single agents
55 // Node realizedFlowNode = processNode.getNode(SlcNames.SLC_FLOW);
56 // NodeIterator nit = realizedFlowNode.getNodes();
57 // if (nit.hasNext()) {
58 // // TODO find a better way to determine which agent to use
59 // // currently we check the agent of the first registered flow
60 // Node firstRealizedFlow = nit.nextNode();
61 // // we assume there is an nt:address
62 // String firstFlowPath = firstRealizedFlow
63 // .getNode(SlcNames.SLC_ADDRESS)
64 // .getProperty(Property.JCR_PATH).getString();
65 // Node flowNode = processNode.getSession().getNode(firstFlowPath);
66 // String agentFactoryPath = SlcJcrUtils
67 // .flowAgentFactoryPath(firstFlowPath);
68 // if (!agentFactories.containsKey(agentFactoryPath))
69 // throw new SlcException("No agent factory registered under "
70 // + agentFactoryPath);
71 // SlcAgentFactory agentFactory = agentFactories.get(agentFactoryPath);
72 // Node agentNode = ((Node) flowNode
73 // .getAncestor(SlcJcrUtils.AGENT_FACTORY_DEPTH + 1));
74 // String agentUuid = agentNode.getProperty(SlcNames.SLC_UUID)
78 // return agentFactory.getAgent(agentUuid);
84 public void setAgent(SlcAgent agent
) {
88 // public synchronized void register(SlcAgentFactory agentFactory,
89 // Map<String, String> properties) {
90 // String path = properties.get(SlcJcrConstants.PROPERTY_PATH);
91 // if (log.isDebugEnabled())
92 // log.debug("Agent factory registered under " + path);
93 // agentFactories.put(path, agentFactory);
96 // public synchronized void unregister(SlcAgentFactory agentFactory,
97 // Map<String, String> properties) {
98 // String path = properties.get(SlcJcrConstants.PROPERTY_PATH);
99 // if (log.isDebugEnabled())
100 // log.debug("Agent factory unregistered from " + path);
101 // agentFactories.remove(path);