Skip to content

Commit 4a96076

Browse files
ravi-devgobletEugen
authored andcommitted
BAEL-538 Basic introduction to JMX technology (eugenp#937)
wordpress link http://inprogress.baeldung.com/wp-admin/post.php?post=27628&action=edit
1 parent 76485ab commit 4a96076

3 files changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.baeldung.jmx;
2+
3+
public class Game implements GameMBean {
4+
5+
private String playerName;
6+
7+
@Override
8+
public void playFootball(String clubName) {
9+
System.out.println(this.playerName + " playing football for " + clubName);
10+
}
11+
12+
@Override
13+
public String getPlayerName() {
14+
System.out.println("Return playerName " + this.playerName);
15+
return playerName;
16+
}
17+
18+
@Override
19+
public void setPlayerName(String playerName) {
20+
System.out.println("Set playerName to value " + playerName);
21+
this.playerName = playerName;
22+
}
23+
24+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.baeldung.jmx;
2+
3+
public interface GameMBean {
4+
5+
public void playFootball(String clubName);
6+
7+
public String getPlayerName();
8+
9+
public void setPlayerName(String playerName);
10+
11+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.baeldung.jmx;
2+
3+
import java.lang.management.ManagementFactory;
4+
import javax.management.InstanceAlreadyExistsException;
5+
import javax.management.MBeanRegistrationException;
6+
import javax.management.MBeanServer;
7+
import javax.management.MalformedObjectNameException;
8+
import javax.management.NotCompliantMBeanException;
9+
import javax.management.ObjectName;
10+
11+
public class JMXTutorialMainlauncher {
12+
13+
public static void main(String[] args) {
14+
// TODO Auto-generated method stub
15+
16+
System.out.println("This is basic JMX tutorial");
17+
ObjectName objectName = null;
18+
try {
19+
objectName = new ObjectName("com.baeldung.tutorial:type=basic,name=game");
20+
} catch (MalformedObjectNameException e) {
21+
e.printStackTrace();
22+
}
23+
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
24+
Game gameObj = new Game();
25+
try {
26+
server.registerMBean(gameObj, objectName);
27+
} catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
28+
e.printStackTrace();
29+
}
30+
System.out.println("Registration for Game mbean with the platform server is successfull");
31+
System.out.println("Please open jconsole to access Game mbean");
32+
while (true) {
33+
// to ensure application does not terminate
34+
}
35+
}
36+
37+
}

0 commit comments

Comments
 (0)