-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Robert Schuh
committed
Jan 2, 2023
1 parent
621dfaa
commit 679ae30
Showing
13 changed files
with
103 additions
and
86 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.github.robbilie.nodegreen; | ||
|
||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
||
import java.util.*; | ||
|
||
public class Flows implements IFlow { | ||
|
||
public Map<String,Flow> activeFlows = new HashMap<>(); | ||
public List<String> activeFlowIds = new ArrayList<>(); | ||
ObjectNode activeFlowConfig; | ||
Map<String, String> activeNodesToFlow = new HashMap<>(); | ||
public void start(ObjectNode newFlowConfig) { | ||
this.stop(); | ||
this.activeFlowConfig = newFlowConfig; | ||
this.activeFlows = new HashMap<>(); | ||
this.activeFlowIds = new ArrayList<>(); | ||
this.activeNodesToFlow = new HashMap<>(); | ||
Flow global = Flow.create(this, this.activeFlowConfig); | ||
this.activeFlows.put("global", global); | ||
this.activeFlowIds.add("global"); | ||
for (Iterator<String> it = this.activeFlowConfig.get("flows").fieldNames(); it.hasNext(); ) { | ||
String id = it.next(); | ||
if (!this.activeFlows.containsKey(id)) { | ||
this.activeFlows.put(id, Flow.create(this, this.activeFlowConfig, (ObjectNode) this.activeFlowConfig.get("flows").get(id))); | ||
this.activeFlowIds.add(id); | ||
} | ||
} | ||
for (String id : this.activeFlowIds) { | ||
this.activeFlows.get(id).start(); | ||
Map<String, INode> activeNodes = this.activeFlows.get(id).getActiveNodes(); | ||
for(String nid : activeNodes.keySet()) { | ||
this.activeNodesToFlow.put(nid, id); | ||
} | ||
} | ||
} | ||
|
||
public void stop() { | ||
List<String> reverseActiveFlowIds = this.activeFlowIds.subList(0, this.activeFlowIds.size()); | ||
Collections.reverse(reverseActiveFlowIds); | ||
for (String id : reverseActiveFlowIds) { | ||
this.activeFlows.get(id).stop(); | ||
} | ||
this.activeFlows = new HashMap<>(); | ||
this.activeFlowIds = new ArrayList<>(); | ||
this.activeNodesToFlow = new HashMap<>(); | ||
} | ||
|
||
public INode getNode(String id) { | ||
if (this.activeNodesToFlow.containsKey(id) && this.activeFlows.containsKey(this.activeNodesToFlow.get(id))) { | ||
return this.activeFlows.get(this.activeNodesToFlow.get(id)).getNode(id); | ||
} | ||
for (String flowId : this.activeFlows.keySet()) { | ||
INode node = activeFlows.get(flowId).getNode(id); | ||
if (node != null) { | ||
return node; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.github.robbilie.nodegreen; | ||
|
||
public interface IFlow { | ||
INode getNode(String id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,6 @@ | ||
package io.github.robbilie.nodegreen; | ||
|
||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
public class RED { | ||
|
||
public static Nodes nodes = new Nodes(); | ||
public static Map<String,Flow> activeFlows = new HashMap<>(); | ||
public static void start(ObjectNode activeFlowConfig) { | ||
RED.stop(); | ||
RED.activeFlows = new HashMap<>(); | ||
RED.activeFlows.put("global", Flow.create(activeFlowConfig)); | ||
for (Iterator<String> it = activeFlowConfig.get("flows").fieldNames(); it.hasNext(); ) { | ||
String id = it.next(); | ||
if (!RED.activeFlows.containsKey(id)) { | ||
RED.activeFlows.put(id, Flow.create(RED.activeFlows.get("global"), activeFlowConfig, (ObjectNode) activeFlowConfig.get("flows").get(id))); | ||
} | ||
} | ||
for (Iterator<String> it = RED.activeFlows.keySet().iterator(); it.hasNext(); ) { | ||
String id = it.next(); | ||
RED.activeFlows.get(id).start(); | ||
} | ||
} | ||
|
||
public static void stop() { | ||
List<String> activeFlowIds = RED.activeFlows.keySet().stream().filter(id -> !id.equals("global")).collect(Collectors.toList()); | ||
if (RED.activeFlows.containsKey("global")) { | ||
activeFlowIds.add("global"); | ||
} | ||
for (Iterator<String> it = activeFlowIds.iterator(); it.hasNext(); ) { | ||
String id = it.next(); | ||
RED.activeFlows.get(id).stop(); | ||
} | ||
RED.activeFlows = new HashMap<>(); | ||
} | ||
public static Flows flows = new Flows(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
src/test/java/io/github/robbilie/nodegreen/nodes/CompositionsNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters