summaryrefslogtreecommitdiff
path: root/gnu/javax/management/Server.java
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/javax/management/Server.java')
-rw-r--r--gnu/javax/management/Server.java63
1 files changed, 50 insertions, 13 deletions
diff --git a/gnu/javax/management/Server.java b/gnu/javax/management/Server.java
index 049b0e360..5501b4af7 100644
--- a/gnu/javax/management/Server.java
+++ b/gnu/javax/management/Server.java
@@ -104,11 +104,16 @@ public class Server
{
/**
+ * The name of the delegate bean.
+ */
+ private static final ObjectName DELEGATE_NAME;
+
+ /**
* The registered beans, represented as a map of
* {@link javax.management.ObjectName}s to
* {@link java.lang.Object}s.
*/
- private Map beans;
+ private final Map beans = new HashMap();
/**
* The default domain.
@@ -121,11 +126,6 @@ public class Server
private MBeanServer outer;
/**
- * The delegate bean.
- */
- private MBeanServerDelegate delegate;
-
- /**
* The class loader repository.
*/
private ClassLoaderRepository repository;
@@ -137,6 +137,24 @@ public class Server
private Map listeners;
/**
+ * Initialise the delegate name.
+ */
+ static
+ {
+ try
+ {
+ DELEGATE_NAME =
+ new ObjectName("JMImplementation:type=MBeanServerDelegate");
+ }
+ catch (MalformedObjectNameException e)
+ {
+ throw (Error)
+ (new InternalError("Failed to construct " +
+ "the delegate's object name.").initCause(e));
+ }
+ }
+
+ /**
* Constructs a new management server using the specified
* default domain, delegate bean and outer server.
*
@@ -153,7 +171,28 @@ public class Server
{
this.defaultDomain = defaultDomain;
this.outer = outer;
- this.delegate = delegate;
+ try
+ {
+ registerMBean(delegate, DELEGATE_NAME);
+ }
+ catch (InstanceAlreadyExistsException e)
+ {
+ throw (Error)
+ (new InternalError("The delegate bean is " +
+ "already registered.").initCause(e));
+ }
+ catch (MBeanRegistrationException e)
+ {
+ throw (Error)
+ (new InternalError("The delegate bean's preRegister " +
+ "methods threw an exception.").initCause(e));
+ }
+ catch (NotCompliantMBeanException e)
+ {
+ throw (Error)
+ (new InternalError("The delegate bean is " +
+ "not compliant.").initCause(e));
+ }
}
/**
@@ -1646,9 +1685,7 @@ public class Server
throw new MBeanRegistrationException(e, "Pre-registration failed.");
}
}
- if (beans == null)
- beans = new HashMap();
- else if (beans.containsKey(name))
+ if (beans.containsKey(name))
{
if (register != null)
register.postRegister(Boolean.FALSE);
@@ -2021,14 +2058,14 @@ public class Server
new IllegalArgumentException("The name was null.");
throw new RuntimeOperationsException(e);
}
- Object bean = getBean(name);
- checkSecurity(name, null, "unregisterMBean");
- if (bean == delegate)
+ if (name.equals(DELEGATE_NAME))
{
RuntimeException e =
new IllegalArgumentException("The delegate can not be unregistered.");
throw new RuntimeOperationsException(e);
}
+ Object bean = getBean(name);
+ checkSecurity(name, null, "unregisterMBean");
MBeanRegistration register = null;
if (bean instanceof MBeanRegistration)
{