diff options
author | 2023-08-19 14:39:39 +0200 | |
---|---|---|
committer | 2023-08-19 14:39:39 +0200 | |
commit | b7a46b805bd7fbb3b21a48a035698ab11fadcb7c (patch) | |
tree | ab8787dd0699cfb5a0fa1084719a0375e5b0c85b /subprojects/viatra-runtime-rete/src/main/java | |
parent | refactor: move ITC algorithms (diff) | |
download | refinery-b7a46b805bd7fbb3b21a48a035698ab11fadcb7c.tar.gz refinery-b7a46b805bd7fbb3b21a48a035698ab11fadcb7c.tar.zst refinery-b7a46b805bd7fbb3b21a48a035698ab11fadcb7c.zip |
feat: interruptible VIATRA engine
Reduce server load by introducing a timeout for semantics analysis.
Diffstat (limited to 'subprojects/viatra-runtime-rete/src/main/java')
2 files changed, 29 insertions, 27 deletions
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/ReteContainer.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/ReteContainer.java index 16e290fd..79e0526d 100644 --- a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/ReteContainer.java +++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/ReteContainer.java | |||
@@ -1,26 +1,17 @@ | |||
1 | /******************************************************************************* | 1 | /******************************************************************************* |
2 | * Copyright (c) 2004-2008 Gabor Bergmann and Daniel Varro | 2 | * Copyright (c) 2004-2008 Gabor Bergmann and Daniel Varro |
3 | * Copyright (c) 2023 The Refinery Authors <https://refinery.tools> | ||
3 | * This program and the accompanying materials are made available under the | 4 | * 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 | * terms of the Eclipse Public License v. 2.0 which is available at |
5 | * http://www.eclipse.org/legal/epl-v20.html. | 6 | * http://www.eclipse.org/legal/epl-v20.html. |
6 | * | 7 | * |
7 | * SPDX-License-Identifier: EPL-2.0 | 8 | * SPDX-License-Identifier: EPL-2.0 |
8 | *******************************************************************************/ | 9 | *******************************************************************************/ |
9 | 10 | ||
10 | package tools.refinery.viatra.runtime.rete.network; | 11 | package tools.refinery.viatra.runtime.rete.network; |
11 | 12 | ||
12 | import java.util.ArrayDeque; | ||
13 | import java.util.ArrayList; | ||
14 | import java.util.Collection; | ||
15 | import java.util.Deque; | ||
16 | import java.util.HashSet; | ||
17 | import java.util.LinkedHashSet; | ||
18 | import java.util.LinkedList; | ||
19 | import java.util.Map; | ||
20 | import java.util.Set; | ||
21 | import java.util.function.Function; | ||
22 | |||
23 | import org.apache.log4j.Logger; | 13 | import org.apache.log4j.Logger; |
14 | import tools.refinery.viatra.runtime.CancellationToken; | ||
24 | import tools.refinery.viatra.runtime.matchers.context.IQueryBackendContext; | 15 | import tools.refinery.viatra.runtime.matchers.context.IQueryBackendContext; |
25 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; | 16 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; |
26 | import tools.refinery.viatra.runtime.matchers.util.Clearable; | 17 | import tools.refinery.viatra.runtime.matchers.util.Clearable; |
@@ -42,6 +33,9 @@ import tools.refinery.viatra.runtime.rete.single.SingleInputNode; | |||
42 | import tools.refinery.viatra.runtime.rete.single.TrimmerNode; | 33 | import tools.refinery.viatra.runtime.rete.single.TrimmerNode; |
43 | import tools.refinery.viatra.runtime.rete.util.Options; | 34 | import tools.refinery.viatra.runtime.rete.util.Options; |
44 | 35 | ||
36 | import java.util.*; | ||
37 | import java.util.function.Function; | ||
38 | |||
45 | /** | 39 | /** |
46 | * @author Gabor Bergmann | 40 | * @author Gabor Bergmann |
47 | * | 41 | * |
@@ -79,6 +73,8 @@ public final class ReteContainer { | |||
79 | 73 | ||
80 | protected final TimelyConfiguration timelyConfiguration; | 74 | protected final TimelyConfiguration timelyConfiguration; |
81 | 75 | ||
76 | private final CancellationToken cancellationToken; | ||
77 | |||
82 | /** | 78 | /** |
83 | * @param threaded | 79 | * @param threaded |
84 | * false if operating in a single-threaded environment | 80 | * false if operating in a single-threaded environment |
@@ -88,6 +84,7 @@ public final class ReteContainer { | |||
88 | this.network = network; | 84 | this.network = network; |
89 | this.backendContext = network.getEngine().getBackendContext(); | 85 | this.backendContext = network.getEngine().getBackendContext(); |
90 | this.timelyConfiguration = network.getEngine().getTimelyConfiguration(); | 86 | this.timelyConfiguration = network.getEngine().getTimelyConfiguration(); |
87 | cancellationToken = backendContext.getRuntimeContext().getCancellationToken(); | ||
91 | 88 | ||
92 | this.delayedCommandQueue = new LinkedHashSet<DelayedCommand>(); | 89 | this.delayedCommandQueue = new LinkedHashSet<DelayedCommand>(); |
93 | this.delayedCommandBuffer = new LinkedHashSet<DelayedCommand>(); | 90 | this.delayedCommandBuffer = new LinkedHashSet<DelayedCommand>(); |
@@ -395,10 +392,10 @@ public final class ReteContainer { | |||
395 | 392 | ||
396 | /** | 393 | /** |
397 | * Retrieves a safe copy of the contents of a supplier. | 394 | * Retrieves a safe copy of the contents of a supplier. |
398 | * | 395 | * |
399 | * <p> Note that there may be multiple copies of a Tuple in case of a {@link TrimmerNode}, so the result is not always a set. | 396 | * <p> Note that there may be multiple copies of a Tuple in case of a {@link TrimmerNode}, so the result is not always a set. |
400 | * | 397 | * |
401 | * @param flush if true, a flush is performed before pulling the contents | 398 | * @param flush if true, a flush is performed before pulling the contents |
402 | * @since 2.3 | 399 | * @since 2.3 |
403 | */ | 400 | */ |
404 | public Collection<Tuple> pullContents(final Supplier supplier, final boolean flush) { | 401 | public Collection<Tuple> pullContents(final Supplier supplier, final boolean flush) { |
@@ -424,7 +421,7 @@ public final class ReteContainer { | |||
424 | 421 | ||
425 | /** | 422 | /** |
426 | * Retrieves the contents of a SingleInputNode's parentage. | 423 | * Retrieves the contents of a SingleInputNode's parentage. |
427 | * | 424 | * |
428 | * @since 2.3 | 425 | * @since 2.3 |
429 | */ | 426 | */ |
430 | public Collection<Tuple> pullPropagatedContents(final SingleInputNode supplier, final boolean flush) { | 427 | public Collection<Tuple> pullPropagatedContents(final SingleInputNode supplier, final boolean flush) { |
@@ -438,7 +435,7 @@ public final class ReteContainer { | |||
438 | 435 | ||
439 | /** | 436 | /** |
440 | * Retrieves the timestamp-aware contents of a SingleInputNode's parentage. | 437 | * Retrieves the timestamp-aware contents of a SingleInputNode's parentage. |
441 | * | 438 | * |
442 | * @since 2.3 | 439 | * @since 2.3 |
443 | */ | 440 | */ |
444 | public Map<Tuple, Timeline<Timestamp>> pullPropagatedContentsWithTimestamp(final SingleInputNode supplier, | 441 | public Map<Tuple, Timeline<Timestamp>> pullPropagatedContentsWithTimestamp(final SingleInputNode supplier, |
@@ -541,7 +538,7 @@ public final class ReteContainer { | |||
541 | 538 | ||
542 | /** | 539 | /** |
543 | * Sends out all pending messages to their receivers. The delivery is governed by the communication tracker. | 540 | * Sends out all pending messages to their receivers. The delivery is governed by the communication tracker. |
544 | * | 541 | * |
545 | * @since 1.6 | 542 | * @since 1.6 |
546 | */ | 543 | */ |
547 | public void deliverMessagesSingleThreaded() { | 544 | public void deliverMessagesSingleThreaded() { |
@@ -620,7 +617,7 @@ public final class ReteContainer { | |||
620 | 617 | ||
621 | /** | 618 | /** |
622 | * Returns an addressed node at this container. | 619 | * Returns an addressed node at this container. |
623 | * | 620 | * |
624 | * @pre: address.container == this, e.g. address MUST be local | 621 | * @pre: address.container == this, e.g. address MUST be local |
625 | * @throws IllegalArgumentException | 622 | * @throws IllegalArgumentException |
626 | * if address is non-local | 623 | * if address is non-local |
@@ -726,4 +723,7 @@ public final class ReteContainer { | |||
726 | return network.getInputConnector(); | 723 | return network.getInputConnector(); |
727 | } | 724 | } |
728 | 725 | ||
726 | public void checkCancelled() { | ||
727 | cancellationToken.checkCancelled(); | ||
728 | } | ||
729 | } | 729 | } |
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/StandardNode.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/StandardNode.java index e7ec36dc..7dc7c4bc 100644 --- a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/StandardNode.java +++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/StandardNode.java | |||
@@ -1,19 +1,15 @@ | |||
1 | /******************************************************************************* | 1 | /******************************************************************************* |
2 | * Copyright (c) 2004-2008 Gabor Bergmann and Daniel Varro | 2 | * Copyright (c) 2004-2008 Gabor Bergmann and Daniel Varro |
3 | * Copyright (c) 2023 The Refinery Authors <https://refinery.tools> | ||
3 | * This program and the accompanying materials are made available under the | 4 | * 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 | * terms of the Eclipse Public License v. 2.0 which is available at |
5 | * http://www.eclipse.org/legal/epl-v20.html. | 6 | * http://www.eclipse.org/legal/epl-v20.html. |
6 | * | 7 | * |
7 | * SPDX-License-Identifier: EPL-2.0 | 8 | * SPDX-License-Identifier: EPL-2.0 |
8 | *******************************************************************************/ | 9 | *******************************************************************************/ |
9 | 10 | ||
10 | package tools.refinery.viatra.runtime.rete.network; | 11 | package tools.refinery.viatra.runtime.rete.network; |
11 | 12 | ||
12 | import java.util.Collection; | ||
13 | import java.util.HashSet; | ||
14 | import java.util.List; | ||
15 | import java.util.Set; | ||
16 | |||
17 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; | 13 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; |
18 | import tools.refinery.viatra.runtime.matchers.tuple.TupleMask; | 14 | import tools.refinery.viatra.runtime.matchers.tuple.TupleMask; |
19 | import tools.refinery.viatra.runtime.matchers.util.CollectionsFactory; | 15 | import tools.refinery.viatra.runtime.matchers.util.CollectionsFactory; |
@@ -24,11 +20,16 @@ import tools.refinery.viatra.runtime.rete.network.communication.Timestamp; | |||
24 | import tools.refinery.viatra.runtime.rete.network.mailbox.Mailbox; | 20 | import tools.refinery.viatra.runtime.rete.network.mailbox.Mailbox; |
25 | import tools.refinery.viatra.runtime.rete.traceability.TraceInfo; | 21 | import tools.refinery.viatra.runtime.rete.traceability.TraceInfo; |
26 | 22 | ||
23 | import java.util.Collection; | ||
24 | import java.util.HashSet; | ||
25 | import java.util.List; | ||
26 | import java.util.Set; | ||
27 | |||
27 | /** | 28 | /** |
28 | * Base implementation for a supplier node. | 29 | * Base implementation for a supplier node. |
29 | * | 30 | * |
30 | * @author Gabor Bergmann | 31 | * @author Gabor Bergmann |
31 | * | 32 | * |
32 | */ | 33 | */ |
33 | public abstract class StandardNode extends BaseNode implements Supplier, NetworkStructureChangeSensitiveNode { | 34 | public abstract class StandardNode extends BaseNode implements Supplier, NetworkStructureChangeSensitiveNode { |
34 | protected final List<Receiver> children = CollectionsFactory.createObserverList(); | 35 | protected final List<Receiver> children = CollectionsFactory.createObserverList(); |
@@ -45,6 +46,7 @@ public abstract class StandardNode extends BaseNode implements Supplier, Network | |||
45 | * @since 2.4 | 46 | * @since 2.4 |
46 | */ | 47 | */ |
47 | protected void propagateUpdate(final Direction direction, final Tuple updateElement, final Timestamp timestamp) { | 48 | protected void propagateUpdate(final Direction direction, final Tuple updateElement, final Timestamp timestamp) { |
49 | reteContainer.checkCancelled(); | ||
48 | for (final Mailbox childMailbox : childMailboxes) { | 50 | for (final Mailbox childMailbox : childMailboxes) { |
49 | childMailbox.postMessage(direction, updateElement, timestamp); | 51 | childMailbox.postMessage(direction, updateElement, timestamp); |
50 | } | 52 | } |