Create the MBean like this
1 2 3 4 5 6 7 8 9 10 11 12 13 |
trait OrderTrackerMBean { def getOrderId : Int def setOrderId(orderId:Int) } class OrderTracker extends OrderTrackerMBean { var orderId = 0 override def getOrderId: Int = orderId override def setOrderId(_orderId: Int)= { orderId = _orderId } } |
NOTE, that the interface/trait must end with MBean in the name
And this is how you register your MBean
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
package com.tsoft.playingWithLogback import java.lang.management.ManagementFactory import javax.management.{ObjectName, MBeanServer} import org.slf4j.{MarkerFactory, Marker, LoggerFactory} import org.slf4j.MDC import scala.concurrent.{Await, Future} import scala.concurrent.duration._ import scala.concurrent.ExecutionContext.Implicits.global object LotsOfLogOutput { val logger = LoggerFactory.getLogger(this.getClass) val orderTrackerBean = new OrderTracker val mbs:MBeanServer = ManagementFactory.getPlatformMBeanServer(); val mBeanName:ObjectName = new ObjectName("com.tsoft.playingWithLogback:type=Tracking"); mbs.registerMBean( orderTrackerBean, mBeanName); ... |
And the simply launch Java Mission Control (imc), attach to the JVM, and modify your MBean attributes as you like.
Enjoy!
Good article, thanks for sharing, please visit
our website
Nice post,thanks for sharing
Visit Us