File tree Expand file tree Collapse file tree
core-java/src/main/java/com/baeldung/jmx Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments