Created
August 11, 2009 08:48
Revisions
-
jboner revised this gist
Aug 11, 2009 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -26,7 +26,7 @@ class RestfulJMX extends Actor with Logging { case Request(service, component, attribute) => reply(retrieveAttribute(service, component, attribute)) } private def retrieveAttribute(service: String, component: String, attribute: String): scala.xml.Elem = { try { var connector = connectors.putIfAbsent(service, JMXConnectorFactory.connect(new JMXServiceURL(service))) <div>{connector.getMBeanServerConnection.getAttribute(new ObjectName(component), attribute).toString}</div> -
jboner created this gist
Aug 11, 2009 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ /** * REST interface to Akka's JMX service. * <p/> * Here is an example that retreives the current number of Actors. * <pre> * http://localhost:9998/management * ?service=service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi * &component=se.scalablesolutions.akka:type=Stats * &attribute=counter_NrOfActors * </pre> */ @Path("/management") class RestfulJMX extends Actor with Logging { private case class Request(service: String, component: String, attribute: String) private val connectors = new ConcurrentHashMap[String, JMXConnector] @GET @Produces(Array("text/html")) def queryJMX( @QueryParam("service") service: String, @QueryParam("component") component: String, @QueryParam("attribute") attribute: String) = (this !! Request(service, component, attribute)).getOrElse(<error>Error in REST JMX management service</error>) override def receive: PartialFunction[Any, Unit] = { case Request(service, component, attribute) => reply(retrieveAttribute(service, component, attribute)) } private def retrieveAttribute(service: String, component: String, attribute: String): scala.xml.Elem = synchronized { try { var connector = connectors.putIfAbsent(service, JMXConnectorFactory.connect(new JMXServiceURL(service))) <div>{connector.getMBeanServerConnection.getAttribute(new ObjectName(component), attribute).toString}</div> } catch { case e: Exception => if (connectors.contains(service)) connectors.remove(service) throw e } } }