Created
October 24, 2012 19:16
-
-
Save johann8384/3948208 to your computer and use it in GitHub Desktop.
Metric Handler
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
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