diff --git a/Core/src/org/sleuthkit/autopsy/geolocation/MBTilesFileConnector.java b/Core/src/org/sleuthkit/autopsy/geolocation/MBTilesFileConnector.java index afd7224cb9..29ed83d590 100755 --- a/Core/src/org/sleuthkit/autopsy/geolocation/MBTilesFileConnector.java +++ b/Core/src/org/sleuthkit/autopsy/geolocation/MBTilesFileConnector.java @@ -161,9 +161,9 @@ final class MBTilesFileConnector { */ private final class ConnectionPool { - private final int POOL_SIZE = 5; + private static final int POOL_SIZE = 5; - private final List connectionPool; + private final List poolConnections; private final List usedConnections; /** @@ -178,9 +178,9 @@ final class MBTilesFileConnector { String path = filePath.replaceAll("\\\\", "/"); String url = String.format(DB_URL, path); - connectionPool = new ArrayList<>(POOL_SIZE); + poolConnections = new ArrayList<>(POOL_SIZE); for (int idx = 0; idx < POOL_SIZE; idx++) { - connectionPool.add(DriverManager.getConnection(url)); + poolConnections.add(DriverManager.getConnection(url)); } } @@ -192,8 +192,8 @@ final class MBTilesFileConnector { */ synchronized Connection getConnection() { Connection connection = null; - if (!connectionPool.isEmpty()) { - connection = connectionPool.remove(connectionPool.size() - 1); + if (!poolConnections.isEmpty()) { + connection = poolConnections.remove(poolConnections.size() - 1); usedConnections.add(connection); } return connection; @@ -211,7 +211,7 @@ final class MBTilesFileConnector { */ synchronized boolean releaseConnection(Connection connection) { if (usedConnections.contains(connection)) { - connectionPool.add(connection); + poolConnections.add(connection); return usedConnections.remove(connection); } diff --git a/Core/src/org/sleuthkit/autopsy/geolocation/MBTilesTileFactory.java b/Core/src/org/sleuthkit/autopsy/geolocation/MBTilesTileFactory.java index 330992a34e..6416d8dcaf 100755 --- a/Core/src/org/sleuthkit/autopsy/geolocation/MBTilesTileFactory.java +++ b/Core/src/org/sleuthkit/autopsy/geolocation/MBTilesTileFactory.java @@ -20,6 +20,8 @@ package org.sleuthkit.autopsy.geolocation; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.net.URI; import java.net.URISyntaxException; import java.util.Comparator; @@ -52,7 +54,7 @@ final class MBTilesTileFactory extends TileFactory { private static final Logger logger = Logger.getLogger(MBTilesTileFactory.class.getName()); private volatile int pendingTiles = 0; - private final int threadPoolSize = 4; + private static final int THREAD_POOL_SIZE = 4; private ExecutorService service; private final Map tileMap; @@ -188,7 +190,7 @@ final class MBTilesTileFactory extends TileFactory { synchronized ExecutorService getService() { if (service == null) { // System.out.println("creating an executor service with a threadpool of size " + threadPoolSize); - service = Executors.newFixedThreadPool(threadPoolSize, new ThreadFactory() { + service = Executors.newFixedThreadPool(THREAD_POOL_SIZE, new ThreadFactory() { private int count = 0; @Override @@ -294,27 +296,10 @@ final class MBTilesTileFactory extends TileFactory { URI uri = getURI(tile); BufferedImage img = cache.get(uri); if (img == null) { - byte[] bimg = connector.getTileBytes(uri.toString()); - if (bimg != null && bimg.length > 0) { - img = ImageIO.read(new ByteArrayInputStream(bimg)); - cache.put(uri, bimg, img); - img = cache.get(uri); - } + img = getImage(uri); } - if (img == null) { - logger.log(Level.INFO, String.format("Failed to load: %s", uri)); - } else { - final BufferedImage image = img; - SwingUtilities.invokeAndWait(new Runnable() { - @Override - public void run() { - if (tile instanceof MBTilesTile) { - ((MBTilesTile) tile).setImage(image); - } - pendingTiles--; - fireTileLoadedEvent(tile); - } - }); + if (img != null) { + addImageToTile(tile, img); } } catch (OutOfMemoryError memErr) { cache.needMoreMemory(); @@ -329,4 +314,41 @@ final class MBTilesTileFactory extends TileFactory { tile.setLoading(false); } } + + /** + * + * @param uri + * @return + * @throws IOException + * @throws GeoLocationDataException + */ + private BufferedImage getImage(URI uri ) throws IOException, GeoLocationDataException{ + BufferedImage img = null; + byte[] bimg = connector.getTileBytes(uri.toString()); + if (bimg != null && bimg.length > 0) { + img = ImageIO.read(new ByteArrayInputStream(bimg)); + cache.put(uri, bimg, img); + } + return img; + } + + /** + * + * @param tile + * @param image + * @throws InterruptedException + * @throws InvocationTargetException + */ + private void addImageToTile(Tile tile, BufferedImage image) throws InterruptedException, InvocationTargetException { + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + if (tile instanceof MBTilesTile) { + ((MBTilesTile) tile).setImage(image); + } + pendingTiles--; + fireTileLoadedEvent(tile); + } + }); + } }