Skip to content

Commit

Permalink
spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
kagkarlsson committed Jul 2, 2024
1 parent 087425a commit af6fcbf
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -80,7 +80,7 @@ protected Scheduler(
Waiter executeDueWaiter,
Duration heartbeatInterval,
int numberOfMissedHeartbeatsBeforeDead,
List<SchedulerListener> schedulerListeners,
List<SchedulerListener> schedulerListeners,
PollingStrategyConfig pollingStrategyConfig,
Duration deleteUnresolvedAfter,
Duration shutdownMaxWait,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -302,7 +300,7 @@ public Scheduler build() {
waiter,
heartbeatInterval,
numberOfMissedHeartbeatsBeforeDead,
schedulerListeners,
schedulerListeners,
pollingStrategyConfig,
deleteUnresolvedAfter,
shutdownMaxWait,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -364,7 +362,6 @@ public Optional<ScheduledExecution<Object>> getScheduledExecution(
taskRepository.getExecution(taskInstanceId.getTaskName(), taskInstanceId.getId());
return e.map(oe -> new ScheduledExecution<>(Object.class, oe));
}

}

class SchedulerClientName implements SchedulerName {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,30 @@
* 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.
* <p>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 <code>SchedulerClient</code> or by a <code>CompletionHandler</code>
* Execution scheduled either by the <code>SchedulerClient</code> or by a <code>CompletionHandler
* </code>
*
* @param taskInstanceId
* @param executionTime
*/
void onExecutionScheduled(TaskInstanceId taskInstanceId, Instant executionTime);

/**
* Will typically run in the same thread as <code>onExecutionComplete</code>
*
* @param currentlyExecuting
*/
void onExecutionStart(CurrentlyExecuting currentlyExecuting);

/**
* Will typically run in the same thread as <code>onExecutionStart</code>
*
* @param executionComplete
*/
void onExecutionComplete(ExecutionComplete executionComplete);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,67 +52,66 @@ 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) {
try {
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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ public class ExecutionOperations<T> {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,7 +59,7 @@ public class ManualScheduler extends Scheduler {
waiter,
heartbeatInterval,
SchedulerBuilder.DEFAULT_MISSED_HEARTBEATS_LIMIT,
schedulerListeners,
schedulerListeners,
pollingStrategyConfig,
deleteUnresolvedAfter,
Duration.ZERO,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit af6fcbf

Please sign in to comment.