001 /* PersistentMBean.java -- Interface for beans that should persist. 002 Copyright (C) 2007 Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 package javax.management; 039 040 /** 041 * Beans may implement this interface in order to become 042 * persistent. The {@link #load()} method should be 043 * called on construction in order to reload the stored 044 * state. The {@link #store()} method should be called 045 * sometime during the bean's lifetime in order to create 046 * a persistent copy of the bean's instance data. This 047 * method may also be called by the {@link MBeanServer} 048 * as a result of the {@link Descriptor} of an 049 * {@link javax.management.modelmbean.ModelMBean}. 050 * 051 * @author Andrew John Hughes (gnu_andrew@member.fsf.org) 052 * @since 1.5 053 */ 054 public interface PersistentMBean 055 { 056 057 /** 058 * Instantiates the bean with the data previously stored 059 * using a call to {@link #store()}. The data stored can 060 * include values held by attributes as well as those returned 061 * by operations. This method should be called during 062 * construction or initialisation of the bean, before 063 * it becomes registered with an {@link MBeanServer}. 064 * 065 * @throws MBeanException if persistence is not supported, 066 * or another exception is thrown 067 * (which this then wraps). 068 * @throws RuntimeOperationsException if the persistence 069 * mechanism throws an 070 * exception. 071 * @throws InstanceNotFoundException if the bean can not 072 * be found in the 073 * persistent store. 074 */ 075 void load() 076 throws MBeanException, RuntimeOperationsException, 077 InstanceNotFoundException; 078 079 /** 080 * <p> 081 * Captures the current state of the bean and stores it 082 * for future retrieval by the {@link #load()} method. 083 * The data stored can include values held by attributes 084 * as well as those returned by operations. 085 * </p> 086 * <p> 087 * Whether the state is stored or not depends on the 088 * <code>persistPolicy</code> field of the MBean/attribute 089 * descriptor. The state should be stored if the policy 090 * is set to any of the following: 091 * </p> 092 * <ul> 093 * <li><code>always</code></li> 094 * <li><code>onTimer</code> and <code>now</code> is 095 * greater than or equal to <code>lastPersistTime + 096 * persistPeriod</code>.</li> 097 * <li><code>noMoreOftenThan</code> and <code>now</code> is 098 * greater than or equal to <code>lastPersistTime + 099 * persistPeriod</code>.</li> 100 * <li>onUnregister</li> 101 * </ul> 102 * <p>If the policy is set to any of the following, the state 103 * should not be stored:</p> 104 * <ul> 105 * <li><code>never</code></li> 106 * <li><code>onUpdate</code></li> 107 * <li><code>onTimer</code> and <code>now</code> is 108 * less than <code>lastPersistTime + persistPeriod</code>. 109 * </li> 110 * </ul> 111 * 112 * @throws MBeanException if persistence is not supported, 113 * or another exception is thrown 114 * (which this then wraps). 115 * @throws RuntimeOperationsException if the persistence 116 * mechanism throws an 117 * exception. 118 * @throws InstanceNotFoundException if the persistent 119 * store can not be found 120 * or accessed. 121 */ 122 void store() 123 throws MBeanException, RuntimeOperationsException, 124 InstanceNotFoundException; 125 126 }