From 45c6bf0a78fc0bb3ae6cce67cf38d5dcc8186325 Mon Sep 17 00:00:00 2001 From: DNx5 Date: Sun, 6 Dec 2015 06:08:52 +0700 Subject: [PATCH] Removed DatabaseCalls class. * this class only contains wrapper of selected datasource type which every method included a code to run the task inside a new Thread. But this class doesn't help improving performance, because it's still running the task synchronously. --- src/main/java/fr/xephi/authme/AuthMe.java | 31 +- .../authme/datasource/DatabaseCalls.java | 513 ------------------ 2 files changed, 21 insertions(+), 523 deletions(-) delete mode 100644 src/main/java/fr/xephi/authme/datasource/DatabaseCalls.java diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 655a1f33b..2f6bf18f1 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -13,10 +13,20 @@ import fr.xephi.authme.command.CommandHandler; import fr.xephi.authme.command.CommandInitializer; import fr.xephi.authme.converter.Converter; import fr.xephi.authme.converter.ForceFlatToSqlite; -import fr.xephi.authme.datasource.*; +import fr.xephi.authme.datasource.CacheDataSource; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.datasource.FlatFile; +import fr.xephi.authme.datasource.MySQL; +import fr.xephi.authme.datasource.SQLite; import fr.xephi.authme.hooks.BungeeCordMessage; import fr.xephi.authme.hooks.EssSpawn; -import fr.xephi.authme.listener.*; +import fr.xephi.authme.listener.AuthMeBlockListener; +import fr.xephi.authme.listener.AuthMeEntityListener; +import fr.xephi.authme.listener.AuthMeInventoryPacketAdapter; +import fr.xephi.authme.listener.AuthMePlayerListener; +import fr.xephi.authme.listener.AuthMePlayerListener16; +import fr.xephi.authme.listener.AuthMePlayerListener18; +import fr.xephi.authme.listener.AuthMeServerListener; import fr.xephi.authme.modules.ModuleManager; import fr.xephi.authme.output.ConsoleFilter; import fr.xephi.authme.output.Log4JFilter; @@ -25,7 +35,9 @@ import fr.xephi.authme.output.Messages; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerPermission; import fr.xephi.authme.process.Management; -import fr.xephi.authme.settings.*; +import fr.xephi.authme.settings.OtherAccounts; +import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.settings.Spawn; import fr.xephi.authme.util.GeoLiteAPI; import fr.xephi.authme.util.StringUtils; import fr.xephi.authme.util.Utils; @@ -579,20 +591,19 @@ public class AuthMe extends JavaPlugin { if (isSQLite) { server.getScheduler().runTaskAsynchronously(this, new Runnable() { - @Override public void run() { int accounts = database.getAccountsRegistered(); - if (accounts >= 4000) - ConsoleLogger.showError("YOU'RE USING THE SQLITE DATABASE WITH " + accounts + "+ ACCOUNTS, FOR BETTER PERFORMANCES, PLEASE UPGRADE TO MYSQL!!"); + if (accounts >= 4000) { + ConsoleLogger.showError("YOU'RE USING THE SQLITE DATABASE WITH " + + accounts + "+ ACCOUNTS, FOR BETTER PERFORMANCES, PLEASE UPGRADE TO MYSQL!!"); + } } }); } if (Settings.isCachingEnabled) { database = new CacheDataSource(this, database); - } else { - database = new DatabaseCalls(database); } if (Settings.getDataSource == DataSource.DataSourceType.FILE) { @@ -920,14 +931,14 @@ public class AuthMe extends JavaPlugin { String realIP = player.getAddress().getAddress().getHostAddress(); String sUrl = "http://monitor-1.verygames.net/api/?action=ipclean-real-ip&out=raw&ip=%IP%&port=%PORT%"; sUrl = sUrl.replace("%IP%", player.getAddress().getAddress().getHostAddress()) - .replace("%PORT%", "" + player.getAddress().getPort()); + .replace("%PORT%", "" + player.getAddress().getPort()); try { URL url = new URL(sUrl); URLConnection urlCon = url.openConnection(); try (BufferedReader in = new BufferedReader(new InputStreamReader(urlCon.getInputStream()))) { String inputLine = in.readLine(); if (!StringUtils.isEmpty(inputLine) && !inputLine.equalsIgnoreCase("error") - && !inputLine.contains("error")) { + && !inputLine.contains("error")) { realIP = inputLine; } } catch (IOException e) { diff --git a/src/main/java/fr/xephi/authme/datasource/DatabaseCalls.java b/src/main/java/fr/xephi/authme/datasource/DatabaseCalls.java deleted file mode 100644 index ebd133e07..000000000 --- a/src/main/java/fr/xephi/authme/datasource/DatabaseCalls.java +++ /dev/null @@ -1,513 +0,0 @@ -package fr.xephi.authme.datasource; - -import fr.xephi.authme.cache.auth.PlayerAuth; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -/** - */ -public class DatabaseCalls implements DataSource { - - private final ExecutorService exec; - private final DataSource database; - - /** - * Constructor for DatabaseCalls. - * - * @param database DataSource - */ - public DatabaseCalls(DataSource database) { - this.database = database; - this.exec = Executors.newCachedThreadPool(); - } - - /** - * Method isAuthAvailable. - * - * @param user String - * - * @return boolean * @see fr.xephi.authme.datasource.DataSource#isAuthAvailable(String) - */ - @Override - public synchronized boolean isAuthAvailable(final String user) { - try { - return exec.submit(new Callable() { - public Boolean call() throws Exception { - return database.isAuthAvailable(user); - } - }).get(); - } catch (Exception e) { - return false; - } - } - - /** - * Method getAuth. - * - * @param user String - * - * @return PlayerAuth * @see fr.xephi.authme.datasource.DataSource#getAuth(String) - */ - @Override - public synchronized PlayerAuth getAuth(final String user) { - try { - return exec.submit(new Callable() { - public PlayerAuth call() throws Exception { - return database.getAuth(user); - } - }).get(); - } catch (Exception e) { - return null; - } - } - - /** - * Method saveAuth. - * - * @param auth PlayerAuth - * - * @return boolean * @see fr.xephi.authme.datasource.DataSource#saveAuth(PlayerAuth) - */ - @Override - public synchronized boolean saveAuth(final PlayerAuth auth) { - try { - return exec.submit(new Callable() { - public Boolean call() throws Exception { - return database.saveAuth(auth); - } - }).get(); - } catch (Exception e) { - return false; - } - } - - /** - * Method updateSession. - * - * @param auth PlayerAuth - * - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSession(PlayerAuth) - */ - @Override - public synchronized boolean updateSession(final PlayerAuth auth) { - try { - return exec.submit(new Callable() { - public Boolean call() throws Exception { - return database.updateSession(auth); - } - }).get(); - } catch (Exception e) { - return false; - } - } - - /** - * Method updatePassword. - * - * @param auth PlayerAuth - * - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updatePassword(PlayerAuth) - */ - @Override - public synchronized boolean updatePassword(final PlayerAuth auth) { - try { - return exec.submit(new Callable() { - public Boolean call() throws Exception { - return database.updatePassword(auth); - } - }).get(); - } catch (Exception e) { - return false; - } - } - - /** - * Method purgeDatabase. - * - * @param until long - * - * @return int * @see fr.xephi.authme.datasource.DataSource#purgeDatabase(long) - */ - @Override - public synchronized int purgeDatabase(final long until) { - try { - return exec.submit(new Callable() { - public Integer call() throws Exception { - return database.purgeDatabase(until); - } - }).get(); - } catch (Exception e) { - return -1; - } - } - - /** - * Method autoPurgeDatabase. - * - * @param until long - * - * @return List * @see fr.xephi.authme.datasource.DataSource#autoPurgeDatabase(long) - */ - @Override - public synchronized List autoPurgeDatabase(final long until) { - try { - return exec.submit(new Callable>() { - public List call() throws Exception { - return database.autoPurgeDatabase(until); - } - }).get(); - } catch (Exception e) { - return new ArrayList<>(); - } - } - - /** - * Method removeAuth. - * - * @param user String - * - * @return boolean * @see fr.xephi.authme.datasource.DataSource#removeAuth(String) - */ - @Override - public synchronized boolean removeAuth(final String user) { - try { - return exec.submit(new Callable() { - public Boolean call() throws Exception { - return database.removeAuth(user); - } - }).get(); - } catch (Exception e) { - return false; - } - } - - /** - * Method updateQuitLoc. - * - * @param auth PlayerAuth - * - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateQuitLoc(PlayerAuth) - */ - @Override - public synchronized boolean updateQuitLoc(final PlayerAuth auth) { - try { - return exec.submit(new Callable() { - public Boolean call() throws Exception { - return database.updateQuitLoc(auth); - } - }).get(); - } catch (Exception e) { - return false; - } - } - - /** - * Method getIps. - * - * @param ip String - * - * @return int * @see fr.xephi.authme.datasource.DataSource#getIps(String) - */ - @Override - public synchronized int getIps(final String ip) { - try { - return exec.submit(new Callable() { - - public Integer call() throws Exception { - return database.getIps(ip); - } - }).get(); - } catch (Exception e) { - return -1; - } - } - - /** - * Method getAllAuthsByName. - * - * @param auth PlayerAuth - * - * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByName(PlayerAuth) - */ - @Override - public synchronized List getAllAuthsByName(final PlayerAuth auth) { - try { - return exec.submit(new Callable>() { - public List call() throws Exception { - return database.getAllAuthsByName(auth); - } - }).get(); - } catch (Exception e) { - return new ArrayList<>(); - } - } - - /** - * Method getAllAuthsByIp. - * - * @param ip String - * - * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByIp(String) - */ - @Override - public synchronized List getAllAuthsByIp(final String ip) { - try { - return exec.submit(new Callable>() { - public List call() throws Exception { - return database.getAllAuthsByIp(ip); - } - }).get(); - } catch (Exception e) { - return new ArrayList<>(); - } - } - - /** - * Method getAllAuthsByEmail. - * - * @param email String - * - * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuthsByEmail(String) - */ - @Override - public synchronized List getAllAuthsByEmail(final String email) { - try { - return exec.submit(new Callable>() { - public List call() throws Exception { - return database.getAllAuthsByEmail(email); - } - }).get(); - } catch (Exception e) { - return new ArrayList<>(); - } - } - - /** - * Method updateEmail. - * - * @param auth PlayerAuth - * - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateEmail(PlayerAuth) - */ - @Override - public synchronized boolean updateEmail(final PlayerAuth auth) { - try { - return exec.submit(new Callable() { - public Boolean call() throws Exception { - return database.updateEmail(auth); - } - }).get(); - } catch (Exception e) { - return false; - } - } - - /** - * Method updateSalt. - * - * @param auth PlayerAuth - * - * @return boolean * @see fr.xephi.authme.datasource.DataSource#updateSalt(PlayerAuth) - */ - @Override - public synchronized boolean updateSalt(final PlayerAuth auth) { - try { - return exec.submit(new Callable() { - public Boolean call() throws Exception { - return database.updateSalt(auth); - } - }).get(); - } catch (Exception e) { - return false; - } - } - - /** - * Method close. - * - * @see fr.xephi.authme.datasource.DataSource#close() - */ - @Override - public synchronized void close() { - exec.shutdown(); - database.close(); - } - - /** - * Method reload. - * - * @see fr.xephi.authme.datasource.DataSource#reload() - */ - @Override - public synchronized void reload() { - database.reload(); - } - - /** - * Method purgeBanned. - * - * @param banned List - * - * @see fr.xephi.authme.datasource.DataSource#purgeBanned(List) - */ - @Override - public synchronized void purgeBanned(final List banned) { - new Thread(new Runnable() { - public synchronized void run() { - database.purgeBanned(banned); - } - }).start(); - } - - /** - * Method getType. - * - * @return DataSourceType * @see fr.xephi.authme.datasource.DataSource#getType() - */ - @Override - public synchronized DataSourceType getType() { - return database.getType(); - } - - /** - * Method isLogged. - * - * @param user String - * - * @return boolean * @see fr.xephi.authme.datasource.DataSource#isLogged(String) - */ - @Override - public synchronized boolean isLogged(final String user) { - try { - return exec.submit(new Callable() { - public Boolean call() throws Exception { - return database.isLogged(user); - } - }).get(); - } catch (Exception e) { - return false; - } - } - - /** - * Method setLogged. - * - * @param user String - * - * @see fr.xephi.authme.datasource.DataSource#setLogged(String) - */ - @Override - public synchronized void setLogged(final String user) { - exec.execute(new Runnable() { - public synchronized void run() { - database.setLogged(user); - } - }); - } - - /** - * Method setUnlogged. - * - * @param user String - * - * @see fr.xephi.authme.datasource.DataSource#setUnlogged(String) - */ - @Override - public synchronized void setUnlogged(final String user) { - exec.execute(new Runnable() { - public synchronized void run() { - database.setUnlogged(user); - } - }); - } - - /** - * Method purgeLogged. - * - * @see fr.xephi.authme.datasource.DataSource#purgeLogged() - */ - @Override - public synchronized void purgeLogged() { - exec.execute(new Runnable() { - public synchronized void run() { - database.purgeLogged(); - } - }); - } - - /** - * Method getAccountsRegistered. - * - * @return int * @see fr.xephi.authme.datasource.DataSource#getAccountsRegistered() - */ - @Override - public synchronized int getAccountsRegistered() { - try { - return exec.submit(new Callable() { - public Integer call() throws Exception { - return database.getAccountsRegistered(); - } - }).get(); - } catch (Exception e) { - return -1; - } - } - - /** - * Method updateName. - * - * @param oldOne String - * @param newOne String - * - * @see fr.xephi.authme.datasource.DataSource#updateName(String, String) - */ - @Override - public synchronized void updateName(final String oldOne, final String newOne) { - exec.execute(new Runnable() { - public synchronized void run() { - database.updateName(oldOne, newOne); - } - }); - } - - /** - * Method getAllAuths. - * - * @return List * @see fr.xephi.authme.datasource.DataSource#getAllAuths() - */ - @Override - public synchronized List getAllAuths() { - try { - return exec.submit(new Callable>() { - public List call() throws Exception { - return database.getAllAuths(); - } - }).get(); - } catch (Exception e) { - return new ArrayList<>(); - } - } - - /** - * Method getLoggedPlayers. - * - * @return List * @see fr.xephi.authme.datasource.DataSource#getLoggedPlayers() - */ - @Override - public List getLoggedPlayers() { - try { - return exec.submit(new Callable>() { - public List call() throws Exception { - return database.getLoggedPlayers(); - } - }).get(); - } catch (Exception e) { - return new ArrayList<>(); - } - } - -}