forked from LogBlock/LogBlock
Use constants for magic values
This commit is contained in:
@@ -54,6 +54,10 @@ import de.diddiz.LogBlock.events.BlockChangePreLogEvent;
|
|||||||
import de.diddiz.util.Utils;
|
import de.diddiz.util.Utils;
|
||||||
|
|
||||||
public class Consumer extends Thread {
|
public class Consumer extends Thread {
|
||||||
|
private static final int MAX_SHUTDOWN_TIME_MILLIS = 20000;
|
||||||
|
private static final int WAIT_FOR_CONNECTION_TIME_MILLIS = 10000;
|
||||||
|
private static final int RETRIES_ON_UNKNOWN_CONNECTION_ERROR = 2;
|
||||||
|
|
||||||
private final Deque<Row> queue = new ArrayDeque<Row>();
|
private final Deque<Row> queue = new ArrayDeque<Row>();
|
||||||
private final LogBlock logblock;
|
private final LogBlock logblock;
|
||||||
private final Map<Actor, Integer> playerIds = new HashMap<>();
|
private final Map<Actor, Integer> playerIds = new HashMap<>();
|
||||||
@@ -448,7 +452,7 @@ public class Consumer extends Thread {
|
|||||||
// wait for a connection
|
// wait for a connection
|
||||||
logblock.getLogger().severe("[Consumer] Could not connect to the database!");
|
logblock.getLogger().severe("[Consumer] Could not connect to the database!");
|
||||||
try {
|
try {
|
||||||
Thread.sleep(10000);
|
Thread.sleep(WAIT_FOR_CONNECTION_TIME_MILLIS);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
@@ -460,7 +464,7 @@ public class Consumer extends Thread {
|
|||||||
synchronized (queue) {
|
synchronized (queue) {
|
||||||
if (shutdown) {
|
if (shutdown) {
|
||||||
// Give this thread some time to process the remaining entries
|
// Give this thread some time to process the remaining entries
|
||||||
if (queue.isEmpty() || System.currentTimeMillis() - shutdownInitialized > 20000) {
|
if (queue.isEmpty() || System.currentTimeMillis() - shutdownInitialized > MAX_SHUTDOWN_TIME_MILLIS) {
|
||||||
if (currentRows.isEmpty()) {
|
if (currentRows.isEmpty()) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
@@ -505,7 +509,7 @@ public class Consumer extends Thread {
|
|||||||
lastCommitsFailed = 0;
|
lastCommitsFailed = 0;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
boolean retry = lastCommitsFailed < 2;
|
boolean retry = lastCommitsFailed < RETRIES_ON_UNKNOWN_CONNECTION_ERROR;
|
||||||
String state = "unknown";
|
String state = "unknown";
|
||||||
if (e instanceof SQLException) {
|
if (e instanceof SQLException) {
|
||||||
// Retry on network errors: SQLSTATE = 08S01 08001 08004 HY000 40001
|
// Retry on network errors: SQLSTATE = 08S01 08001 08004 HY000 40001
|
||||||
|
Reference in New Issue
Block a user