Path: blob/master/src/java.management/share/classes/javax/management/MBeanRegistration.java
41154 views
/*1* Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.management;262728/**29* <p>Can be implemented by an MBean in order to30* carry out operations before and after being registered or unregistered from31* the MBean Server. An MBean can also implement this interface in order32* to get a reference to the MBean Server and/or its name within that33* MBean Server.</p>34*35* @since 1.536*/37public interface MBeanRegistration {383940/**41* Allows the MBean to perform any operations it needs before42* being registered in the MBean Server. If the name of the MBean43* is not specified, the MBean can provide a name for its44* registration. If any exception is raised, the MBean will not be45* registered in the MBean Server.46*47* @param server The MBean Server in which the MBean will be registered.48*49* @param name The object name of the MBean. This name is null if50* the name parameter to one of the <code>createMBean</code> or51* <code>registerMBean</code> methods in the {@link MBeanServer}52* interface is null. In that case, this method must return a53* non-null ObjectName for the new MBean.54*55* @return The name under which the MBean is to be registered.56* This value must not be null. If the <code>name</code>57* parameter is not null, it will usually but not necessarily be58* the returned value.59*60* @exception java.lang.Exception This exception will be caught by61* the MBean Server and re-thrown as an {@link62* MBeanRegistrationException}.63*/64public ObjectName preRegister(MBeanServer server,65ObjectName name) throws java.lang.Exception;6667/**68* Allows the MBean to perform any operations needed after having been69* registered in the MBean server or after the registration has failed.70* <p>If the implementation of this method throws a {@link RuntimeException}71* or an {@link Error}, the MBean Server will rethrow those inside72* a {@link RuntimeMBeanException} or {@link RuntimeErrorException},73* respectively. However, throwing an exception in {@code postRegister}74* will not change the state of the MBean:75* if the MBean was already registered ({@code registrationDone} is76* {@code true}), the MBean will remain registered. </p>77* <p>This might be confusing for the code calling {@code createMBean()}78* or {@code registerMBean()}, as such code might assume that MBean79* registration has failed when such an exception is raised.80* Therefore it is recommended that implementations of81* {@code postRegister} do not throw Runtime Exceptions or Errors if it82* can be avoided.</p>83* @param registrationDone Indicates whether or not the MBean has84* been successfully registered in the MBean server. The value85* false means that the registration phase has failed.86*/87public void postRegister(Boolean registrationDone);8889/**90* Allows the MBean to perform any operations it needs before91* being unregistered by the MBean server.92*93* @exception java.lang.Exception This exception will be caught by94* the MBean server and re-thrown as an {@link95* MBeanRegistrationException}.96*/97public void preDeregister() throws java.lang.Exception ;9899/**100* Allows the MBean to perform any operations needed after having been101* unregistered in the MBean server.102* <p>If the implementation of this method throws a {@link RuntimeException}103* or an {@link Error}, the MBean Server will rethrow those inside104* a {@link RuntimeMBeanException} or {@link RuntimeErrorException},105* respectively. However, throwing an exception in {@code postDeregister}106* will not change the state of the MBean:107* the MBean was already successfully deregistered and will remain so. </p>108* <p>This might be confusing for the code calling109* {@code unregisterMBean()}, as it might assume that MBean deregistration110* has failed. Therefore it is recommended that implementations of111* {@code postDeregister} do not throw Runtime Exceptions or Errors if it112* can be avoided.</p>113*/114public void postDeregister();115116}117118119