aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime-rete/src/main/java
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2023-08-19 14:39:39 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2023-08-19 14:39:39 +0200
commitb7a46b805bd7fbb3b21a48a035698ab11fadcb7c (patch)
treeab8787dd0699cfb5a0fa1084719a0375e5b0c85b /subprojects/viatra-runtime-rete/src/main/java
parentrefactor: move ITC algorithms (diff)
downloadrefinery-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')
-rw-r--r--subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/ReteContainer.java38
-rw-r--r--subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/network/StandardNode.java18
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
10package tools.refinery.viatra.runtime.rete.network; 11package tools.refinery.viatra.runtime.rete.network;
11 12
12import java.util.ArrayDeque;
13import java.util.ArrayList;
14import java.util.Collection;
15import java.util.Deque;
16import java.util.HashSet;
17import java.util.LinkedHashSet;
18import java.util.LinkedList;
19import java.util.Map;
20import java.util.Set;
21import java.util.function.Function;
22
23import org.apache.log4j.Logger; 13import org.apache.log4j.Logger;
14import tools.refinery.viatra.runtime.CancellationToken;
24import tools.refinery.viatra.runtime.matchers.context.IQueryBackendContext; 15import tools.refinery.viatra.runtime.matchers.context.IQueryBackendContext;
25import tools.refinery.viatra.runtime.matchers.tuple.Tuple; 16import tools.refinery.viatra.runtime.matchers.tuple.Tuple;
26import tools.refinery.viatra.runtime.matchers.util.Clearable; 17import tools.refinery.viatra.runtime.matchers.util.Clearable;
@@ -42,6 +33,9 @@ import tools.refinery.viatra.runtime.rete.single.SingleInputNode;
42import tools.refinery.viatra.runtime.rete.single.TrimmerNode; 33import tools.refinery.viatra.runtime.rete.single.TrimmerNode;
43import tools.refinery.viatra.runtime.rete.util.Options; 34import tools.refinery.viatra.runtime.rete.util.Options;
44 35
36import java.util.*;
37import 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
10package tools.refinery.viatra.runtime.rete.network; 11package tools.refinery.viatra.runtime.rete.network;
11 12
12import java.util.Collection;
13import java.util.HashSet;
14import java.util.List;
15import java.util.Set;
16
17import tools.refinery.viatra.runtime.matchers.tuple.Tuple; 13import tools.refinery.viatra.runtime.matchers.tuple.Tuple;
18import tools.refinery.viatra.runtime.matchers.tuple.TupleMask; 14import tools.refinery.viatra.runtime.matchers.tuple.TupleMask;
19import tools.refinery.viatra.runtime.matchers.util.CollectionsFactory; 15import tools.refinery.viatra.runtime.matchers.util.CollectionsFactory;
@@ -24,11 +20,16 @@ import tools.refinery.viatra.runtime.rete.network.communication.Timestamp;
24import tools.refinery.viatra.runtime.rete.network.mailbox.Mailbox; 20import tools.refinery.viatra.runtime.rete.network.mailbox.Mailbox;
25import tools.refinery.viatra.runtime.rete.traceability.TraceInfo; 21import tools.refinery.viatra.runtime.rete.traceability.TraceInfo;
26 22
23import java.util.Collection;
24import java.util.HashSet;
25import java.util.List;
26import 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 */
33public abstract class StandardNode extends BaseNode implements Supplier, NetworkStructureChangeSensitiveNode { 34public 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 }