forked from LogBlock/LogBlock
Merge branch 'dev'
This commit is contained in:
@@ -3,7 +3,9 @@ package de.diddiz.LogBlock;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.util.config.Configuration;
|
import org.bukkit.util.config.Configuration;
|
||||||
@@ -30,8 +32,8 @@ public class Config {
|
|||||||
public final boolean logChestAccess;
|
public final boolean logChestAccess;
|
||||||
public final boolean logKills;
|
public final boolean logKills;
|
||||||
public final LogKillsLevel logKillsLevel;
|
public final LogKillsLevel logKillsLevel;
|
||||||
public final List<Integer> dontRollback;
|
public final Set<Integer> dontRollback;
|
||||||
public final List<Integer> replaceAnyway;
|
public final Set<Integer> replaceAnyway;
|
||||||
public final int defaultDist;
|
public final int defaultDist;
|
||||||
public final int defaultTime;
|
public final int defaultTime;
|
||||||
public final int toolID;
|
public final int toolID;
|
||||||
@@ -159,8 +161,8 @@ public class Config {
|
|||||||
} catch (final IllegalArgumentException ex) {
|
} catch (final IllegalArgumentException ex) {
|
||||||
throw new Exception("lookup.toolblockID doesn't appear to be a valid log level. Allowed are 'PLAYERS', 'MONSTERS' and 'ANIMALS'");
|
throw new Exception("lookup.toolblockID doesn't appear to be a valid log level. Allowed are 'PLAYERS', 'MONSTERS' and 'ANIMALS'");
|
||||||
}
|
}
|
||||||
dontRollback = config.getIntList("rollback.dontRollback", null);
|
dontRollback = new HashSet<Integer>(config.getIntList("rollback.dontRollback", null));
|
||||||
replaceAnyway = config.getIntList("rollback.replaceAnyway", null);
|
replaceAnyway = new HashSet<Integer>(config.getIntList("rollback.replaceAnyway", null));
|
||||||
defaultDist = config.getInt("lookup.defaultDist", 20);
|
defaultDist = config.getInt("lookup.defaultDist", 20);
|
||||||
defaultTime = LogBlock.parseTimeSpec(config.getString("lookup.defaultTime"));
|
defaultTime = LogBlock.parseTimeSpec(config.getString("lookup.defaultTime"));
|
||||||
toolID = config.getInt("lookup.toolID", 270);
|
toolID = config.getInt("lookup.toolID", 270);
|
||||||
|
@@ -74,6 +74,7 @@ public class LogBlock extends JavaPlugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
log.info("[LogBlock] Connecting to " + config.user + "@" + config.url + "...");
|
||||||
pool = new ConnectionPool(config.url, config.user, config.password);
|
pool = new ConnectionPool(config.url, config.user, config.password);
|
||||||
final Connection conn = getConnection();
|
final Connection conn = getConnection();
|
||||||
conn.close();
|
conn.close();
|
||||||
|
@@ -16,7 +16,6 @@ import java.sql.SQLXML;
|
|||||||
import java.sql.Savepoint;
|
import java.sql.Savepoint;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.sql.Struct;
|
import java.sql.Struct;
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
@@ -39,51 +38,42 @@ public class ConnectionPool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized Connection getConnection() throws SQLException {
|
public synchronized Connection getConnection() throws SQLException {
|
||||||
JDCConnection c;
|
JDCConnection conn;
|
||||||
for (int i = 0; i < connections.size(); i++) {
|
for (int i = 0; i < connections.size(); i++) {
|
||||||
c = connections.elementAt(i);
|
conn = connections.get(i);
|
||||||
if (c.lease()) {
|
if (conn.lease()) {
|
||||||
if (c.isValid())
|
if (conn.isValid())
|
||||||
return c;
|
return conn;
|
||||||
else {
|
else {
|
||||||
c.terminate();
|
conn.terminate();
|
||||||
removeConnection(c);
|
connections.remove(conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c = new JDCConnection(DriverManager.getConnection(url, user, password));
|
conn = new JDCConnection(DriverManager.getConnection(url, user, password));
|
||||||
c.lease();
|
conn.lease();
|
||||||
if (!c.isValid()) {
|
if (!conn.isValid()) {
|
||||||
c.terminate();
|
conn.terminate();
|
||||||
throw new SQLException("Failed to validate a brand new connection");
|
throw new SQLException("Failed to validate a brand new connection");
|
||||||
}
|
}
|
||||||
connections.addElement(c);
|
connections.add(conn);
|
||||||
return c;
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void reapConnections() {
|
private synchronized void reapConnections() {
|
||||||
final long stale = System.currentTimeMillis() - timeout;
|
final long stale = System.currentTimeMillis() - timeout;
|
||||||
final Enumeration<JDCConnection> connlist = connections.elements();
|
for (final JDCConnection conn : connections)
|
||||||
while (connlist != null && connlist.hasMoreElements()) {
|
|
||||||
final JDCConnection conn = connlist.nextElement();
|
|
||||||
if (conn.inUse() && stale > conn.getLastUse() && !conn.isValid())
|
if (conn.inUse() && stale > conn.getLastUse() && !conn.isValid())
|
||||||
removeConnection(conn);
|
connections.remove(conn);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void closeConnections() {
|
public synchronized void closeConnections() {
|
||||||
final Enumeration<JDCConnection> connlist = connections.elements();
|
for (final JDCConnection conn : connections) {
|
||||||
while (connlist != null && connlist.hasMoreElements()) {
|
|
||||||
final JDCConnection conn = connlist.nextElement();
|
|
||||||
conn.terminate();
|
conn.terminate();
|
||||||
removeConnection(conn);
|
connections.remove(conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void removeConnection(JDCConnection conn) {
|
|
||||||
connections.removeElement(conn);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ConnectionReaper extends Thread
|
private class ConnectionReaper extends Thread
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@@ -116,9 +106,9 @@ public class ConnectionPool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean lease() {
|
public synchronized boolean lease() {
|
||||||
if (inuse) {
|
if (inuse)
|
||||||
return false;
|
return false;
|
||||||
} else {
|
else {
|
||||||
inuse = true;
|
inuse = true;
|
||||||
timestamp = System.currentTimeMillis();
|
timestamp = System.currentTimeMillis();
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user