This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Callable <CompletionStage<ClubDetailsFromXternalSource>> workingCallable = | |
| new Callable<CompletionStage<ClubDetailsFromXternalSource>>() { | |
| @Override | |
| public CompletionStage<ClubDetailsFromXternalSource> call() throws Exception { | |
| return ( | |
| CompletableFuture.supplyAsync( | |
| new Supplier<ClubDetailsFromXternalSource>() { | |
| @Override | |
| public ClubDetailsFromXternalSource get() { | |
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | if (clubID == 0) { // A forced 'fail' timeout situation, for demonstration | |
| PatternsCS | |
| .pipe( | |
| circuitBreaker.callWithCircuitBreakerCS(nonWorkingCallable), | |
| getContext().system().dispatcher() | |
| ) | |
| .to(getSender()); | |
| } | |
| else { | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | { // Emulating a failed call to the external service | |
| Thread.sleep(2000); | |
| getSender().tell( | |
| new InteractionProtocol.UnavailableClubDetails("timed out"), | |
| getSelf() | |
| ); | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | if ( arg0 instanceof ClubDetailsFromXternalSource) { | |
| ClubDetailsFromXternalSource m = (ClubDetailsFromXternalSource)arg0; | |
| ActorRef originalSender = m.originallyAskedBy; | |
| String details = m.clubInfoAsJSON; | |
| originalSender.tell (details, getSelf()); | |
| } else | |
| if ( arg0 instanceof TimedOutClubDetails ) { | |
| TimedOutClubDetails m = (TimedOutClubDetails) arg0; | |
| m.toBSentTo.tell("Service unresponsive, try again later", getSelf()); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | PatternsCS.pipe( | |
| PatternsCS.ask( | |
| circuitBreakerJeeves, | |
| new InteractionProtocol.RetrievableClubIDMessageWithFinalDeliveryAddress( | |
| clubID, getSender() | |
| ), | |
| ASK_TIMEOUT | |
| ) | |
| .handle((messageOK, exceptionReported) -> { | |
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def retrieveTablesPlayerIsAt(p: Player) = { | |
| lobby.get(p).outgoing.view | |
| .filter(e => e.label == "IsPlayingAt") | |
| .map(e => e.target) | |
| .map(_.value) | |
| .collect { case t: GameTable => t } | |
| .toList | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def retrieveAllPlayersOnTable(tableToSearch: GameTable) = { | |
| val innerTableNode = retrieveAllTablesInner | |
| .view | |
| .filter(nextTable => nextTable == tableToSearch) | |
| .head | |
| innerTableNode.outgoing | |
| .view.filter(nextOut => nextOut.label == "seatOccupiedBy") | |
| .view.map(e => e.target) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def assignPlayersToTable(pairs: List[(Player,GameTable)]) = { | |
| lobby = lobby ++ | |
| pairs.foldLeft(IndexedSeq[LDiEdge[LobbyNode]]())((holder,nextPair) => { | |
| (holder) ++ giveSeatToPlayer(nextPair._1,nextPair._2) | |
| }).toList | |
| } | |
| def giveSeatToPlayer(p: Player, t: GameTable) = { | |
| IndexedSeq[LDiEdge[LobbyNode]]( | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def assignPlayersToTable(pairs: List[(Player,GameTable)]) = { | |
| lobby = lobby ++ | |
| pairs.foldLeft(IndexedSeq[LDiEdge[LobbyNode]]())((holder,nextPair) => { | |
| (holder :+ rootToPlayer :+ playerToRoot) ++ giveSeatToPlayer(nextPair._1,nextPair._2) | |
| }).toList | |
| } | |
| def giveSeatToPlayer(p: Player, t: GameTable) = { | |
| IndexedSeq[LDiEdge[LobbyNode]]( | |
| setRelationWithLabel(p,t,"IsPlayingAt"), | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def assignPlayersToTable(pairs: List[(Player,GameTable)]) = { | |
| lobby = lobby ++ | |
| pairs.foldLeft(IndexedSeq[LDiEdge[LobbyNode]]())((holder,nextPair) => { | |
| val rootToPlayer = setRelationWithLabel(playerRootNode,nextPair._1,"IsAPlayer") | |
| val playerToRoot = setRelationWithLabel(nextPair._1,playerRootNode,"RootedAt") | |
| (holder :+ rootToPlayer :+ playerToRoot) ++ giveSeatToPlayer(nextPair._1,nextPair._2) | |
| }).toList | |
| } | 
NewerOlder