You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2021/06/11 08:04:28 UTC

[isis] 01/02: ISIS-2726: removes TickingClockService

This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch ISIS-2726
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 945404c4272b5af6d42f92191985da3d01097add
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Fri Jun 11 08:57:43 2021 +0100

    ISIS-2726: removes TickingClockService
---
 .../IsisModuleExtCommandReplaySecondary.java       |   2 -
 .../commandreplay/secondary/SecondaryStatus.java   |   2 -
 .../secondary/clock/TickingClockService.java       | 154 ---------------------
 .../secondary/job/ReplicateAndReplayJob.java       |  20 +--
 .../jobcallables/IsTickingClockInitialized.java    |  42 ------
 .../jobcallables/ReplicateAndRunCommands.java      |   5 +-
 6 files changed, 4 insertions(+), 221 deletions(-)

diff --git a/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/IsisModuleExtCommandReplaySecondary.java b/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/IsisModuleExtCommandReplaySecondary.java
index 972a2b4..f8e5245 100644
--- a/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/IsisModuleExtCommandReplaySecondary.java
+++ b/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/IsisModuleExtCommandReplaySecondary.java
@@ -42,7 +42,6 @@ import org.apache.isis.extensions.commandlog.model.IsisModuleExtCommandLogApplib
 import org.apache.isis.extensions.commandreplay.secondary.analyser.CommandReplayAnalyserException;
 import org.apache.isis.extensions.commandreplay.secondary.analyser.CommandReplayAnalyserResult;
 import org.apache.isis.extensions.commandreplay.secondary.analysis.CommandReplayAnalysisService;
-import org.apache.isis.extensions.commandreplay.secondary.clock.TickingClockService;
 import org.apache.isis.extensions.commandreplay.secondary.config.SecondaryConfig;
 import org.apache.isis.extensions.commandreplay.secondary.fetch.CommandFetcher;
 import org.apache.isis.extensions.commandreplay.secondary.job.ReplicateAndReplayJob;
@@ -68,7 +67,6 @@ import lombok.val;
         CommandReplayAnalyserException.class,
         CommandReplayAnalysisService.class,
         CommandReplayOnSecondaryService.class,
-        TickingClockService.class,
 
         // @Service's
         SecondaryConfig.class,
diff --git a/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/SecondaryStatus.java b/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/SecondaryStatus.java
index f590b2e..f0a1905 100644
--- a/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/SecondaryStatus.java
+++ b/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/SecondaryStatus.java
@@ -22,8 +22,6 @@ package org.apache.isis.extensions.commandreplay.secondary;
  * @since 2.0 {@index}
  */
 public enum SecondaryStatus {
-    TICKING_CLOCK_STATUS_UNKNOWN,
-    TICKING_CLOCK_NOT_YET_INITIALIZED,
     OK,
     REST_CALL_FAILING,
     FAILED_TO_UNMARSHALL_RESPONSE,
diff --git a/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/clock/TickingClockService.java b/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/clock/TickingClockService.java
deleted file mode 100644
index 7bf5542..0000000
--- a/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/clock/TickingClockService.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- *  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.extensions.commandreplay.secondary.clock;
-
-import java.sql.Timestamp;
-import java.util.function.Supplier;
-
-import javax.annotation.PostConstruct;
-import javax.inject.Named;
-
-import org.springframework.core.annotation.Order;
-import org.springframework.stereotype.Service;
-
-import org.apache.isis.applib.annotation.OrderPrecedence;
-import org.apache.isis.core.config.IsisConfiguration;
-import org.apache.isis.testing.fixtures.applib.clock.clock.Clock;
-import org.apache.isis.testing.fixtures.applib.clock.clock.TickingFixtureClock;
-
-import lombok.RequiredArgsConstructor;
-import lombok.val;
-import lombok.extern.log4j.Log4j2;
-
-/**
- * Only enabled for the <tt>secondary</tt> profile, where it sets up the
- * framework to use {@link TickingFixtureClock} so that time can be changed
- * dynamically when running.
- *
- * <p>
- *     As an additional safeguard, if the configuration keys to access the
- *     primary are not provided, then the service will not initialize.
- * </p>
- *
- * <p>
- *     IMPORTANT: the methods provided by this service are not thread-safe,
- *     because the clock is a globally-scoped singleton rather than a
- *     thread-local.  These methods should therefore only be used in single-user
- *     systems, eg a replay secondary.
- * </p>
- *
- * @since 2.0 {@index}
- */
-@Service()
-@Named("isis.ext.commandReplaySecondary.TickingClockService")
-@Order(OrderPrecedence.MIDPOINT)
-@Log4j2
-@RequiredArgsConstructor
-public class TickingClockService {
-
-    final IsisConfiguration isisConfiguration;
-
-    @PostConstruct
-    public void init() {
-        val baseUrl = isisConfiguration.getExtensions().getCommandReplay().getPrimaryAccess().getBaseUrlRestful();
-        val user = isisConfiguration.getExtensions().getCommandReplay().getPrimaryAccess().getUser();
-        val password = isisConfiguration.getExtensions().getCommandReplay().getPrimaryAccess().getPassword();
-
-        if( !baseUrl.isPresent()||
-            !user.isPresent() ||
-            !password.isPresent()) {
-            log.warn("init() - skipping, one or more 'isis.extensions.command-replay.primary' configuration properties has not been set");
-            return;
-        }
-
-        log.info("init() - replacing existing clock with TickingFixtureClock");
-        TickingFixtureClock.replaceExisting();
-    }
-
-    public boolean isInitialized() {
-        return Clock.getInstance() instanceof TickingFixtureClock;
-    }
-
-
-    /**
-     * Executes the runnable, setting the clock to be the specified time
-     * beforehand (and reinstating it to its original time afterwards).
-     *
-     * <p>
-     *     IMPORTANT: this method is not thread-safe, because the clock is a
-     *     globally-scoped singleton rather than a thread-local.  This method
-     *     should therefore only be used in single-user systems, eg a replay
-     *     secondary.
-     * </p>
-     */
-    public void at(Timestamp timestamp, Runnable runnable) {
-        ensureInitialized();
-
-        val tickingFixtureClock = (TickingFixtureClock) TickingFixtureClock.getInstance();
-        val previous = TickingFixtureClock.getEpochMillis();
-        val wallTime0 = System.currentTimeMillis();
-        try {
-            tickingFixtureClock.setTime(timestamp);
-            runnable.run();
-        } finally {
-            final long wallTime1 = System.currentTimeMillis();
-            tickingFixtureClock.setTime(previous + wallTime1 - wallTime0);
-        }
-    }
-
-    /**
-     * Executes the callable, setting the clock to be the specified time
-     * beforehand (and reinstating it to its original time afterwards).
-     *
-     * <p>
-     *     IMPORTANT: this method is not thread-safe, because the clock is a
-     *     globally-scoped singleton rather than a thread-local.  This method
-     *     should therefore only be used in single-user systems, eg a replay
-     *     secondary.
-     * </p>
-     */
-    public <T> T at(Timestamp timestamp, Supplier<T> supplier) {
-        ensureInitialized();
-
-        val tickingFixtureClock = (TickingFixtureClock) TickingFixtureClock.getInstance();
-
-        val previous = TickingFixtureClock.getEpochMillis();
-        val wallTime0 = System.currentTimeMillis();
-
-        try {
-            tickingFixtureClock.setTime(timestamp);
-            return supplier.get();
-        } finally {
-            final long wallTime1 = System.currentTimeMillis();
-            tickingFixtureClock.setTime(previous + wallTime1 - wallTime0);
-        }
-    }
-
-    private void ensureInitialized() {
-        if(!isInitialized()) {
-            throw new IllegalStateException(
-                "Not initialized.  " +
-                "Make sure that the application is configured as a " +
-                "replay secondary by configuring the " +
-                "'isis.extensions.command-replay.primary' " +
-                "configuration properties.");
-        }
-    }
-
-}
diff --git a/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/job/ReplicateAndReplayJob.java b/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/job/ReplicateAndReplayJob.java
index ed9c3eb..7cee960 100644
--- a/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/job/ReplicateAndReplayJob.java
+++ b/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/job/ReplicateAndReplayJob.java
@@ -30,7 +30,6 @@ import org.apache.isis.applib.services.iactnlayer.InteractionService;
 import org.apache.isis.applib.services.user.UserMemento;
 import org.apache.isis.extensions.commandreplay.secondary.SecondaryStatus;
 import org.apache.isis.extensions.commandreplay.secondary.config.SecondaryConfig;
-import org.apache.isis.extensions.commandreplay.secondary.jobcallables.IsTickingClockInitialized;
 import org.apache.isis.extensions.commandreplay.secondary.jobcallables.ReplicateAndRunCommands;
 
 import lombok.val;
@@ -68,23 +67,9 @@ public class ReplicateAndReplayJob implements Job {
 
     private void exec(final JobExecutionContext quartzContext) {
         val ssh = new SecondaryStatusData(quartzContext);
-        val secondaryStatus = ssh.getSecondaryStatus(SecondaryStatus.TICKING_CLOCK_STATUS_UNKNOWN);
+        val secondaryStatus = ssh.getSecondaryStatus(SecondaryStatus.OK);
 
         switch (secondaryStatus) {
-
-            case TICKING_CLOCK_STATUS_UNKNOWN:
-            case TICKING_CLOCK_NOT_YET_INITIALIZED:
-                ssh.setSecondaryStatus(
-                        isTickingClockInitialized(authentication)
-                            ? SecondaryStatus.OK
-                            : SecondaryStatus.TICKING_CLOCK_NOT_YET_INITIALIZED);
-                if(ssh.getSecondaryStatus() == SecondaryStatus.OK) {
-                    log.info("Ticking clock now initialised");
-                } else {
-                    log.info("Still waiting for ticking clock to be initialised: {}" , secondaryStatus);
-                }
-                return;
-
             case OK:
                 val newStatus =
                         interactionService.call(authentication, new ReplicateAndRunCommands());
@@ -104,9 +89,6 @@ public class ReplicateAndReplayJob implements Job {
         }
     }
 
-    private boolean isTickingClockInitialized(final InteractionContext authentication) {
-        return interactionService.call(authentication, new IsTickingClockInitialized());
-    }
 
 }
 
diff --git a/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/jobcallables/IsTickingClockInitialized.java b/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/jobcallables/IsTickingClockInitialized.java
deleted file mode 100644
index c16da72..0000000
--- a/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/jobcallables/IsTickingClockInitialized.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- *  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.extensions.commandreplay.secondary.jobcallables;
-
-import java.util.concurrent.Callable;
-
-import javax.inject.Inject;
-
-import org.apache.isis.applib.services.xactn.TransactionService;
-import org.apache.isis.extensions.commandreplay.secondary.clock.TickingClockService;
-
-public class IsTickingClockInitialized implements Callable<Boolean> {
-
-    @Inject
-    TransactionService transactionService;
-    @Inject
-    TickingClockService tickingClockService;
-
-    @Override
-    public Boolean call() {
-        return transactionService.callWithinCurrentTransactionElseCreateNew(
-                () -> tickingClockService.isInitialized())
-                .optionalElseFail()
-                .orElse(null);
-    }
-}
diff --git a/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/jobcallables/ReplicateAndRunCommands.java b/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/jobcallables/ReplicateAndRunCommands.java
index cb4c916..78d6f24 100644
--- a/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/jobcallables/ReplicateAndRunCommands.java
+++ b/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/jobcallables/ReplicateAndRunCommands.java
@@ -18,6 +18,7 @@
  */
 package org.apache.isis.extensions.commandreplay.secondary.jobcallables;
 
+import java.util.Collections;
 import java.util.List;
 import java.util.Optional;
 import java.util.concurrent.Callable;
@@ -155,7 +156,7 @@ public class ReplicateAndRunCommands implements Callable<SecondaryStatus> {
                     transactionService.callWithinCurrentTransactionElseCreateNew(
                             () -> commandModelRepository.findByParent(parent))
                     .optionalElseFail()
-                    .orElse(null);
+                    .orElse(Collections.emptyList());
             for (val childCommand : childCommands) {
                 val childReplayState = executeCommandInTranAndAnalyse(childCommand);
                 if(childReplayState.isFailed()) {
@@ -173,7 +174,7 @@ public class ReplicateAndRunCommands implements Callable<SecondaryStatus> {
         transactionService.runWithinCurrentTransactionElseCreateNew(
                 () -> {
                     commandExecutorService.executeCommand(
-                        CommandExecutorService.SudoPolicy.SWITCH_USER_ONLY, commandJdo.getCommandDto(), commandJdo.outcomeHandler());
+                        CommandExecutorService.SudoPolicy.SWITCH_USER_AND_TIME, commandJdo.getCommandDto(), commandJdo.outcomeHandler());
                 });
 
         transactionService.runWithinCurrentTransactionElseCreateNew(() -> {