You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by da...@apache.org on 2024/05/29 19:13:20 UTC
(causeway) branch CAUSEWAY-3755 created (now 829067d102)
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a change to branch CAUSEWAY-3755
in repository https://gitbox.apache.org/repos/asf/causeway.git
at 829067d102 CAUSEWAY-3755: adds Listener for RunBackgroundCommandsJob
This branch includes the following new commits:
new 829067d102 CAUSEWAY-3755: adds Listener for RunBackgroundCommandsJob
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(causeway) 01/01: CAUSEWAY-3755: adds Listener for RunBackgroundCommandsJob
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch CAUSEWAY-3755
in repository https://gitbox.apache.org/repos/asf/causeway.git
commit 829067d102e33023bf62a9b664101e60177eacf8
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Wed May 29 20:13:15 2024 +0100
CAUSEWAY-3755: adds Listener for RunBackgroundCommandsJob
---
.../applib/job/RunBackgroundCommandsJob.java | 9 ++++
.../spi/RunBackgroundCommandsJobListener.java | 51 ++++++++++++++++++++++
2 files changed, 60 insertions(+)
diff --git a/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/job/RunBackgroundCommandsJob.java b/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/job/RunBackgroundCommandsJob.java
index 4dec5bfeb9..8be8d591c1 100644
--- a/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/job/RunBackgroundCommandsJob.java
+++ b/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/job/RunBackgroundCommandsJob.java
@@ -28,6 +28,8 @@ import javax.inject.Inject;
import org.apache.causeway.commons.functional.Try;
import org.apache.causeway.extensions.commandlog.applib.dom.CommandLogEntryRepository;
+import org.apache.causeway.extensions.commandlog.applib.spi.RunBackgroundCommandsJobListener;
+
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
@@ -80,6 +82,7 @@ public class RunBackgroundCommandsJob implements Job {
@Inject CommandExecutorService commandExecutorService;
@Inject BackgroundCommandsJobControl backgroundCommandsJobControl;
+ @Inject List<RunBackgroundCommandsJobListener> listeners;
@Override
public void execute(final JobExecutionContext quartzContext) {
@@ -100,7 +103,13 @@ public class RunBackgroundCommandsJob implements Job {
for (val commandDto : commandDtos) {
executeCommandWithinOwnTransaction(commandDto, interactionContext);
}
+
+ val interactionIds = commandDtos.stream().map(CommandDto::getInteractionId).collect(Collectors.toList());
+ listeners.forEach(listener -> {
+ listener.executed(interactionIds);
+ });
});
+
}
private Optional<List<CommandDto>> pendingCommandDtos(final InteractionContext interactionContext) {
diff --git a/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/spi/RunBackgroundCommandsJobListener.java b/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/spi/RunBackgroundCommandsJobListener.java
new file mode 100644
index 0000000000..c5f13df69f
--- /dev/null
+++ b/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/spi/RunBackgroundCommandsJobListener.java
@@ -0,0 +1,51 @@
+/*
+ * 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.causeway.extensions.commandlog.applib.spi;
+
+import java.util.List;
+
+import org.apache.causeway.extensions.commandlog.applib.dom.CommandLogEntry;
+import org.apache.causeway.schema.cmd.v2.CommandDto;
+
+/**
+ * Listens to the processing of the
+ * {@link org.apache.causeway.extensions.commandlog.applib.job.RunBackgroundCommandsJob}.
+ */
+public interface RunBackgroundCommandsJobListener {
+
+ /**
+ * The {@link CommandDto#getInteractionId() interactionId}s of the {@link CommandDto}s that were executed.
+ *
+ * <p>
+ * The commands thus identified may or may not have executed successfully; indeed if there was a deadlock then
+ * the transaction will have been rolled back and so the command may not even have been executed at all.
+ * </p>
+ *
+ * <p>
+ * Implementation note: the {@link CommandDto}s are not passed in, instead only the command's
+ * {@link CommandDto#getInteractionId() interactionId}, to avoid issues and complications with the state of
+ * the in-memory {@link CommandDto}; is it in sync with the database if a deadlock occurred for example?
+ * Passing in just the identifier means that it's the responsibility of the listener to determine the state,
+ * typically by refetching the {@link org.apache.causeway.extensions.commandlog.applib.dom.CommandLogEntry}
+ * (that {@link CommandLogEntry#getCommandDto() contains} the {@link CommandDto}) in a separate transaction.
+ * </p>
+ * @param commandInteractionIds
+ */
+ void executed(List<String> commandInteractionIds);
+}