Dramastically increase performance
Maybe fix low tps :O
This commit is contained in:
@@ -1,250 +1,245 @@
|
||||
package fr.xephi.authme.datasource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
|
||||
public class CacheDataSource extends Thread implements DataSource {
|
||||
|
||||
private DataSource source;
|
||||
public AuthMe plugin;
|
||||
private ConcurrentHashMap<String, PlayerAuth> cache = new ConcurrentHashMap<String, PlayerAuth>();
|
||||
|
||||
public CacheDataSource(AuthMe plugin, DataSource source) {
|
||||
this.plugin = plugin;
|
||||
this.source = source;
|
||||
/*
|
||||
* We need to load all players in cache ...
|
||||
* It will took more time to load the server,
|
||||
* but it will be much easier to check for an isAuthAvailable !
|
||||
*/
|
||||
for(PlayerAuth auth : source.getAllAuths())
|
||||
cache.put(auth.getNickname().toLowerCase(), auth);
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
this.setName("AuthMeCacheThread");
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean isAuthAvailable(String user) {
|
||||
if (cache.containsKey(user.toLowerCase()))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized PlayerAuth getAuth(String user) {
|
||||
user = user.toLowerCase();
|
||||
if (cache.containsKey(user)) {
|
||||
return cache.get(user);
|
||||
} else {
|
||||
PlayerAuth auth = source.getAuth(user);
|
||||
if (auth != null)
|
||||
cache.put(user, auth);
|
||||
return auth;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean saveAuth(PlayerAuth auth) {
|
||||
if (source.saveAuth(auth)) {
|
||||
cache.put(auth.getNickname(), auth);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean updatePassword(PlayerAuth auth) {
|
||||
if (source.updatePassword(auth)) {
|
||||
if (cache.containsKey(auth.getNickname()))
|
||||
cache.get(auth.getNickname()).setHash(auth.getHash());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateSession(PlayerAuth auth) {
|
||||
if (source.updateSession(auth)) {
|
||||
if (cache.containsKey(auth.getNickname())) {
|
||||
cache.get(auth.getNickname()).setIp(auth.getIp());
|
||||
cache.get(auth.getNickname()).setLastLogin(auth.getLastLogin());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateQuitLoc(PlayerAuth auth) {
|
||||
if (source.updateQuitLoc(auth)) {
|
||||
if (cache.containsKey(auth.getNickname())) {
|
||||
cache.get(auth.getNickname()).setQuitLocX(auth.getQuitLocX());
|
||||
cache.get(auth.getNickname()).setQuitLocY(auth.getQuitLocY());
|
||||
cache.get(auth.getNickname()).setQuitLocZ(auth.getQuitLocZ());
|
||||
cache.get(auth.getNickname()).setWorld(auth.getWorld());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIps(String ip) {
|
||||
return source.getIps(ip);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int purgeDatabase(long until) {
|
||||
int cleared = source.purgeDatabase(until);
|
||||
if (cleared > 0) {
|
||||
for (PlayerAuth auth : cache.values()) {
|
||||
if (auth.getLastLogin() < until) {
|
||||
cache.remove(auth.getNickname());
|
||||
}
|
||||
}
|
||||
}
|
||||
return cleared;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> autoPurgeDatabase(long until) {
|
||||
List<String> cleared = source.autoPurgeDatabase(until);
|
||||
if (cleared.size() > 0) {
|
||||
for (PlayerAuth auth : cache.values()) {
|
||||
if (auth.getLastLogin() < until) {
|
||||
cache.remove(auth.getNickname());
|
||||
}
|
||||
}
|
||||
}
|
||||
return cleared;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean removeAuth(String user) {
|
||||
if (source.removeAuth(user)) {
|
||||
cache.remove(user);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void close() {
|
||||
source.close();
|
||||
this.interrupt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
cache.clear();
|
||||
source.reload();
|
||||
for (Player player : plugin.getServer().getOnlinePlayers()) {
|
||||
String user = player.getName().toLowerCase();
|
||||
if (PlayerCache.getInstance().isAuthenticated(user)) {
|
||||
try {
|
||||
PlayerAuth auth = source.getAuth(user);
|
||||
cache.put(user, auth);
|
||||
} catch (NullPointerException npe) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean updateEmail(PlayerAuth auth) {
|
||||
if (source.updateEmail(auth)) {
|
||||
if (cache.containsKey(auth.getNickname()))
|
||||
cache.get(auth.getNickname()).setEmail(auth.getEmail());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean updateSalt(PlayerAuth auth) {
|
||||
if (source.updateSalt(auth)) {
|
||||
if (cache.containsKey(auth.getNickname()))
|
||||
cache.get(auth.getNickname()).setSalt(auth.getSalt());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<String> getAllAuthsByName(PlayerAuth auth) {
|
||||
return source.getAllAuthsByName(auth);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<String> getAllAuthsByIp(String ip) {
|
||||
return source.getAllAuthsByIp(ip);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<String> getAllAuthsByEmail(String email) {
|
||||
return source.getAllAuthsByEmail(email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void purgeBanned(List<String> banned) {
|
||||
source.purgeBanned(banned);
|
||||
for (PlayerAuth auth : cache.values()) {
|
||||
if (banned.contains(auth.getNickname())) {
|
||||
cache.remove(auth.getNickname());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSourceType getType() {
|
||||
return source.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLogged(String user) {
|
||||
return source.isLogged(user.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLogged(String user) {
|
||||
source.setLogged(user.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUnlogged(String user) {
|
||||
source.setUnlogged(user.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void purgeLogged() {
|
||||
source.purgeLogged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAccountsRegistered() {
|
||||
return source.getAccountsRegistered();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateName(String oldone, String newone) {
|
||||
if (cache.containsKey(oldone)) {
|
||||
cache.put(newone, cache.get(oldone));
|
||||
cache.remove(oldone);
|
||||
}
|
||||
source.updateName(oldone, newone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PlayerAuth> getAllAuths() {
|
||||
return source.getAllAuths();
|
||||
}
|
||||
}
|
||||
package fr.xephi.authme.datasource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
|
||||
public class CacheDataSource implements DataSource {
|
||||
|
||||
private DataSource source;
|
||||
public AuthMe plugin;
|
||||
private ConcurrentHashMap<String, PlayerAuth> cache = new ConcurrentHashMap<String, PlayerAuth>();
|
||||
|
||||
public CacheDataSource(AuthMe plugin, DataSource source) {
|
||||
this.plugin = plugin;
|
||||
this.source = source;
|
||||
/*
|
||||
* We need to load all players in cache ... It will took more time to
|
||||
* load the server, but it will be much easier to check for an
|
||||
* isAuthAvailable !
|
||||
*/
|
||||
for (PlayerAuth auth : source.getAllAuths())
|
||||
cache.put(auth.getNickname().toLowerCase(), auth);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean isAuthAvailable(String user) {
|
||||
if (cache.containsKey(user.toLowerCase()))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized PlayerAuth getAuth(String user) {
|
||||
user = user.toLowerCase();
|
||||
if (cache.containsKey(user)) {
|
||||
return cache.get(user);
|
||||
} else {
|
||||
PlayerAuth auth = source.getAuth(user);
|
||||
if (auth != null)
|
||||
cache.put(user, auth);
|
||||
return auth;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean saveAuth(PlayerAuth auth) {
|
||||
if (source.saveAuth(auth)) {
|
||||
cache.put(auth.getNickname(), auth);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean updatePassword(PlayerAuth auth) {
|
||||
if (source.updatePassword(auth)) {
|
||||
if (cache.containsKey(auth.getNickname()))
|
||||
cache.get(auth.getNickname()).setHash(auth.getHash());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateSession(PlayerAuth auth) {
|
||||
if (source.updateSession(auth)) {
|
||||
if (cache.containsKey(auth.getNickname())) {
|
||||
cache.get(auth.getNickname()).setIp(auth.getIp());
|
||||
cache.get(auth.getNickname()).setLastLogin(auth.getLastLogin());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateQuitLoc(PlayerAuth auth) {
|
||||
if (source.updateQuitLoc(auth)) {
|
||||
if (cache.containsKey(auth.getNickname())) {
|
||||
cache.get(auth.getNickname()).setQuitLocX(auth.getQuitLocX());
|
||||
cache.get(auth.getNickname()).setQuitLocY(auth.getQuitLocY());
|
||||
cache.get(auth.getNickname()).setQuitLocZ(auth.getQuitLocZ());
|
||||
cache.get(auth.getNickname()).setWorld(auth.getWorld());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIps(String ip) {
|
||||
return source.getIps(ip);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int purgeDatabase(long until) {
|
||||
int cleared = source.purgeDatabase(until);
|
||||
if (cleared > 0) {
|
||||
for (PlayerAuth auth : cache.values()) {
|
||||
if (auth.getLastLogin() < until) {
|
||||
cache.remove(auth.getNickname());
|
||||
}
|
||||
}
|
||||
}
|
||||
return cleared;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> autoPurgeDatabase(long until) {
|
||||
List<String> cleared = source.autoPurgeDatabase(until);
|
||||
if (cleared.size() > 0) {
|
||||
for (PlayerAuth auth : cache.values()) {
|
||||
if (auth.getLastLogin() < until) {
|
||||
cache.remove(auth.getNickname());
|
||||
}
|
||||
}
|
||||
}
|
||||
return cleared;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean removeAuth(String user) {
|
||||
if (source.removeAuth(user)) {
|
||||
cache.remove(user);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void close() {
|
||||
source.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
cache.clear();
|
||||
source.reload();
|
||||
for (Player player : plugin.getServer().getOnlinePlayers()) {
|
||||
String user = player.getName().toLowerCase();
|
||||
if (PlayerCache.getInstance().isAuthenticated(user)) {
|
||||
try {
|
||||
PlayerAuth auth = source.getAuth(user);
|
||||
cache.put(user, auth);
|
||||
} catch (NullPointerException npe) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean updateEmail(PlayerAuth auth) {
|
||||
if (source.updateEmail(auth)) {
|
||||
if (cache.containsKey(auth.getNickname()))
|
||||
cache.get(auth.getNickname()).setEmail(auth.getEmail());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean updateSalt(PlayerAuth auth) {
|
||||
if (source.updateSalt(auth)) {
|
||||
if (cache.containsKey(auth.getNickname()))
|
||||
cache.get(auth.getNickname()).setSalt(auth.getSalt());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<String> getAllAuthsByName(PlayerAuth auth) {
|
||||
return source.getAllAuthsByName(auth);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<String> getAllAuthsByIp(String ip) {
|
||||
return source.getAllAuthsByIp(ip);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<String> getAllAuthsByEmail(String email) {
|
||||
return source.getAllAuthsByEmail(email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void purgeBanned(List<String> banned) {
|
||||
source.purgeBanned(banned);
|
||||
for (PlayerAuth auth : cache.values()) {
|
||||
if (banned.contains(auth.getNickname())) {
|
||||
cache.remove(auth.getNickname());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSourceType getType() {
|
||||
return source.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLogged(String user) {
|
||||
return source.isLogged(user.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLogged(String user) {
|
||||
source.setLogged(user.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUnlogged(String user) {
|
||||
source.setUnlogged(user.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void purgeLogged() {
|
||||
source.purgeLogged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAccountsRegistered() {
|
||||
return source.getAccountsRegistered();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateName(String oldone, String newone) {
|
||||
if (cache.containsKey(oldone)) {
|
||||
cache.put(newone, cache.get(oldone));
|
||||
cache.remove(oldone);
|
||||
}
|
||||
source.updateName(oldone, newone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PlayerAuth> getAllAuths() {
|
||||
return source.getAllAuths();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,68 +1,68 @@
|
||||
package fr.xephi.authme.datasource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
|
||||
public interface DataSource {
|
||||
|
||||
public enum DataSourceType {
|
||||
|
||||
MYSQL,
|
||||
FILE,
|
||||
SQLITE
|
||||
}
|
||||
|
||||
boolean isAuthAvailable(String user);
|
||||
|
||||
PlayerAuth getAuth(String user);
|
||||
|
||||
boolean saveAuth(PlayerAuth auth);
|
||||
|
||||
boolean updateSession(PlayerAuth auth);
|
||||
|
||||
boolean updatePassword(PlayerAuth auth);
|
||||
|
||||
int purgeDatabase(long until);
|
||||
|
||||
List<String> autoPurgeDatabase(long until);
|
||||
|
||||
boolean removeAuth(String user);
|
||||
|
||||
boolean updateQuitLoc(PlayerAuth auth);
|
||||
|
||||
int getIps(String ip);
|
||||
|
||||
List<String> getAllAuthsByName(PlayerAuth auth);
|
||||
|
||||
List<String> getAllAuthsByIp(String ip);
|
||||
|
||||
List<String> getAllAuthsByEmail(String email);
|
||||
|
||||
boolean updateEmail(PlayerAuth auth);
|
||||
|
||||
boolean updateSalt(PlayerAuth auth);
|
||||
|
||||
void close();
|
||||
|
||||
void reload();
|
||||
|
||||
void purgeBanned(List<String> banned);
|
||||
|
||||
DataSourceType getType();
|
||||
|
||||
boolean isLogged(String user);
|
||||
|
||||
void setLogged(String user);
|
||||
|
||||
void setUnlogged(String user);
|
||||
|
||||
void purgeLogged();
|
||||
|
||||
int getAccountsRegistered();
|
||||
|
||||
void updateName(String oldone, String newone);
|
||||
|
||||
List<PlayerAuth> getAllAuths();
|
||||
|
||||
}
|
||||
package fr.xephi.authme.datasource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
|
||||
public interface DataSource {
|
||||
|
||||
public enum DataSourceType {
|
||||
|
||||
MYSQL,
|
||||
FILE,
|
||||
SQLITE
|
||||
}
|
||||
|
||||
boolean isAuthAvailable(String user);
|
||||
|
||||
PlayerAuth getAuth(String user);
|
||||
|
||||
boolean saveAuth(PlayerAuth auth);
|
||||
|
||||
boolean updateSession(PlayerAuth auth);
|
||||
|
||||
boolean updatePassword(PlayerAuth auth);
|
||||
|
||||
int purgeDatabase(long until);
|
||||
|
||||
List<String> autoPurgeDatabase(long until);
|
||||
|
||||
boolean removeAuth(String user);
|
||||
|
||||
boolean updateQuitLoc(PlayerAuth auth);
|
||||
|
||||
int getIps(String ip);
|
||||
|
||||
List<String> getAllAuthsByName(PlayerAuth auth);
|
||||
|
||||
List<String> getAllAuthsByIp(String ip);
|
||||
|
||||
List<String> getAllAuthsByEmail(String email);
|
||||
|
||||
boolean updateEmail(PlayerAuth auth);
|
||||
|
||||
boolean updateSalt(PlayerAuth auth);
|
||||
|
||||
void close();
|
||||
|
||||
void reload();
|
||||
|
||||
void purgeBanned(List<String> banned);
|
||||
|
||||
DataSourceType getType();
|
||||
|
||||
boolean isLogged(String user);
|
||||
|
||||
void setLogged(String user);
|
||||
|
||||
void setUnlogged(String user);
|
||||
|
||||
void purgeLogged();
|
||||
|
||||
int getAccountsRegistered();
|
||||
|
||||
void updateName(String oldone, String newone);
|
||||
|
||||
List<PlayerAuth> getAllAuths();
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,382 @@
|
||||
package fr.xephi.authme.datasource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
|
||||
public class DatabaseCalls implements DataSource {
|
||||
|
||||
private AuthMe plugin;
|
||||
private DataSource database;
|
||||
|
||||
public DatabaseCalls(AuthMe plugin, DataSource database) {
|
||||
this.plugin = plugin;
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean isAuthAvailable(final String user) {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
|
||||
|
||||
public Boolean call() throws Exception {
|
||||
return database.isAuthAvailable(user);
|
||||
}
|
||||
});
|
||||
try {
|
||||
return result.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized PlayerAuth getAuth(final String user) {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Future<PlayerAuth> result = executor.submit(new Callable<PlayerAuth>() {
|
||||
|
||||
public PlayerAuth call() throws Exception {
|
||||
return database.getAuth(user);
|
||||
}
|
||||
});
|
||||
try {
|
||||
return result.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean saveAuth(final PlayerAuth auth) {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
|
||||
|
||||
public Boolean call() throws Exception {
|
||||
return database.saveAuth(auth);
|
||||
}
|
||||
});
|
||||
try {
|
||||
return result.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean updateSession(final PlayerAuth auth) {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
|
||||
|
||||
public Boolean call() throws Exception {
|
||||
return database.updateSession(auth);
|
||||
}
|
||||
});
|
||||
try {
|
||||
return result.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean updatePassword(final PlayerAuth auth) {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
|
||||
|
||||
public Boolean call() throws Exception {
|
||||
return database.updatePassword(auth);
|
||||
}
|
||||
});
|
||||
try {
|
||||
return result.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int purgeDatabase(final long until) {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Future<Integer> result = executor.submit(new Callable<Integer>() {
|
||||
|
||||
public Integer call() throws Exception {
|
||||
return database.purgeDatabase(until);
|
||||
}
|
||||
});
|
||||
try {
|
||||
return result.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<String> autoPurgeDatabase(final long until) {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Future<List<String>> result = executor.submit(new Callable<List<String>>() {
|
||||
|
||||
public List<String> call() throws Exception {
|
||||
return database.autoPurgeDatabase(until);
|
||||
}
|
||||
});
|
||||
try {
|
||||
return result.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
return (new ArrayList<String>());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean removeAuth(final String user) {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
|
||||
|
||||
public Boolean call() throws Exception {
|
||||
return database.removeAuth(user);
|
||||
}
|
||||
});
|
||||
try {
|
||||
return result.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean updateQuitLoc(final PlayerAuth auth) {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
|
||||
|
||||
public Boolean call() throws Exception {
|
||||
return database.updateQuitLoc(auth);
|
||||
}
|
||||
});
|
||||
try {
|
||||
return result.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int getIps(final String ip) {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Future<Integer> result = executor.submit(new Callable<Integer>() {
|
||||
|
||||
public Integer call() throws Exception {
|
||||
return database.getIps(ip);
|
||||
}
|
||||
});
|
||||
try {
|
||||
return result.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<String> getAllAuthsByName(final PlayerAuth auth) {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Future<List<String>> result = executor.submit(new Callable<List<String>>() {
|
||||
|
||||
public List<String> call() throws Exception {
|
||||
return database.getAllAuthsByName(auth);
|
||||
}
|
||||
});
|
||||
try {
|
||||
return result.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
return (new ArrayList<String>());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<String> getAllAuthsByIp(final String ip) {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Future<List<String>> result = executor.submit(new Callable<List<String>>() {
|
||||
|
||||
public List<String> call() throws Exception {
|
||||
return database.getAllAuthsByIp(ip);
|
||||
}
|
||||
});
|
||||
try {
|
||||
return result.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
return (new ArrayList<String>());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<String> getAllAuthsByEmail(final String email) {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Future<List<String>> result = executor.submit(new Callable<List<String>>() {
|
||||
|
||||
public List<String> call() throws Exception {
|
||||
return database.getAllAuthsByEmail(email);
|
||||
}
|
||||
});
|
||||
try {
|
||||
return result.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
return (new ArrayList<String>());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean updateEmail(final PlayerAuth auth) {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
|
||||
|
||||
public Boolean call() throws Exception {
|
||||
return database.updateEmail(auth);
|
||||
}
|
||||
});
|
||||
try {
|
||||
return result.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean updateSalt(final PlayerAuth auth) {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
|
||||
|
||||
public Boolean call() throws Exception {
|
||||
return database.updateSalt(auth);
|
||||
}
|
||||
});
|
||||
try {
|
||||
return result.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void close() {
|
||||
database.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void reload() {
|
||||
database.reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void purgeBanned(final List<String> banned) {
|
||||
new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public synchronized void run() {
|
||||
database.purgeBanned(banned);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized DataSourceType getType() {
|
||||
return database.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean isLogged(final String user) {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
|
||||
|
||||
public Boolean call() throws Exception {
|
||||
return database.isLogged(user);
|
||||
}
|
||||
});
|
||||
try {
|
||||
return result.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void setLogged(final String user) {
|
||||
new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public synchronized void run() {
|
||||
database.setLogged(user);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void setUnlogged(final String user) {
|
||||
new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public synchronized void run() {
|
||||
database.setUnlogged(user);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void purgeLogged() {
|
||||
new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public synchronized void run() {
|
||||
database.purgeLogged();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int getAccountsRegistered() {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Future<Integer> result = executor.submit(new Callable<Integer>() {
|
||||
|
||||
public Integer call() throws Exception {
|
||||
return database.getAccountsRegistered();
|
||||
}
|
||||
});
|
||||
try {
|
||||
return result.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void updateName(final String oldone, final String newone) {
|
||||
new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public synchronized void run() {
|
||||
database.updateName(oldone, newone);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<PlayerAuth> getAllAuths() {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Future<List<PlayerAuth>> result = executor.submit(new Callable<List<PlayerAuth>>() {
|
||||
|
||||
public List<PlayerAuth> call() throws Exception {
|
||||
return database.getAllAuths();
|
||||
}
|
||||
});
|
||||
try {
|
||||
return result.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
return (new ArrayList<PlayerAuth>());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+740
-744
File diff suppressed because it is too large
Load Diff
+2
-3
@@ -18,7 +18,7 @@ import fr.xephi.authme.datasource.MiniConnectionPoolManager.TimeoutException;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
public class MySQLThread extends Thread implements DataSource {
|
||||
public class MySQL implements DataSource {
|
||||
|
||||
private String host;
|
||||
private String port;
|
||||
@@ -42,7 +42,7 @@ public class MySQLThread extends Thread implements DataSource {
|
||||
private List<String> columnOthers;
|
||||
private MiniConnectionPoolManager conPool;
|
||||
|
||||
public void run() {
|
||||
public MySQL() {
|
||||
this.host = Settings.getMySQLHost;
|
||||
this.port = Settings.getMySQLPort;
|
||||
this.username = Settings.getMySQLUsername;
|
||||
@@ -94,7 +94,6 @@ public class MySQLThread extends Thread implements DataSource {
|
||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||
return;
|
||||
}
|
||||
this.setName("AuthMeMySQLThread");
|
||||
}
|
||||
|
||||
private synchronized void connect() throws ClassNotFoundException,
|
||||
+2
-3
@@ -16,7 +16,7 @@ import fr.xephi.authme.datasource.MiniConnectionPoolManager.TimeoutException;
|
||||
import fr.xephi.authme.settings.PlayersLogs;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
public class SQLiteThread extends Thread implements DataSource {
|
||||
public class SQLite implements DataSource {
|
||||
|
||||
private String database;
|
||||
private String tableName;
|
||||
@@ -34,7 +34,7 @@ public class SQLiteThread extends Thread implements DataSource {
|
||||
private String columnID;
|
||||
private Connection con;
|
||||
|
||||
public void run() {
|
||||
public SQLite() {
|
||||
this.database = Settings.getMySQLDatabase;
|
||||
this.tableName = Settings.getMySQLTablename;
|
||||
this.columnName = Settings.getMySQLColumnName;
|
||||
@@ -72,7 +72,6 @@ public class SQLiteThread extends Thread implements DataSource {
|
||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||
return;
|
||||
}
|
||||
this.setName("AuthMeSQLiteThread");
|
||||
}
|
||||
|
||||
private synchronized void connect() throws ClassNotFoundException,
|
||||
Reference in New Issue
Block a user