Skip to content

Instantly share code, notes, and snippets.

@kastoestoramadus
Created July 16, 2015 08:18
Show Gist options
  • Save kastoestoramadus/70b7bb7520a171708c36 to your computer and use it in GitHub Desktop.
Save kastoestoramadus/70b7bb7520a171708c36 to your computer and use it in GitHub Desktop.
file logger com.codahale.metrics fix akka
// cancel sheduler and cloase file as one cancelable
private def fileLogger(): Cancellable with Object {def cancel(): Boolean; def isCancelled: Boolean} = {
val w = new BufferedWriter(new FileWriter(
s"../metrics_${TcpUtil.firstPartFromIp}_${numberOfClients}_${LocalTime.now()}.dat"))
val scheduled = context.system.scheduler.schedule(Config.STAT_PROBE_DURATION, Config.STAT_PROBE_DURATION) {
w.write( LineLog.toFileString(LocalTime.now(),
beats.getCount, fails.getCount, closings.getCount, receives.getCount, reconnects.getCount)+"\n")
w.flush()
}
// binding two bounded resources to be released at once
new Cancellable {
@deprecated override def isCancelled: Boolean = scheduled.isCancelled
override def cancel(): Boolean = {
scheduled.cancel()
w.close() // should wait for canceling schedule?
true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment