Created
July 16, 2015 08:18
-
-
Save kastoestoramadus/70b7bb7520a171708c36 to your computer and use it in GitHub Desktop.
file logger com.codahale.metrics fix akka
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
// 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