Merge pull request #251 from mikeprimm/master

Add some cleanup to help avoid exceptions on /reload and shutdown/disable
This commit is contained in:
mikeprimm 2011-06-28 23:38:04 -07:00
commit e0f9a2f1e2
2 changed files with 32 additions and 24 deletions

View File

@ -10,6 +10,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
@ -99,6 +100,7 @@ public class MapManager {
@Override @Override
public void execute(final Runnable r) { public void execute(final Runnable r) {
final Runnable rr = r; final Runnable rr = r;
try {
super.execute(new Runnable() { super.execute(new Runnable() {
public void run() { public void run() {
try { try {
@ -109,9 +111,12 @@ public class MapManager {
} }
} }
}); });
} catch (RejectedExecutionException rxe) { /* Pool shutdown - nominal for reload or unload */
}
} }
@Override @Override
public ScheduledFuture<?> schedule(final Runnable command, long delay, TimeUnit unit) { public ScheduledFuture<?> schedule(final Runnable command, long delay, TimeUnit unit) {
try {
return super.schedule(new Runnable() { return super.schedule(new Runnable() {
public void run() { public void run() {
try { try {
@ -122,6 +127,9 @@ public class MapManager {
} }
} }
}, delay, unit); }, delay, unit);
} catch (RejectedExecutionException rxe) {
return null; /* Pool shut down when we reload or unload */
}
} }
} }
/* This always runs on render pool threads - no bukkit calls from here */ /* This always runs on render pool threads - no bukkit calls from here */
@ -496,10 +504,7 @@ public class MapManager {
} }
public void stopRendering() { public void stopRendering() {
if(renderpool != null) {
renderpool.shutdown(); renderpool.shutdown();
renderpool = null;
}
tileQueue.stop(); tileQueue.stop();
} }

View File

@ -45,12 +45,14 @@ public class HttpServer extends Thread {
public void run() { public void run() {
try { try {
ServerSocket s = sock;
while (listeningThread == Thread.currentThread()) { while (listeningThread == Thread.currentThread()) {
try { try {
Socket socket = sock.accept(); Socket socket = s.accept();
HttpServerConnection requestThread = new HttpServerConnection(socket, this); HttpServerConnection requestThread = new HttpServerConnection(socket, this);
requestThread.start(); requestThread.start();
} catch (IOException e) { } catch (IOException e) {
if(listeningThread != null) /* Only report this if we didn't initiate the shutdown */
Log.info("map WebServer.run() stops with IOException"); Log.info("map WebServer.run() stops with IOException");
break; break;
} }
@ -63,13 +65,14 @@ public class HttpServer extends Thread {
public void shutdown() { public void shutdown() {
Log.info("Shutting down webserver..."); Log.info("Shutting down webserver...");
listeningThread = null;
try { try {
if (sock != null) { if (sock != null) {
sock.close(); sock.close();
sock = null;
} }
} catch (IOException e) { } catch (IOException e) {
Log.warning("Exception while closing socket for webserver shutdown", e); Log.warning("Exception while closing socket for webserver shutdown", e);
} }
listeningThread = null;
} }
} }