diff --git a/bindings/java/src/org/hyperic/sigar/jmx/AbstractMBean.java b/bindings/java/src/org/hyperic/sigar/jmx/AbstractMBean.java
index fd38b172..96d876af 100644
--- a/bindings/java/src/org/hyperic/sigar/jmx/AbstractMBean.java
+++ b/bindings/java/src/org/hyperic/sigar/jmx/AbstractMBean.java
@@ -24,8 +24,6 @@ import javax.management.AttributeNotFoundException;
import javax.management.DynamicMBean;
import javax.management.MBeanException;
import javax.management.MBeanRegistration;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
import javax.management.ReflectionException;
import org.hyperic.sigar.Sigar;
@@ -43,7 +41,7 @@ import org.hyperic.sigar.SigarProxy;
* @author Bjoern Martin
* @since 1.5
*/
-public abstract class AbstractMBean implements DynamicMBean, MBeanRegistration {
+public abstract class AbstractMBean implements DynamicMBean {
public static final String MBEAN_DOMAIN = SigarInvokerJMX.DOMAIN_NAME;
public static final String MBEAN_ATTR_TYPE = SigarInvokerJMX.PROP_TYPE;
@@ -58,16 +56,6 @@ public abstract class AbstractMBean implements DynamicMBean, MBeanRegistration {
*/
protected final SigarProxy sigar;
- /**
- * The MBean server this MBean is registered to. Set during the MBean's
- * registration to the MBean server and unset to null
when
- * the deregistration finished.
- *
- * @see #preRegister(MBeanServer, ObjectName)
- * @see #postDeregister()
- */
- protected MBeanServer mbeanServer;
-
/**
*
Creates a new instance of this class. The SigarProxy instance is stored (and * accessible) via the {@link #sigar} member. @@ -145,59 +133,6 @@ public abstract class AbstractMBean implements DynamicMBean, MBeanRegistration { return result; } - // ------- - // Implementation of the MBeanRegistration interface - // ------- - - /** - *
Returns new ObjectName(this.getObjectName())
to guarantee
- * a reliable and reproducable object name.
Note: Make sure any subclass does a super call to this method, - * otherwise the implementation might be broken.
- * - * @see MBeanRegistration#preRegister(MBeanServer, ObjectName) - */ - public ObjectName preRegister(MBeanServer server, ObjectName name) - throws Exception { - this.mbeanServer = server; - return new ObjectName(getObjectName()); - } - - /** - * Empty implementation, allowing subclasses to ignore the interface. - * - *Note: Make sure any subclass does a super call to this method, - * otherwise the implementation might be broken.
- * - * @see MBeanRegistration#postRegister(Boolean) - */ - public void postRegister(Boolean success) { - } - - /** - * Empty implementation, allowing subclasses to ignore the interface. - * - *Note: Make sure any subclass does a super call to this method, - * otherwise the implementation might be broken.
- * - * @see MBeanRegistration#preDeregister() - */ - public void preDeregister() throws Exception { - } - - /** - * Empty implementation, allowing subclasses to ignore the interface. - * - *Note: Make sure any subclass does a super call to this method, - * otherwise the implementation might be broken.
- * - * @see MBeanRegistration#postDeregister() - */ - public void postDeregister() { - this.mbeanServer = null; - } - public void setAttribute(Attribute attr) throws AttributeNotFoundException { throw new AttributeNotFoundException(attr.getName()); } diff --git a/bindings/java/src/org/hyperic/sigar/jmx/SigarRegistry.java b/bindings/java/src/org/hyperic/sigar/jmx/SigarRegistry.java index 80b08f63..e93927d9 100644 --- a/bindings/java/src/org/hyperic/sigar/jmx/SigarRegistry.java +++ b/bindings/java/src/org/hyperic/sigar/jmx/SigarRegistry.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import javax.management.AttributeNotFoundException; import javax.management.MBeanInfo; +import javax.management.MBeanRegistration; import javax.management.MBeanServer; import javax.management.ObjectInstance; import javax.management.ObjectName; @@ -57,7 +58,7 @@ import org.hyperic.sigar.SigarProxy; * @author Bjoern Martin * @since 1.5 */ -public class SigarRegistry extends AbstractMBean { +public class SigarRegistry extends AbstractMBean implements MBeanRegistration { private static final String MBEAN_TYPE = "SigarRegistry"; @@ -79,6 +80,7 @@ public class SigarRegistry extends AbstractMBean { private final String objectName; private final ArrayList managedBeans; + private MBeanServer mbeanServer; public SigarRegistry(SigarProxy sigar) { super(sigar); @@ -117,6 +119,11 @@ public class SigarRegistry extends AbstractMBean { // ------- // Implementation of the MBeanRegistration interface // ------- + public ObjectName preRegister(MBeanServer server, ObjectName name) + throws Exception { + this.mbeanServer = server; + return new ObjectName(getObjectName()); + } /** * Registers the default set of Sigar MBeans. Before doing so, a super call @@ -127,8 +134,6 @@ public class SigarRegistry extends AbstractMBean { public void postRegister(Boolean success) { ReflectedMBean mbean; - super.postRegister(success); - if (!success.booleanValue()) return; @@ -239,8 +244,9 @@ public class SigarRegistry extends AbstractMBean { } } } + } - // do the super call - super.preDeregister(); + public void postDeregister() { + this.mbeanServer = null; } }