diff options
Diffstat (limited to 'subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/mailbox/timeless/AbstractUpdateSplittingMailbox.java')
-rw-r--r-- | subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/mailbox/timeless/AbstractUpdateSplittingMailbox.java | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/mailbox/timeless/AbstractUpdateSplittingMailbox.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/mailbox/timeless/AbstractUpdateSplittingMailbox.java new file mode 100644 index 00000000..1e1ada71 --- /dev/null +++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/mailbox/timeless/AbstractUpdateSplittingMailbox.java | |||
@@ -0,0 +1,109 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2018, Tamas Szabo, 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.network.mailbox.timeless; | ||
10 | |||
11 | import tools.refinery.viatra.runtime.rete.network.Receiver; | ||
12 | import tools.refinery.viatra.runtime.rete.network.ReteContainer; | ||
13 | import tools.refinery.viatra.runtime.rete.network.communication.CommunicationGroup; | ||
14 | import tools.refinery.viatra.runtime.rete.network.indexer.MessageIndexer; | ||
15 | import tools.refinery.viatra.runtime.rete.network.mailbox.Mailbox; | ||
16 | import tools.refinery.viatra.runtime.rete.network.mailbox.MessageIndexerFactory; | ||
17 | |||
18 | /** | ||
19 | * An abstract mailbox implementation that is capable of splitting update messages based on some form of monotonicity | ||
20 | * (anti-monotone and monotone). The monotonicity is either defined by the less or equal operator of a poset or, it can | ||
21 | * be the standard subset ordering among sets of tuples. | ||
22 | * | ||
23 | * @author Tamas Szabo | ||
24 | * @since 2.0 | ||
25 | * | ||
26 | */ | ||
27 | public abstract class AbstractUpdateSplittingMailbox<IndexerType extends MessageIndexer, ReceiverType extends Receiver> implements Mailbox { | ||
28 | |||
29 | protected IndexerType monotoneQueue; | ||
30 | protected IndexerType antiMonotoneQueue; | ||
31 | protected IndexerType monotoneBuffer; | ||
32 | protected IndexerType antiMonotoneBuffer; | ||
33 | protected boolean deliveringMonotone; | ||
34 | protected boolean deliveringAntiMonotone; | ||
35 | protected final ReceiverType receiver; | ||
36 | protected final ReteContainer container; | ||
37 | protected CommunicationGroup group; | ||
38 | |||
39 | public AbstractUpdateSplittingMailbox(final ReceiverType receiver, final ReteContainer container, | ||
40 | final MessageIndexerFactory<IndexerType> factory) { | ||
41 | this.receiver = receiver; | ||
42 | this.container = container; | ||
43 | this.monotoneQueue = factory.create(); | ||
44 | this.antiMonotoneQueue = factory.create(); | ||
45 | this.monotoneBuffer = factory.create(); | ||
46 | this.antiMonotoneBuffer = factory.create(); | ||
47 | this.deliveringMonotone = false; | ||
48 | this.deliveringAntiMonotone = false; | ||
49 | } | ||
50 | |||
51 | protected void swapAndClearMonotone() { | ||
52 | final IndexerType tmp = this.monotoneQueue; | ||
53 | this.monotoneQueue = this.monotoneBuffer; | ||
54 | this.monotoneBuffer = tmp; | ||
55 | this.monotoneBuffer.clear(); | ||
56 | } | ||
57 | |||
58 | protected void swapAndClearAntiMonotone() { | ||
59 | final IndexerType tmp = this.antiMonotoneQueue; | ||
60 | this.antiMonotoneQueue = this.antiMonotoneBuffer; | ||
61 | this.antiMonotoneBuffer = tmp; | ||
62 | this.antiMonotoneBuffer.clear(); | ||
63 | } | ||
64 | |||
65 | protected IndexerType getActiveMonotoneQueue() { | ||
66 | if (this.deliveringMonotone) { | ||
67 | return this.monotoneBuffer; | ||
68 | } else { | ||
69 | return this.monotoneQueue; | ||
70 | } | ||
71 | } | ||
72 | |||
73 | protected IndexerType getActiveAntiMonotoneQueue() { | ||
74 | if (this.deliveringAntiMonotone) { | ||
75 | return this.antiMonotoneBuffer; | ||
76 | } else { | ||
77 | return this.antiMonotoneQueue; | ||
78 | } | ||
79 | } | ||
80 | |||
81 | @Override | ||
82 | public ReceiverType getReceiver() { | ||
83 | return this.receiver; | ||
84 | } | ||
85 | |||
86 | @Override | ||
87 | public void clear() { | ||
88 | this.monotoneQueue.clear(); | ||
89 | this.antiMonotoneQueue.clear(); | ||
90 | this.monotoneBuffer.clear(); | ||
91 | this.antiMonotoneBuffer.clear(); | ||
92 | } | ||
93 | |||
94 | @Override | ||
95 | public boolean isEmpty() { | ||
96 | return this.getActiveMonotoneQueue().isEmpty() && this.getActiveAntiMonotoneQueue().isEmpty(); | ||
97 | } | ||
98 | |||
99 | @Override | ||
100 | public CommunicationGroup getCurrentGroup() { | ||
101 | return this.group; | ||
102 | } | ||
103 | |||
104 | @Override | ||
105 | public void setCurrentGroup(final CommunicationGroup group) { | ||
106 | this.group = group; | ||
107 | } | ||
108 | |||
109 | } | ||