BAEL-538 Basic introduction to JMX technology (#937)
wordpress link http://inprogress.baeldung.com/wp-admin/post.php?post=27628&action=edit
This commit is contained in:
parent
76485ab399
commit
4a96076ecf
|
@ -0,0 +1,24 @@
|
|||
package com.baeldung.jmx;
|
||||
|
||||
public class Game implements GameMBean {
|
||||
|
||||
private String playerName;
|
||||
|
||||
@Override
|
||||
public void playFootball(String clubName) {
|
||||
System.out.println(this.playerName + " playing football for " + clubName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerName() {
|
||||
System.out.println("Return playerName " + this.playerName);
|
||||
return playerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerName(String playerName) {
|
||||
System.out.println("Set playerName to value " + playerName);
|
||||
this.playerName = playerName;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.baeldung.jmx;
|
||||
|
||||
public interface GameMBean {
|
||||
|
||||
public void playFootball(String clubName);
|
||||
|
||||
public String getPlayerName();
|
||||
|
||||
public void setPlayerName(String playerName);
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.baeldung.jmx;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import javax.management.InstanceAlreadyExistsException;
|
||||
import javax.management.MBeanRegistrationException;
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.MalformedObjectNameException;
|
||||
import javax.management.NotCompliantMBeanException;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
public class JMXTutorialMainlauncher {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
System.out.println("This is basic JMX tutorial");
|
||||
ObjectName objectName = null;
|
||||
try {
|
||||
objectName = new ObjectName("com.baeldung.tutorial:type=basic,name=game");
|
||||
} catch (MalformedObjectNameException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
|
||||
Game gameObj = new Game();
|
||||
try {
|
||||
server.registerMBean(gameObj, objectName);
|
||||
} catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("Registration for Game mbean with the platform server is successfull");
|
||||
System.out.println("Please open jconsole to access Game mbean");
|
||||
while (true) {
|
||||
// to ensure application does not terminate
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue