Moved the creation of games and broadcasting outside of tournament lock to prevent theoretical deadlocks. These actions are now made through a list of actions returned from tournament advance method.

This commit is contained in:
MarcinSc
2024-08-28 22:59:33 +07:00
parent cc4677aca6
commit 0b79c44806
8 changed files with 29 additions and 13 deletions

View File

@@ -65,7 +65,7 @@ public class DefaultTournament implements Tournament {
public DefaultTournament(TournamentService tournamentService, String tournamentId, public DefaultTournament(TournamentService tournamentService, String tournamentId,
String tournamentName, String format, CollectionType collectionType, String tournamentName, String format, CollectionType collectionType,
int tournamentRound, Stage tournamentStage, int tournamentRound, Stage tournamentStage,
PairingMechanism pairingMechanism, TournamentPrizes tournamentPrizes, PairingMechanism pairingMechanism, TournamentPrizes tournamentPrizes,
CollectionsManager collectionsManager, ProductLibrary productLibrary, DraftPack draftPack) { CollectionsManager collectionsManager, ProductLibrary productLibrary, DraftPack draftPack) {
_tournamentService = tournamentService; _tournamentService = tournamentService;
@@ -107,6 +107,8 @@ public class DefaultTournament implements Tournament {
_players); _players);
} else if (_tournamentStage == Stage.DECK_BUILDING) { } else if (_tournamentStage == Stage.DECK_BUILDING) {
_deckBuildStartTime = System.currentTimeMillis(); _deckBuildStartTime = System.currentTimeMillis();
} else if (_tournamentStage == Stage.AWAITING_KICKOFF || _tournamentStage == Stage.PAUSED) {
} else if (_tournamentStage == Stage.FINISHED) { } else if (_tournamentStage == Stage.FINISHED) {
_finishedTournamentMatches.addAll(_tournamentService.getMatches(_tournamentId)); _finishedTournamentMatches.addAll(_tournamentService.getMatches(_tournamentId));
} }
@@ -314,7 +316,12 @@ public class DefaultTournament implements Tournament {
result.add(new BroadcastAction("Deck building in tournament " + _tournamentName + " has finished")); result.add(new BroadcastAction("Deck building in tournament " + _tournamentName + " has finished"));
} }
} }
if (_tournamentStage == Stage.PLAYING_GAMES) { if (_tournamentStage == Stage.AWAITING_KICKOFF || _tournamentStage == Stage.PAUSED) {
} else if (_tournamentStage == Stage.PREPARING) {
_tournamentStage = Stage.PLAYING_GAMES;
_tournamentService.updateTournamentStage(_tournamentId, _tournamentStage);
} else if (_tournamentStage == Stage.PLAYING_GAMES) {
if (_currentlyPlayingPlayers.isEmpty()) { if (_currentlyPlayingPlayers.isEmpty()) {
if (_pairingMechanism.isFinished(_tournamentRound, _players, _droppedPlayers)) { if (_pairingMechanism.isFinished(_tournamentRound, _players, _droppedPlayers)) {
result.add(finishTournament(collectionsManager)); result.add(finishTournament(collectionsManager));

View File

@@ -46,7 +46,7 @@ public class ImmediateRecurringQueue extends AbstractTournamentQueue implements
} }
var info = new TournamentInfo(tournamentId, null, tournamentName, _format, ZonedDateTime.now(), var info = new TournamentInfo(tournamentId, null, tournamentName, _format, ZonedDateTime.now(),
_collectionType, Tournament.Stage.PLAYING_GAMES, 0, _collectionType, Tournament.Stage.PLAYING_GAMES, 0, false,
Tournament.getPairingMechanism("singleElimination"), _tournamentPrizes); Tournament.getPairingMechanism("singleElimination"), _tournamentPrizes);
var tournament = _tournamentService.addTournament(info); var tournament = _tournamentService.addTournament(info);

View File

@@ -71,7 +71,7 @@ public class RecurringScheduledQueue extends AbstractTournamentQueue implements
_tournamentService.addPlayer(tournamentId, player, _playerDecks.get(player)); _tournamentService.addPlayer(tournamentId, player, _playerDecks.get(player));
var info = new TournamentInfo(tournamentId, null, tournamentName, _format, ZonedDateTime.now(), var info = new TournamentInfo(tournamentId, null, tournamentName, _format, ZonedDateTime.now(),
_collectionType, Tournament.Stage.PLAYING_GAMES, 0, _collectionType, Tournament.Stage.PLAYING_GAMES, 0, false,
_pairingMechanism, _tournamentPrizes); _pairingMechanism, _tournamentPrizes);
var tournament = _tournamentService.addTournament(info); var tournament = _tournamentService.addTournament(info);

View File

@@ -35,7 +35,11 @@ public class ScheduledTournamentQueue extends AbstractTournamentQueue implements
_startCondition = "at " + _startTime.format(DateUtils.DateTimeFormat); _startCondition = "at " + _startTime.format(DateUtils.DateTimeFormat);
_minimumPlayers = info.minimum_players; _minimumPlayers = info.minimum_players;
_stage = Tournament.Stage.PLAYING_GAMES; if (info.manual_kickoff) {
_stage = Tournament.Stage.AWAITING_KICKOFF;
} else {
_stage = Tournament.Stage.PLAYING_GAMES;
}
} }
@Override @Override
@@ -62,7 +66,7 @@ public class ScheduledTournamentQueue extends AbstractTournamentQueue implements
_tournamentService.addPlayer(_scheduledTournamentId, player, _playerDecks.get(player)); _tournamentService.addPlayer(_scheduledTournamentId, player, _playerDecks.get(player));
var info = new TournamentInfo(_scheduledTournamentId, null, _tournamentName, _format, ZonedDateTime.now(), var info = new TournamentInfo(_scheduledTournamentId, null, _tournamentName, _format, ZonedDateTime.now(),
_collectionType, _stage, 0, _collectionType, _stage, 0, false,
_pairingMechanism, _tournamentPrizes); _pairingMechanism, _tournamentPrizes);
var tournament = _tournamentService.addTournament(info); var tournament = _tournamentService.addTournament(info);

View File

@@ -6,6 +6,9 @@ import com.gempukku.lotro.competitive.PlayerStanding;
import com.gempukku.lotro.db.vo.CollectionType; import com.gempukku.lotro.db.vo.CollectionType;
import com.gempukku.lotro.draft.Draft; import com.gempukku.lotro.draft.Draft;
import com.gempukku.lotro.game.CardNotFoundException; import com.gempukku.lotro.game.CardNotFoundException;
import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
import com.gempukku.lotro.game.SortAndFilterCards;
import com.gempukku.lotro.game.formats.LotroFormatLibrary;
import com.gempukku.lotro.logic.vo.LotroDeck; import com.gempukku.lotro.logic.vo.LotroDeck;
import com.gempukku.lotro.packs.ProductLibrary; import com.gempukku.lotro.packs.ProductLibrary;
import com.gempukku.lotro.tournament.action.TournamentProcessAction; import com.gempukku.lotro.tournament.action.TournamentProcessAction;
@@ -16,6 +19,9 @@ public interface Tournament {
public enum Stage { public enum Stage {
DRAFT("Drafting"), DRAFT("Drafting"),
DECK_BUILDING("Deck building"), DECK_BUILDING("Deck building"),
AWAITING_KICKOFF("Awaiting kickoff"),
PAUSED("Paused"),
PREPARING("Preparing"),
PLAYING_GAMES("Playing games"), PLAYING_GAMES("Playing games"),
FINISHED("Finished"); FINISHED("Finished");

View File

@@ -10,21 +10,21 @@ import java.util.List;
public record TournamentInfo(String tournamentId, String draftType, String name, String format, public record TournamentInfo(String tournamentId, String draftType, String name, String format,
ZonedDateTime startDate, CollectionType collectionType, ZonedDateTime startDate, CollectionType collectionType,
Tournament.Stage tournamentStage, int round, Tournament.Stage tournamentStage, int round, boolean manualKickoff,
PairingMechanism pairingMechanism, TournamentPrizes prizesScheme PairingMechanism pairingMechanism, TournamentPrizes prizesScheme
) { ) {
public TournamentInfo(ProductLibrary library, DBDefs.Tournament info) { public TournamentInfo(ProductLibrary library, DBDefs.Tournament info) {
this(info.tournament_id, info.draft_type, info.name, info.format, info.GetUTCStartDate(), this(info.tournament_id, info.draft_type, info.name, info.format, info.GetUTCStartDate(),
CollectionType.parseCollectionCode(info.collection), Tournament.Stage.parseStage(info.stage), CollectionType.parseCollectionCode(info.collection), Tournament.Stage.parseStage(info.stage),
info.round, Tournament.getPairingMechanism(info.pairing), info.round, info.manual_kickoff, Tournament.getPairingMechanism(info.pairing),
Tournament.getTournamentPrizes(library, info.prizes)); Tournament.getTournamentPrizes(library, info.prizes));
} }
public TournamentInfo(ProductLibrary library, DBDefs.ScheduledTournament info) { public TournamentInfo(ProductLibrary library, DBDefs.ScheduledTournament info) {
this(info.tournament_id, null, info.name, info.format, info.GetUTCStartDate(), this(info.tournament_id, null, info.name, info.format, info.GetUTCStartDate(),
CollectionType.ALL_CARDS, Tournament.Stage.PLAYING_GAMES, CollectionType.ALL_CARDS, info.manual_kickoff ? Tournament.Stage.AWAITING_KICKOFF : Tournament.Stage.PLAYING_GAMES,
0, Tournament.getPairingMechanism(info.playoff), 0, info.manual_kickoff, Tournament.getPairingMechanism(info.playoff),
Tournament.getTournamentPrizes(library, info.prizes)); Tournament.getTournamentPrizes(library, info.prizes));
} }
@@ -38,6 +38,7 @@ public record TournamentInfo(String tournamentId, String draftType, String name,
tourney.collection = this.collectionType.getCode(); tourney.collection = this.collectionType.getCode();
tourney.stage = this.tournamentStage.getHumanReadable(); tourney.stage = this.tournamentStage.getHumanReadable();
tourney.round = this.round; tourney.round = this.round;
tourney.manual_kickoff = this.manualKickoff;
tourney.pairing = this.pairingMechanism.getRegistryRepresentation(); tourney.pairing = this.pairingMechanism.getRegistryRepresentation();
tourney.prizes = this.prizesScheme.getRegistryRepresentation(); tourney.prizes = this.prizesScheme.getRegistryRepresentation();

View File

@@ -299,8 +299,8 @@ public class TournamentService {
private Tournament createTournamentAndStoreInCache(TournamentInfo info) { private Tournament createTournamentAndStoreInCache(TournamentInfo info) {
Tournament tournament; Tournament tournament;
try { try {
DraftPack draftPack = null;
//The below appears to be half-finished and completely pointless //The below appears to be half-finished and completely pointless
// DraftPack draftPack = null;
// String draftType = info.getDraftType(); // String draftType = info.getDraftType();
// if (draftType != null) // if (draftType != null)
// _draftPackStorage.getDraftPack(draftType); // _draftPackStorage.getDraftPack(draftType);

View File

@@ -3,9 +3,7 @@ package com.gempukku.lotro.tournament;
import com.gempukku.lotro.at.AbstractAtTest; import com.gempukku.lotro.at.AbstractAtTest;
import com.gempukku.lotro.collection.CollectionsManager; import com.gempukku.lotro.collection.CollectionsManager;
import com.gempukku.lotro.db.vo.CollectionType; import com.gempukku.lotro.db.vo.CollectionType;
import com.gempukku.lotro.draft.DraftPack;
import com.gempukku.lotro.logic.vo.LotroDeck; import com.gempukku.lotro.logic.vo.LotroDeck;
import com.gempukku.lotro.packs.ProductLibrary;
import com.gempukku.lotro.tournament.action.TournamentProcessAction; import com.gempukku.lotro.tournament.action.TournamentProcessAction;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mockito; import org.mockito.Mockito;