Class MongoMatchUtils
java.lang.Object
dev.getelements.elements.dao.mongo.match.MongoMatchUtils
Used to actually perform the match between two players. This ensures that two matches are made
with consistency and all appropriate diffs are created.
Created by patricktwohig on 7/27/17.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> TattemptLock(jakarta.inject.Provider<T> resultProvider, MongoMatch... mongoMatches) Intended to be used in the scope ofMongoConcurrentUtils.performOptimistic(MongoConcurrentUtils.CriticalOperation), this will attempt to lock theMongoMatchusing a uniqueMongoMatchLock.attemptToPairCandidates(MongoMatch playerMatch, MongoMatch opponentMatch, BiFunction<Match, Match, String> finalizer) Attempts to pair the two matches in the database.attemptToPairCandidates(MongoMatch playerMatch, List<MongoMatch> candidatesList, BiFunction<Match, Match, String> finalizer) dev.morphia.DatastorevoidsetDatastore(dev.morphia.Datastore datastore) voidsetDozerMapper(MapperRegistry dozerMapperRegistry) voidsetMongoDBUtils(MongoDBUtils mongoDBUtils)
-
Constructor Details
-
MongoMatchUtils
public MongoMatchUtils()
-
-
Method Details
-
attemptLock
public <T> T attemptLock(jakarta.inject.Provider<T> resultProvider, MongoMatch... mongoMatches) throws MongoConcurrentUtils.ContentionException Intended to be used in the scope ofMongoConcurrentUtils.performOptimistic(MongoConcurrentUtils.CriticalOperation), this will attempt to lock theMongoMatchusing a uniqueMongoMatchLock. If successful, this will perform the operation defined by the suppliedjakarta.inject.Provider<T>instance. If the lock fails, then this will throw an instance ofMongoConcurrentUtils.ContentionExceptionto indicate that a re-lock must be attempted or the process abandoned by the calling code. This is necessary because matching may happen at any time which involves controlling access to multiple documents. Therefore code which mutates or deletes aMongoMatchshould only be done within the context of a lock. This allows for acquiring multipleMongoMatchLockinstances and safely unlocking them even if the code specified in thejakarta.inject.Provider<T>fails to execute.- Type Parameters:
T- the return type- Parameters:
resultProvider- thejakarta.inject.Provider<T>defining the operation to performmongoMatches- one orMongoMatchinstances to return- Returns:
- the value returned by the supplied provider
- Throws:
MongoConcurrentUtils.ContentionException- if locking fails
-
attemptToPairCandidates
public Matchmaker.SuccessfulMatchTuple attemptToPairCandidates(MongoMatch playerMatch, List<MongoMatch> candidatesList, BiFunction<Match, Match, throws NoSuitableMatchExceptionString> finalizer) - Throws:
NoSuitableMatchException
-
attemptToPairCandidates
public Matchmaker.SuccessfulMatchTuple attemptToPairCandidates(MongoMatch playerMatch, MongoMatch opponentMatch, BiFunction<Match, Match, throws NoSuitableMatchExceptionString> finalizer) Attempts to pair the two matches in the database. If this succeeds, an instance ofMatchmaker.SuccessfulMatchTuplewill be returned. If not an instance ofNoSuitableMatchExceptionwill be thrown.- Parameters:
playerMatch- the player to match to the opponentopponentMatch- the opponent to match to the player- Returns:
- an instance of
Matchmaker.SuccessfulMatchTuplecomplete with delta log - Throws:
NoSuitableMatchException- if the matching fails
-
getDatastore
public dev.morphia.Datastore getDatastore() -
setDatastore
@Inject public void setDatastore(dev.morphia.Datastore datastore) -
getDozerMapper
-
setDozerMapper
-
getMongoDBUtils
-
setMongoDBUtils
-