chenld / jmx-annotations Goto Github PK
View Code? Open in Web Editor NEWThis project forked from wjw465150/jmx-annotations
Create and register JMX MBeans by adding some simple annotations to your classes
This project forked from wjw465150/jmx-annotations
Create and register JMX MBeans by adding some simple annotations to your classes
Introduction Create and register JMX MBeans by adding some simple annotations to your classes. The project was inspired by the JSR-255 (JMX 2.0) specification, which provides annotations to create MBeans, but it is currently inactive. However, it goes further by allowing you to automatically or programmatically create and register the MBeans. Currently, it only works with CDI (JEE6) as a portable extension, but I plan to support Seam as well as Spring. Automatic creation and registration An MBean is created and registered automatically when your class is instantiated. Programatic creation and registration If you don't want to register your MBean automatically, you can deactivate the auto register feature and the use the API to programatically create and register an MBean within the MBeanServer. Status Example import org.wstone.jmx.*; @MBean(description = "访问计数类") public class VisitorCounter { @ManagedAttribute(description = "访问次数", writable = false, readable = true) private int visits; @ManagedOperation(description = "重置访问次数", impact = Impact.WRITE) public void resetVisits() { this.visits = 0; } @ManagedOperation(description = "带参数的重置访问次数", impact = Impact.WRITE) public void resetVisits(@Description("次数") int visits) { this.visits = visits; } @ManagedOperation(description = "累加访问次数", impact = Impact.READ_WRITE) public int incVisits() { return ++this.visits; } @ManagedOperation(description = "设置访问次数", impact = Impact.WRITE) public void setVisits(@Description("次数") int visits) { this.visits = visits; } public int getVisits() { return visits; } } You can also use the API to programmatically create and register your MBeans: import javax.management.DynamicMBean; import javax.management.MBeanServer; import javax.management.ObjectName; import org.wstone.jmx.MBeanFactory; import org.wstone.jmx.std.StandardMBeanFactory; import org.wstone.jmx.util.MBeanServerLocator; public class TestMain { public static void main(String[] args) { try { MBeanFactory mBeanFactory = new StandardMBeanFactory(); // create the MBean VisitorCounter visitorCounterA = new VisitorCounter(); DynamicMBean mBean = mBeanFactory.createMBean(visitorCounterA); // find MBeanServer MBeanServer ms = MBeanServerLocator.instance().getmBeanServer(); // register the MBean ms.registerMBean(mBean, new ObjectName("org.test:type=VisitorCounter")); ms.registerMBean(mBean, null); //由mBean自动提供ObjectName System.out.println("started MBeanServer..."); for (;;) { try { java.util.concurrent.TimeUnit.SECONDS.sleep(10); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); System.exit(0); } } } catch (Exception e) { e.printStackTrace(); } } }
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.