You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2021/03/26 12:18:08 UTC
[isis] branch master updated: ISIS-2573: xray: fully integrate exec
publishing
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new 653330f ISIS-2573: xray: fully integrate exec publishing
653330f is described below
commit 653330f43d26c4412c92fbb5c7a6ec5e40c4995b
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri Mar 26 13:17:56 2021 +0100
ISIS-2573: xray: fully integrate exec publishing
---
.../debug/xray/sequence/SequenceDiagram.java | 2 +-
.../apache/isis/core/runtime/util/XrayUtil.java | 35 +++++++
.../publish/CommandPublisherDefault.java | 6 +-
.../publish/ExecutionPublisherDefault.java | 30 +++---
.../isis/core/runtimeservices/publish/_Xray.java | 113 ++++++++++++---------
5 files changed, 121 insertions(+), 65 deletions(-)
diff --git a/commons/src/main/java/org/apache/isis/commons/internal/debug/xray/sequence/SequenceDiagram.java b/commons/src/main/java/org/apache/isis/commons/internal/debug/xray/sequence/SequenceDiagram.java
index c228d2b..df9b579 100644
--- a/commons/src/main/java/org/apache/isis/commons/internal/debug/xray/sequence/SequenceDiagram.java
+++ b/commons/src/main/java/org/apache/isis/commons/internal/debug/xray/sequence/SequenceDiagram.java
@@ -84,7 +84,7 @@ public class SequenceDiagram {
private final static int PARTICIPANT_MAX_CHAR_PER_LINE = 26;
private final static Optional<Font> PARTICIPANT_FONT = _Graphics.lookupFont("Verdana", 12.f);
- private final static int CONNECTION_MARGIN_V = 5;
+ private final static int CONNECTION_MARGIN_V = 12;
private final static int CONNECTION_LABEL_PADDING_H = 8;
private final static int CONNECTION_LABEL_PADDING_V = 3;
private final static int CONNECTION_LABEL_LINEGAP = 0;
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/util/XrayUtil.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/util/XrayUtil.java
index 09b3f7f..d503bbc 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/util/XrayUtil.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/util/XrayUtil.java
@@ -21,10 +21,14 @@ package org.apache.isis.core.runtime.util;
import java.util.Optional;
import java.util.UUID;
+import org.apache.isis.commons.collections.Can;
import org.apache.isis.commons.internal.debug.xray.XrayModel.ThreadMemento;
+import org.apache.isis.commons.internal.exceptions._Exceptions;
import org.apache.isis.core.interaction.session.InteractionTracker;
+import lombok.Builder;
import lombok.NonNull;
+import lombok.Value;
import lombok.val;
public final class XrayUtil {
@@ -54,4 +58,35 @@ public final class XrayUtil {
return "ia-" + (authenticationStackSize-1);
}
+ // -- SEQUENCE HANDLE
+
+ public static Optional<SequenceHandle> createSequenceHandle(
+ final @NonNull InteractionTracker iaTracker,
+ final String ... callees) {
+
+ if(!iaTracker.isInInteractionSession()) {
+ return Optional.empty();
+ }
+
+ final int authStackSize = iaTracker.getAuthenticationLayerCount();
+ val conversationId = iaTracker.getConversationId().orElseThrow(_Exceptions::unexpectedCodeReach);
+
+ val handle = SequenceHandle.builder()
+ .sequenceId(XrayUtil.sequenceId(conversationId))
+ .caller(authStackSize>0
+ ? XrayUtil.nestedInteractionId(authStackSize)
+ : "thread")
+ .callees(Can.ofArray(callees))
+ .build();
+
+ return Optional.of(handle);
+ }
+
+ @Value @Builder
+ public static final class SequenceHandle {
+ final @NonNull String sequenceId;
+ final @NonNull String caller;
+ final @NonNull Can<String> callees;
+ }
+
}
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/publish/CommandPublisherDefault.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/publish/CommandPublisherDefault.java
index de823da..8491518 100644
--- a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/publish/CommandPublisherDefault.java
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/publish/CommandPublisherDefault.java
@@ -46,7 +46,7 @@ import lombok.extern.log4j.Log4j2;
@Named("isis.runtimeservices.CommandPublisherDefault")
@Order(OrderPrecedence.MIDPOINT)
@Primary
-@Qualifier("Internal")
+@Qualifier("Default")
@RequiredArgsConstructor(onConstructor_ = {@Inject})
@Log4j2
public class CommandPublisherDefault implements CommandPublisher {
@@ -54,7 +54,7 @@ public class CommandPublisherDefault implements CommandPublisher {
private final List<CommandSubscriber> subscribers;
private final InteractionTracker iaTracker;
- private Can<CommandSubscriber> enabledSubscribers;
+ private Can<CommandSubscriber> enabledSubscribers = Can.empty();
@PostConstruct
public void init() {
@@ -73,7 +73,7 @@ public class CommandPublisherDefault implements CommandPublisher {
enabledSubscribers.forEach(subscriber -> subscriber.onCompleted(command));
}
- _Xray.exitCommandPublishing(handle);
+ _Xray.exitPublishing(handle);
}
// -- HELPER
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/publish/ExecutionPublisherDefault.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/publish/ExecutionPublisherDefault.java
index ac48b9a..652e3a3 100644
--- a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/publish/ExecutionPublisherDefault.java
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/publish/ExecutionPublisherDefault.java
@@ -38,6 +38,7 @@ import org.apache.isis.applib.services.iactn.Execution;
import org.apache.isis.applib.services.publishing.spi.ExecutionSubscriber;
import org.apache.isis.commons.collections.Can;
import org.apache.isis.commons.having.HasEnabling;
+import org.apache.isis.core.interaction.session.InteractionTracker;
import org.apache.isis.core.metamodel.services.publishing.ExecutionPublisher;
import lombok.RequiredArgsConstructor;
@@ -55,8 +56,9 @@ public class ExecutionPublisherDefault
implements ExecutionPublisher {
private final List<ExecutionSubscriber> subscribers;
+ private final InteractionTracker iaTracker;
- private Can<ExecutionSubscriber> enabledSubscribers;
+ private Can<ExecutionSubscriber> enabledSubscribers = Can.empty();
@PostConstruct
public void init() {
@@ -84,24 +86,28 @@ implements ExecutionPublisher {
}
}
- // -- HELPERS
+ // -- HELPER
private void notifySubscribers(final Execution<?,?> execution) {
- if(isSuppressed()) {
- return;
- }
- for (val subscriber : enabledSubscribers) {
- subscriber.onExecution(execution);
+
+ val canPublish = canPublish();
+ val handle = _Xray.enterExecutionPublishing(iaTracker, execution, canPublish, enabledSubscribers);
+
+ if(canPublish) {
+ for (val subscriber : enabledSubscribers) {
+ subscriber.onExecution(execution);
+ }
}
+
+ _Xray.exitPublishing(handle);
+
}
private final LongAdder suppressionRequestCounter = new LongAdder();
- private boolean isSuppressed() {
- return enabledSubscribers == null
- || enabledSubscribers.isEmpty()
- || suppressionRequestCounter.intValue() > 0;
- }
+ private boolean canPublish() {
+ return enabledSubscribers.isNotEmpty()
+ && suppressionRequestCounter.longValue() < 1L; }
}
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/publish/_Xray.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/publish/_Xray.java
index 6169dbe..8a9daf8 100644
--- a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/publish/_Xray.java
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/publish/_Xray.java
@@ -18,97 +18,112 @@
*/
package org.apache.isis.core.runtimeservices.publish;
-import java.util.UUID;
-
import javax.annotation.Nullable;
import org.apache.isis.applib.services.command.Command;
+import org.apache.isis.applib.services.iactn.Execution;
import org.apache.isis.applib.services.publishing.spi.CommandSubscriber;
+import org.apache.isis.applib.services.publishing.spi.ExecutionSubscriber;
import org.apache.isis.commons.collections.Can;
import org.apache.isis.commons.internal.debug.xray.XrayUi;
-import org.apache.isis.commons.internal.exceptions._Exceptions;
import org.apache.isis.core.interaction.session.InteractionTracker;
import org.apache.isis.core.runtime.util.XrayUtil;
+import org.apache.isis.core.runtime.util.XrayUtil.SequenceHandle;
-import lombok.Builder;
import lombok.NonNull;
import lombok.val;
final class _Xray {
- static Handle enterCommandPublishing(
+ // -- COMMAND
+
+ static SequenceHandle enterCommandPublishing(
final @NonNull InteractionTracker iaTracker,
final @Nullable Command command,
final boolean canPublish,
final @NonNull Can<CommandSubscriber> enabledSubscribers) {
- if(!XrayUi.isXrayEnabled()
- || !iaTracker.isInInteractionSession()) {
+ if(!XrayUi.isXrayEnabled()) {
return null;
}
- final int authStackSize = iaTracker.getAuthenticationLayerCount();
- val conversationId = iaTracker.getConversationId().orElseThrow(_Exceptions::unexpectedCodeReach);
-
- val handle = createHandle(conversationId, authStackSize, "command-publisher");
val enteringLabel = canPublish
? String.format("publishing command to %d subscriber(s)", enabledSubscribers.size())
: "not publishing command";
- XrayUi.updateModel(model->{
- model.lookupSequence(handle.sequenceId)
- .ifPresent(sequence->{
- val sequenceData = sequence.getData();
-
- sequenceData.alias(handle.callee, "Command-\nPublisher-\n(Default)");
- sequenceData.enter(handle.caller, handle.callee, enteringLabel);
-
+ val handleIfAny = XrayUtil.createSequenceHandle(iaTracker, "cmd-publisher");
+ handleIfAny.ifPresent(handle->{
+
+ XrayUi.updateModel(model->{
+ model.lookupSequence(handle.getSequenceId())
+ .ifPresent(sequence->{
+ val sequenceData = sequence.getData();
+
+ sequenceData.alias("cmd-publisher", "Command-\nPublisher-\n(Default)");
+ sequenceData.enter(handle.getCaller(), handle.getCallees().getFirstOrFail(), enteringLabel);
+
+ });
});
+
});
- return handle;
+ return handleIfAny.orElse(null);
+
}
-
-
- public static void exitCommandPublishing(final @Nullable Handle handle) {
+
+ // -- EXECUTION
+
+ public static SequenceHandle enterExecutionPublishing(
+ final @NonNull InteractionTracker iaTracker,
+ final @Nullable Execution<?, ?> command,
+ final boolean canPublish,
+ final @NonNull Can<ExecutionSubscriber> enabledSubscribers) {
+
+ if(!XrayUi.isXrayEnabled()) {
+ return null;
+ }
+
+ val enteringLabel = canPublish
+ ? String.format("publishing execution to %d subscriber(s)", enabledSubscribers.size())
+ : "not publishing execution";
+
+ val handleIfAny = XrayUtil.createSequenceHandle(iaTracker, "exec-publisher");
+ handleIfAny.ifPresent(handle->{
+
+ XrayUi.updateModel(model->{
+ model.lookupSequence(handle.getSequenceId())
+ .ifPresent(sequence->{
+ val sequenceData = sequence.getData();
+
+ sequenceData.alias("exec-publisher", "Execution-\nPublisher-\n(Default)");
+ sequenceData.enter(handle.getCaller(), handle.getCallees().getFirstOrFail(), enteringLabel);
+
+ });
+ });
+
+ });
+
+ return handleIfAny.orElse(null);
+
+ }
+
+ // -- EXIT
+
+ public static void exitPublishing(final @Nullable SequenceHandle handle) {
if(handle==null) {
return; // x-ray is not enabled
}
XrayUi.updateModel(model->{
- model.lookupSequence(handle.sequenceId)
+ model.lookupSequence(handle.getSequenceId())
.ifPresent(sequence->{
val sequenceData = sequence.getData();
- sequenceData.exit(handle.callee, handle.caller);
+ sequenceData.exit(handle.getCallees().getFirstOrFail(), handle.getCaller());
});
});
}
-
- // -- HELPER
-
- private static Handle createHandle(
- final UUID interactionId,
- final int authStackSize,
- final String participantLabel) {
- val handle = Handle.builder()
- .sequenceId(XrayUtil.sequenceId(interactionId))
- .caller(authStackSize>0
- ? XrayUtil.nestedInteractionId(authStackSize)
- : "thread")
- .callee(participantLabel)
- .build();
-
- return handle;
- }
-
- @Builder
- static final class Handle {
- final @NonNull String sequenceId;
- final @NonNull String caller;
- final @NonNull String callee;
- }
}