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> T
attemptLock
(jakarta.inject.Provider<T> resultProvider, MongoMatch... mongoMatches) Intended to be used in the scope ofMongoConcurrentUtils.performOptimistic(MongoConcurrentUtils.CriticalOperation)
, this will attempt to lock theMongoMatch
using 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.Datastore
void
setDatastore
(dev.morphia.Datastore datastore) void
setDozerMapper
(MapperRegistry dozerMapperRegistry) void
setMongoDBUtils
(MongoDBUtils mongoDBUtils)
-
Constructor Details
-
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 theMongoMatch
using 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.ContentionException
to 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 aMongoMatch
should only be done within the context of a lock. This allows for acquiring multipleMongoMatchLock
instances 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 orMongoMatch
instances 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.SuccessfulMatchTuple
will be returned. If not an instance ofNoSuitableMatchException
will be thrown.- Parameters:
playerMatch
- the player to match to the opponentopponentMatch
- the opponent to match to the player- Returns:
- an instance of
Matchmaker.SuccessfulMatchTuple
complete 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
-