Created
September 3, 2014 09:45
-
-
Save kulikov/d0af7f67b83d4fc36b0c to your computer and use it in GitHub Desktop.
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
| object FlagsRegistry { | |
| private val flagsRegistry = new FlagsRegistry(config, dao, executorService) | |
| def check(serviceId: Long, flag: FlagEnum) = flagsRegistry.check(serviceId, flag) | |
| } | |
| class FlagsRegistry(conf, dao, executorService) { | |
| private val UpdateInterval: Long = conf.get("bla.bla.update-interval") | |
| @volatile private var flags: Map[Long, Map[FlagEnum, Flag]] = fetchAllFlags() | |
| sheduleNextTimer(UpdateInterval) | |
| def check(serviceId: Long, flag: FlagEnum) = | |
| flags.get(serviceId).flatMap(_.get(flag)).exists(_.value == true) | |
| private def fetchAllFlags(): Map[Long, Map[FlagEnum, Flag]] = | |
| dao.getAllServiceFlags() map { result ⇒ | |
| ??? | |
| } | |
| private def sheduleNextTimer(timeout: Long) { | |
| executorService.schedule(new Runnable { | |
| def run() { | |
| flags = fetchAllFlags() | |
| sheduleNextTimer(math.min(UpdateInterval, findNextExpiredTimeout)) | |
| } | |
| }, | |
| timeout, | |
| TimeUnit.MILLISECONDS | |
| ) | |
| } | |
| private def findNextExpiredTimeout: Long = ??? | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment