Listing 2: A basic JMX agent to expose your MBean.
import javax.management.MBeanServer;
import javax.management.ObjectName;
import java.lang.management.ManagementFactory;
public class BasicAgent {
private MBeanServer mbeanServer = null;
public BasicAgent() {
//get an instance of MyProcess
MyProcess myProcessBean = new MyProcess();
//Get the MBeanServer
mbeanServer = ManagementFactory.getPlatformMBeanServer();
try{
//the MBeans must have an unique indentifier
ObjectName myProcessName = new ObjectName
("BasicAgent:name=MyProcessAgent");
//register the MBean
mbeanServer.registerMBean(myProcessBean, myProcessName);
}catch(Exception e) { System.out.println("Error
(BasicAgent), code 0:" + e.getMessage()); }
}
//A simple way to persist running
private static void waitKeyboardEnterEvent() {
try{
System.out.println("Press Enter key to continue ...");
System.in.read();
} catch (Exception e) { System.out.println("Error
(BasicAgent), code 1:" + e.getMessage()); }
}
//main method
public static void main(String argv[]) {
BasicAgent basicAgent = new BasicAgent();
System.out.println("BasicAgent is ready and is running ...");
BasicAgent.waitKeyboardEnterEvent();
}
}
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.