Clearing queues, when server goes down.

This commit is contained in:
marcins78@gmail.com
2012-07-03 13:29:21 +00:00
parent 17a07a46a2
commit cea2d7de85
4 changed files with 23 additions and 1 deletions

View File

@@ -226,6 +226,10 @@ public class CollectionsManager {
}
}
public void addCurrencyToPlayerCollection(String player, CollectionType collectionType, int currency) {
addCurrencyToPlayerCollection(_playerDAO.getPlayer(player), collectionType, currency);
}
public void addCurrencyToPlayerCollection(Player player, CollectionType collectionType, int currency) {
_readWriteLock.writeLock().lock();
try {

View File

@@ -106,7 +106,8 @@ public class HallServer extends AbstractServer {
}
private void cancelTournamentQueues() {
for (TournamentQueue tournamentQueue : _tournamentQueues.values())
tournamentQueue.leaveAllPlayers(_collectionsManager);
}
/**
@@ -160,6 +161,9 @@ public class HallServer extends AbstractServer {
}
public boolean joinQueue(String queueId, Player player, String deckName) throws HallException {
if (_shutdown)
throw new HallException("Server is in shutdown mode. Server will be restarted after all running games are finished.");
_hallDataAccessLock.writeLock().lock();
try {
if (isPlayerBusy(player.getName()))
@@ -185,6 +189,9 @@ public class HallServer extends AbstractServer {
* @return If table joined, otherwise <code>false</code> (if the user already is sitting at a table or playing).
*/
public boolean joinTableAsPlayer(String tableId, Player player, String deckName) throws HallException {
if (_shutdown)
throw new HallException("Server is in shutdown mode. Server will be restarted after all running games are finished.");
_hallDataAccessLock.writeLock().lock();
try {
if (isPlayerBusy(player.getName()))

View File

@@ -94,6 +94,15 @@ public class SingleEliminationRecurringQueue implements TournamentQueue {
}
}
@Override
public void leaveAllPlayers(CollectionsManager collectionsManager) {
if (_cost > 0) {
for (String player : _playerDecks.keySet())
collectionsManager.addCurrencyToPlayerCollection(player, _currencyCollection, _cost);
}
_playerDecks.clear();
}
@Override
public synchronized boolean isPlayerSignedUp(String player) {
return _playerDecks.containsKey(player);

View File

@@ -19,6 +19,8 @@ public interface TournamentQueue {
public void leavePlayer(CollectionsManager collectionsManager, Player player);
public void leaveAllPlayers(CollectionsManager collectionsManager);
public int getPlayerCount();
public boolean isPlayerSignedUp(String player);