Shift all imageIO and file I/O to async thread

Minus the version change in plugin.yml.
This commit is contained in:
Mike Primm 2011-05-10 23:03:11 -05:00 committed by FrozenCow
parent 619485212d
commit 0a8f2a182a
4 changed files with 150 additions and 88 deletions

View file

@ -11,8 +11,10 @@ import javax.imageio.ImageIO;
import org.bukkit.Location;
import org.bukkit.World;
import org.dynmap.Client;
import org.dynmap.ColorScheme;
import org.dynmap.DynmapChunk;
import org.dynmap.MapManager;
import org.dynmap.MapTile;
import org.dynmap.MapType;
import org.dynmap.debug.Debug;
@ -120,15 +122,26 @@ public class FlatMap extends MapType {
raster.setPixel(t.size-y-1, x, pixel);
rendered = true;
}
/* Hand encoding and writing file off to MapManager */
final File fname = outputFile;
final MapTile mtile = tile;
final BufferedImage img = im;
MapManager.mapman.enqueueImageWrite(new Runnable() {
public void run() {
Debug.debug("saving image " + fname.getPath());
try {
ImageIO.write(img, "png", fname);
} catch (IOException e) {
Debug.error("Failed to save image: " + fname.getPath(), e);
} catch (java.lang.NullPointerException e) {
Debug.error("Failed to save image (NullPointerException): " + fname.getPath(), e);
}
img.flush();
MapManager.mapman.pushUpdate(mtile.getWorld(),
new Client.Tile(mtile.getFilename()));
}
});
try {
ImageIO.write(im, "png", outputFile);
} catch (IOException e) {
Debug.error("Failed to save image: " + outputFile.getPath(), e);
} catch (java.lang.NullPointerException e) {
Debug.error("Failed to save image (NullPointerException): " + outputFile.getPath(), e);
}
im.flush();
return rendered;
}