From af6fcbf5941630eadc5f312427effde4a9e82e5f Mon Sep 17 00:00:00 2001 From: Gustav Karlsson Date: Tue, 2 Jul 2024 22:17:50 +0200 Subject: [PATCH] spotless --- .../kagkarlsson/scheduler/ExecutePicked.java | 8 +-- .../scheduler/FetchCandidates.java | 5 +- .../ImmediateCheckForDueExecutions.java | 3 +- .../scheduler/LockAndFetchCandidates.java | 3 +- .../scheduler/RunUntilShutdown.java | 1 - .../kagkarlsson/scheduler/Scheduler.java | 6 +- .../scheduler/SchedulerBuilder.java | 8 +-- .../scheduler/SchedulerClient.java | 5 +- .../scheduler/event/SchedulerListener.java | 9 ++- .../scheduler/event/SchedulerListeners.java | 61 +++++++++---------- .../scheduler/task/ExecutionOperations.java | 4 +- .../scheduler/testhelper/ManualScheduler.java | 4 +- .../scheduler/RunUntilShutdownTest.java | 1 - 13 files changed, 52 insertions(+), 66 deletions(-) diff --git a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/ExecutePicked.java b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/ExecutePicked.java index de0c5348..97b3d18a 100644 --- a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/ExecutePicked.java +++ b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/ExecutePicked.java @@ -15,11 +15,10 @@ import static com.github.kagkarlsson.scheduler.ExceptionUtils.describe; -import com.github.kagkarlsson.scheduler.event.SchedulerListeners; -import com.github.kagkarlsson.scheduler.logging.ConfigurableLogger; -import com.github.kagkarlsson.scheduler.event.SchedulerListener; import com.github.kagkarlsson.scheduler.event.SchedulerListener.CandidateEventType; import com.github.kagkarlsson.scheduler.event.SchedulerListener.SchedulerEventType; +import com.github.kagkarlsson.scheduler.event.SchedulerListeners; +import com.github.kagkarlsson.scheduler.logging.ConfigurableLogger; import com.github.kagkarlsson.scheduler.task.CompletionHandler; import com.github.kagkarlsson.scheduler.task.Execution; import com.github.kagkarlsson.scheduler.task.ExecutionComplete; @@ -122,8 +121,7 @@ private void complete( ExecutionComplete.success(execution, executionStarted, clock.now()); try { completion.complete( - completeEvent, - new ExecutionOperations(taskRepository, schedulerListeners, execution)); + completeEvent, new ExecutionOperations(taskRepository, schedulerListeners, execution)); } catch (Throwable e) { schedulerListeners.onSchedulerEvent(SchedulerEventType.COMPLETIONHANDLER_ERROR); schedulerListeners.onSchedulerEvent(SchedulerEventType.UNEXPECTED_ERROR); diff --git a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/FetchCandidates.java b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/FetchCandidates.java index eef34cc5..e7f6d7f3 100644 --- a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/FetchCandidates.java +++ b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/FetchCandidates.java @@ -13,11 +13,10 @@ */ package com.github.kagkarlsson.scheduler; -import com.github.kagkarlsson.scheduler.event.SchedulerListeners; -import com.github.kagkarlsson.scheduler.logging.ConfigurableLogger; -import com.github.kagkarlsson.scheduler.event.SchedulerListener; import com.github.kagkarlsson.scheduler.event.SchedulerListener.CandidateEventType; import com.github.kagkarlsson.scheduler.event.SchedulerListener.SchedulerEventType; +import com.github.kagkarlsson.scheduler.event.SchedulerListeners; +import com.github.kagkarlsson.scheduler.logging.ConfigurableLogger; import com.github.kagkarlsson.scheduler.task.Execution; import java.time.Instant; import java.util.List; diff --git a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/ImmediateCheckForDueExecutions.java b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/ImmediateCheckForDueExecutions.java index 5f461180..a3eaf5fc 100644 --- a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/ImmediateCheckForDueExecutions.java +++ b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/ImmediateCheckForDueExecutions.java @@ -24,8 +24,7 @@ class ImmediateCheckForDueExecutions extends AbstractSchedulerListener { private final Scheduler scheduler; private Clock clock; - public ImmediateCheckForDueExecutions( - Scheduler scheduler, Clock clock) { + public ImmediateCheckForDueExecutions(Scheduler scheduler, Clock clock) { this.scheduler = scheduler; this.clock = clock; } diff --git a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/LockAndFetchCandidates.java b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/LockAndFetchCandidates.java index 98511c73..2cbe3482 100644 --- a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/LockAndFetchCandidates.java +++ b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/LockAndFetchCandidates.java @@ -13,10 +13,9 @@ */ package com.github.kagkarlsson.scheduler; +import com.github.kagkarlsson.scheduler.event.SchedulerListener.SchedulerEventType; import com.github.kagkarlsson.scheduler.event.SchedulerListeners; import com.github.kagkarlsson.scheduler.logging.ConfigurableLogger; -import com.github.kagkarlsson.scheduler.event.SchedulerListener; -import com.github.kagkarlsson.scheduler.event.SchedulerListener.SchedulerEventType; import com.github.kagkarlsson.scheduler.task.Execution; import java.time.Instant; import java.util.List; diff --git a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/RunUntilShutdown.java b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/RunUntilShutdown.java index 25d1f376..6a089b0f 100644 --- a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/RunUntilShutdown.java +++ b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/RunUntilShutdown.java @@ -13,7 +13,6 @@ */ package com.github.kagkarlsson.scheduler; -import com.github.kagkarlsson.scheduler.event.SchedulerListener; import com.github.kagkarlsson.scheduler.event.SchedulerListener.SchedulerEventType; import com.github.kagkarlsson.scheduler.event.SchedulerListeners; import org.slf4j.Logger; diff --git a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/Scheduler.java b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/Scheduler.java index 42cd3536..e20af64b 100644 --- a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/Scheduler.java +++ b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/Scheduler.java @@ -17,11 +17,11 @@ import static java.util.stream.Collectors.toList; import com.github.kagkarlsson.scheduler.SchedulerState.SettableSchedulerState; +import com.github.kagkarlsson.scheduler.event.SchedulerListener; +import com.github.kagkarlsson.scheduler.event.SchedulerListener.SchedulerEventType; import com.github.kagkarlsson.scheduler.event.SchedulerListeners; import com.github.kagkarlsson.scheduler.logging.ConfigurableLogger; import com.github.kagkarlsson.scheduler.logging.LogLevel; -import com.github.kagkarlsson.scheduler.event.SchedulerListener; -import com.github.kagkarlsson.scheduler.event.SchedulerListener.SchedulerEventType; import com.github.kagkarlsson.scheduler.task.Execution; import com.github.kagkarlsson.scheduler.task.ExecutionComplete; import com.github.kagkarlsson.scheduler.task.ExecutionOperations; @@ -80,7 +80,7 @@ protected Scheduler( Waiter executeDueWaiter, Duration heartbeatInterval, int numberOfMissedHeartbeatsBeforeDead, - List schedulerListeners, + List schedulerListeners, PollingStrategyConfig pollingStrategyConfig, Duration deleteUnresolvedAfter, Duration shutdownMaxWait, diff --git a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/SchedulerBuilder.java b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/SchedulerBuilder.java index 1c642a92..ddf17db1 100644 --- a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/SchedulerBuilder.java +++ b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/SchedulerBuilder.java @@ -17,12 +17,12 @@ import static com.github.kagkarlsson.scheduler.Scheduler.THREAD_PREFIX; import static java.util.Optional.ofNullable; +import com.github.kagkarlsson.scheduler.event.SchedulerListener; import com.github.kagkarlsson.scheduler.jdbc.AutodetectJdbcCustomization; import com.github.kagkarlsson.scheduler.jdbc.JdbcCustomization; import com.github.kagkarlsson.scheduler.jdbc.JdbcTaskRepository; import com.github.kagkarlsson.scheduler.logging.LogLevel; import com.github.kagkarlsson.scheduler.serializer.Serializer; -import com.github.kagkarlsson.scheduler.event.SchedulerListener; import com.github.kagkarlsson.scheduler.stats.StatsRegistry; import com.github.kagkarlsson.scheduler.stats.StatsRegistryAdapter; import com.github.kagkarlsson.scheduler.task.OnStartup; @@ -132,9 +132,7 @@ public SchedulerBuilder housekeeperExecutor(ScheduledExecutorService housekeeper return this; } - /** - * Deprecated, use addSchedulerListener instead - */ + /** Deprecated, use addSchedulerListener instead */ @Deprecated public SchedulerBuilder statsRegistry(StatsRegistry statsRegistry) { this.statsRegistry = statsRegistry; @@ -302,7 +300,7 @@ public Scheduler build() { waiter, heartbeatInterval, numberOfMissedHeartbeatsBeforeDead, - schedulerListeners, + schedulerListeners, pollingStrategyConfig, deleteUnresolvedAfter, shutdownMaxWait, diff --git a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/SchedulerClient.java b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/SchedulerClient.java index 4f643838..b8920fdc 100644 --- a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/SchedulerClient.java +++ b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/SchedulerClient.java @@ -247,9 +247,7 @@ class StandardSchedulerClient implements SchedulerClient { } StandardSchedulerClient( - TaskRepository taskRepository, - SchedulerListeners schedulerListeners, - Clock clock) { + TaskRepository taskRepository, SchedulerListeners schedulerListeners, Clock clock) { this.taskRepository = taskRepository; this.schedulerListeners = schedulerListeners; this.clock = clock; @@ -364,7 +362,6 @@ public Optional> getScheduledExecution( taskRepository.getExecution(taskInstanceId.getTaskName(), taskInstanceId.getId()); return e.map(oe -> new ScheduledExecution<>(Object.class, oe)); } - } class SchedulerClientName implements SchedulerName { diff --git a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/event/SchedulerListener.java b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/event/SchedulerListener.java index 8726d540..94816ce7 100644 --- a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/event/SchedulerListener.java +++ b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/event/SchedulerListener.java @@ -25,12 +25,15 @@ * The method-parameters might be subject to change. For instance, Event-types might be introduced * to hold the data relevant to the event. * - * Will typically run in the same Thread as the execution, so must not do IO or similar slow operations. + *

Will typically run in the same Thread as the execution, so must not do IO or similar slow + * operations. */ public interface SchedulerListener { /** - * Execution scheduled either by the SchedulerClient or by a CompletionHandler + * Execution scheduled either by the SchedulerClient or by a CompletionHandler + * + * * @param taskInstanceId * @param executionTime */ @@ -38,12 +41,14 @@ public interface SchedulerListener { /** * Will typically run in the same thread as onExecutionComplete + * * @param currentlyExecuting */ void onExecutionStart(CurrentlyExecuting currentlyExecuting); /** * Will typically run in the same thread as onExecutionStart + * * @param executionComplete */ void onExecutionComplete(ExecutionComplete executionComplete); diff --git a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/event/SchedulerListeners.java b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/event/SchedulerListeners.java index 5d2c2a2c..c104d5d2 100644 --- a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/event/SchedulerListeners.java +++ b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/event/SchedulerListeners.java @@ -16,14 +16,10 @@ import com.github.kagkarlsson.scheduler.CurrentlyExecuting; import com.github.kagkarlsson.scheduler.event.SchedulerListener.CandidateEventType; import com.github.kagkarlsson.scheduler.event.SchedulerListener.SchedulerEventType; -import com.github.kagkarlsson.scheduler.stats.StatsRegistry.CandidateStatsEvent; -import com.github.kagkarlsson.scheduler.stats.StatsRegistry.SchedulerStatsEvent; import com.github.kagkarlsson.scheduler.task.Execution; import com.github.kagkarlsson.scheduler.task.ExecutionComplete; import com.github.kagkarlsson.scheduler.task.TaskInstanceId; import java.time.Instant; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,56 +52,56 @@ public void onExecutionScheduled(TaskInstanceId taskInstanceId, Instant executio @Override public void onExecutionStart(CurrentlyExecuting currentlyExecuting) { schedulerListeners.forEach( - listener -> { - fireAndLogErrors( - listener, "onExecutionStart", () -> listener.onExecutionStart(currentlyExecuting)); - }); + listener -> { + fireAndLogErrors( + listener, "onExecutionStart", () -> listener.onExecutionStart(currentlyExecuting)); + }); } @Override public void onExecutionComplete(ExecutionComplete executionComplete) { schedulerListeners.forEach( - listener -> { - fireAndLogErrors( - listener, - "onExecutionComplete", - () -> listener.onExecutionComplete(executionComplete)); - }); + listener -> { + fireAndLogErrors( + listener, + "onExecutionComplete", + () -> listener.onExecutionComplete(executionComplete)); + }); } @Override public void onExecutionDead(Execution execution) { schedulerListeners.forEach( - listener -> { - fireAndLogErrors(listener, "onExecutionDead", () -> listener.onExecutionDead(execution)); - }); + listener -> { + fireAndLogErrors(listener, "onExecutionDead", () -> listener.onExecutionDead(execution)); + }); } @Override public void onExecutionFailedHeartbeat(CurrentlyExecuting currentlyExecuting) { schedulerListeners.forEach( - listener -> { - fireAndLogErrors( - listener, - "onExecutionFailedHeartbeat", - () -> listener.onExecutionFailedHeartbeat(currentlyExecuting)); - }); + listener -> { + fireAndLogErrors( + listener, + "onExecutionFailedHeartbeat", + () -> listener.onExecutionFailedHeartbeat(currentlyExecuting)); + }); } @Override public void onSchedulerEvent(SchedulerEventType type) { schedulerListeners.forEach( - listener -> { - fireAndLogErrors(listener, "onSchedulerEvent", () -> listener.onSchedulerEvent(type)); - }); + listener -> { + fireAndLogErrors(listener, "onSchedulerEvent", () -> listener.onSchedulerEvent(type)); + }); } @Override public void onCandidateEvent(CandidateEventType type) { schedulerListeners.forEach( - listener -> { - fireAndLogErrors(listener, "onCandidateEvent", () -> listener.onCandidateEvent(type)); - }); + listener -> { + fireAndLogErrors(listener, "onCandidateEvent", () -> listener.onCandidateEvent(type)); + }); } public void fireAndLogErrors(SchedulerListener listener, String method, Runnable r) { @@ -113,10 +109,9 @@ public void fireAndLogErrors(SchedulerListener listener, String method, Runnable r.run(); } catch (RuntimeException e) { LOG.warn( - "Listener '{}' method '{}' threw an unexpected Exception", - listener.getClass().getName(), - method); + "Listener '{}' method '{}' threw an unexpected Exception", + listener.getClass().getName(), + method); } } - } diff --git a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/task/ExecutionOperations.java b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/task/ExecutionOperations.java index 963bd862..f25a0469 100644 --- a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/task/ExecutionOperations.java +++ b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/task/ExecutionOperations.java @@ -24,9 +24,7 @@ public class ExecutionOperations { private final Execution execution; public ExecutionOperations( - TaskRepository taskRepository, - SchedulerListeners schedulerListeners, - Execution execution) { + TaskRepository taskRepository, SchedulerListeners schedulerListeners, Execution execution) { this.taskRepository = taskRepository; this.schedulerListeners = schedulerListeners; this.execution = execution; diff --git a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/testhelper/ManualScheduler.java b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/testhelper/ManualScheduler.java index f77dafab..658f6bf2 100644 --- a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/testhelper/ManualScheduler.java +++ b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/testhelper/ManualScheduler.java @@ -14,8 +14,8 @@ package com.github.kagkarlsson.scheduler.testhelper; import com.github.kagkarlsson.scheduler.*; -import com.github.kagkarlsson.scheduler.logging.LogLevel; import com.github.kagkarlsson.scheduler.event.SchedulerListener; +import com.github.kagkarlsson.scheduler.logging.LogLevel; import com.github.kagkarlsson.scheduler.task.OnStartup; import java.time.Duration; import java.time.Instant; @@ -59,7 +59,7 @@ public class ManualScheduler extends Scheduler { waiter, heartbeatInterval, SchedulerBuilder.DEFAULT_MISSED_HEARTBEATS_LIMIT, - schedulerListeners, + schedulerListeners, pollingStrategyConfig, deleteUnresolvedAfter, Duration.ZERO, diff --git a/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/RunUntilShutdownTest.java b/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/RunUntilShutdownTest.java index c615d5a3..5e695ce6 100644 --- a/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/RunUntilShutdownTest.java +++ b/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/RunUntilShutdownTest.java @@ -3,7 +3,6 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; -import com.github.kagkarlsson.scheduler.event.SchedulerListener; import com.github.kagkarlsson.scheduler.event.SchedulerListeners; import java.time.Duration; import org.junit.jupiter.api.Assertions;