diff options
Diffstat (limited to 'subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/communication/CommunicationGroup.java')
-rw-r--r-- | subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/communication/CommunicationGroup.java | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/communication/CommunicationGroup.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/communication/CommunicationGroup.java new file mode 100644 index 00000000..8cedeb11 --- /dev/null +++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/communication/CommunicationGroup.java | |||
@@ -0,0 +1,103 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2017, 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.communication; | ||
10 | |||
11 | import java.util.Collection; | ||
12 | import java.util.Map; | ||
13 | |||
14 | import tools.refinery.viatra.runtime.rete.network.Node; | ||
15 | import tools.refinery.viatra.runtime.rete.network.mailbox.Mailbox; | ||
16 | |||
17 | /** | ||
18 | * A communication group represents a set of nodes in the communication graph that form a strongly connected component. | ||
19 | * | ||
20 | * @author Tamas Szabo | ||
21 | * @since 1.6 | ||
22 | */ | ||
23 | public abstract class CommunicationGroup implements Comparable<CommunicationGroup> { | ||
24 | |||
25 | public static final String UNSUPPORTED_MESSAGE_KIND = "Unsupported message kind "; | ||
26 | |||
27 | /** | ||
28 | * Marker for the {@link CommunicationTracker} | ||
29 | */ | ||
30 | public boolean isEnqueued = false; | ||
31 | |||
32 | protected final Node representative; | ||
33 | |||
34 | /** | ||
35 | * May be changed during bumping in {@link CommunicationTracker.registerDependency} | ||
36 | */ | ||
37 | protected int identifier; | ||
38 | |||
39 | /** | ||
40 | * @since 1.7 | ||
41 | */ | ||
42 | protected final CommunicationTracker tracker; | ||
43 | |||
44 | /** | ||
45 | * @since 1.7 | ||
46 | */ | ||
47 | public CommunicationGroup(final CommunicationTracker tracker, final Node representative, final int identifier) { | ||
48 | this.tracker = tracker; | ||
49 | this.representative = representative; | ||
50 | this.identifier = identifier; | ||
51 | } | ||
52 | |||
53 | public abstract void deliverMessages(); | ||
54 | |||
55 | public Node getRepresentative() { | ||
56 | return representative; | ||
57 | } | ||
58 | |||
59 | public abstract boolean isEmpty(); | ||
60 | |||
61 | /** | ||
62 | * @since 2.0 | ||
63 | */ | ||
64 | public abstract void notifyLostAllMessages(final Mailbox mailbox, final MessageSelector kind); | ||
65 | |||
66 | /** | ||
67 | * @since 2.0 | ||
68 | */ | ||
69 | public abstract void notifyHasMessage(final Mailbox mailbox, final MessageSelector kind); | ||
70 | |||
71 | public abstract Map<MessageSelector, Collection<Mailbox>> getMailboxes(); | ||
72 | |||
73 | public abstract boolean isRecursive(); | ||
74 | |||
75 | @Override | ||
76 | public int hashCode() { | ||
77 | return this.identifier; | ||
78 | } | ||
79 | |||
80 | @Override | ||
81 | public String toString() { | ||
82 | return this.getClass().getSimpleName() + " " + this.identifier + " - representative: " + this.representative | ||
83 | + " - isEmpty: " + isEmpty(); | ||
84 | } | ||
85 | |||
86 | @Override | ||
87 | public boolean equals(final Object obj) { | ||
88 | if (obj == null || this.getClass() != obj.getClass()) { | ||
89 | return false; | ||
90 | } else if (this == obj) { | ||
91 | return true; | ||
92 | } else { | ||
93 | final CommunicationGroup that = (CommunicationGroup) obj; | ||
94 | return this.identifier == that.identifier; | ||
95 | } | ||
96 | } | ||
97 | |||
98 | @Override | ||
99 | public int compareTo(final CommunicationGroup that) { | ||
100 | return this.identifier - that.identifier; | ||
101 | } | ||
102 | |||
103 | } | ||