KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webjmx > example > SimpleStandard


1 package org.webjmx.example;
2
3 /**
4  * Simple definition of a standard MBean, named "SimpleStandard".
5  *
6  * The "SimpleStandard" standard MBean shows how to expose attributes and
7  * operations for management by implementing its corresponding
8  * "SimpleStandardMBean" management interface.
9  *
10  * This MBean has two attributes and one operation exposed
11  * for management by a JMX agent:
12  * - the read/write "State" attribute,
13  * - the read only "Type" attribute,
14  * - the read only "NbChanges" attribute,
15  * - the "reset()" operation.
16  *
17  * This object also has one property and one method not exposed
18  * for management by a JMX agent:
19  * - the "NbResets" property,
20  * - the "getNbResets()" method.
21  */

22 public class SimpleStandard implements SimpleStandardMBean {
23
24     /*
25      * -----------------------------------------------------
26      * CONSTRUCTORS
27      * -----------------------------------------------------
28      */

29      public SimpleStandard()
30      { }
31
32      public SimpleStandard(String JavaDoc startState)
33      {
34          state = startState;
35      }
36
37     /*
38      * -----------------------------------------------------
39      * IMPLEMENTATION OF THE SimpleStandardMBean INTERFACE
40      * -----------------------------------------------------
41      */

42
43     /**
44      * Getter: get the "State" attribute of the "SimpleStandard" standard MBean.
45      * @return the current value of the "State" attribute.
46      */

47     public String JavaDoc getState() {
48         return state;
49     }
50
51     /**
52      * Setter: set the "State" attribute of the "SimpleStandard" standard MBean.
53      * @param <VAR>s</VAR> the new value of the "State" attribute.
54      */

55     public void setState(String JavaDoc s) {
56         state = s;
57         nbChanges++;
58     }
59
60     /**
61      * Getter: get the "NbChanges" attribute of the "SimpleStandard" standard MBean.
62      * @return the current value of the "NbChanges" attribute.
63      */

64     public Integer JavaDoc getNbChanges() {
65         return new Integer JavaDoc(nbChanges);
66     }
67
68     /**
69      * Operation: reset to their initial values the "State" and "NbChanges"
70      * attributes of the "SimpleStandard" standard MBean.
71      */

72     public void reset() {
73     state = "initial state";
74         nbChanges = 0;
75     nbResets++;
76         type = new SimpleStandardType();
77     }
78
79     /**
80      * Operation: reset to initial value "NbChanges" and set a new value for "State"
81      * attributes of the "SimpleStandard" standard MBean.
82      * @param startState
83      */

84     public void reset(String JavaDoc startState) {
85         reset();
86     state = startState;
87     }
88
89
90     /*
91      * -----------------------------------------------------
92      * METHOD NOT EXPOSED FOR MANAGEMENT BY A JMX AGENT
93      * -----------------------------------------------------
94      */

95
96     /**
97      * Return the "NbResets" property.
98      * This method is not a Getter in the JMX sense because
99      * it is not exposed in the "SimpleStandardMBean" interface.
100      *
101      * @return the current value of the "NbResets" property.
102      */

103     public Integer JavaDoc getNbResets() {
104     return new Integer JavaDoc(nbResets);
105     }
106
107     /**
108      * Setter: set the "Type" attribute of the "SimpleStandard" standard MBean.
109      *
110      * @param <VAR>s</VAR> the new value of the "Type" attribute.
111      */

112     public void setType(SimpleStandardType t)
113     {
114         type = t;
115     }
116
117     /**
118      * Getter: set the "Type" attribute of the "SimpleStandard" standard MBean.
119      *
120      * @return the current value of the "Type" attribute.
121      */

122     public SimpleStandardType getType()
123     {
124         return type;
125     }
126     
127     /*
128      * -----------------------------------------------------
129      * ATTRIBUTES ACCESSIBLE FOR MANAGEMENT BY A JMX AGENT
130      * -----------------------------------------------------
131      */

132
133     private String JavaDoc state = "initial state";
134     private int nbChanges = 0;
135     private SimpleStandardType type = new SimpleStandardType();
136
137
138     /*
139      * -----------------------------------------------------
140      * PROPERTY NOT ACCESSIBLE FOR MANAGEMENT BY A JMX AGENT
141      * -----------------------------------------------------
142      */

143
144     private int nbResets = 0;
145 }
146
Popular Tags