Class MongoFIFOMatchmaker
- All Implemented Interfaces:
Matchmaker
-
Nested Class Summary
Nested classes/interfaces inherited from interface dev.getelements.elements.sdk.dao.Matchmaker
Matchmaker.Factory, Matchmaker.SuccessfulMatchTuple
-
Field Summary
Fields inherited from interface dev.getelements.elements.sdk.dao.Matchmaker
DEFAULT_MAX_CANDIDATES
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionattemptToFindOpponent
(Match match, int maxCandidatesToConsider, BiFunction<Match, Match, String> finalizer) Attempts to find an opponent for the suppliedMatch
instance.Returns theMatchingAlgorithm
implemented by this matchmaker.dev.morphia.Datastore
void
setDatastore
(dev.morphia.Datastore datastore) void
setMongoMatchDao
(MongoMatchDao mongoMatchDao) void
setMongoMatchUtils
(MongoMatchUtils mongoMatchUtils) Restricts thisMatchmaker
to the supplied scope.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface dev.getelements.elements.sdk.dao.Matchmaker
attemptToFindOpponent
-
Constructor Details
-
Method Details
-
getAlgorithm
Description copied from interface:Matchmaker
Returns theMatchingAlgorithm
implemented by this matchmaker.- Specified by:
getAlgorithm
in interfaceMatchmaker
- Returns:
- the
MatchingAlgorithm
-
attemptToFindOpponent
public Matchmaker.SuccessfulMatchTuple attemptToFindOpponent(Match match, int maxCandidatesToConsider, BiFunction<Match, Match, throws NoSuitableMatchExceptionString> finalizer) Description copied from interface:Matchmaker
Attempts to find an opponent for the suppliedMatch
instance. This will query the database for suitable matches. This will return aMatchmaker.SuccessfulMatchTuple
combining the match of the player and the opponent's match.Thia also finalizes the matching process by flagging the
Match
instances for deletion and invoking the finalizerSupplier<String>
. The suppliedSupplier<String>
returns a system-wide unique ID used to process to identify the game that was created as the result of theMatch
. The return value of this method will be assigned to the match usingMatch.setGameId(String)
.Note that this method guarantees that the supplied
Supplier<String>
finalizer will only ever be called once per successful matching tuple as multiple players may attempt to finalize the pairing at the same time. The return value indicates the affectedMatch
instances, or returns an emnpty stream if noMatch
instances were affected by the finalization.Because both players may not have read the
Match
, the involvedMatch
instances will be marked for timeout and deletion at a later time.- Specified by:
attemptToFindOpponent
in interfaceMatchmaker
- Parameters:
match
- theMatch
the player matchmaxCandidatesToConsider
- the maximum number of candidates to considerfinalizer
- theSupplier
used to finalize the match and provide the resulting game id- Returns:
- a
Matchmaker.SuccessfulMatchTuple
representing a successful match, never null - Throws:
NoSuitableMatchException
- if there is no suitable match found
-
withScope
Description copied from interface:Matchmaker
Restricts thisMatchmaker
to the supplied scope. Will return only whoseMatch.getScope()
method matches the supplied scope. UnscopedMatch
instances will also be excluded from the candidate pool.- Specified by:
withScope
in interfaceMatchmaker
- Parameters:
scope
- the scope- Returns:
- this instance
-
getDatastore
public dev.morphia.Datastore getDatastore() -
setDatastore
@Inject public void setDatastore(dev.morphia.Datastore datastore) -
getMongoMatchDao
-
setMongoMatchDao
-
getMongoMatchUtils
-
setMongoMatchUtils
-