Do not spam exceptions when the database connection pool is closed

When some database access is still running asynchronously, it will
create an SQLException when the pool is closed (on shutdown). Just
silently ignore them in this case.
This commit is contained in:
Brokkonaut
2018-08-03 14:20:55 +02:00
parent 6168ef1713
commit 66070e2b38
3 changed files with 38 additions and 15 deletions

View File

@@ -426,7 +426,9 @@ public class CommandsHandler implements CommandExecutor {
rs.close(); rs.close();
} }
} catch (final SQLException ex) { } catch (final SQLException ex) {
logblock.getLogger().log(Level.SEVERE, "[CommandsHandler] SQL exception on close", ex); if (logblock.isCompletelyEnabled()) {
logblock.getLogger().log(Level.SEVERE, "[CommandsHandler] SQL exception on close", ex);
}
} }
} }
} }
@@ -490,8 +492,10 @@ public class CommandsHandler implements CommandExecutor {
getSession(sender).lookupCache = null; getSession(sender).lookupCache = null;
} }
} catch (final Exception ex) { } catch (final Exception ex) {
sender.sendMessage(ChatColor.RED + "Exception, check error log"); if (logblock.isCompletelyEnabled() || !(ex instanceof SQLException)) {
logblock.getLogger().log(Level.SEVERE, "[Lookup] " + params.getQuery() + ": ", ex); sender.sendMessage(ChatColor.RED + "Exception, check error log");
logblock.getLogger().log(Level.SEVERE, "[Lookup] " + params.getQuery() + ": ", ex);
}
} finally { } finally {
close(); close();
} }
@@ -546,8 +550,10 @@ public class CommandsHandler implements CommandExecutor {
writer.close(); writer.close();
sender.sendMessage(ChatColor.GREEN + "Wrote " + counter + " lines."); sender.sendMessage(ChatColor.GREEN + "Wrote " + counter + " lines.");
} catch (final Exception ex) { } catch (final Exception ex) {
sender.sendMessage(ChatColor.RED + "Exception, check error log"); if (logblock.isCompletelyEnabled() || !(ex instanceof SQLException)) {
logblock.getLogger().log(Level.SEVERE, "[WriteLogFile] " + params.getQuery() + " (file was " + file.getAbsolutePath() + "): ", ex); sender.sendMessage(ChatColor.RED + "Exception, check error log");
logblock.getLogger().log(Level.SEVERE, "[WriteLogFile] " + params.getQuery() + " (file was " + file.getAbsolutePath() + "): ", ex);
}
} finally { } finally {
close(); close();
} }
@@ -606,8 +612,10 @@ public class CommandsHandler implements CommandExecutor {
sender.sendMessage(ChatColor.RED + "No block change found to teleport to"); sender.sendMessage(ChatColor.RED + "No block change found to teleport to");
} }
} catch (final Exception ex) { } catch (final Exception ex) {
sender.sendMessage(ChatColor.RED + "Exception, check error log"); if (logblock.isCompletelyEnabled() || !(ex instanceof SQLException)) {
logblock.getLogger().log(Level.SEVERE, "[Teleport] " + params.getQuery() + ": ", ex); sender.sendMessage(ChatColor.RED + "Exception, check error log");
logblock.getLogger().log(Level.SEVERE, "[Teleport] " + params.getQuery() + ": ", ex);
}
} finally { } finally {
close(); close();
} }
@@ -693,8 +701,10 @@ public class CommandsHandler implements CommandExecutor {
} }
} }
} catch (final Exception ex) { } catch (final Exception ex) {
sender.sendMessage(ChatColor.RED + "Exception, check error log"); if (logblock.isCompletelyEnabled() || !(ex instanceof SQLException)) {
logblock.getLogger().log(Level.SEVERE, "[Rollback] " + params.getQuery() + ": ", ex); sender.sendMessage(ChatColor.RED + "Exception, check error log");
logblock.getLogger().log(Level.SEVERE, "[Rollback] " + params.getQuery() + ": ", ex);
}
} finally { } finally {
close(); close();
} }
@@ -766,8 +776,10 @@ public class CommandsHandler implements CommandExecutor {
editor.start(); editor.start();
sender.sendMessage(ChatColor.GREEN + "Redo finished successfully (" + editor.getElapsedTime() + " ms, " + editor.getSuccesses() + "/" + changes + " blocks" + (editor.getErrors() > 0 ? ", " + ChatColor.RED + editor.getErrors() + " errors" + ChatColor.GREEN : "") + (editor.getBlacklistCollisions() > 0 ? ", " + editor.getBlacklistCollisions() + " blacklist collisions" : "") + ")"); sender.sendMessage(ChatColor.GREEN + "Redo finished successfully (" + editor.getElapsedTime() + " ms, " + editor.getSuccesses() + "/" + changes + " blocks" + (editor.getErrors() > 0 ? ", " + ChatColor.RED + editor.getErrors() + " errors" + ChatColor.GREEN : "") + (editor.getBlacklistCollisions() > 0 ? ", " + editor.getBlacklistCollisions() + " blacklist collisions" : "") + ")");
} catch (final Exception ex) { } catch (final Exception ex) {
sender.sendMessage(ChatColor.RED + "Exception, check error log"); if (logblock.isCompletelyEnabled() || !(ex instanceof SQLException)) {
logblock.getLogger().log(Level.SEVERE, "[Redo] " + params.getQuery() + ": ", ex); sender.sendMessage(ChatColor.RED + "Exception, check error log");
logblock.getLogger().log(Level.SEVERE, "[Redo] " + params.getQuery() + ": ", ex);
}
} finally { } finally {
close(); close();
} }
@@ -841,8 +853,10 @@ public class CommandsHandler implements CommandExecutor {
sender.sendMessage(ChatColor.GREEN + "Cleared out table " + table + "-chestdata. Deleted " + deleted + " entries."); sender.sendMessage(ChatColor.GREEN + "Cleared out table " + table + "-chestdata. Deleted " + deleted + " entries.");
} }
} catch (final Exception ex) { } catch (final Exception ex) {
sender.sendMessage(ChatColor.RED + "Exception, check error log"); if (logblock.isCompletelyEnabled() || !(ex instanceof SQLException)) {
logblock.getLogger().log(Level.SEVERE, "[ClearLog] Exception: ", ex); sender.sendMessage(ChatColor.RED + "Exception, check error log");
logblock.getLogger().log(Level.SEVERE, "[ClearLog] Exception: ", ex);
}
} finally { } finally {
close(); close();
} }

View File

@@ -40,11 +40,16 @@ public class LogBlock extends JavaPlugin {
private boolean errorAtLoading = false, noDb = false, connected = true; private boolean errorAtLoading = false, noDb = false, connected = true;
private PlayerInfoLogging playerInfoLogging; private PlayerInfoLogging playerInfoLogging;
private Questioner questioner; private Questioner questioner;
private volatile boolean isCompletelyEnabled;
public static LogBlock getInstance() { public static LogBlock getInstance() {
return logblock; return logblock;
} }
public boolean isCompletelyEnabled() {
return isCompletelyEnabled;
}
public Consumer getConsumer() { public Consumer getConsumer() {
return consumer; return consumer;
} }
@@ -120,7 +125,6 @@ public class LogBlock extends JavaPlugin {
new DumpedLogImporter(this).run(); new DumpedLogImporter(this).run();
registerEvents(); registerEvents();
consumer.start(); consumer.start();
getServer().getScheduler().runTaskAsynchronously(this, new Updater.PlayerCountChecker(this));
for (final Tool tool : toolsByType.values()) { for (final Tool tool : toolsByType.values()) {
if (pm.getPermission("logblock.tools." + tool.name) == null) { if (pm.getPermission("logblock.tools." + tool.name) == null) {
final Permission perm = new Permission("logblock.tools." + tool.name, tool.permissionDefault); final Permission perm = new Permission("logblock.tools." + tool.name, tool.permissionDefault);
@@ -128,6 +132,8 @@ public class LogBlock extends JavaPlugin {
} }
} }
questioner = new Questioner(this); questioner = new Questioner(this);
isCompletelyEnabled = true;
getServer().getScheduler().runTaskAsynchronously(this, new Updater.PlayerCountChecker(this));
try { try {
Metrics metrics = new Metrics(this); Metrics metrics = new Metrics(this);
metrics.start(); metrics.start();
@@ -204,6 +210,7 @@ public class LogBlock extends JavaPlugin {
@Override @Override
public void onDisable() { public void onDisable() {
isCompletelyEnabled = false;
if (timer != null) { if (timer != null) {
timer.cancel(); timer.cancel();
} }

View File

@@ -825,7 +825,9 @@ class Updater {
st.close(); st.close();
conn.close(); conn.close();
} catch (final SQLException ex) { } catch (final SQLException ex) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex); if (logblock.isCompletelyEnabled()) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
}
} }
} }
} }