More exception handling and messages.

This commit is contained in:
FrozenCow 2011-01-15 02:57:11 +01:00
parent b22a48d5cb
commit b501f1d8cb
5 changed files with 86 additions and 54 deletions

View File

@ -99,6 +99,7 @@ public class MapManager extends Thread {
/* initialize and start map manager */
public void startManager()
{
synchronized(lock) {
running = true;
this.start();
try {
@ -107,56 +108,63 @@ public class MapManager extends Thread {
} catch(SecurityException e) {
log.info("Failed to set minimum priority for worker thread!");
}
}
}
/* stop map manager */
public void stopManager()
{
if(!running)
return;
log.info("Stopping map renderer...");
running = false;
try {
this.join();
} catch(InterruptedException e) {
log.info("Waiting for map renderer to stop is interrupted");
synchronized(lock) {
if(!running)
return;
log.info("Stopping map renderer...");
running = false;
try {
this.join();
} catch(InterruptedException e) {
log.info("Waiting for map renderer to stop is interrupted");
}
}
}
/* the worker/renderer thread */
public void run()
{
log.info("Map renderer has started.");
while(running) {
boolean found = false;
MapTile t = staleQueue.popStaleTile();
if(t != null) {
debugger.debug("rendering tile " + t + "...");
t.getMap().render(t);
staleQueue.onTileUpdated(t);
try {
this.sleep(renderWait);
} catch(InterruptedException e) {
try {
log.info("Map renderer has started.");
while(running) {
boolean found = false;
MapTile t = staleQueue.popStaleTile();
if(t != null) {
debugger.debug("rendering tile " + t + "...");
t.getMap().render(t);
staleQueue.onTileUpdated(t);
try {
Thread.sleep(renderWait);
} catch(InterruptedException e) {
}
found = true;
}
found = true;
}
if(!found) {
try {
this.sleep(500);
} catch(InterruptedException e) {
if(!found) {
try {
Thread.sleep(500);
} catch(InterruptedException e) {
}
}
}
log.info("Map renderer has stopped.");
} catch(Exception ex) {
debugger.error("Exception on rendering-thread: " + ex.toString());
}
log.info("Map renderer has stopped.");
}
public void touch(int x, int y, int z) {

View File

@ -34,18 +34,22 @@ public class WebServer extends Thread {
public void run()
{
while (running) {
try {
Socket socket = sock.accept();
WebServerRequest requestThread = new WebServerRequest(socket, mgr, server, debugger);
requestThread.start();
}
catch (IOException e) {
log.info("map WebServer.run() stops with IOException");
break;
try {
while (running) {
try {
Socket socket = sock.accept();
WebServerRequest requestThread = new WebServerRequest(socket, mgr, server, debugger);
requestThread.start();
}
catch (IOException e) {
log.info("map WebServer.run() stops with IOException");
break;
}
}
log.info("map WebServer run() exiting");
} catch (Exception ex) {
debugger.error("Exception on WebServer-thread: " + ex.toString());
}
log.info("map WebServer run() exiting");
}
public void shutdown()

View File

@ -94,6 +94,9 @@ public class WebServerRequest extends Thread {
}
}
}
catch(Exception ex) {
debugger.error("Exception on WebRequest-thread: " + ex.toString());
}
}
public void handleUp(BufferedOutputStream out, String path) throws IOException {

View File

@ -34,45 +34,45 @@ public class BukkitPlayerDebugger implements Debugger {
prepend = pdfFile.getName() + ": ";
}
public void enable() {
public synchronized void enable() {
plugin.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, new CommandListener(), Priority.Normal, plugin);
plugin.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT, new CommandListener(), Priority.Normal, plugin);
log.info("Debugger enabled, use: " + debugCommand);
}
public void disable() {
public synchronized void disable() {
clearDebugees();
}
public void addDebugee(Player p) {
public synchronized void addDebugee(Player p) {
debugees.add(p);
}
public void removeDebugee(Player p) {
public synchronized void removeDebugee(Player p) {
debugees.remove(p);
}
public void clearDebugees() {
public synchronized void clearDebugees() {
debugees.clear();
}
public void sendToDebuggees(String message) {
public synchronized void sendToDebuggees(String message) {
for (Player p : debugees) {
p.sendMessage(prepend + message);
}
}
public void debug(String message) {
public synchronized void debug(String message) {
sendToDebuggees(message);
if (isLogging) log.info(prepend + message);
}
public void error(String message) {
public synchronized void error(String message) {
sendToDebuggees(prepend + ChatColor.RED + message);
if (isLogging) log.log(Level.SEVERE, prepend + message);
}
public void error(String message, Throwable thrown) {
public synchronized void error(String message, Throwable thrown) {
sendToDebuggees(prepend + ChatColor.RED + message);
sendToDebuggees(thrown.toString());
if (isLogging) log.log(Level.SEVERE, prepend + message);

View File

@ -13,6 +13,8 @@ import java.util.logging.Logger;
import javax.imageio.ImageIO;
import org.bukkit.Block;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.dynmap.MapManager;
import org.dynmap.MapTile;
@ -40,6 +42,21 @@ public class DefaultTileRenderer implements MapTileRenderer {
int ix = tile.mx;
int iy = tile.my;
int iz = tile.mz;
Block block = tile.getMap().getWorld().getBlockAt(ix, iy, iz);
if (block == null) {
debugger.debug("Could not get block for rendering.");
return;
}
Chunk chunk = block.getChunk();
if (chunk == null) {
debugger.debug("Could not get chunk for rendering.");
return;
}
if (!world.isChunkLoaded(chunk)) {
debugger.debug("Chunk was not loaded, but we'll still continue render.");
}
int jx, jz;
int x, y;