refactor: require redis for jt808 mileage state
This commit is contained in:
@@ -6,7 +6,6 @@ import com.lingniu.ingest.vehiclestat.JdbcVehicleStatMetricRepository;
|
||||
import com.lingniu.ingest.vehiclestat.VehicleStatController;
|
||||
import com.lingniu.ingest.vehiclestat.VehicleStatEnvelopeIngestor;
|
||||
import com.lingniu.ingest.vehiclestat.VehicleStatRepository;
|
||||
import com.lingniu.ingest.vehiclestat.jt808.InMemoryJt808MileageStateStore;
|
||||
import com.lingniu.ingest.vehiclestat.jt808.Jt808LocationPointExtractor;
|
||||
import com.lingniu.ingest.vehiclestat.jt808.Jt808MileageStateStore;
|
||||
import com.lingniu.ingest.vehiclestat.jt808.Jt808MileageStreamProcessor;
|
||||
@@ -63,14 +62,6 @@ public class VehicleStatAutoConfiguration {
|
||||
jt808.getRedisKeyPrefix(), Duration.ofDays(jt808.getStateTtlDays()));
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "lingniu.ingest.vehicle-stat.jt808", name = "enabled", havingValue = "true")
|
||||
@ConditionalOnProperty(prefix = "lingniu.ingest.vehicle-stat.jt808", name = "state-store", havingValue = "memory")
|
||||
@ConditionalOnMissingBean(Jt808MileageStateStore.class)
|
||||
public Jt808MileageStateStore inMemoryJt808MileageStateStore() {
|
||||
return new InMemoryJt808MileageStateStore();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean({Jt808LocationPointExtractor.class, Jt808MileageStateStore.class,
|
||||
VehicleStatRepository.class})
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
package com.lingniu.ingest.vehiclestat.jt808;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public final class InMemoryJt808MileageStateStore implements Jt808MileageStateStore {
|
||||
|
||||
private final Map<String, Jt808DailyMileageState> states = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public Optional<Jt808DailyMileageState> load(String vehicleKey, LocalDate statDate) {
|
||||
return Optional.ofNullable(states.get(key(vehicleKey, statDate)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(Jt808DailyMileageState state) {
|
||||
states.put(key(state.vehicleKey(), state.statDate()), state);
|
||||
}
|
||||
|
||||
private static String key(String vehicleKey, LocalDate statDate) {
|
||||
return statDate + ":" + vehicleKey;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user