Interface Matchmaker
- All Known Implementing Classes:
MongoFIFOMatchmaker
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceSupplies aMatchmakerbased on the algorithm.static interfaceCombines aMatchfor both a player and an opponent. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionattemptToFindOpponent(Match match, int maxCandidatesToConsider, BiFunction<Match, Match, String> finalizer) Attempts to find an opponent for the suppliedMatchinstance.default Matchmaker.SuccessfulMatchTupleattemptToFindOpponent(Match match, BiFunction<Match, Match, String> finalizer) InvokesattemptToFindOpponent(Match, int, BiFunction<Match, Match, String>)using theDEFAULT_MAX_CANDIDATESvalue.Returns theMatchingAlgorithmimplemented by this matchmaker.Restricts thisMatchmakerto the supplied scope.
-
Field Details
-
DEFAULT_MAX_CANDIDATES
static final int DEFAULT_MAX_CANDIDATES- See Also:
-
-
Method Details
-
getAlgorithm
MatchingAlgorithm getAlgorithm()Returns theMatchingAlgorithmimplemented by this matchmaker.- Returns:
- the
MatchingAlgorithm
-
attemptToFindOpponent
default Matchmaker.SuccessfulMatchTuple attemptToFindOpponent(Match match, BiFunction<Match, Match, throws NoSuitableMatchExceptionString> finalizer) InvokesattemptToFindOpponent(Match, int, BiFunction<Match, Match, String>)using theDEFAULT_MAX_CANDIDATESvalue.- Parameters:
match- theMatchto use- Returns:
- a
Matchmaker.SuccessfulMatchTuplerepresenting a successful match, never null - Throws:
NoSuitableMatchException- if there is no suitable match found
-
attemptToFindOpponent
Matchmaker.SuccessfulMatchTuple attemptToFindOpponent(Match match, int maxCandidatesToConsider, BiFunction<Match, Match, throws NoSuitableMatchExceptionString> finalizer) Attempts to find an opponent for the suppliedMatchinstance. This will query the database for suitable matches. This will return aMatchmaker.SuccessfulMatchTuplecombining the match of the player and the opponent's match.Thia also finalizes the matching process by flagging the
Matchinstances 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 affectedMatchinstances, or returns an emnpty stream if noMatchinstances were affected by the finalization.Because both players may not have read the
Match, the involvedMatchinstances will be marked for timeout and deletion at a later time.- Parameters:
match- theMatchthe player matchmaxCandidatesToConsider- the maximum number of candidates to considerfinalizer- theSupplierused to finalize the match and provide the resulting game id- Returns:
- a
Matchmaker.SuccessfulMatchTuplerepresenting a successful match, never null - Throws:
NoSuitableMatchException- if there is no suitable match found
-
withScope
Restricts thisMatchmakerto the supplied scope. Will return only whoseMatch.getScope()method matches the supplied scope. UnscopedMatchinstances will also be excluded from the candidate pool.- Parameters:
scope- the scope- Returns:
- this instance
-