enhancement #I8UQR4 while组件本身加入loopIndex

This commit is contained in:
everywhere.z
2024-01-09 14:31:55 +08:00
parent 9b7e0d004e
commit 3059db967c
5 changed files with 8 additions and 26 deletions

View File

@@ -39,7 +39,7 @@ public class WhileCondition extends LoopCondition {
int index = 0;
if(!this.isParallel()){
//串行循环
while (getWhileResult(slotIndex)) {
while (getWhileResult(slotIndex, index)) {
executableItem.setCurrChainId(this.getCurrChainId());
setLoopIndex(executableItem, index);
executableItem.execute(slotIndex);
@@ -60,7 +60,7 @@ public class WhileCondition extends LoopCondition {
List<CompletableFuture<LoopFutureObj>> futureList = new ArrayList<>();
//获取并行循环的线程池
ExecutorService parallelExecutor = ExecutorHelper.loadInstance().buildLoopParallelExecutor();
while (getWhileResult(slotIndex)){
while (getWhileResult(slotIndex, index)){
CompletableFuture<LoopFutureObj> future =
CompletableFuture.supplyAsync(new LoopParallelSupplier(executableItem, this.getCurrChainId(), slotIndex, index), parallelExecutor);
futureList.add(future);
@@ -81,10 +81,11 @@ public class WhileCondition extends LoopCondition {
}
}
private boolean getWhileResult(Integer slotIndex) throws Exception {
Executable whileItem = this.getWhileItem();
private boolean getWhileResult(Integer slotIndex, int loopIndex) throws Exception {
Node whileItem = (Node) this.getWhileItem();
// 执行while组件
whileItem.setCurrChainId(this.getCurrChainId());
whileItem.setLoopIndex(loopIndex);
whileItem.execute(slotIndex);
return whileItem.getItemResultMetaValue(slotIndex);

View File

@@ -15,7 +15,6 @@ public class CCmp extends NodeComponent {
@Override
public void process() {
System.out.println(this.getLoopIndex());
System.out.println("CCmp executed!");
}

View File

@@ -16,15 +16,7 @@ public class DCmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
String key = "test";
if (context.hasData(key)) {
int count = context.getData(key);
context.setData(key, ++count);
}
else {
context.setData(key, 1);
}
System.out.println("DCmp executed!");
}
}

View File

@@ -10,9 +10,7 @@ public class YCmp extends NodeBreakComponent {
@Override
public boolean processBreak() throws Exception {
DefaultContext context = this.getFirstContextBean();
int count = context.getData("test");
return count > 3;
return this.getLoopIndex() > 2;
}
}

View File

@@ -10,15 +10,7 @@ public class ZCmp extends NodeWhileComponent {
@Override
public boolean processWhile() throws Exception {
DefaultContext context = this.getFirstContextBean();
String key = "test";
if (context.hasData(key)) {
int count = context.getData("test");
return count < 5;
}
else {
return true;
}
return this.getLoopIndex()<5;
}
}