Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

PersistableSlidingWindow#load() modification #495

Merged
merged 3 commits into from
Oct 28, 2020
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 @@ -49,17 +49,22 @@ public PersistableSlidingWindow(int slidingWindowSize,
Path filePath) {
super(slidingWindowSize, timeUnit);
this.pathToFile = filePath;
if (this.pathToFile == null) {
this.enablePersistence = false;
} else {
this.enablePersistence = true;
// setting the last write time to now will cause our first write to occur 5 minutes after construction
this.lastWriteTimeEpochMs = Instant.now().toEpochMilli();
this.enablePersistence = this.pathToFile != null;
if (!enablePersistence) {
LOG.debug("Persistence is not enabled for {}:{}", this.getClass().getSimpleName(), this);
return;
}
this.lastWriteTimeEpochMs = Instant.now().toEpochMilli();
if (Files.exists(filePath)) {
try {
load(this.pathToFile);
} catch (IOException ex) {
LOG.error("Unable to load previous data from {} into {}", this.pathToFile, getClass().getSimpleName());
LOG.error("Unable to load previous data from {} into {}", this.pathToFile,
getClass().getSimpleName(), ex);
}
} else {
LOG.warn("{}:{} attempted to load data from {}, but the file doesn't exist",
this.getClass().getSimpleName(), this, filePath);
}
}

Expand All @@ -69,9 +74,6 @@ public PersistableSlidingWindow(int slidingWindowSize,
* @throws IOException If there is an error reading the file
*/
protected synchronized void load(Path path) throws IOException {
if (!enablePersistence) {
return;
}
LineIterator it = FileUtils.lineIterator(path.toFile(), "UTF-8");
try {
while (it.hasNext()) {
Expand Down