Skip to content

Commit aa8bd63

Browse files
committed
added "unregisterManagedResource" method to MBeanExporter/MBeanExportOperations (SPR-5517)
1 parent 5885c70 commit aa8bd63

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

org.springframework.context/src/main/java/org/springframework/jmx/export/MBeanExportOperations.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2005 the original author or authors.
2+
* Copyright 2002-2009 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -54,4 +54,10 @@ public interface MBeanExportOperations {
5454
*/
5555
void registerManagedResource(Object managedResource, ObjectName objectName) throws MBeanExportException;
5656

57+
/**
58+
* Remove the specified MBean from the underlying MBeanServer registry.
59+
* @param objectName the {@link ObjectName} of the resource to remove
60+
*/
61+
void unregisterManagedResource(ObjectName objectName);
62+
5763
}

org.springframework.context/src/main/java/org/springframework/jmx/export/MBeanExporter.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,19 @@
6666
import org.springframework.util.ObjectUtils;
6767

6868
/**
69-
* JMX exporter that allows for exposing any <i>Spring-managed bean</i>
70-
* to a JMX <code>MBeanServer</code>, without the need to define any
69+
* JMX exporter that allows for exposing any <i>Spring-managed bean</i> to a
70+
* JMX {@link javax.management.MBeanServer}, without the need to define any
7171
* JMX-specific information in the bean classes.
7272
*
73-
* <p>If the bean implements one of the JMX management interfaces,
74-
* then MBeanExporter can simply register the MBean with the server
75-
* automatically, through its autodetection process.
73+
* <p>If a bean implements one of the JMX management interfaces, MBeanExporter can
74+
* simply register the MBean with the server through its autodetection process.
7675
*
77-
* <p>If the bean does not implement one of the JMX management interfaces,
78-
* then MBeanExporter will create the management information using the
79-
* supplied {@link MBeanInfoAssembler} implementation.
76+
* <p>If a bean does not implement one of the JMX management interfaces, MBeanExporter
77+
* will create the management information using the supplied {@link MBeanInfoAssembler}.
8078
*
81-
* <p>A list of {@link MBeanExporterListener MBeanExporterListeners}
82-
* can be registered via the
83-
* {@link #setListeners(MBeanExporterListener[]) listeners} property,
84-
* allowing application code to be notified of MBean registration and
85-
* unregistration events.
79+
* <p>A list of {@link MBeanExporterListener MBeanExporterListeners} can be registered
80+
* via the {@link #setListeners(MBeanExporterListener[]) listeners} property, allowing
81+
* application code to be notified of MBean registration and unregistration events.
8682
*
8783
* <p>This exporter is compatible with JMX 1.2 on Java 5 and above.
8884
* As of Spring 2.5, it also autodetects and exports Java 6 MXBeans.
@@ -442,7 +438,7 @@ public void destroy() {
442438

443439
public ObjectName registerManagedResource(Object managedResource) throws MBeanExportException {
444440
Assert.notNull(managedResource, "Managed resource must not be null");
445-
ObjectName objectName = null;
441+
ObjectName objectName;
446442
try {
447443
objectName = getObjectName(managedResource, null);
448444
if (this.ensureUniqueRuntimeObjectNames) {
@@ -475,6 +471,11 @@ public void registerManagedResource(Object managedResource, ObjectName objectNam
475471
}
476472
}
477473

474+
public void unregisterManagedResource(ObjectName objectName) {
475+
Assert.notNull(objectName, "ObjectName must not be null");
476+
doUnregister(objectName);
477+
}
478+
478479

479480
//---------------------------------------------------------------------
480481
// Exporter implementation

0 commit comments

Comments
 (0)