diff options
author | Kristóf Marussy <marussy@mit.bme.hu> | 2023-09-14 19:29:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-14 19:29:36 +0200 |
commit | 98ed3b6db5f4e51961a161050cc31c66015116e8 (patch) | |
tree | 8bfd6d9bc8d6ed23b9eb0f889dd40b6c24fe8f92 /subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/misc/SimpleReceiver.java | |
parent | Merge pull request #38 from nagilooh/design-space-exploration (diff) | |
parent | Merge remote-tracking branch 'upstream/main' into partial-interpretation (diff) | |
download | refinery-98ed3b6db5f4e51961a161050cc31c66015116e8.tar.gz refinery-98ed3b6db5f4e51961a161050cc31c66015116e8.tar.zst refinery-98ed3b6db5f4e51961a161050cc31c66015116e8.zip |
Merge pull request #39 from kris7t/partial-interpretation
Implement partial interpretation based model generation
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.java | 109 |
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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.rete.misc; | ||
10 | |||
11 | import java.util.Collection; | ||
12 | import java.util.Collections; | ||
13 | |||
14 | import tools.refinery.viatra.runtime.rete.network.BaseNode; | ||
15 | import tools.refinery.viatra.runtime.rete.network.Receiver; | ||
16 | import tools.refinery.viatra.runtime.rete.network.ReteContainer; | ||
17 | import tools.refinery.viatra.runtime.rete.network.Supplier; | ||
18 | import tools.refinery.viatra.runtime.rete.network.mailbox.Mailbox; | ||
19 | import tools.refinery.viatra.runtime.rete.network.mailbox.timeless.BehaviorChangingMailbox; | ||
20 | import tools.refinery.viatra.runtime.rete.network.mailbox.timely.TimelyMailbox; | ||
21 | import tools.refinery.viatra.runtime.rete.traceability.TraceInfo; | ||
22 | |||
23 | /** | ||
24 | * @author Bergmann Gabor | ||
25 | * | ||
26 | */ | ||
27 | public 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 | ||