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