--- /dev/null
+package org.argeo.slc.execution.tasks;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.process.Executable;
+
+public class Echo implements Executable {
+ private final static Log defaultLog = LogFactory.getLog(Echo.class);
+
+ private Log log;
+ private String message;
+
+ public void execute() {
+ log().info(message);
+ }
+
+ protected Log log() {
+ return log != null ? log : defaultLog;
+ }
+
+ public void setLog(Log log) {
+ this.log = log;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+}
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.slc.logging.Log4jUtils;
+import org.argeo.slc.process.SlcExecution;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry;
import org.springframework.beans.factory.xml.XmlBeanDefinitionParser;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.ApplicationEvent;
+import org.springframework.context.ApplicationListener;
import org.springframework.context.support.FileSystemXmlApplicationContext;
+import org.springframework.context.support.GenericApplicationContext;
-public class EfLauncher {
- private static Log log;
+public class EfLauncher implements ApplicationListener {
+ private final Log log;
- public static void main(String[] args) {
- init();
-
- String script = "src/slc/conf/main.xml";
- //describe(script);
-
- FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(
- script);
- // context.start();
- log.info("Context initialized");
+ private boolean running = false;
- ExecutionFlow main = (ExecutionFlow)context.getBean("main");
- main.execute();
- /*
- Map<String, ExecutionFlow> eFlows = context
- .getBeansOfType(ExecutionFlow.class);
- for (String name : eFlows.keySet()) {
- log.info("##\n## Execute ExecutionFlow " + name);
- ExecutionFlow eFlow = eFlows.get(name);
- eFlow.execute();
-
- }*/
- }
-
- private static void describe(String script){
- SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
- XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry);
- reader.loadBeanDefinitions("file:" + script);
- new ConsoleContextDescriber().describeContext(registry);
- }
-
- private static void init() {
+ public EfLauncher() {
Properties userProperties = new Properties();
FileInputStream in = null;
try {
Log4jUtils.initLog4j(null);
log = LogFactory.getLog(EfLauncher.class);
+ }
+
+ public void launch(String script) {
+ // describe(script);
+
+ GenericApplicationContext context = new GenericApplicationContext();
+ XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
+ reader.loadBeanDefinitions(script);
+ // FileSystemXmlApplicationContext context = new
+ // FileSystemXmlApplicationContext(
+ // script);
+ context.addApplicationListener(this);
+ context.refresh();
+ context.start();
+ log.debug("Context initialized");
+ SlcExecution slcExecution = new SlcExecution();
+ slcExecution.getAttributes().put("slc.flows", "main");
+
+ running = true;
+ context.publishEvent(new NewExecutionEvent(this, slcExecution));
+
+ synchronized (this) {
+ while (running)
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ // silent
+ }
+ }
}
+ public synchronized boolean isRunning() {
+ return running;
+ }
+
+ public synchronized void setRunning(boolean running) {
+ this.running = running;
+ }
+
+ public void onApplicationEvent(ApplicationEvent event) {
+ if (event instanceof ExecutionFinishedEvent) {
+ ExecutionContext executionContext = ((ExecutionFinishedEvent) event)
+ .getExecutionContext();
+ log.debug("Execution " + executionContext.getUuid()
+ + " finished, stopping launcher...");
+ synchronized (this) {
+ running = false;
+ notifyAll();
+ }
+ }
+
+ }
+
+ public static void main(String[] args) {
+ String script = "file:src/slc/conf/main.xml";
+ new EfLauncher().launch(script);
+
+ // ExecutionFlow main = (ExecutionFlow)context.getBean("main");
+ // main.execute();
+ /*
+ * Map<String, ExecutionFlow> eFlows = context
+ * .getBeansOfType(ExecutionFlow.class); for (String name :
+ * eFlows.keySet()) { log.info("##\n## Execute ExecutionFlow " + name);
+ * ExecutionFlow eFlow = eFlows.get(name); eFlow.execute();
+ *
+ * }
+ */
+ }
+
+ private static void describe(String script) {
+ SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
+ XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry);
+ reader.loadBeanDefinitions(script);
+ new ConsoleContextDescriber().describeContext(registry);
+ }
}
package org.argeo.slc.executionflow;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Stack;
+import java.util.UUID;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.slc.SlcException;
+import org.argeo.slc.process.SlcExecution;
+import org.springframework.beans.factory.ObjectFactory;
public class ExecutionContext {
private final static Log log = LogFactory.getLog(ExecutionContext.class);
private final static ThreadLocal<ExecutionContext> executionContext = new ThreadLocal<ExecutionContext>();
- private final Stack<ExecutionFlow> stack = new Stack<ExecutionFlow>();
+ private final Stack<ExecutionFlowRuntime> stack = new Stack<ExecutionFlowRuntime>();
- public static ExecutionFlow getCurrentFlow() {
+ // TODO: make it thread safe?
+ private final Map<String, Object> variables = new HashMap<String, Object>();
+
+ private final String uuid = UUID.randomUUID().toString();
+
+ public static Map<String, Object> getVariables() {
+ if (executionContext.get() == null)
+ return null;
+ return executionContext.get().variables;
+ }
+
+ public static ExecutionContext getCurrent() {
+ return executionContext.get();
+ }
+
+ public static String getExecutionUuid() {
if (executionContext.get() == null)
return null;
- return executionContext.get().stack.peek();
+ return executionContext.get().getUuid();
}
+ public static void registerExecutionContext(ExecutionContext context) {
+ if (executionContext.get() != null)
+ throw new SlcException("Context #" + executionContext.get().uuid
+ + " already registered.");
+ executionContext.set(context);
+ }
+
+ // public static ExecutionFlow getCurrentFlow() {
+ // if (executionContext.get() == null)
+ // return null;
+ // return executionContext.get().stack.peek();
+ // }
+
public static void enterFlow(ExecutionFlow executionFlow) {
- if (executionContext.get() == null) {
- // TODO: deal with parallell flows
- executionContext.set(new ExecutionContext());
- }
- Stack<ExecutionFlow> stack = executionContext.get().stack;
- stack.push(executionFlow);
- if (log.isDebugEnabled())
- log.debug("Depth: " + stack.size() + ". Enter " + executionFlow);
+ Stack<ExecutionFlowRuntime> stack = executionContext.get().stack;
+ stack.push(new ExecutionFlowRuntime(executionFlow));
+ if (log.isTraceEnabled())
+ log.debug(depthSpaces(stack.size()) + "=> " + executionFlow + " #"
+ + getCurrentStackUuid() + ", depth=" + stack.size());
+ }
+
+ private static String depthSpaces(int depth) {
+ StringBuffer buf = new StringBuffer(depth * 2);
+ for (int i = 0; i < depth - 1; i++)
+ buf.append(" ");
+ return buf.toString();
}
public static void leaveFlow(ExecutionFlow executionFlow) {
- Stack<ExecutionFlow> stack = executionContext.get().stack;
- if (log.isDebugEnabled())
- log.debug("Depth: " + stack.size() + ". Leave " + executionFlow);
- ExecutionFlow leftEf = stack.pop();
+ Stack<ExecutionFlowRuntime> stack = executionContext.get().stack;
+ if (log.isTraceEnabled())
+ log.debug(depthSpaces(stack.size()) + "<= " + executionFlow + " #"
+ + getCurrentStackUuid() + ", depth=" + stack.size());
+ ExecutionFlowRuntime leftEf = stack.pop();
leftEf.getScopedObjects().clear();
- if (!leftEf.getUuid().equals(executionFlow.getUuid())) {
+
+ if (!leftEf.getExecutionFlow().getUuid()
+ .equals(executionFlow.getUuid())) {
throw new SlcException("Asked to leave " + executionFlow
+ " but last is " + leftEf);
}
}
+
+ public static String getCurrentStackUuid() {
+ return getWithCheck().stack.peek().uuid;
+ }
+
+ public static ExecutionFlow getCurrentFlow() {
+ return getWithCheck().stack.peek().executionFlow;
+ }
+
+ public static Boolean isExecuting() {
+ return executionContext.get() != null;
+ }
+
+ private static ExecutionContext getWithCheck() {
+ if (executionContext.get() == null)
+ throw new SlcException("No execution context");
+ return executionContext.get();
+ }
+
+ public static Object findOrAddScopedObject(String name,
+ ObjectFactory objectFactory) {
+ ExecutionContext executionContext = getWithCheck();
+ Object obj = executionContext.findScopedObject(name);
+ if (obj == null) {
+ obj = objectFactory.getObject();
+ executionContext.stack.peek().getScopedObjects().put(name, obj);
+ }
+ return obj;
+ }
+
+ /** return null if not found */
+ protected Object findScopedObject(String key) {
+ Object obj = null;
+ for (int i = stack.size() - 1; i >= 0; i--) {
+ if (stack.get(i).getScopedObjects().containsKey(key)) {
+ obj = stack.get(i).getScopedObjects().get(key);
+ break;
+ }
+ }
+ return obj;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ private static class ExecutionFlowRuntime {
+ private final ExecutionFlow executionFlow;
+ private final Map<String, Object> scopedObjects = new HashMap<String, Object>();
+ private final String uuid = UUID.randomUUID().toString();
+
+ public ExecutionFlowRuntime(ExecutionFlow executionFlow) {
+ this.executionFlow = executionFlow;
+ }
+
+ public ExecutionFlow getExecutionFlow() {
+ return executionFlow;
+ }
+
+ public Map<String, Object> getScopedObjects() {
+ return scopedObjects;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ }
}
--- /dev/null
+package org.argeo.slc.executionflow;
+
+import org.springframework.context.ApplicationEvent;
+
+public class ExecutionFinishedEvent extends ApplicationEvent {
+ static final long serialVersionUID = 012;
+
+ private final ExecutionContext executionContext;
+
+ public ExecutionFinishedEvent(Object source, ExecutionContext executionContext) {
+ super(source);
+ this.executionContext = executionContext;
+ }
+
+ public ExecutionContext getExecutionContext() {
+ return executionContext;
+ }
+
+}
public Map<String, Object> getAttributes();
public ExecutionSpec getExecutionSpec();
public String getUuid();
- public Map<String, Object> getScopedObjects();
}
public PropertyValues postProcessPropertyValues(PropertyValues pvs,
PropertyDescriptor[] pds, Object bean, String beanName)
throws BeansException {
- ExecutionFlow currentFlow = ExecutionContext.getCurrentFlow();
- if (currentFlow == null)
+ if (!ExecutionContext.isExecuting())
return pvs;
+ ExecutionFlow currentFlow = ExecutionContext.getCurrentFlow();
+
Properties props = new Properties();
Map<String, Object> attributes = currentFlow.getAttributes();
Map<String, ExecutionSpecAttribute> specAttributes = currentFlow
+ " is not set in " + currentFlow);
props.setProperty(key, attributes.get(key).toString());
-// if (log.isTraceEnabled())
-// log.trace("Use attribute " + key);
+ // if (log.isTraceEnabled())
+ // log.trace("Use attribute " + key);
}
}
CustomPpc ppc = new CustomPpc(props);
tsv.setValue(convertedValue);
if (log.isTraceEnabled()) {
if (!originalValue.equals(convertedValue))
- log.trace("Converted " + beanName + "[" + pv.getName()
- + "]: " + originalValue + " to "
- + convertedValue);
+ log.trace("Converted field '" + pv.getName() + "': '"
+ + originalValue + "' to '" + convertedValue
+ + "' in bean " + beanName);
}
} else {
-// if (log.isTraceEnabled())
-// log.trace(beanName + "[" + pv.getName() + "]: "
-// + pv.getValue().getClass());
+ // if (log.isTraceEnabled())
+ // log.trace(beanName + "[" + pv.getName() + "]: "
+ // + pv.getValue().getClass());
}
}
}
public String process(String strVal) {
- String value = parseStringValue(strVal, this.props, new HashSet<String>());
+ String value = parseStringValue(strVal, this.props,
+ new HashSet<String>());
return (value.equals(nullValue) ? null : value);
}
}
--- /dev/null
+package org.argeo.slc.executionflow;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Autowired;
+
+public class ExecutionRegister implements InitializingBean {
+ private final static Log log = LogFactory.getLog(ExecutionRegister.class);
+
+ @Autowired
+ private Set<ExecutionFlow> executionFlows;
+
+ @Autowired
+ private Set<ExecutionSpec> executionSpecs;
+
+ 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));
+ }
+ }
+
+ 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"));
+ }
+ }
+
+ }
+}
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.SlcException;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.config.Scope;
public Object get(String name, ObjectFactory objectFactory) {
if (log.isTraceEnabled())
- log.info("Getting scoped bean " + name);
- ExecutionFlow executionFlow = ExecutionContext.getCurrentFlow();
- // returns cached instance
- if (executionFlow.getScopedObjects().containsKey(name)) {
- Object obj = executionFlow.getScopedObjects().get(name);
- if (log.isTraceEnabled())
- log.info("Return cached scoped object " + obj);
- return obj;
- }
- // creates instance
- Object obj = objectFactory.getObject();
- if (obj instanceof ExecutionFlow) {
- // add to itself (it is not yet the current flow)
- ((ExecutionFlow) obj).getScopedObjects().put(name, obj);
- if (log.isTraceEnabled())
- log.info("Cached flow object " + obj + " in itself");
- } else {
- executionFlow.getScopedObjects().put(name, obj);
- if (log.isTraceEnabled())
- log.info("Created regular scoped object " + obj);
- }
- return obj;
+ log.trace("Getting scoped bean " + name);
+ return ExecutionContext.findOrAddScopedObject(name, objectFactory);
+
+ // if (ExecutionContext.getScopedObjects().containsKey(name)) {
+ // // returns cached instance
+ // Object obj = ExecutionContext.getScopedObjects().get(name);
+ // if (log.isTraceEnabled())
+ // log.trace("Return cached scoped object " + obj);
+ // return obj;
+ // } else {
+ // // creates instance
+ // Object obj = objectFactory.getObject();
+ // ExecutionContext.getScopedObjects().put(name, obj);
+ // if (log.isTraceEnabled())
+ // log.trace("Created regular scoped object " + obj);
+ // return obj;
+ // }
}
public String getConversationId() {
- ExecutionFlow executionFlow = ExecutionContext.getCurrentFlow();
- return executionFlow.getUuid();
+ return ExecutionContext.getCurrentStackUuid();
}
public void registerDestructionCallback(String name, Runnable callback) {
package org.argeo.slc.executionflow;
+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.TargetSource;
public class ExecutionTargetSource implements TargetSource {
private final static Log log = LogFactory
.getLog(ExecutionTargetSource.class);
- private String name;
- private Class targetClass;
+ private final String name;
+ private final Class<?> targetClass;
+ private final ExecutionFlow executionFlow;
+
+ public ExecutionTargetSource(ExecutionFlow executionFlow,
+ Class<?> targetClass, String name) {
+ this.executionFlow = executionFlow;
+ this.targetClass = targetClass;
+ this.name = name;
+ }
public Object getTarget() throws Exception {
if (log.isTraceEnabled())
log.trace("Getting object " + name);
- ExecutionFlow executionFlow = ExecutionContext.getCurrentFlow();
- Object obj = executionFlow.getAttributes().get(name);
+ Map<String, Object> attributes = executionFlow.getAttributes();
+ if (!attributes.containsKey(name))
+ throw new SlcException("Key " + name + " is not registered in "
+ + executionFlow);
+ Object obj = attributes.get(name);
if (log.isTraceEnabled())
log.trace("Target object " + obj);
return obj;
}
- public void setName(String name) {
- this.name = name;
- }
-
- public void setTargetClass(Class targetClass) {
- this.targetClass = targetClass;
- }
-
}
--- /dev/null
+package org.argeo.slc.executionflow;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.process.SlcExecution;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.ApplicationEvent;
+import org.springframework.context.ApplicationListener;
+
+public class Executor implements ApplicationListener, ApplicationContextAware {
+ private final static Log log = LogFactory.getLog(Executor.class);
+
+ private ApplicationContext applicationContext;
+
+ public void onApplicationEvent(ApplicationEvent event) {
+ if (event instanceof NewExecutionEvent) {
+ SlcExecution slcExecution = ((NewExecutionEvent) event)
+ .getSlcExecution();
+ ExecutionContext executionContext = new ExecutionContext();
+ ExecutionThread thread = new ExecutionThread(executionContext,
+ slcExecution);
+ thread.start();
+ }
+
+ }
+
+ public void setApplicationContext(ApplicationContext applicationContext)
+ throws BeansException {
+ this.applicationContext = applicationContext;
+ }
+
+ private class ExecutionThread extends Thread {
+ private final SlcExecution slcExecution;
+ private final ExecutionContext executionContext;
+
+ public ExecutionThread(ExecutionContext executionContext,
+ SlcExecution slcExecution) {
+ super("SLC Execution #" + executionContext.getUuid());
+ this.slcExecution = slcExecution;
+ this.executionContext = executionContext;
+ }
+
+ public void run() {
+ // Initialize from SlcExecution
+ ExecutionContext.registerExecutionContext(executionContext);
+ ExecutionContext.getVariables()
+ .putAll(slcExecution.getAttributes());
+
+ try {
+ log
+ .info("Start execution #"
+ + ExecutionContext.getExecutionUuid());
+ String executionBean = slcExecution.getAttributes().get(
+ "slc.flows");
+ ExecutionFlow main = (ExecutionFlow) applicationContext
+ .getBean(executionBean);
+ main.execute();
+ } finally {
+ applicationContext.publishEvent(new ExecutionFinishedEvent(
+ this, executionContext));
+ }
+
+ }
+ }
+
+}
--- /dev/null
+package org.argeo.slc.executionflow;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;
+
+public class InstantiationPostProcessor extends
+ InstantiationAwareBeanPostProcessorAdapter {
+ private final static Log log = LogFactory
+ .getLog(InstantiationPostProcessor.class);
+
+ @Override
+ public boolean postProcessAfterInstantiation(Object bean, String beanName)
+ throws BeansException {
+ if (bean instanceof ExecutionFlow)
+ SimpleExecutionSpec.flowInitializationStarted((ExecutionFlow) bean);
+ return true;
+ }
+
+ @Override
+ public Object postProcessBeforeInitialization(Object bean, String beanName)
+ throws BeansException {
+ if (bean instanceof ExecutionFlow)
+ SimpleExecutionSpec
+ .flowInitializationFinished((ExecutionFlow) bean);
+ return bean;
+ }
+}
--- /dev/null
+package org.argeo.slc.executionflow;
+
+import org.argeo.slc.process.SlcExecution;
+import org.springframework.context.ApplicationEvent;
+
+public class NewExecutionEvent extends ApplicationEvent {
+ static final long serialVersionUID = 012;
+
+ private final SlcExecution slcExecution;
+
+ public NewExecutionEvent(Object source, SlcExecution slcExecution) {
+ super(source);
+ this.slcExecution = slcExecution;
+ }
+
+ public SlcExecution getSlcExecution() {
+ return slcExecution;
+ }
+
+}
public class SimpleExecutionFlow implements ExecutionFlow, InitializingBean,
BeanNameAware {
- // private static ThreadLocal<ExecutionFlow> executionFlow = new
- // ThreadLocal<ExecutionFlow>();
-
private ExecutionSpec executionSpec = new SimpleExecutionSpec();
private String name = null;
private Map<String, Object> attributes = new HashMap<String, Object>();
- private Map<String, Object> scopedObjects = new HashMap<String, Object>();
private List<Executable> executables = new ArrayList<Executable>();
private final String uuid = UUID.randomUUID().toString();
public void execute() {
- try {
- // ExecutionContext.enterFlow(this);
- for (Executable executable : executables) {
- executable.execute();
- }
- } finally {
- // ExecutionContext.leaveFlow(this);
+ for (Executable executable : executables) {
+ executable.execute();
}
}
if (executionSpecAttr instanceof RefSpecAttribute) {
RefSpecAttribute rsa = (RefSpecAttribute) executionSpecAttr;
Class targetClass = rsa.getTargetClass();
- if (!targetClass.isAssignableFrom(obj.getClass()))
- errors.rejectValue(key,
- "Not compatible with target class "
- + targetClass);
+ if (!targetClass.isAssignableFrom(obj.getClass())) {
+ errors.reject(key
+ + " not compatible with target class "
+ + targetClass);
+ }
}
}
}
return uuid;
}
- public Map<String, Object> getScopedObjects() {
- return scopedObjects;
- }
-
public ExecutionSpec getExecutionSpec() {
return executionSpec;
}
public String toString() {
- return new StringBuffer("Flow ").append(name).append(" [#")
- .append(uuid).append(']').toString();
+ return new StringBuffer("Flow ").append(name).toString();// .append(" [#")
+ // .append(uuid).append(']').toString();
}
}
import java.util.HashMap;
import java.util.Map;
+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 ThreadLocal<ExecutionFlow> initializingFlow = new ThreadLocal<ExecutionFlow>();
-public class SimpleExecutionSpec implements ExecutionSpec {
private Map<String, ExecutionSpecAttribute> attributes = new HashMap<String, ExecutionSpecAttribute>();
+ private String name = null;
+
public Map<String, ExecutionSpecAttribute> getAttributes() {
return attributes;
}
}
public Object createRef(String name) {
+ ExecutionFlow flow = initializingFlow.get();
+ 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();
- targetSource.setName(name);
- targetSource.setTargetClass(targetClass);
+ 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();
}
+
+ public void setBeanName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public static void flowInitializationStarted(ExecutionFlow flow) {
+ initializingFlow.set(flow);
+ }
+
+ public static void flowInitializationFinished(ExecutionFlow flow) {
+ 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);
+ }
}
<property name="executionSpec" ref="basic.executionSpec" />\r
<property name="executables">\r
<list>\r
+ <ref bean="echo1" />\r
<bean parent="testRun">\r
<property name="testDefinition" ref="testDef" />\r
<property name="testData">\r
</bean>\r
<bean parent="testRun">\r
<property name="testDefinition" ref="testDef" />\r
- <property name="testData">\r
- <bean parent="basic.ref">\r
- <constructor-arg value="testData2" />\r
- </bean>\r
- </property>\r
+ <property name="testData" ref="ref1" />\r
</bean>\r
</list>\r
</property>\r
</bean>\r
\r
+ <bean id="ref1" parent="basic.ref" scope="prototype">\r
+ <constructor-arg value="testData2" />\r
+ </bean>\r
+\r
<bean id="testDef" class="org.argeo.slc.core.test.BasicTestDefinition"\r
scope="prototype" />\r
\r
<?xml version="1.0" encoding="UTF-8"?>\r
<beans xmlns="http://www.springframework.org/schema/beans"\r
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"\r
- xmlns:aop="http://www.springframework.org/schema/aop"\r
+ xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"\r
xsi:schemaLocation="\r
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd\r
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd\r
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd\r
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">\r
\r
<import resource="testCases/basic-001.xml" />\r
<import resource="testCases/basic-002.xml" />\r
\r
<bean id="main" class="org.argeo.slc.executionflow.SimpleExecutionFlow">\r
+ <property name="executionSpec">\r
+ <bean class="org.argeo.slc.executionflow.SimpleExecutionSpec">\r
+ <property name="attributes">\r
+ <map>\r
+ <entry key="testKey">\r
+ <bean parent="specAttribute" p:value="660" />\r
+ </entry>\r
+ </map>\r
+ </property>\r
+ </bean>\r
+ </property>\r
<property name="executables">\r
<list>\r
+ <ref local="echo1" />\r
<ref bean="basic.001" />\r
<ref bean="basic.001" />\r
<ref bean="basic.002" />\r
</property>\r
</bean>\r
\r
+ <bean id="echo1" parent="echoTemplate" scope="execution">\r
+ <property name="message" value="From main! @{testKey}" />\r
+ <aop:scoped-proxy />\r
+ </bean>\r
+\r
+ <bean id="echoTemplate" class="org.argeo.slc.execution.tasks.Echo"\r
+ abstract="true">\r
+ </bean>\r
+\r
+ <context:annotation-config />\r
+ <bean class="org.argeo.slc.executionflow.ExecutionRegister" />\r
+\r
+\r
<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">\r
<property name="scopes">\r
<map>\r
<bean\r
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />\r
<bean class="org.argeo.slc.executionflow.ExecutionParameterPostProcessor" />\r
+ <bean class="org.argeo.slc.executionflow.InstantiationPostProcessor" />\r
+ <bean class="org.argeo.slc.executionflow.Executor" />\r
\r
<bean class="org.argeo.slc.executionflow.ExecutionAspect"></bean>\r
<aop:aspectj-autoproxy />\r
## Levels
log4j.logger.org.argeo=DEBUG
log4j.logger.org.argeo.slc.executionflow.ExecutionParameterPostProcessor=TRACE
+log4j.logger.org.argeo.slc.executionflow.ExecutionContext=DEBUG
## Appenders
# console is set to be a ConsoleAppender.
\r
<import resource="../basic.xml" />\r
\r
- <bean id="basic.001" parent="basic.executionFlowTemplate" scope="execution">\r
- <aop:scoped-proxy />\r
+ <bean id="basic.001" parent="basic.executionFlowTemplate">\r
<property name="attributes">\r
<map>\r
<entry key="testData1" value-ref="basic.001.testData" />\r
<entry key="testData2">\r
- <bean class="org.argeo.slc.core.test.BasicTestData">\r
- <property name="expected" value="tata" />\r
- <property name="reached" value="tata" />\r
+ <bean class="org.argeo.slc.core.test.BasicTestData" scope="execution">\r
+ <aop:scoped-proxy />\r
+ <property name="expected" value="tata101" />\r
+ <property name="reached" value="tata@{testedComponentId}" />\r
</bean>\r
</entry>\r
</map>\r