Skip to content

Instantly share code, notes, and snippets.

@johann8384
Created October 24, 2012 19:16
Show Gist options
  • Save johann8384/3948208 to your computer and use it in GitHub Desktop.
Save johann8384/3948208 to your computer and use it in GitHub Desktop.
Metric Handler
type MetricHandler = (MetricName, Map[String, Any]) => String
val metricHandlers = Map("counter" -> handleCounter _, "timer" -> handleTimer _, "meter" -> handleMeter _)
/*
* This is the core function in this class
* accept a parsed metric object and delegate it to an appropriate handler
*/
def handleMetric(metricMap : Map[String, Any]) : String = {
try {
val metricType = metricMap("type").toString
val name = metricMap("name").toString
val metricName: MetricName = new MetricName(getClass(), name)
// Update Internal Metrics
internalMetrics
metricHandlers.get(metricType) match {
case Some(handleFunction) => return handleFunction(metricName, metricMap)
case None => throw new Exception("No Handler for " + metricType + " defined")
}
}
catch {
case e: Exception => {
println(e.toString)
return "FAILURE: " + e.toString
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment