Class MongoFIFOMatchmaker

java.lang.Object
dev.getelements.elements.dao.mongo.match.MongoFIFOMatchmaker
All Implemented Interfaces:
Matchmaker

public class MongoFIFOMatchmaker extends Object implements Matchmaker
Created by patricktwohig on 7/27/17.
  • Constructor Details Link icon

    • MongoFIFOMatchmaker Link icon

      public MongoFIFOMatchmaker()
  • Method Details Link icon

    • getAlgorithm Link icon

      public MatchingAlgorithm getAlgorithm()
      Description copied from interface: Matchmaker
      Returns the MatchingAlgorithm implemented by this matchmaker.
      Specified by:
      getAlgorithm in interface Matchmaker
      Returns:
      the MatchingAlgorithm
    • attemptToFindOpponent Link icon

      public Matchmaker.SuccessfulMatchTuple attemptToFindOpponent(Match match, int maxCandidatesToConsider, BiFunction<Match,Match,String> finalizer) throws NoSuitableMatchException
      Description copied from interface: Matchmaker
      Attempts to find an opponent for the supplied Match instance. This will query the database for suitable matches. This will return a Matchmaker.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 finalizer Supplier<String>. The supplied Supplier<String> returns a system-wide unique ID used to process to identify the game that was created as the result of the Match. The return value of this method will be assigned to the match using Match.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 affected Match instances, or returns an emnpty stream if no Match instances were affected by the finalization.

      Because both players may not have read the Match, the involved Match instances will be marked for timeout and deletion at a later time.

      Specified by:
      attemptToFindOpponent in interface Matchmaker
      Parameters:
      match - the Match the player match
      maxCandidatesToConsider - the maximum number of candidates to consider
      finalizer - the Supplier 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 Link icon

      public Matchmaker withScope(String scope)
      Description copied from interface: Matchmaker
      Restricts this Matchmaker to the supplied scope. Will return only whose Match.getScope() method matches the supplied scope. Unscoped Match instances will also be excluded from the candidate pool.
      Specified by:
      withScope in interface Matchmaker
      Parameters:
      scope - the scope
      Returns:
      this instance
    • getDatastore Link icon

      public dev.morphia.Datastore getDatastore()
    • setDatastore Link icon

      @Inject public void setDatastore(dev.morphia.Datastore datastore)
    • getMongoMatchDao Link icon

      public MongoMatchDao getMongoMatchDao()
    • setMongoMatchDao Link icon

      @Inject public void setMongoMatchDao(MongoMatchDao mongoMatchDao)
    • getMongoMatchUtils Link icon

      public MongoMatchUtils getMongoMatchUtils()
    • setMongoMatchUtils Link icon

      @Inject public void setMongoMatchUtils(MongoMatchUtils mongoMatchUtils)