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 09:46:33 UTC
[isis] 01/02: ISIS-2573: xray: integrate with publishing (wip)
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
commit 00a1fce77466a65e8e51ea539c8d59845ea689af
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri Mar 26 10:41:25 2021 +0100
ISIS-2573: xray: integrate with publishing (wip)
---
.../publish/CommandPublisherDefault.java | 30 +++---
.../isis/core/runtimeservices/publish/_Xray.java | 116 +++++++++++++++++++++
.../publishing/jdo/JdoCommandPublishingTest.java | 3 +-
3 files changed, 131 insertions(+), 18 deletions(-)
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 3794cab..de823da 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
@@ -34,10 +34,12 @@ import org.apache.isis.applib.services.command.Command;
import org.apache.isis.applib.services.publishing.spi.CommandSubscriber;
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.CommandPublisher;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
+import lombok.val;
import lombok.extern.log4j.Log4j2;
@Service
@@ -50,6 +52,7 @@ import lombok.extern.log4j.Log4j2;
public class CommandPublisherDefault implements CommandPublisher {
private final List<CommandSubscriber> subscribers;
+ private final InteractionTracker iaTracker;
private Can<CommandSubscriber> enabledSubscribers;
@@ -60,30 +63,25 @@ public class CommandPublisherDefault implements CommandPublisher {
}
@Override
- public void complete(final @NonNull Command command) {
+ public void complete(final @NonNull Command command) {
- if(!canPublish()) {
- return;
- }
-
- if(!command.isPublishingEnabled()) {
- return;
- }
+ val canPublish = canPublish(command);
+ val handle = _Xray.enterCommandPublishing(iaTracker, command, canPublish, enabledSubscribers);
- if(command.getLogicalMemberIdentifier() == null) {
- // eg if seed fixtures
- return;
+ if(canPublish) {
+ log.debug("about to PUBLISH command: {} to {}", command, enabledSubscribers);
+ enabledSubscribers.forEach(subscriber -> subscriber.onCompleted(command));
}
- log.debug("about to PUSH command: {} to {}", command, enabledSubscribers);
-
- enabledSubscribers.forEach(subscriber -> subscriber.onCompleted(command));
+ _Xray.exitCommandPublishing(handle);
}
// -- HELPER
- private boolean canPublish() {
- return enabledSubscribers.isNotEmpty();
+ private boolean canPublish(final Command command) {
+ return enabledSubscribers.isNotEmpty()
+ && command.isPublishingEnabled()
+ && command.getLogicalMemberIdentifier() != null; // eg null when seed fixtures
}
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
new file mode 100644
index 0000000..7c53f6f
--- /dev/null
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/publish/_Xray.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+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.publishing.spi.CommandSubscriber;
+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 lombok.Builder;
+import lombok.NonNull;
+import lombok.val;
+
+final class _Xray {
+
+ static Handle enterCommandPublishing(
+ final @NonNull InteractionTracker iaTracker,
+ final @Nullable Command command,
+ final boolean canPublish,
+ final @NonNull Can<CommandSubscriber> enabledSubscribers) {
+
+ if(!XrayUi.isXrayEnabled()
+ || !iaTracker.isInInteractionSession()) {
+ return null;
+ }
+
+ final int authStackSize = iaTracker.getAuthenticationLayerCount();
+ val conversationId = iaTracker.getConversationId().orElseThrow(_Exceptions::unexpectedCodeReach);
+
+ val handle = createHandle(conversationId, authStackSize, null, null);
+ val enteringLabel = "publishing";
+
+ XrayUi.updateModel(model->{
+ model.lookupSequence(handle.sequenceId)
+ .ifPresent(sequence->{
+ val sequenceData = sequence.getData();
+
+ sequenceData.alias("command-publisher", "Command-\nPublisher-\n(Default)");
+
+ sequenceData.enter(handle.caller, "command-publisher");
+
+ sequenceData.enter("executor", handle.callee, enteringLabel);
+ });
+ });
+
+ return handle;
+ }
+
+
+ public static void exitCommandPublishing(final @Nullable Handle handle) {
+
+ if(handle==null) {
+ return; // x-ray is not enabled
+ }
+
+ XrayUi.updateModel(model->{
+ model.lookupSequence(handle.sequenceId)
+ .ifPresent(sequence->{
+ val sequenceData = sequence.getData();
+ sequenceData.exit(handle.callee, "command-publisher");
+ sequenceData.exit("executor", handle.caller);
+ });
+ });
+
+ }
+
+ // -- HELPER
+
+ private static Handle createHandle(
+ final UUID interactionId,
+ final int authStackSize,
+ final String participantLabel,
+ final String enteringLabel) {
+
+ 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;
+ }
+
+}
diff --git a/regressiontests/incubating/src/test/java/org/apache/isis/testdomain/applayer/publishing/jdo/JdoCommandPublishingTest.java b/regressiontests/incubating/src/test/java/org/apache/isis/testdomain/applayer/publishing/jdo/JdoCommandPublishingTest.java
index a57c0f7..d0470a9 100644
--- a/regressiontests/incubating/src/test/java/org/apache/isis/testdomain/applayer/publishing/jdo/JdoCommandPublishingTest.java
+++ b/regressiontests/incubating/src/test/java/org/apache/isis/testdomain/applayer/publishing/jdo/JdoCommandPublishingTest.java
@@ -42,7 +42,6 @@ import org.apache.isis.testdomain.applayer.publishing.conf.Configuration_usingCo
import org.apache.isis.testdomain.conf.Configuration_usingJdo;
import org.apache.isis.testdomain.util.CollectionAssertions;
import org.apache.isis.testdomain.util.kv.KVStoreForTesting;
-import org.apache.isis.testing.integtestsupport.applib.IsisIntegrationTestAbstract;
import lombok.val;
@@ -60,7 +59,7 @@ import lombok.val;
@TestPropertySource({
IsisPresets.UseLog4j2Test
})
-class JdoCommandPublishingTest extends IsisIntegrationTestAbstract {
+class JdoCommandPublishingTest {
@Inject private ApplicationLayerTestFactory testFactory;
@Inject private KVStoreForTesting kvStore;