Skip to content

Commit

Permalink
#39 Deprecate TimeProvider to use Clock instead
Browse files Browse the repository at this point in the history
  • Loading branch information
amanteaux committed Nov 7, 2024
1 parent e630e39 commit 595129a
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

import com.coreoz.wisp.time.TimeProvider;

import java.time.Clock;

class PlumeTimeProvider implements TimeProvider {

private final com.coreoz.plume.services.time.TimeProvider plumeTimeProvider;
private final Clock clock;

public PlumeTimeProvider(com.coreoz.plume.services.time.TimeProvider plumeTimeProvider) {
this.plumeTimeProvider = plumeTimeProvider;
public PlumeTimeProvider(Clock clock) {
this.clock = clock;
}

@Override
public long currentTime() {
return plumeTimeProvider.currentTime();
return clock.millis();
}

}
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package com.coreoz.plume.scheduler;

import com.coreoz.wisp.Scheduler;
import com.coreoz.wisp.SchedulerConfig;
import jakarta.inject.Inject;
import jakarta.inject.Provider;
import jakarta.inject.Singleton;

import com.coreoz.plume.services.time.TimeProvider;
import com.coreoz.wisp.Scheduler;
import com.coreoz.wisp.SchedulerConfig;
import java.time.Clock;

@Singleton
public class SchedulerProvider implements Provider<Scheduler> {

private final Scheduler scheduler;

@Inject
public SchedulerProvider(TimeProvider timeProvider) {
public SchedulerProvider(Clock clock) {
this.scheduler = new Scheduler(
SchedulerConfig
.builder()
.timeProvider(new PlumeTimeProvider(timeProvider))
.timeProvider(new PlumeTimeProvider(clock))
.build()
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.coreoz.plume.guice;

import com.coreoz.plume.services.time.ClockProvider;
import com.coreoz.plume.services.time.SystemTimeProvider;
import com.coreoz.plume.services.time.TimeProvider;
import com.google.inject.AbstractModule;

import java.time.Clock;

public class GuiceServicesModule extends AbstractModule {

@Override
protected void configure() {
bind(Clock.class).toProvider(ClockProvider.class);
bind(TimeProvider.class).to(SystemTimeProvider.class);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.coreoz.plume.services.time;

import jakarta.inject.Inject;
import jakarta.inject.Provider;
import jakarta.inject.Singleton;

import java.time.Clock;

@Singleton
public class ClockProvider implements Provider<Clock> {
private final Clock clock;

@Inject
public ClockProvider() {
this.clock = Clock.systemDefaultZone();
}

@Override
public Clock get() {
return clock;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
import jakarta.inject.Inject;
import jakarta.inject.Singleton;

/**
* @deprecated {@link Clock} should be used instead
*/
@Deprecated
@Singleton
public class SystemTimeProvider implements TimeProvider {

private final Clock clock;

@Inject
public SystemTimeProvider() {
this.clock = Clock.systemDefaultZone();
public SystemTimeProvider(Clock clock) {
this.clock = clock;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
* @deprecated {@link Clock} should be used instead
*/
@Deprecated
public interface TimeProvider {

Clock clock();
Expand Down

0 comments on commit 595129a

Please sign in to comment.