Interface Matchmaker
- All Known Implementing Classes:
MongoFIFOMatchmaker
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
Combines aMatch
for 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 suppliedMatch
instance.default Matchmaker.SuccessfulMatchTuple
attemptToFindOpponent
(Match match, BiFunction<Match, Match, String> finalizer) InvokesattemptToFindOpponent(Match, int, BiFunction<Match, Match, String>)
using theDEFAULT_MAX_CANDIDATES
value.Restricts thisMatchmaker
to the supplied scope.
-
Field Details
-
DEFAULT_MAX_CANDIDATES
static final int DEFAULT_MAX_CANDIDATES- See Also:
-
-
Method Details
-
attemptToFindOpponent
default Matchmaker.SuccessfulMatchTuple attemptToFindOpponent(Match match, BiFunction<Match, Match, throws NoSuitableMatchExceptionString> finalizer) InvokesattemptToFindOpponent(Match, int, BiFunction<Match, Match, String>)
using theDEFAULT_MAX_CANDIDATES
value.- Parameters:
match
- theMatch
to use- Returns:
- a
Matchmaker.SuccessfulMatchTuple
representing 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 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.- 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
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.- Parameters:
scope
- the scope- Returns:
- this instance
-