diff options
Diffstat (limited to 'subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/Receiver.java')
-rw-r--r-- | subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/Receiver.java | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/Receiver.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/Receiver.java new file mode 100644 index 00000000..3dc9aad7 --- /dev/null +++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/Receiver.java | |||
@@ -0,0 +1,85 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2004-2008 Gabor Bergmann 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 | |||
10 | package tools.refinery.viatra.runtime.rete.network; | ||
11 | |||
12 | import java.util.Collection; | ||
13 | import java.util.Map; | ||
14 | import java.util.Map.Entry; | ||
15 | |||
16 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; | ||
17 | import tools.refinery.viatra.runtime.matchers.util.Direction; | ||
18 | import tools.refinery.viatra.runtime.rete.network.communication.Timestamp; | ||
19 | import tools.refinery.viatra.runtime.rete.network.mailbox.Mailbox; | ||
20 | |||
21 | /** | ||
22 | * ALL METHODS: FOR INTERNAL USE ONLY; ONLY INVOKE FROM {@link ReteContainer} | ||
23 | * | ||
24 | * @author Gabor Bergmann | ||
25 | * @noimplement This interface is not intended to be implemented by external clients. | ||
26 | */ | ||
27 | public interface Receiver extends Node { | ||
28 | |||
29 | /** | ||
30 | * Updates the receiver with a newly found or lost partial matching. | ||
31 | * | ||
32 | * @since 2.4 | ||
33 | */ | ||
34 | public void update(final Direction direction, final Tuple updateElement, final Timestamp timestamp); | ||
35 | |||
36 | /** | ||
37 | * Updates the receiver in batch style with a collection of updates. The input collection consists of pairs in the | ||
38 | * form (t, c) where t is an update tuple and c is the count. The count can also be negative, and it specifies how | ||
39 | * many times the tuple t gets deleted or inserted. The default implementation of this method simply calls | ||
40 | * {@link #update(Direction, Tuple, Timestamp)} individually for all updates. | ||
41 | * | ||
42 | * @since 2.8 | ||
43 | */ | ||
44 | public default void batchUpdate(final Collection<Map.Entry<Tuple, Integer>> updates, final Timestamp timestamp) { | ||
45 | for (final Entry<Tuple, Integer> entry : updates) { | ||
46 | int count = entry.getValue(); | ||
47 | |||
48 | Direction direction; | ||
49 | if (count < 0) { | ||
50 | direction = Direction.DELETE; | ||
51 | count = -count; | ||
52 | } else { | ||
53 | direction = Direction.INSERT; | ||
54 | } | ||
55 | |||
56 | for (int i = 0; i < count; i++) { | ||
57 | update(direction, entry.getKey(), timestamp); | ||
58 | } | ||
59 | } | ||
60 | } | ||
61 | |||
62 | /** | ||
63 | * Returns the {@link Mailbox} of this receiver. | ||
64 | * | ||
65 | * @return the mailbox | ||
66 | * @since 2.0 | ||
67 | */ | ||
68 | public Mailbox getMailbox(); | ||
69 | |||
70 | /** | ||
71 | * appends a parent that will continuously send insert and revoke updates to this supplier | ||
72 | */ | ||
73 | void appendParent(final Supplier supplier); | ||
74 | |||
75 | /** | ||
76 | * removes a parent | ||
77 | */ | ||
78 | void removeParent(final Supplier supplier); | ||
79 | |||
80 | /** | ||
81 | * access active parent | ||
82 | */ | ||
83 | Collection<Supplier> getParents(); | ||
84 | |||
85 | } | ||