X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.support.jcr%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fjcr%2Fexecution%2FJcrProcessThread.java;h=ce9aa1da391f9cd425f9540be0d43714dc57ce88;hb=99acd32f30678d05eaacc6c5db41d6134d9ce6f9;hp=26e3737b0be824d3cd0f257a7595ab1629024c5f;hpb=26cd9f658531888bfa9ba69ea5c034839b4c4149;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrProcessThread.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrProcessThread.java index 26e3737b0..ce9aa1da3 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrProcessThread.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrProcessThread.java @@ -16,6 +16,7 @@ import org.argeo.slc.core.execution.PrimitiveUtils; import org.argeo.slc.core.execution.ProcessThread; import org.argeo.slc.execution.ExecutionFlowDescriptor; import org.argeo.slc.execution.ExecutionModulesManager; +import org.argeo.slc.execution.ExecutionProcess; import org.argeo.slc.execution.ExecutionSpecAttribute; import org.argeo.slc.jcr.SlcJcrUtils; import org.argeo.slc.jcr.SlcNames; @@ -25,19 +26,47 @@ import org.argeo.slc.process.RealizedFlow; /** Where the actual execution takes place */ public class JcrProcessThread extends ProcessThread implements SlcNames { - public JcrProcessThread(ExecutionModulesManager executionModulesManager, + public JcrProcessThread(ThreadGroup processesThreadGroup, + ExecutionModulesManager executionModulesManager, JcrExecutionProcess process) { - super(executionModulesManager, process); + super(processesThreadGroup, executionModulesManager, process); } @Override - protected void process() { + protected void process() throws InterruptedException { try { - Node realizedFlowNode = getNode().getNode(SLC_FLOW); + Node rootRealizedFlowNode = getNode().getNode(SLC_FLOW); // we just manage one level for the time being - NodeIterator nit = realizedFlowNode.getNodes(SLC_FLOW); + NodeIterator nit = rootRealizedFlowNode.getNodes(SLC_FLOW); while (nit.hasNext()) { - process(nit.nextNode()); + Node realizedFlowNode = nit.nextNode(); + + // set status on realized flow + realizedFlowNode.setProperty(SLC_STATUS, + ExecutionProcess.RUNNING); + realizedFlowNode.getSession().save(); + try { + execute(realizedFlowNode); + + // set status on realized flow + realizedFlowNode.setProperty(SLC_STATUS, + ExecutionProcess.COMPLETED); + realizedFlowNode.getSession().save(); + } catch (RepositoryException e) { + throw e; + } catch (InterruptedException e) { + // set status on realized flow + realizedFlowNode.setProperty(SLC_STATUS, + ExecutionProcess.KILLED); + realizedFlowNode.getSession().save(); + throw e; + } catch (RuntimeException e) { + // set status on realized flow + realizedFlowNode.setProperty(SLC_STATUS, + ExecutionProcess.ERROR); + realizedFlowNode.getSession().save(); + throw e; + } } } catch (RepositoryException e) { throw new ArgeoException("Cannot process " + getNode(), e); @@ -45,7 +74,8 @@ public class JcrProcessThread extends ProcessThread implements SlcNames { } /** Configure the realized flows */ - protected void process(Node realizedFlowNode) throws RepositoryException { + protected void execute(Node realizedFlowNode) throws RepositoryException, + InterruptedException { if (realizedFlowNode.hasNode(SLC_ADDRESS)) { String flowPath = realizedFlowNode.getNode(SLC_ADDRESS) .getProperty(Property.JCR_PATH).getString(); @@ -78,34 +108,20 @@ public class JcrProcessThread extends ProcessThread implements SlcNames { Map attrs = readExecutionSpecAttributes(realizedFlowNode); Map values = new HashMap(); for (String attrName : attrs.keySet()) { - if (flowNode.hasNode(attrName)) { - // we assume this is a primitive - // since ref are not yet implemented - Node valueNode = flowNode.getNode(attrName); - String type = valueNode.getProperty(SLC_TYPE).getString(); - String valueStr = valueNode.getProperty(SLC_VALUE) - .getString(); - Object value = PrimitiveUtils.convert(type, valueStr); - values.put(attrName, value); - // Property prop = flowNode.getNode(attrName).getProperty( - // SLC_VALUE); - // // yes, this could be a switch... (patches welcome) - // if (prop.getType() == PropertyType.STRING) - // values.put(attrName, prop.getString()); - // else if (prop.getType() == PropertyType.LONG) - // values.put(attrName, prop.getLong()); - // else if (prop.getType() == PropertyType.DOUBLE) - // values.put(attrName, prop.getDouble()); - // else if (prop.getType() == PropertyType.BOOLEAN) - // values.put(attrName, prop.getBoolean()); - // else - // throw new SlcException("Unsupported value type " - // + PropertyType.nameFromValue(prop.getType())); - } else { +// if (flowNode.hasNode(attrName)) { +// // we assume this is a primitive +// // since ref are not yet implemented +// Node valueNode = flowNode.getNode(attrName); +// String type = valueNode.getProperty(SLC_TYPE).getString(); +// String valueStr = valueNode.getProperty(SLC_VALUE) +// .getString(); +// Object value = PrimitiveUtils.convert(type, valueStr); +// values.put(attrName, value); +// } else { ExecutionSpecAttribute attr = attrs.get(attrName); Object value = attr.getValue(); values.put(attrName, value); - } +// } } // if(executionSpec!=null) @@ -114,7 +130,11 @@ public class JcrProcessThread extends ProcessThread implements SlcNames { values, executionSpec); realizedFlow.setFlowDescriptor(efd); + // + // EXECUTE THE FLOW + // execute(realizedFlow, true); + // } } @@ -128,14 +148,15 @@ public class JcrProcessThread extends ProcessThread implements SlcNames { .isNodeType(SlcTypes.SLC_PRIMITIVE_SPEC_ATTRIBUTE)) { String type = specAttrNode.getProperty(SLC_TYPE) .getString(); + Object value = null; if (specAttrNode.hasProperty(SLC_VALUE)) { String valueStr = specAttrNode.getProperty(SLC_VALUE) .getString(); - Object value = PrimitiveUtils.convert(type, valueStr); - PrimitiveSpecAttribute specAttr = new PrimitiveSpecAttribute( - type, value); - attrs.put(specAttrNode.getName(), specAttr); + value = PrimitiveUtils.convert(type, valueStr); } + PrimitiveSpecAttribute specAttr = new PrimitiveSpecAttribute( + type, value); + attrs.put(specAttrNode.getName(), specAttr); } }