aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/misc/SimpleReceiver.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/misc/SimpleReceiver.java')
-rw-r--r--subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/misc/SimpleReceiver.java109
1 files changed, 109 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/misc/SimpleReceiver.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/misc/SimpleReceiver.java
new file mode 100644
index 00000000..dcf9ae78
--- /dev/null
+++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/misc/SimpleReceiver.java
@@ -0,0 +1,109 @@
1/*******************************************************************************
2 * Copyright (c) 2010-2012, Bergmann Gabor, Istvan Rath 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 *******************************************************************************/
9package tools.refinery.viatra.runtime.rete.misc;
10
11import java.util.Collection;
12import java.util.Collections;
13
14import tools.refinery.viatra.runtime.rete.network.BaseNode;
15import tools.refinery.viatra.runtime.rete.network.Receiver;
16import tools.refinery.viatra.runtime.rete.network.ReteContainer;
17import tools.refinery.viatra.runtime.rete.network.Supplier;
18import tools.refinery.viatra.runtime.rete.network.mailbox.Mailbox;
19import tools.refinery.viatra.runtime.rete.network.mailbox.timeless.BehaviorChangingMailbox;
20import tools.refinery.viatra.runtime.rete.network.mailbox.timely.TimelyMailbox;
21import tools.refinery.viatra.runtime.rete.traceability.TraceInfo;
22
23/**
24 * @author Bergmann Gabor
25 *
26 */
27public abstract class SimpleReceiver extends BaseNode implements Receiver {
28
29 protected Supplier parent = null;
30 /**
31 * @since 1.6
32 */
33 protected final Mailbox mailbox;
34
35 /**
36 * @param reteContainer
37 */
38 public SimpleReceiver(ReteContainer reteContainer) {
39 super(reteContainer);
40 mailbox = instantiateMailbox();
41 reteContainer.registerClearable(mailbox);
42 }
43
44 /**
45 * Instantiates the {@link Mailbox} of this receiver.
46 * Subclasses may override this method to provide their own mailbox implementation.
47 *
48 * @return the mailbox
49 * @since 2.0
50 */
51 protected Mailbox instantiateMailbox() {
52 if (this.reteContainer.isTimelyEvaluation()) {
53 return new TimelyMailbox(this, this.reteContainer);
54 } else {
55 return new BehaviorChangingMailbox(this, this.reteContainer);
56 }
57 }
58
59 @Override
60 public Mailbox getMailbox() {
61 return this.mailbox;
62 }
63
64 @Override
65 public void appendParent(Supplier supplier) {
66 if (parent == null)
67 parent = supplier;
68 else
69 throw new UnsupportedOperationException("Illegal RETE edge: " + this + " already has a parent (" + parent
70 + ") and cannot connect to additional parent (" + supplier
71 + ") as it is not a Uniqueness Enforcer Node. ");
72 }
73
74 @Override
75 public void removeParent(Supplier supplier) {
76 if (parent == supplier)
77 parent = null;
78 else
79 throw new IllegalArgumentException("Illegal RETE edge removal: the parent of " + this + " is not "
80 + supplier);
81 }
82
83 @Override
84 public Collection<Supplier> getParents() {
85 if (parent == null)
86 return Collections.emptySet();
87 else
88 return Collections.singleton(parent);
89 }
90
91 /**
92 * Disconnects this node from the network. Can be called publicly.
93 *
94 * @pre: child nodes, if any, must already be disconnected.
95 */
96 public void disconnectFromNetwork() {
97 if (parent != null)
98 reteContainer.disconnect(parent, this);
99 }
100
101 @Override
102 public void assignTraceInfo(TraceInfo traceInfo) {
103 super.assignTraceInfo(traceInfo);
104 if (traceInfo.propagateFromStandardNodeToSupplierParent())
105 if (parent != null)
106 parent.acceptPropagatedTraceInfo(traceInfo);
107 }
108
109} \ No newline at end of file