01: /*
02: * Copyright (C) The MX4J Contributors.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the MX4J License version 1.0.
06: * See the terms of the MX4J License in the documentation provided with this software.
07: */
08: package mx4j.examples.tools.persister;
09:
10: import java.io.Serializable;
11: import javax.management.MBeanServer;
12: import javax.management.ObjectName;
13:
14: /**
15: * The MBean that gets to be stored Please note must be Serializable
16: *
17: * @version $Revision: 1.1 $
18: */
19: interface MBeanTwoMBean {
20: public void storeIt(MBeanServer server, ObjectName name);
21:
22: public Object loadIt(MBeanServer server, ObjectName name);
23: }
24:
25: public class MBeanTwo implements MBeanTwoMBean, Serializable {
26: private Integer number = null;
27:
28: public MBeanTwo(Integer amount) {
29: number = amount;
30: }
31:
32: public void storeIt(MBeanServer server, ObjectName name) {
33: try {
34: server.invoke(name, "store", new Object[] { this },
35: new String[] { "java.lang.Object" });
36: } catch (Exception ex) {
37: System.out.println("exception: MBeanTwo: storeIt");
38: ex.printStackTrace();
39: }
40: }
41:
42: public Object loadIt(MBeanServer server, ObjectName name) {
43: Object me = null;
44: try {
45: me = (MBeanTwo) server.invoke(name, "load", new Object[0],
46: new String[0]);
47: } catch (Exception ex) {
48: ex.printStackTrace();
49: }
50: return me;
51: }
52: }
|