Load simple clan token on player login to reduce overhead.

Increased dbpool connections to 4
This commit is contained in:
Jonathan Williams 2016-04-04 13:47:45 -05:00
parent a91ef68978
commit 60010f90b4
6 changed files with 47 additions and 48 deletions

View File

@ -1,5 +1,7 @@
package mineplex.hub.server;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -26,7 +28,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import mineplex.core.MiniPlugin;
import mineplex.core.MiniDbClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
@ -48,10 +50,10 @@ import mineplex.core.shop.ShopBase;
import mineplex.core.status.ServerStatusManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.core.repository.tokens.SimpleClanToken;
import mineplex.hub.HubManager;
import mineplex.hub.modules.StackerManager;
import mineplex.hub.queue.QueueManager;
import mineplex.hub.queue.ui.QueueShop;
import mineplex.hub.server.ui.LobbyShop;
import mineplex.hub.server.ui.QuickShop;
import mineplex.hub.server.ui.ServerCountSorter;
@ -61,7 +63,7 @@ import mineplex.serverdata.Region;
import mineplex.serverdata.data.MinecraftServer;
import mineplex.serverdata.data.ServerGroup;
public class ServerManager extends MiniPlugin
public class ServerManager extends MiniDbClientPlugin<SimpleClanToken>
{
private static final Long FREE_PORTAL_TIMER = 20000L;
private static final Long BETA_PORTAL_TIMER = 120000L;
@ -77,8 +79,6 @@ public class ServerManager extends MiniPlugin
private PartyManager _partyManager;
private ServerStatusManager _statusManager;
private HubManager _hubManager;
private StackerManager _stackerManager;
private QueueManager _queueManager;
private NautHashMap<String, Long> _queueCooldowns = new NautHashMap<String, Long>();
private NautHashMap<String, HashSet<ServerInfo>> _serverKeyInfoMap = new NautHashMap<String, HashSet<ServerInfo>>();
@ -93,7 +93,6 @@ public class ServerManager extends MiniPlugin
// Join Time for Free Players Timer
private NautHashMap<String, Long> _joinTime = new NautHashMap<String, Long>();
private QueueShop _domShop;
private QuickShop _quickShop;
private LobbyShop _lobbyShop;
@ -103,7 +102,7 @@ public class ServerManager extends MiniPlugin
public ServerManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, Portal portal, PartyManager partyManager, ServerStatusManager statusManager, HubManager hubManager, StackerManager stackerManager, QueueManager queueManager)
{
super("Server Manager", plugin);
super("Server Manager", plugin, clientManager);
_clientManager = clientManager;
_donationManager = donationManager;
@ -111,8 +110,6 @@ public class ServerManager extends MiniPlugin
_partyManager = partyManager;
_statusManager = statusManager;
_hubManager = hubManager;
_stackerManager = stackerManager;
_queueManager = queueManager;
plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, "BungeeCord");
@ -120,7 +117,6 @@ public class ServerManager extends MiniPlugin
_quickShop = new QuickShop(this, clientManager, donationManager, "Quick Menu");
_lobbyShop = new LobbyShop(this, clientManager, donationManager, "Lobby Menu");
//_domShop = new new QueueShop(_queueManager, clientManager, donationManager, "Dominate");
// TODO: Find more appropriate place to initialize Clans server shop?
_clansShop = new ClansServerShop(this, _clientManager, _donationManager);
@ -918,4 +914,33 @@ public class ServerManager extends MiniPlugin
{
return _serverNpcShopMap.get("Valentines Vendetta");
}
@Override
public String getQuery(int accountId, String uuid, String name)
{
return "SELECT clans.name, accountClan.clanRole, clanServer.serverName, clans.id FROM accountClan INNER JOIN clans ON clans.id = accountClan.clanId INNER JOIN clanServer ON clans.serverId = clanServer.id WHERE accountClan.accountId = " + accountId + "?;";
}
@Override
public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException
{
SimpleClanToken clanToken = new SimpleClanToken();
while (resultSet.next())
{
String clanName = resultSet.getString(1);
String clanRole = resultSet.getString(2);
String homeServer = resultSet.getString(3);
int clanId = resultSet.getInt(4);
clanToken = new SimpleClanToken(clanName, clanRole, homeServer, clanId);
}
Set(playerName, clanToken);
}
@Override
protected SimpleClanToken AddPlayer(String player)
{
return new SimpleClanToken();
}
}

View File

@ -4,7 +4,6 @@ import org.bukkit.Sound;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.donation.DonationManager;
import mineplex.core.party.Party;

View File

@ -27,16 +27,10 @@ import mineplex.serverdata.data.DataRepository;
public class ClansServerPage extends ShopPageBase<ServerManager, ClansServerShop>
{
private ClanRepository _repository;
private int _accountId;
public ClansServerPage(ServerManager plugin, ClansServerShop shop, CoreClientManager clientManager,
DonationManager donationManager, Player player, ClanRepository repository)
DonationManager donationManager, Player player)
{
super(plugin, shop, clientManager, donationManager, "Clans Beta", player, 54);
_repository = repository;
_accountId = clientManager.getAccountId(player);
buildPage();
}
@ -44,33 +38,14 @@ public class ClansServerPage extends ShopPageBase<ServerManager, ClansServerShop
@Override
protected void buildPage()
{
getPlugin().runAsync(new Runnable()
if (!getPlugin().Get(_player).getClanName().isEmpty())
{
public void run()
{
_repository.retrievePlayersClan(_accountId, new Callback<SimpleClanToken>()
{
@Override
public void run(SimpleClanToken data)
{
getPlugin().runSync(new Runnable()
{
public void run()
{
if (data != null)
{
buildClanPage(data);
}
else
{
buildNoClanPage();
}
}
});
}
});
}
});
buildClanPage(getPlugin().Get(_player));
}
else
{
buildNoClanPage();
}
}
private void buildClanPage(SimpleClanToken clan)

View File

@ -26,7 +26,7 @@ public class ClansServerShop extends ShopBase<ServerManager>
@Override
protected ShopPageBase<ServerManager, ? extends ShopBase<ServerManager>> buildPagesFor(Player player)
{
return new ClansServerPage(getPlugin(), this, getClientManager(), getDonationManager(), player, _repository);
return new ClansServerPage(getPlugin(), this, getClientManager(), getDonationManager(), player);
}
@Override

View File

@ -29,8 +29,8 @@ public final class DBPool
source.setUrl(url);
source.setUsername(username);
source.setPassword(password);
source.setMaxTotal(3);
source.setMaxIdle(3);
source.setMaxTotal(4);
source.setMaxIdle(4);
source.setTimeBetweenEvictionRunsMillis(180 * 1000);
source.setSoftMinEvictableIdleTimeMillis(180 * 1000);

View File

@ -143,7 +143,7 @@ public abstract class RepositoryBase
}
protected void executeQuery(String query, ResultSetCallable callable, Column<?>...columns)
{
{
// Automatic resource management for handling/closing objects.
try (
Connection connection = getConnection();