1 package org
.argeo
.slc
.client
.ui
.controllers
;
3 import java
.util
.HashMap
;
7 import javax
.jcr
.NodeIterator
;
8 import javax
.jcr
.Property
;
9 import javax
.jcr
.RepositoryException
;
11 import org
.apache
.commons
.logging
.Log
;
12 import org
.apache
.commons
.logging
.LogFactory
;
13 import org
.argeo
.slc
.SlcException
;
14 import org
.argeo
.slc
.jcr
.SlcJcrConstants
;
15 import org
.argeo
.slc
.jcr
.SlcJcrUtils
;
16 import org
.argeo
.slc
.jcr
.SlcNames
;
17 import org
.argeo
.slc
.jcr
.execution
.JcrExecutionProcess
;
18 import org
.argeo
.slc
.process
.SlcExecution
;
19 import org
.argeo
.slc
.runtime
.SlcAgent
;
20 import org
.argeo
.slc
.runtime
.SlcAgentFactory
;
21 import org
.argeo
.slc
.services
.SlcExecutionService
;
23 public class ProcessController
{
24 private final static Log log
= LogFactory
.getLog(ProcessController
.class);
25 private SlcExecutionService slcExecutionService
;
26 private Map
<String
, SlcAgentFactory
> agentFactories
= new HashMap
<String
, SlcAgentFactory
>();
28 public void execute(SlcAgent agent
, SlcExecution slcExecution
) {
29 slcExecutionService
.newExecution(slcExecution
);
30 agent
.process(slcExecution
);
31 if (log
.isDebugEnabled())
32 log
.debug("SlcExcution " + slcExecution
.getUuid()
33 + " launched on Agent " + agent
.toString());
36 public void process(Node processNode
) {
38 // we currently only deal with single agents
39 Node flowNode
= processNode
.getNode(SlcNames
.SLC_FLOW
);
40 NodeIterator nit
= flowNode
.getNodes();
42 Node firstFlow
= nit
.nextNode();
43 // we assume there is an nt:address
44 String firstFlowPath
= firstFlow
.getNode(SlcNames
.SLC_ADDRESS
)
45 .getProperty(Property
.JCR_PATH
).getString();
46 String agentFactoryPath
= SlcJcrUtils
47 .flowAgentFactoryPath(firstFlowPath
);
48 if (!agentFactories
.containsKey(agentFactoryPath
))
49 throw new SlcException("No agent factory registered under "
51 SlcAgentFactory agentFactory
= agentFactories
52 .get(agentFactoryPath
);
53 String agentUuid
= ((Node
) processNode
54 .getAncestor(SlcJcrUtils
.AGENT_FACTORY_DEPTH
+ 1))
58 SlcAgent slcAgent
= agentFactory
.getAgent(agentUuid
);
59 slcAgent
.process(new JcrExecutionProcess(processNode
));
61 } catch (RepositoryException e
) {
62 throw new SlcException("Cannot execute " + processNode
, e
);
66 public void setSlcExecutionService(SlcExecutionService slcExecutionService
) {
67 this.slcExecutionService
= slcExecutionService
;
70 public synchronized void register(SlcAgentFactory agentFactory
,
71 Map
<String
, String
> properties
) {
72 String path
= properties
.get(SlcJcrConstants
.PROPERTY_PATH
);
73 if (log
.isDebugEnabled())
74 log
.debug("Agent factory registered under " + path
);
75 agentFactories
.put(path
, agentFactory
);
78 public synchronized void unregister(SlcAgentFactory agentFactory
,
79 Map
<String
, String
> properties
) {
80 String path
= properties
.get(SlcJcrConstants
.PROPERTY_PATH
);
81 if (log
.isDebugEnabled())
82 log
.debug("Agent factory unregistered from " + path
);
83 agentFactories
.remove(path
);