aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/SingleInputNode.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/SingleInputNode.java')
-rw-r--r--subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/SingleInputNode.java126
1 files changed, 126 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/SingleInputNode.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/SingleInputNode.java
new file mode 100644
index 00000000..99fc45b2
--- /dev/null
+++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/SingleInputNode.java
@@ -0,0 +1,126 @@
1/*******************************************************************************
2 * Copyright (c) 2004-2008 Gabor Bergmann and Daniel Varro
3 * This program and the accompanying materials are made available under the
4 * terms of the Eclipse Public License v. 2.0 which is available at
5 * http://www.eclipse.org/legal/epl-v20.html.
6 *
7 * SPDX-License-Identifier: EPL-2.0
8 *******************************************************************************/
9
10package tools.refinery.viatra.runtime.rete.single;
11
12import java.util.Collection;
13import java.util.Collections;
14import java.util.Map;
15
16import tools.refinery.viatra.runtime.matchers.tuple.Tuple;
17import tools.refinery.viatra.runtime.matchers.util.timeline.Timeline;
18import tools.refinery.viatra.runtime.rete.network.ReteContainer;
19import tools.refinery.viatra.runtime.rete.network.StandardNode;
20import tools.refinery.viatra.runtime.rete.network.Supplier;
21import tools.refinery.viatra.runtime.rete.network.Tunnel;
22import tools.refinery.viatra.runtime.rete.network.communication.CommunicationTracker;
23import tools.refinery.viatra.runtime.rete.network.communication.Timestamp;
24import tools.refinery.viatra.runtime.rete.network.mailbox.Mailbox;
25import tools.refinery.viatra.runtime.rete.network.mailbox.timeless.BehaviorChangingMailbox;
26import tools.refinery.viatra.runtime.rete.network.mailbox.timely.TimelyMailbox;
27import tools.refinery.viatra.runtime.rete.traceability.TraceInfo;
28
29/**
30 * @author Gabor Bergmann
31 *
32 */
33public abstract class SingleInputNode extends StandardNode implements Tunnel {
34
35 protected Supplier parent;
36 /**
37 * @since 1.6
38 */
39 protected Mailbox mailbox;
40
41 public SingleInputNode(ReteContainer reteContainer) {
42 super(reteContainer);
43 mailbox = instantiateMailbox();
44 reteContainer.registerClearable(mailbox);
45 parent = null;
46 }
47
48 /**
49 * Instantiates the {@link Mailbox} of this receiver.
50 * Subclasses may override this method to provide their own mailbox implementation.
51 *
52 * @return the mailbox
53 * @since 2.0
54 */
55 protected Mailbox instantiateMailbox() {
56 if (this.reteContainer.isTimelyEvaluation()) {
57 return new TimelyMailbox(this, this.reteContainer);
58 } else {
59 return new BehaviorChangingMailbox(this, this.reteContainer);
60 }
61 }
62
63 @Override
64 public CommunicationTracker getCommunicationTracker() {
65 return this.reteContainer.getCommunicationTracker();
66 }
67
68 @Override
69 public Mailbox getMailbox() {
70 return this.mailbox;
71 }
72
73 @Override
74 public void appendParent(Supplier supplier) {
75 if (parent == null)
76 parent = supplier;
77 else
78 throw new UnsupportedOperationException("Illegal RETE edge: " + this + " already has a parent (" + parent
79 + ") and cannot connect to additional parent (" + supplier
80 + ") as it is not a Uniqueness Enforcer Node. ");
81 }
82
83 @Override
84 public void removeParent(Supplier supplier) {
85 if (parent == supplier)
86 parent = null;
87 else
88 throw new IllegalArgumentException("Illegal RETE edge removal: the parent of " + this + " is not "
89 + supplier);
90 }
91
92 /**
93 * To be called by derived classes and ReteContainer.
94 */
95 public void propagatePullInto(final Collection<Tuple> collector, final boolean flush) {
96 if (parent != null) {
97 parent.pullInto(collector, flush);
98 }
99 }
100
101 /**
102 * To be called by derived classes and ReteContainer.
103 */
104 public void propagatePullIntoWithTimestamp(final Map<Tuple, Timeline<Timestamp>> collector, final boolean flush) {
105 if (parent != null) {
106 parent.pullIntoWithTimeline(collector, flush);
107 }
108 }
109
110 @Override
111 public Collection<Supplier> getParents() {
112 if (parent == null)
113 return Collections.emptySet();
114 else
115 return Collections.singleton(parent);
116 }
117
118 @Override
119 public void assignTraceInfo(TraceInfo traceInfo) {
120 super.assignTraceInfo(traceInfo);
121 if (traceInfo.propagateFromStandardNodeToSupplierParent())
122 if (parent != null)
123 parent.acceptPropagatedTraceInfo(traceInfo);
124 }
125
126}