Skip to content

Commit 716ae46

Browse files
authored
Merge pull request #51 from alibaba/classloader
update task node
2 parents 464b09f + 1efbb15 commit 716ae46

File tree

5 files changed

+48
-20
lines changed

5 files changed

+48
-20
lines changed

src/main/java/com/alibaba/compileflow/engine/process/preruntime/generator/impl/AbstractInOutActionNodeGenerator.java

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,41 @@ public AbstractInOutActionNodeGenerator(AbstractProcessRuntime runtime, N flowNo
3535
protected void generateCode(String event, CodeTargetSupport codeTargetSupport) {
3636

3737
HasInOutAction hasInOutAction = (HasInOutAction) flowNode;
38-
IAction inAction = hasInOutAction.getInAction();
39-
if (inAction != null) {
38+
39+
if (isTriggerMethod(codeTargetSupport)) {
40+
// codeTargetSupport.addBodyLine("// entry wait node...");
41+
42+
IAction inAction = hasInOutAction.getInAction();
43+
codeTargetSupport.addBodyLine("if (trigger) {");
44+
45+
codeTargetSupport.addBodyLine("if(\"" + event + "\".equals(event)) {");
46+
IAction outAction = hasInOutAction.getOutAction();
47+
generateActionMethodCode(codeTargetSupport, outAction);
48+
codeTargetSupport.addBodyLine("} else {");
49+
50+
codeTargetSupport.addBodyLine("running = false;");
51+
codeTargetSupport.addBodyLine("} ");
52+
53+
codeTargetSupport.addBodyLine("} else {");
54+
55+
if (inAction != null) {
56+
generateActionMethodCode(codeTargetSupport, inAction);
57+
codeTargetSupport.addBodyLine(" trigger = false;");
58+
}
59+
codeTargetSupport.addBodyLine("running = false;");
60+
codeTargetSupport.addBodyLine("}");
61+
62+
} else {
63+
64+
IAction inAction = hasInOutAction.getInAction();
4065
generateActionMethodCode(codeTargetSupport, inAction);
41-
}
42-
generateNodeComment(codeTargetSupport);
66+
codeTargetSupport.addBodyLine("if(wait_event) {");
67+
codeTargetSupport.addBodyLine("return _pResult;");
68+
codeTargetSupport.addBodyLine("} ");
4369

44-
codeTargetSupport.addBodyLine("if (trigger) {");
45-
codeTargetSupport.addBodyLine("if(\"" + event + "\".equals(event)) {");
46-
IAction outAction = hasInOutAction.getOutAction();
47-
generateActionMethodCode(codeTargetSupport, outAction);
48-
codeTargetSupport.addBodyLine("} else {");
49-
codeTargetSupport.addBodyLine("running = false;");
50-
codeTargetSupport.addBodyLine("} ");
70+
}
5171

52-
codeTargetSupport.addBodyLine("} else {");
5372

54-
codeTargetSupport.addBodyLine("running = false;");
55-
codeTargetSupport.addBodyLine("}");
5673
}
5774

5875
}

src/main/java/com/alibaba/compileflow/engine/process/preruntime/generator/impl/container/ContainerGenerator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ private void generateCode(TransitionNode flowNode, CodeTargetSupport codeTargetS
4747
return;
4848
}
4949
if (flowNode instanceof WaitElement) {
50+
// 这里要产生wait节点里的前置任务
51+
Generator generator = getGenerator(flowNode);
52+
generator.generateCode(codeTargetSupport);
5053
return;
5154
}
5255
if (flowNode instanceof SubBpmNode && ((SubBpmNode) flowNode).isWaitForTrigger()) {

src/main/java/com/alibaba/compileflow/engine/process/preruntime/generator/impl/tbbpm/WaitEventTaskGenerator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.alibaba.compileflow.engine.process.preruntime.generator.impl.tbbpm;
22

3+
import com.alibaba.compileflow.engine.definition.common.action.HasInOutAction;
4+
import com.alibaba.compileflow.engine.definition.common.action.IAction;
35
import com.alibaba.compileflow.engine.definition.tbbpm.WaitEventTaskNode;
46
import com.alibaba.compileflow.engine.process.preruntime.generator.code.CodeTargetSupport;
57
import com.alibaba.compileflow.engine.process.preruntime.generator.constansts.SystemEventConstants;

src/main/java/com/alibaba/compileflow/engine/runtime/impl/AbstractProcessRuntime.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,17 @@ public Map<String, Object> trigger(String tag, String event, Map<String, Object>
169169
public abstract FlowModelType getFlowModelType();
170170

171171
public String generateJavaCode() {
172-
if (isStateful()) {
172+
boolean stateful = isStateful();
173+
if (stateful) {
173174
classTarget.addSuperInterface(ClassWrapper.of(StatefulProcessInstance.class));
174175
classTarget.addImportedType(ClassWrapper.of(SystemEventConstants.class));
175176
} else {
176177
classTarget.addSuperInterface(ClassWrapper.of(ProcessInstance.class));
177178
}
178179
generateFlowMethod(MethodConstants.EXECUTE_METHOD_NAME,
179180
Collections.singletonList(ParamTarget.of(ClassWrapper.of("Map<String, Object>"), "_pContext")),
180-
this::generateExecuteMethodBody);
181-
if (isStateful()) {
181+
this::generateExecuteMethodBody, stateful);
182+
if (stateful) {
182183
List<ParamTarget> paramTargets = new ArrayList<>(2);
183184
paramTargets.add(ParamTarget.of(ClassWrapper.of("String"), "tag"));
184185
paramTargets.add(ParamTarget.of(ClassWrapper.of("Map<String, Object>"), "_pContext"));
@@ -191,7 +192,7 @@ public String generateJavaCode() {
191192
paramTargets.add(ParamTarget.of(ClassWrapper.of("String"), "event"));
192193
paramTargets.add(ParamTarget.of(ClassWrapper.of("Map<String, Object>"), "_pContext"));
193194
EventTriggerMethodGenerator eventTriggerMethodGenerator = new EventTriggerMethodGenerator(this);
194-
generateFlowMethod(MethodConstants.TRIGGER_METHOD_NAME, paramTargets, eventTriggerMethodGenerator);
195+
generateFlowMethod(MethodConstants.TRIGGER_METHOD_NAME, paramTargets, eventTriggerMethodGenerator, stateful);
195196
}
196197
return classTarget.generateCode();
197198
}
@@ -333,7 +334,7 @@ private Class<?> compileJavaCode(String source, ClassLoader classLoader) {
333334

334335
protected MethodTarget generateFlowMethod(String methodName,
335336
List<ParamTarget> paramTypes,
336-
Generator methodExecuteBodyGenerator) {
337+
Generator methodExecuteBodyGenerator, boolean stateful) {
337338
MethodTarget methodTarget = generateMethodDefinition(methodName, paramTypes);
338339
classTarget.addMethod(methodTarget);
339340

@@ -362,6 +363,10 @@ protected MethodTarget generateFlowMethod(String methodName,
362363
}
363364

364365
methodTarget.addBodyLine("Map<String, Object> _pResult = new HashMap<>();");
366+
// add trigger status
367+
if (stateful && MethodConstants.EXECUTE_METHOD_NAME.equals(methodName)) {
368+
methodTarget.addBodyLine("boolean wait_event = true;");
369+
}
365370
methodTarget.addNewLine();
366371
methodExecuteBodyGenerator.generateCode(methodTarget);
367372
methodTarget.addNewLine();

src/test/java/com/allibaba/compileflow/test/ProcessEngineTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public void testTbbpmModelConvert() {
7575
@Test
7676
public void testWaitPayProcess() {
7777
String code = "bpm.om.waitPaySuccessFlow";
78-
System.out.println(ProcessEngineFactory.getProcessEngine().getJavaCode(code));
78+
String javaCode = ProcessEngineFactory.getProcessEngine().getJavaCode(code);
79+
System.out.println(javaCode);
7980
Map<String, Object> context = new HashMap<>();
8081
context.put("num", 100d);
8182

0 commit comments

Comments
 (0)