KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mx4j > persist > MBeanPersister


1 /*
2  * Copyright (C) The MX4J Contributors.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the MX4J License version 1.0.
6  * See the terms of the MX4J License in the documentation provided with this software.
7  */

8
9 package mx4j.persist;
10
11 import javax.management.InstanceNotFoundException JavaDoc;
12 import javax.management.MBeanException JavaDoc;
13 import javax.management.MBeanServer JavaDoc;
14 import javax.management.MBeanServerInvocationHandler JavaDoc;
15 import javax.management.ObjectName JavaDoc;
16 import javax.management.RuntimeOperationsException JavaDoc;
17
18 /**
19  * A persister that delegates the persistence to a registered persister MBean.
20  *
21  * @version $Revision: 1.7 $
22  */

23 public class MBeanPersister extends Persister
24 {
25    private MBeanServer JavaDoc m_server;
26    private ObjectName JavaDoc m_name;
27    private PersisterMBean m_proxy;
28
29    /**
30     * Creates a new MBeanPersister that delegates persistence to a persister MBean
31     * registered in the specified MBeanServer with the specified ObjectName.
32     */

33    public MBeanPersister(MBeanServer JavaDoc server, ObjectName JavaDoc name)
34    {
35       m_server = server;
36       m_name = name;
37       m_proxy = (PersisterMBean)MBeanServerInvocationHandler.newProxyInstance(server, name, PersisterMBean.class, false);
38    }
39
40    public Object JavaDoc load() throws MBeanException JavaDoc, RuntimeOperationsException JavaDoc, InstanceNotFoundException JavaDoc
41    {
42       return m_proxy.load();
43    }
44
45    public void store(Object JavaDoc data) throws MBeanException JavaDoc, RuntimeOperationsException JavaDoc, InstanceNotFoundException JavaDoc
46    {
47       m_proxy.store(data);
48    }
49 }
50
Popular Tags