Skip to content
Prev Previous commit
Next Next commit
renderer2d/tiles: Improve debug information format to write to NeptusLog
  • Loading branch information
edramos-97 committed Jul 28, 2019
commit 7ad5cee5299aad63fce04d511c5e83af52d95cc7
19 changes: 10 additions & 9 deletions src/pt/lsts/neptus/renderer2d/tiles/Tile.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Timer;
Expand Down Expand Up @@ -421,8 +422,8 @@ public boolean saveTile() {
File outFile = new File(getTileFilePath());
outFile.getParentFile().mkdirs();
outFile.createNewFile();
System.out.println("Saving expiration date for tile: " + getId() + " from map: " + getClass().getSimpleName());
System.out.println("expiration = " + expiration);
NeptusLog.pub().debug("Saving expiration date for tile: " + getId() + " from map: " + getClass().getSimpleName());
NeptusLog.pub().debug("expiration = " + new Date(expiration));


// https://docs.oracle.com/javase/8/docs/api/javax/imageio/metadata/doc-files/png_metadata.html
Expand Down Expand Up @@ -506,7 +507,7 @@ public boolean loadTile() {
// scheduleLoadImageFromLowerLevelOfDetail();
return false;
} else {
System.out.println("Checking file expiration");
NeptusLog.pub().debug("Checking file expiration");
if(hasExpired(inFile)){
state = TileState.ERROR;
return false;
Expand Down Expand Up @@ -602,10 +603,10 @@ public static void setCache(String mapKey, boolean state) {
}

private static HashMap<String, Long> loadCacheExpiration(String mapKey) {
System.out.println("Loading cache file for: " + mapKey);
NeptusLog.pub().info("Loading cache file for: " + mapKey);
File serFile = new File(TILE_BASE_CACHE_DIR + "/serializedCaches/" + mapKey);
if(!serFile.exists()) {
System.out.println(String.format("No cache expiration found at '%s'", serFile.getPath()));
NeptusLog.pub().error(String.format("No cache expiration found at '%s'", serFile.getPath()));
return new HashMap<>();
}

Expand All @@ -618,16 +619,16 @@ private static HashMap<String, Long> loadCacheExpiration(String mapKey) {
throw new Exception("Saved Object is not instance of HashMap");
}
} catch(Exception e) {
System.out.println("An error occurred while saving cache expiration data");
NeptusLog.pub().error("An error occurred while saving cache expiration data");
e.printStackTrace();
return new HashMap<>();
}
}

private static void saveCacheExpiration() {
System.out.println("Saving cache");
NeptusLog.pub().debug("Saving tile cache");
for (Map.Entry<String, HashMap<String, Long>> mapEntry : cacheExpiration.entrySet()) {
System.out.println("Key = " + mapEntry.getKey());
NeptusLog.pub().debug("Saving Map Style: " + mapEntry.getKey());
try {
File serFile = new File(TILE_BASE_CACHE_DIR + "/serializedCaches/" + mapEntry.getKey());
serFile.getParentFile().mkdirs();
Expand All @@ -638,7 +639,7 @@ private static void saveCacheExpiration() {
oos.close();
fos.close();
} catch(IOException ioe) {
System.out.println("An error occurred while saving cache expiration data");
NeptusLog.pub().error("An error occurred while saving cache expiration data for map style: " + mapEntry.getKey());
ioe.printStackTrace();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/pt/lsts/neptus/renderer2d/tiles/TileHttpFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ else if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
retries = 0;
isInStateForbidden = false;

System.out.println("Fetched tile from: " + urlGet);
NeptusLog.pub().debug("Fetched tile from: " + urlGet);
parseExpirationHeader(resp, urlGet);

InputStream is = resp.getEntity().getContent();
Expand Down Expand Up @@ -670,7 +670,7 @@ else if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
retries = 0;
isInStateForbidden = false;

System.out.println("Fetched tile from: " + urlGet);
NeptusLog.pub().debug("Fetched tile from: " + urlGet);
parseExpirationHeader(resp, urlGet);

InputStream is = resp.getEntity().getContent();
Expand Down
4 changes: 2 additions & 2 deletions src/pt/lsts/neptus/renderer2d/tiles/TileOpenStreetMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ protected String createTileRequestURL() {
// urlGet = "http://" + sv + "." + "tile.opencyclemap.org/cycle/" + levelOfDetail + "/"
// + tileX + "/" + tileY + ".png";
// else
String urlGet = "http://localhost:8080/openstreetmap/" + levelOfDetail + "/"
+ tileX + "/" + tileY;
String urlGet = "http://" + sv + ".tile.openstreetmap.org/" + levelOfDetail + "/"
+ tileX + "/" + tileY + ".png";

return urlGet;

Expand Down