01: /* JFox, the OpenSource J2EE Application Server
02: *
03: * Copyright (C) 2002 huihoo.org
04: * Distributable under GNU LGPL license
05: * See the GNU Lesser General Public License for more details.
06: */
07:
08: package example.jmx.monitor;
09:
10: import javax.management.ObjectName;
11: import javax.management.MBeanRegistration;
12: import javax.management.MBeanServer;
13:
14: /**
15: *
16: * @author <a href="mailto:young_yy@hotmail.org">Young Yang</a>
17: */
18:
19: public class StandardObservedObject implements
20: StandardObservedObjectMBean, MBeanRegistration {
21: /*
22: * ------------------------------------------
23: * PRIVATE VARIABLES
24: * ------------------------------------------
25: */
26:
27: private MBeanServer server = null;
28:
29: /*
30: * ------------------------------------------
31: * PUBLIC METHODS
32: * ------------------------------------------
33: */
34:
35: public ObjectName preRegister(MBeanServer server, ObjectName name)
36: throws java.lang.Exception {
37:
38: if (name == null)
39: name = new ObjectName(server.getDefaultDomain() + ":name="
40: + this .getClass().getName());
41:
42: this .server = server;
43: return name;
44: }
45:
46: public void postRegister(Boolean registrationDone) {
47: }
48:
49: public void preDeregister() throws java.lang.Exception {
50: }
51:
52: public void postDeregister() {
53: }
54:
55: // GETTERS AND SETTERS
56: //--------------------
57:
58: public Integer getNbObjects() {
59:
60: try {
61: return new Integer((server.queryMBeans(
62: new ObjectName("*:*"), null)).size());
63: } catch (Exception e) {
64: return new Integer(-1);
65: }
66: }
67:
68: }
|