Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[energidataservice] Fix IllegalStateException #15693

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ public class CacheManager {
private final Clock clock;
private final PriceListParser priceListParser = new PriceListParser();

private Map<DatahubTariff, Collection<DatahubPricelistRecord>> datahubRecordsMap = new HashMap<>();

private Map<Instant, BigDecimal> spotPriceMap = new ConcurrentHashMap<>(SPOT_PRICE_MAX_CACHE_SIZE);

private Map<DatahubTariff, Collection<DatahubPricelistRecord>> datahubRecordsMap = new HashMap<>();
private Map<DatahubTariff, Map<Instant, BigDecimal>> tariffsMap = new ConcurrentHashMap<>();

public CacheManager() {
Expand All @@ -63,19 +62,29 @@ public CacheManager() {
public CacheManager(Clock clock) {
this.clock = clock.withZone(NORD_POOL_TIMEZONE);

for (DatahubTariff tariff : DatahubTariff.values()) {
datahubRecordsMap.put(tariff, new ArrayList<>());
tariffsMap.put(tariff, new ConcurrentHashMap<>(TARIFF_MAX_CACHE_SIZE));
for (DatahubTariff datahubTariff : DatahubTariff.values()) {
datahubRecordsMap.put(datahubTariff, new ArrayList<>());
tariffsMap.put(datahubTariff, new ConcurrentHashMap<>(TARIFF_MAX_CACHE_SIZE));
}
}

/**
* Clear all cached data.
*/
public void clear() {
datahubRecordsMap.clear();
spotPriceMap.clear();
tariffsMap.clear();

for (DatahubTariff datahubTariff : DatahubTariff.values()) {
Collection<DatahubPricelistRecord> datahubRecords = datahubRecordsMap.get(datahubTariff);
if (datahubRecords != null) {
datahubRecords.clear();
}

Map<Instant, BigDecimal> tariffs = tariffsMap.get(datahubTariff);
if (tariffs != null) {
tariffs.clear();
}
}
}

/**
Expand Down