+ getCurrentStackUuid() + ", depth=" + stack.size());
ExecutionFlowRuntime leftEf = stack.pop();
- if (!leftEf.getExecutionFlow().getUuid()
- .equals(executionFlow.getUuid()))
+ if (!leftEf.getExecutionFlow().getName()
+ .equals(executionFlow.getName()))
throw new SlcException("Asked to leave " + executionFlow
+ " but last is " + leftEf);
public interface ExecutionFlow extends Executable{
public Object getParameter(String name);
public ExecutionSpec getExecutionSpec();
- public String getUuid();
+ public String getName();
}
--- /dev/null
+package org.argeo.slc.execution;
+
+import java.util.Map;
+
+public class ExecutionFlowDescriptor {
+ private String name;
+ private Map<String, Object> values;
+ private ExecutionSpec executionSpec;
+
+ public ExecutionFlowDescriptor() {
+ }
+
+ public ExecutionFlowDescriptor(String name, Map<String, Object> values,
+ ExecutionSpec executionSpec) {
+ this.name = name;
+ this.values = values;
+ this.executionSpec = executionSpec;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Map<String, Object> getValues() {
+ return values;
+ }
+
+ public ExecutionSpec getExecutionSpec() {
+ return executionSpec;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setValues(Map<String, Object> values) {
+ this.values = values;
+ }
+
+ public void setExecutionSpec(ExecutionSpec executionSpec) {
+ this.executionSpec = executionSpec;
+ }
+
+}
--- /dev/null
+package org.argeo.slc.execution;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ExecutionModuleDescriptor {
+ private List<ExecutionSpec> executionSpecs = new ArrayList<ExecutionSpec>();
+ private List<ExecutionFlowDescriptor> executionFlows = new ArrayList<ExecutionFlowDescriptor>();
+
+ public List<ExecutionSpec> getExecutionSpecs() {
+ return executionSpecs;
+ }
+
+ public List<ExecutionFlowDescriptor> getExecutionFlows() {
+ return executionFlows;
+ }
+
+ public void setExecutionSpecs(List<ExecutionSpec> executionSpecs) {
+ this.executionSpecs = executionSpecs;
+ }
+
+ public void setExecutionFlows(List<ExecutionFlowDescriptor> executionFlows) {
+ this.executionFlows = executionFlows;
+ }
+
+}
package org.argeo.slc.execution;
+import java.util.HashMap;
import java.util.Map;
-import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.generic.GenericBeanFactoryAccessor;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.util.Assert;
-public class ExecutionRegister implements InitializingBean {
+public class ExecutionRegister implements InitializingBean,
+ ApplicationContextAware {
private final static Log log = LogFactory.getLog(ExecutionRegister.class);
- @Autowired
- private Set<ExecutionFlow> executionFlows;
+ private ApplicationContext applicationContext;
- @Autowired
- private Set<ExecutionSpec> executionSpecs;
+ public ExecutionModuleDescriptor getDescriptor() {
+ ExecutionModuleDescriptor md = new ExecutionModuleDescriptor();
- public void afterPropertiesSet() throws Exception {
- log.debug("Register: " + executionSpecs.size() + " specs");
- for (ExecutionSpec spec : executionSpecs) {
- log.debug(spec);
- Map<String, ExecutionSpecAttribute> attributes = spec
- .getAttributes();
- log.debug("Spec attributes: ");
- for (String key : attributes.keySet()) {
- log.debug(" " + key + "\t" + attributes.get(key));
+ GenericBeanFactoryAccessor accessor = new GenericBeanFactoryAccessor(
+ applicationContext);
+ Map<String, ExecutionFlow> executionFlows = accessor
+ .getBeansOfType(ExecutionFlow.class);
+
+ for (String name : executionFlows.keySet()) {
+ ExecutionFlow executionFlow = executionFlows.get(name);
+
+ Assert.notNull(executionFlow.getName());
+ Assert.state(name.equals(executionFlow.getName()));
+
+ ExecutionSpec executionSpec = executionFlow.getExecutionSpec();
+ Assert.notNull(executionSpec);
+ Assert.notNull(executionSpec.getName());
+
+ Map<String, Object> values = new HashMap<String, Object>();
+ for (String key : executionSpec.getAttributes().keySet()) {
+ ExecutionSpecAttribute attribute = executionSpec
+ .getAttributes().get(key);
+ if (attribute instanceof SimpleExecutionSpec
+ && attribute.getIsParameter()) {
+ values.put(key, executionFlow.getParameter(key));
+ }
}
- }
- log.debug("Register: " + executionFlows.size() + " flows");
- for (ExecutionFlow flow : executionFlows) {
- log.debug(flow);
-// Map<String, Object> attributes = flow.getAttributes();
-// log.debug("Specified parameters: ");
-// for (String key : flow.getExecutionSpec().getAttributes().keySet()) {
-// log.debug(" "
-// + key
-// + "\t"
-// + (attributes.containsKey(key) ? "SPECIFIED"
-// : "TO SPECIFY"));
-// }
+ ExecutionFlowDescriptor efd = new ExecutionFlowDescriptor(name,
+ values, executionSpec);
+
+ if (!md.getExecutionSpecs().contains(executionSpec))
+ md.getExecutionSpecs().add(executionSpec);
+ md.getExecutionFlows().add(efd);
}
+ return md;
}
+
+ public void afterPropertiesSet() throws Exception {
+ log.debug("Execution Module Descriptor:\n" + getDescriptor());
+ }
+
+ public void setApplicationContext(ApplicationContext applicationContext)
+ throws BeansException {
+ this.applicationContext = applicationContext;
+ }
+
}
public interface ExecutionSpec {
public Map<String, ExecutionSpecAttribute> getAttributes();
+
+ public String getName();
}
private Map<String, Object> parameters = new HashMap<String, Object>();
private List<Executable> executables = new ArrayList<Executable>();
- private final String uuid = UUID.randomUUID().toString();
-
- public SimpleExecutionFlow(){
-
+ public SimpleExecutionFlow() {
+
}
- public SimpleExecutionFlow(Map<String, Object> parameters){
+ public SimpleExecutionFlow(Map<String, Object> parameters) {
this.parameters.putAll(parameters);
}
return;
MapBindingResult errors = new MapBindingResult(parameters, "execution#"
- + getUuid());
+ + getName());
for (String key : executionSpec.getAttributes().keySet()) {
ExecutionSpecAttribute executionSpecAttr = executionSpec
.getAttributes().get(key);
this.parameters = attributes;
}
- public String getUuid() {
- return uuid;
+ public String getName() {
+ return name;
}
public ExecutionSpec getExecutionSpec() {
return esa.getValue();
} else {
throw new SlcException("Key " + name
- + " is not define in the specifications of "
+ + " is not defined in the specifications of "
+ toString());
}
}
}
public String toString() {
- return new StringBuffer("Flow ").append(name).toString();// .append(" [#")
- // .append(uuid).append(']').toString();
+ return new StringBuffer("Flow ").append(name).toString();
+ }
+
+ public boolean equals(Object obj) {
+ return ((ExecutionFlow) obj).getName().equals(name);
}
}
import java.util.HashMap;
import java.util.Map;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.argeo.slc.SlcException;
-import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.BeanNameAware;
public class SimpleExecutionSpec implements ExecutionSpec, BeanNameAware {
+ private final static Log log = LogFactory.getLog(SimpleExecutionSpec.class);
+
private final static ThreadLocal<ExecutionFlow> initializingFlow = new ThreadLocal<ExecutionFlow>();
private Map<String, ExecutionSpecAttribute> attributes = new HashMap<String, ExecutionSpecAttribute>();
if (flow == null)
throw new SlcException("No flow is currently initializing."
+ " Declare flow refs as inner beans or prototypes.");
-/*
- RefSpecAttribute refSpecAttribute = (RefSpecAttribute) attributes
- .get(name);
- Class<?> targetClass = refSpecAttribute.getTargetClass();
- ExecutionTargetSource targetSource = new ExecutionTargetSource(flow,
- targetClass, name);
- ProxyFactory proxyFactory = new ProxyFactory();
- proxyFactory.setTargetClass(targetClass);
- proxyFactory.setProxyTargetClass(true);
- proxyFactory.setTargetSource(targetSource);
-
- return proxyFactory.getProxy();*/
+ /*
+ * RefSpecAttribute refSpecAttribute = (RefSpecAttribute) attributes
+ * .get(name); Class<?> targetClass = refSpecAttribute.getTargetClass();
+ * ExecutionTargetSource targetSource = new ExecutionTargetSource(flow,
+ * targetClass, name); ProxyFactory proxyFactory = new ProxyFactory();
+ * proxyFactory.setTargetClass(targetClass);
+ * proxyFactory.setProxyTargetClass(true);
+ * proxyFactory.setTargetSource(targetSource);
+ *
+ * return proxyFactory.getProxy();
+ */
return flow.getParameter(name);
}
return name;
}
+ // FLOWS INITIALIZATION SUPPORT
+
public static void flowInitializationStarted(ExecutionFlow flow) {
+ if (log.isTraceEnabled())
+ log.trace("Start initialization of " + flow.hashCode() + " ("
+ + flow + " - " + flow.getClass() + ")");
initializingFlow.set(flow);
}
public static void flowInitializationFinished(ExecutionFlow flow) {
+ if (log.isTraceEnabled())
+ log.trace("Finish initialization of " + flow.hashCode() + " ("
+ + flow + " - " + flow.getClass() + ")");
ExecutionFlow registeredFlow = initializingFlow.get();
- if (registeredFlow == null)
- throw new SlcException("No flow registered");
- if (!flow.getUuid().equals(registeredFlow.getUuid()))
- throw new SlcException("Current flow is " + flow);
- initializingFlow.set(null);
+ if (registeredFlow != null) {
+ if (!flow.getName().equals(registeredFlow.getName()))
+ throw new SlcException("Current flow is " + flow);
+ initializingFlow.set(null);
+ }
}
public static Object getInitializingFlowParameter(String key) {
public static Boolean isInFlowInitialization() {
return initializingFlow.get() != null;
}
+
+ public boolean equals(Object obj) {
+ return ((ExecutionSpec) obj).getName().equals(name);
+ }
+
}