Skip to content

Commit

Permalink
Log errors instead of printing
Browse files Browse the repository at this point in the history
  • Loading branch information
bchapuis committed Nov 15, 2023
1 parent 671d9de commit 4b9e296
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.baremaps.openstreetmap.state;



import com.google.common.io.CharStreams;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -34,16 +33,22 @@
import java.util.Map;
import java.util.Optional;
import org.apache.baremaps.openstreetmap.model.State;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Utility class for reading OSM state files. This code has been adapted from pyosmium (BSD 2-Clause
* "Simplified" License).
*/
public class StateReader {

private final String replicationUrl;
private static final Logger logger = LoggerFactory.getLogger(StateReader.class);

private String replicationUrl;

private boolean balancedSearch;

private final boolean balancedSearch;
private int retries = 2;

public StateReader() {
this("https://planet.osm.org/replication/hour", true);
Expand Down Expand Up @@ -148,12 +153,12 @@ public Optional<State> getStateFromTimestamp(LocalDateTime timestamp) {
}

public Optional<State> getState(Optional<Long> sequenceNumber) {
for (int i = 0; i < 3; i++) {
for (int i = 0; i < retries + 1; i++) {
try (var inputStream = getStateUrl(sequenceNumber).openStream()) {
var state = new StateReader().readState(inputStream);
return Optional.of(state);
} catch (Exception e) {
e.printStackTrace();
logger.error("Error while reading state file", e);
}
}
return Optional.empty();
Expand Down

0 comments on commit 4b9e296

Please sign in to comment.