下面列出了怎么用javax.management.MBeanServerDelegate的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Creates a DefaultMBeanServerInterceptor with the specified
* repository instance.
* <p>Do not forget to call <code>initialize(outer,delegate)</code>
* before using this object.
* @param outer A pointer to the MBeanServer object that must be
* passed to the MBeans when invoking their
* {@link javax.management.MBeanRegistration} interface.
* @param delegate A pointer to the MBeanServerDelegate associated
* with the new MBeanServer. The new MBeanServer must register
* this MBean in its MBean repository.
* @param instantiator The MBeanInstantiator that will be used to
* instantiate MBeans and take care of class loading issues.
* @param repository The repository to use for this MBeanServer.
*/
public DefaultMBeanServerInterceptor(MBeanServer outer,
MBeanServerDelegate delegate,
MBeanInstantiator instantiator,
Repository repository) {
if (outer == null) throw new
IllegalArgumentException("outer MBeanServer cannot be null");
if (delegate == null) throw new
IllegalArgumentException("MBeanServerDelegate cannot be null");
if (instantiator == null) throw new
IllegalArgumentException("MBeanInstantiator cannot be null");
if (repository == null) throw new
IllegalArgumentException("Repository cannot be null");
this.server = outer;
this.delegate = delegate;
this.instantiator = instantiator;
this.repository = repository;
this.domain = repository.getDefaultDomain();
}
/**
* Sends an MBeanServerNotifications with the specified type for the
* MBean with the specified ObjectName
*/
private void sendNotification(String NotifType, ObjectName name) {
// ------------------------------
// ------------------------------
// ---------------------
// Create notification
// ---------------------
MBeanServerNotification notif = new MBeanServerNotification(
NotifType,MBeanServerDelegate.DELEGATE_NAME,0,name);
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
MBEANSERVER_LOGGER.logp(Level.FINER,
DefaultMBeanServerInterceptor.class.getName(),
"sendNotification", NotifType + " " + name);
}
delegate.sendNotification(notif);
}
private void destroyListeners() {
checkNoLocks();
logger.debug("destroyListeners", "starts");
try {
removeNotificationListener(MBeanServerDelegate.DELEGATE_NAME,
creationListener);
} catch (Exception e) {
logger.warning("remove listener from MBeanServer delegate", e);
}
Set<ObjectName> names = queryNames(null, broadcasterQuery);
for (final ObjectName name : names) {
if (logger.debugOn())
logger.debug("destroyListeners",
"remove listener from " + name);
removeBufferListener(name);
}
logger.debug("destroyListeners", "ends");
}
/**
* Creates a DefaultMBeanServerInterceptor with the specified
* repository instance.
* <p>Do not forget to call <code>initialize(outer,delegate)</code>
* before using this object.
* @param outer A pointer to the MBeanServer object that must be
* passed to the MBeans when invoking their
* {@link javax.management.MBeanRegistration} interface.
* @param delegate A pointer to the MBeanServerDelegate associated
* with the new MBeanServer. The new MBeanServer must register
* this MBean in its MBean repository.
* @param instantiator The MBeanInstantiator that will be used to
* instantiate MBeans and take care of class loading issues.
* @param repository The repository to use for this MBeanServer.
*/
public DefaultMBeanServerInterceptor(MBeanServer outer,
MBeanServerDelegate delegate,
MBeanInstantiator instantiator,
Repository repository) {
if (outer == null) throw new
IllegalArgumentException("outer MBeanServer cannot be null");
if (delegate == null) throw new
IllegalArgumentException("MBeanServerDelegate cannot be null");
if (instantiator == null) throw new
IllegalArgumentException("MBeanInstantiator cannot be null");
if (repository == null) throw new
IllegalArgumentException("Repository cannot be null");
this.server = outer;
this.delegate = delegate;
this.instantiator = instantiator;
this.repository = repository;
this.domain = repository.getDefaultDomain();
}
/**
* Creates a DefaultMBeanServerInterceptor with the specified
* repository instance.
* <p>Do not forget to call <code>initialize(outer,delegate)</code>
* before using this object.
* @param outer A pointer to the MBeanServer object that must be
* passed to the MBeans when invoking their
* {@link javax.management.MBeanRegistration} interface.
* @param delegate A pointer to the MBeanServerDelegate associated
* with the new MBeanServer. The new MBeanServer must register
* this MBean in its MBean repository.
* @param instantiator The MBeanInstantiator that will be used to
* instantiate MBeans and take care of class loading issues.
* @param repository The repository to use for this MBeanServer.
*/
public DefaultMBeanServerInterceptor(MBeanServer outer,
MBeanServerDelegate delegate,
MBeanInstantiator instantiator,
Repository repository) {
if (outer == null) throw new
IllegalArgumentException("outer MBeanServer cannot be null");
if (delegate == null) throw new
IllegalArgumentException("MBeanServerDelegate cannot be null");
if (instantiator == null) throw new
IllegalArgumentException("MBeanInstantiator cannot be null");
if (repository == null) throw new
IllegalArgumentException("Repository cannot be null");
this.server = outer;
this.delegate = delegate;
this.instantiator = instantiator;
this.repository = repository;
this.domain = repository.getDefaultDomain();
}
/**
* Sends an MBeanServerNotifications with the specified type for the
* MBean with the specified ObjectName
*/
private void sendNotification(String NotifType, ObjectName name) {
// ------------------------------
// ------------------------------
// ---------------------
// Create notification
// ---------------------
MBeanServerNotification notif = new MBeanServerNotification(
NotifType,MBeanServerDelegate.DELEGATE_NAME,0,name);
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
MBEANSERVER_LOGGER.logp(Level.FINER,
DefaultMBeanServerInterceptor.class.getName(),
"sendNotification", NotifType + " " + name);
}
delegate.sendNotification(notif);
}
private void destroyListeners() {
checkNoLocks();
logger.debug("destroyListeners", "starts");
try {
removeNotificationListener(MBeanServerDelegate.DELEGATE_NAME,
creationListener);
} catch (Exception e) {
logger.warning("remove listener from MBeanServer delegate", e);
}
Set<ObjectName> names = queryNames(null, broadcasterQuery);
for (final ObjectName name : names) {
if (logger.debugOn())
logger.debug("destroyListeners",
"remove listener from " + name);
removeBufferListener(name);
}
logger.debug("destroyListeners", "ends");
}
protected void removeListenerForMBeanRemovedNotif(Integer id)
throws IOException, InstanceNotFoundException,
ListenerNotFoundException {
try {
connection.removeNotificationListeners(
MBeanServerDelegate.DELEGATE_NAME,
new Integer[] {id},
null);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
connection.removeNotificationListeners(
MBeanServerDelegate.DELEGATE_NAME,
new Integer[] {id},
null);
}
}
public static void main(String[] args) throws Exception {
System.out.println(
"Test that <MBeanServerDelegate.DELEGATE_NAME> equals " +
"<new ObjectName(\"JMImplementation:type=MBeanServerDelegate\")>");
final ObjectName delegateName =
new ObjectName("JMImplementation:type=MBeanServerDelegate");
if (!delegateName.equals(MBeanServerDelegate.DELEGATE_NAME))
throw new AssertionError("Unexpected value: " +
"MBeanServerDelegate.DELEGATE_NAME = " +
MBeanServerDelegate.DELEGATE_NAME);
System.out.println("MBeanServerDelegate.DELEGATE_NAME = " +
"new ObjectName(\"" + delegateName + "\")");
System.out.println("Test that <ObjectName.WILDCARD> " +
"equals <new ObjectName(\"*:*\")>");
final ObjectName wildcardName = new ObjectName("*:*");
if (!wildcardName.equals(ObjectName.WILDCARD))
throw new AssertionError("Unexpected value: " +
"ObjectName.WILDCARD = " +
ObjectName.WILDCARD);
System.out.println("ObjectName.WILDCARD = " +
"new ObjectName(\"" + wildcardName + "\")");
System.out.println("Test passes: constants were initialized properly");
}
public static void main(String[] args) throws Exception {
System.out.println(
"Test that <MBeanServerDelegate.DELEGATE_NAME> equals " +
"<new ObjectName(\"JMImplementation:type=MBeanServerDelegate\")>");
final ObjectName delegateName =
new ObjectName("JMImplementation:type=MBeanServerDelegate");
if (!delegateName.equals(MBeanServerDelegate.DELEGATE_NAME))
throw new AssertionError("Unexpected value: " +
"MBeanServerDelegate.DELEGATE_NAME = " +
MBeanServerDelegate.DELEGATE_NAME);
System.out.println("MBeanServerDelegate.DELEGATE_NAME = " +
"new ObjectName(\"" + delegateName + "\")");
System.out.println("Test that <ObjectName.WILDCARD> " +
"equals <new ObjectName(\"*:*\")>");
final ObjectName wildcardName = new ObjectName("*:*");
if (!wildcardName.equals(ObjectName.WILDCARD))
throw new AssertionError("Unexpected value: " +
"ObjectName.WILDCARD = " +
ObjectName.WILDCARD);
System.out.println("ObjectName.WILDCARD = " +
"new ObjectName(\"" + wildcardName + "\")");
System.out.println("Test passes: constants were initialized properly");
}
private void destroyListeners() {
checkNoLocks();
logger.debug("destroyListeners", "starts");
try {
removeNotificationListener(MBeanServerDelegate.DELEGATE_NAME,
creationListener);
} catch (Exception e) {
logger.warning("remove listener from MBeanServer delegate", e);
}
Set<ObjectName> names = queryNames(null, broadcasterQuery);
for (final ObjectName name : names) {
if (logger.debugOn())
logger.debug("destroyListeners",
"remove listener from " + name);
removeBufferListener(name);
}
logger.debug("destroyListeners", "ends");
}
protected void removeListenerForMBeanRemovedNotif(Integer id)
throws IOException, InstanceNotFoundException,
ListenerNotFoundException {
try {
connection.removeNotificationListeners(
MBeanServerDelegate.DELEGATE_NAME,
new Integer[] {id},
null);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
connection.removeNotificationListeners(
MBeanServerDelegate.DELEGATE_NAME,
new Integer[] {id},
null);
}
}
/**
* Sends an MBeanServerNotifications with the specified type for the
* MBean with the specified ObjectName
*/
private void sendNotification(String NotifType, ObjectName name) {
// ------------------------------
// ------------------------------
// ---------------------
// Create notification
// ---------------------
MBeanServerNotification notif = new MBeanServerNotification(
NotifType,MBeanServerDelegate.DELEGATE_NAME,0,name);
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
MBEANSERVER_LOGGER.logp(Level.FINER,
DefaultMBeanServerInterceptor.class.getName(),
"sendNotification", NotifType + " " + name);
}
delegate.sendNotification(notif);
}
/**
* <b>Package:</b> Creates an MBeanServer.
* @param domain The default domain name used by this MBeanServer.
* @param outer A pointer to the MBeanServer object that must be
* passed to the MBeans when invoking their
* {@link javax.management.MBeanRegistration} interface.
* @param delegate A pointer to the MBeanServerDelegate associated
* with the new MBeanServer. The new MBeanServer must register
* this MBean in its MBean repository.
* @param instantiator The MBeanInstantiator that will be used to
* instantiate MBeans and take care of class loading issues.
* @param metadata The MetaData object that will be used by the
* MBean server in order to invoke the MBean interface of
* the registered MBeans.
* @param interceptors If <code>true</code>,
* {@link MBeanServerInterceptor} will be enabled (default is
* <code>false</code>).
* @param fairLock If {@code true}, the MBean repository will use a {@link
* java.util.concurrent.locks.ReentrantReadWriteLock#ReentrantReadWriteLock(boolean)
* fair locking} policy.
*/
JmxMBeanServer(String domain, MBeanServer outer,
MBeanServerDelegate delegate,
MBeanInstantiator instantiator,
boolean interceptors,
boolean fairLock) {
if (instantiator == null) {
final ModifiableClassLoaderRepository
clr = new ClassLoaderRepositorySupport();
instantiator = new MBeanInstantiator(clr);
}
final MBeanInstantiator fInstantiator = instantiator;
this.secureClr = new
SecureClassLoaderRepository(AccessController.doPrivileged(new PrivilegedAction<ClassLoaderRepository>() {
@Override
public ClassLoaderRepository run() {
return fInstantiator.getClassLoaderRepository();
}
})
);
if (delegate == null)
delegate = new MBeanServerDelegateImpl();
if (outer == null)
outer = this;
this.instantiator = instantiator;
this.mBeanServerDelegateObject = delegate;
this.outerShell = outer;
final Repository repository = new Repository(domain);
this.mbsInterceptor =
new DefaultMBeanServerInterceptor(outer, delegate, instantiator,
repository);
this.interceptorsEnabled = interceptors;
initialize();
}
private void snoopOnUnregister(NotificationResult nr) {
List<IdAndFilter> copy = null;
synchronized (listenerMap) {
Set<IdAndFilter> delegateSet = listenerMap.get(MBeanServerDelegate.DELEGATE_NAME);
if (delegateSet == null || delegateSet.isEmpty()) {
return;
}
copy = new ArrayList<>(delegateSet);
}
for (TargetedNotification tn : nr.getTargetedNotifications()) {
Integer id = tn.getListenerID();
for (IdAndFilter idaf : copy) {
if (idaf.id == id) {
// This is a notification from the MBeanServerDelegate.
Notification n = tn.getNotification();
if (n instanceof MBeanServerNotification &&
n.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
MBeanServerNotification mbsn = (MBeanServerNotification) n;
ObjectName gone = mbsn.getMBeanName();
synchronized (listenerMap) {
listenerMap.remove(gone);
}
}
}
}
}
}
private void createListeners() {
logger.debug("createListeners", "starts");
synchronized (this) {
createdDuringQuery = new HashSet<ObjectName>();
}
try {
addNotificationListener(MBeanServerDelegate.DELEGATE_NAME,
creationListener, creationFilter, null);
logger.debug("createListeners", "added creationListener");
} catch (Exception e) {
final String msg = "Can't add listener to MBean server delegate: ";
RuntimeException re = new IllegalArgumentException(msg + e);
EnvHelp.initCause(re, e);
logger.fine("createListeners", msg + e);
logger.debug("createListeners", e);
throw re;
}
/* Spec doesn't say whether Set returned by QueryNames can be modified
so we clone it. */
Set<ObjectName> names = queryNames(null, broadcasterQuery);
names = new HashSet<ObjectName>(names);
synchronized (this) {
names.addAll(createdDuringQuery);
createdDuringQuery = null;
}
for (ObjectName name : names)
addBufferListener(name);
logger.debug("createListeners", "ends");
}
OldMBeanServer(String defaultDomain, MBeanServerDelegate delegate) {
this.defaultDomain = defaultDomain;
this.delegate = delegate;
try {
registerMBean(delegate, MBeanServerDelegate.DELEGATE_NAME);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private void snoopOnUnregister(NotificationResult nr) {
List<IdAndFilter> copy = null;
synchronized (listenerMap) {
Set<IdAndFilter> delegateSet = listenerMap.get(MBeanServerDelegate.DELEGATE_NAME);
if (delegateSet == null || delegateSet.isEmpty()) {
return;
}
copy = new ArrayList<>(delegateSet);
}
for (TargetedNotification tn : nr.getTargetedNotifications()) {
Integer id = tn.getListenerID();
for (IdAndFilter idaf : copy) {
if (idaf.id == id) {
// This is a notification from the MBeanServerDelegate.
Notification n = tn.getNotification();
if (n instanceof MBeanServerNotification &&
n.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
MBeanServerNotification mbsn = (MBeanServerNotification) n;
ObjectName gone = mbsn.getMBeanName();
synchronized (listenerMap) {
listenerMap.remove(gone);
}
}
}
}
}
}
private void createListeners() {
logger.debug("createListeners", "starts");
synchronized (this) {
createdDuringQuery = new HashSet<ObjectName>();
}
try {
addNotificationListener(MBeanServerDelegate.DELEGATE_NAME,
creationListener, creationFilter, null);
logger.debug("createListeners", "added creationListener");
} catch (Exception e) {
final String msg = "Can't add listener to MBean server delegate: ";
RuntimeException re = new IllegalArgumentException(msg + e);
EnvHelp.initCause(re, e);
logger.fine("createListeners", msg + e);
logger.debug("createListeners", e);
throw re;
}
/* Spec doesn't say whether Set returned by QueryNames can be modified
so we clone it. */
Set<ObjectName> names = queryNames(null, broadcasterQuery);
names = new HashSet<ObjectName>(names);
synchronized (this) {
names.addAll(createdDuringQuery);
createdDuringQuery = null;
}
for (ObjectName name : names)
addBufferListener(name);
logger.debug("createListeners", "ends");
}
public void unregisterMBean(ObjectName name)
throws InstanceNotFoundException, MBeanRegistrationException {
forbidJMImpl(name);
DynamicMBean mbean = getMBean(name);
if (mbean == null)
throw new InstanceNotFoundException(name.toString());
MBeanRegistration reg = mbeanRegistration(mbean);
try {
reg.preDeregister();
} catch (Exception e) {
throw new MBeanRegistrationException(e);
}
if (!mbeans.remove(name, mbean))
throw new InstanceNotFoundException(name.toString());
// This is incorrect because we've invoked preDeregister
Object userMBean = getUserMBean(mbean);
if (userMBean instanceof ClassLoader)
clr.removeLoader((ClassLoader) userMBean);
Notification n = new MBeanServerNotification(
MBeanServerNotification.REGISTRATION_NOTIFICATION,
MBeanServerDelegate.DELEGATE_NAME,
0,
name);
delegate.sendNotification(n);
reg.postDeregister();
}
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
NotificationFilterSupport clientFilter =
new NotificationFilterSupport();
clientFilter.enableType(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
MarshalledObject<NotificationFilter> sFilter =
new MarshalledObject<NotificationFilter>(clientFilter);
Integer[] listenerIDs;
final ObjectName[] names =
new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
final MarshalledObject<NotificationFilter>[] filters =
Util.cast(new MarshalledObject<?>[] {sFilter});
final Subject[] subjects = new Subject[] {null};
try {
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
}
return listenerIDs[0];
}
private void snoopOnUnregister(NotificationResult nr) {
List<IdAndFilter> copy = null;
synchronized (listenerMap) {
Set<IdAndFilter> delegateSet = listenerMap.get(MBeanServerDelegate.DELEGATE_NAME);
if (delegateSet == null || delegateSet.isEmpty()) {
return;
}
copy = new ArrayList<>(delegateSet);
}
for (TargetedNotification tn : nr.getTargetedNotifications()) {
Integer id = tn.getListenerID();
for (IdAndFilter idaf : copy) {
if (idaf.id == id) {
// This is a notification from the MBeanServerDelegate.
Notification n = tn.getNotification();
if (n instanceof MBeanServerNotification &&
n.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
MBeanServerNotification mbsn = (MBeanServerNotification) n;
ObjectName gone = mbsn.getMBeanName();
synchronized (listenerMap) {
listenerMap.remove(gone);
}
}
}
}
}
}
private void createListeners() {
logger.debug("createListeners", "starts");
synchronized (this) {
createdDuringQuery = new HashSet<ObjectName>();
}
try {
addNotificationListener(MBeanServerDelegate.DELEGATE_NAME,
creationListener, creationFilter, null);
logger.debug("createListeners", "added creationListener");
} catch (Exception e) {
final String msg = "Can't add listener to MBean server delegate: ";
RuntimeException re = new IllegalArgumentException(msg + e);
EnvHelp.initCause(re, e);
logger.fine("createListeners", msg + e);
logger.debug("createListeners", e);
throw re;
}
/* Spec doesn't say whether Set returned by QueryNames can be modified
so we clone it. */
Set<ObjectName> names = queryNames(null, broadcasterQuery);
names = new HashSet<ObjectName>(names);
synchronized (this) {
names.addAll(createdDuringQuery);
createdDuringQuery = null;
}
for (ObjectName name : names)
addBufferListener(name);
logger.debug("createListeners", "ends");
}
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
NotificationFilterSupport clientFilter =
new NotificationFilterSupport();
clientFilter.enableType(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
MarshalledObject<NotificationFilter> sFilter =
new MarshalledObject<NotificationFilter>(clientFilter);
Integer[] listenerIDs;
final ObjectName[] names =
new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
final MarshalledObject<NotificationFilter>[] filters =
Util.cast(new MarshalledObject<?>[] {sFilter});
final Subject[] subjects = new Subject[] {null};
try {
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
}
return listenerIDs[0];
}
public MBeanServer newMBeanServer(
String defaultDomain,
MBeanServer outer,
MBeanServerDelegate delegate) {
final MBeanServerForwarder mbsf =
MBeanServerForwarderInvocationHandler.newProxyInstance();
final MBeanServer innerMBeanServer =
inner.newMBeanServer(defaultDomain,
(outer == null ? mbsf : outer),
delegate);
mbsf.setMBeanServer(innerMBeanServer);
return mbsf;
}
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
NotificationFilterSupport clientFilter =
new NotificationFilterSupport();
clientFilter.enableType(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
MarshalledObject<NotificationFilter> sFilter =
new MarshalledObject<NotificationFilter>(clientFilter);
Integer[] listenerIDs;
final ObjectName[] names =
new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
final MarshalledObject<NotificationFilter>[] filters =
Util.cast(new MarshalledObject<?>[] {sFilter});
final Subject[] subjects = new Subject[] {null};
try {
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
}
return listenerIDs[0];
}
OldMBeanServer(String defaultDomain, MBeanServerDelegate delegate) {
this.defaultDomain = defaultDomain;
this.delegate = delegate;
try {
registerMBean(delegate, MBeanServerDelegate.DELEGATE_NAME);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private void snoopOnUnregister(NotificationResult nr) {
List<IdAndFilter> copy = null;
synchronized (listenerMap) {
Set<IdAndFilter> delegateSet = listenerMap.get(MBeanServerDelegate.DELEGATE_NAME);
if (delegateSet == null || delegateSet.isEmpty()) {
return;
}
copy = new ArrayList<>(delegateSet);
}
for (TargetedNotification tn : nr.getTargetedNotifications()) {
Integer id = tn.getListenerID();
for (IdAndFilter idaf : copy) {
if (idaf.id == id) {
// This is a notification from the MBeanServerDelegate.
Notification n = tn.getNotification();
if (n instanceof MBeanServerNotification &&
n.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
MBeanServerNotification mbsn = (MBeanServerNotification) n;
ObjectName gone = mbsn.getMBeanName();
synchronized (listenerMap) {
listenerMap.remove(gone);
}
}
}
}
}
}
OldMBeanServer(String defaultDomain, MBeanServerDelegate delegate) {
this.defaultDomain = defaultDomain;
this.delegate = delegate;
try {
registerMBean(delegate, MBeanServerDelegate.DELEGATE_NAME);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public void unregisterMBean(ObjectName name)
throws InstanceNotFoundException, MBeanRegistrationException {
forbidJMImpl(name);
DynamicMBean mbean = getMBean(name);
if (mbean == null)
throw new InstanceNotFoundException(name.toString());
MBeanRegistration reg = mbeanRegistration(mbean);
try {
reg.preDeregister();
} catch (Exception e) {
throw new MBeanRegistrationException(e);
}
if (!mbeans.remove(name, mbean))
throw new InstanceNotFoundException(name.toString());
// This is incorrect because we've invoked preDeregister
Object userMBean = getUserMBean(mbean);
if (userMBean instanceof ClassLoader)
clr.removeLoader((ClassLoader) userMBean);
Notification n = new MBeanServerNotification(
MBeanServerNotification.REGISTRATION_NOTIFICATION,
MBeanServerDelegate.DELEGATE_NAME,
0,
name);
delegate.sendNotification(n);
reg.postDeregister();
}