001: /* JFox, the OpenSource J2EE Application Server
002: *
003: * Copyright (C) 2002 huihoo.org
004: * Distributable under GNU LGPL license
005: * See the GNU Lesser General Public License for more details.
006: */
007:
008: package example.jmx.modelmbean;
009:
010: /**
011: *
012: * @author <a href="mailto:young_yy@hotmail.org">Young Yang</a>
013: */
014:
015: public class TestBean implements java.io.Serializable {
016:
017: /*
018: * -----------------------------------------------------
019: * CONSTRUCTORS
020: * -----------------------------------------------------
021: */
022:
023: public TestBean() {
024: echo("\n\tTestBean Constructor Invoked: State " + state
025: + " nbChanges: " + nbChanges + " nbResets: " + nbResets);
026:
027: }
028:
029: /*
030: * -----------------------------------------------------
031: * OTHER PUBLIC METHODS
032: * -----------------------------------------------------
033: */
034:
035: /**
036: * Getter: get the "State" attribute of the "TestBean" managed resource.
037: */
038: public String getState() {
039: echo("\n\tTestBean: getStatus invoked: " + state);
040: return state;
041: }
042:
043: /**
044: * Setter: set the "State" attribute of the "TestBean" managed resource.
045: */
046: public void setState(String s) {
047: state = s;
048: nbChanges++;
049: echo("\n\tTestBean: setState to " + state + " nbChanges: "
050: + nbChanges);
051: }
052:
053: /**
054: * Getter: get the "NbChanges" attribute of the "TestBean" managed resource.
055: */
056: public Integer getNbChanges() {
057: echo("\n\tTestBean: getNbChanges invoked: " + nbChanges);
058: return new Integer(nbChanges);
059: }
060:
061: /**
062: * Operation: reset to their initial values the "State" and "NbChanges"
063: * attributes of the "SimpleDynamic" dynamic MBean.
064: */
065: public void reset() {
066: echo("\n\tTestBean: reset invoked ");
067: state = "reset initial state";
068: nbChanges = 0;
069: nbResets++;
070: }
071:
072: /**
073: * Return the "NbResets" property.
074: * This method is not a Getter in the JMX sense because
075: * it is not returned by the getMBeanInfo() method.
076: */
077: public Integer getNbResets() {
078: echo("\n\tTestBean: getNbResets invoked: " + nbResets);
079: return new Integer(nbResets);
080: }
081:
082: /*
083: * -----------------------------------------------------
084: * PRIVATE METHODS
085: * -----------------------------------------------------
086: */
087: private void echo(String outstr) {
088: System.out.println(outstr);
089: }
090:
091: /**
092:
093: /*
094: * -----------------------------------------------------
095: * PRIVATE VARIABLES
096: * -----------------------------------------------------
097: */
098:
099: private String state = "initial state";
100: private int nbChanges = 0;
101: private int nbResets = 0;
102:
103: }
|