aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/RefineryConnectionFactoryExtensions.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/RefineryConnectionFactoryExtensions.java')
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/RefineryConnectionFactoryExtensions.java47
1 files changed, 47 insertions, 0 deletions
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/RefineryConnectionFactoryExtensions.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/RefineryConnectionFactoryExtensions.java
new file mode 100644
index 00000000..0fe5ee27
--- /dev/null
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/RefineryConnectionFactoryExtensions.java
@@ -0,0 +1,47 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.query.viatra.internal.rete.network;
7
8import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
9import org.eclipse.viatra.query.runtime.rete.network.Node;
10import org.eclipse.viatra.query.runtime.rete.network.ReteContainer;
11import org.eclipse.viatra.query.runtime.rete.network.Supplier;
12import org.eclipse.viatra.query.runtime.rete.remote.Address;
13import org.eclipse.viatra.query.runtime.rete.traceability.RecipeTraceInfo;
14import tools.refinery.store.query.viatra.internal.rete.recipe.RepresentativeElectionRecipe;
15
16import java.util.ArrayList;
17
18public class RefineryConnectionFactoryExtensions {
19 private final ReteContainer reteContainer;
20
21 public RefineryConnectionFactoryExtensions(ReteContainer reteContainer) {
22 this.reteContainer = reteContainer;
23 }
24
25 public boolean connectToParents(RecipeTraceInfo recipeTrace, Node freshNode) {
26 var recipe = recipeTrace.getRecipe();
27 if (recipe instanceof RepresentativeElectionRecipe representativeElectionRecipe) {
28 connectToParents(representativeElectionRecipe, (RepresentativeElectionNode) freshNode);
29 return true;
30 }
31 return false;
32 }
33
34 private void connectToParents(RepresentativeElectionRecipe recipe, RepresentativeElectionNode freshNode) {
35 var parentRecipe = recipe.getParent();
36 // Apparently VIATRA ensures that this cast is safe, see
37 // {@link org.eclipse.viatra.query.runtime.rete.network.ConnectionFactory.connectToParent}.
38 @SuppressWarnings("unchecked")
39 var parentAddress = (Address<? extends Supplier>) reteContainer.getNetwork()
40 .getExistingNodeByRecipe(parentRecipe);
41 var parentSupplier = reteContainer.getProvisioner().asSupplier(parentAddress);
42 var tuples = new ArrayList<Tuple>();
43 parentSupplier.pullInto(tuples, true);
44 freshNode.reinitializeWith(tuples);
45 reteContainer.connect(parentSupplier, freshNode);
46 }
47}