Skip to content

Instantly share code, notes, and snippets.

@kulikov
Created September 3, 2014 09:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kulikov/d0af7f67b83d4fc36b0c to your computer and use it in GitHub Desktop.
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