Created
February 3, 2016 13:23
-
-
Save spockz/8aad66e714fd6e628c4f to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Wraps two services in a new service which checks whether the {{primaryService}} is | |
* available and uses it when it is available. Otherwise, it will use the {{backupService}}. | |
*/ | |
class FailoveringService[Req, Rep](primaryService: Service[Req, Rep], | |
backupService: Service[Req, Rep]) | |
extends Service[Req, Rep] { | |
override def apply(request: Req) = | |
(if (primaryService.isAvailable) primaryService else backupService) (request) | |
override def status = Status.best(primaryService.status, backupService.status) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment