User: ejort
Date: 02/04/20 09:31:00
Modified: src/main/org/jboss/mx/server/registry
BasicMBeanRegistry.java MBeanEntry.java
MBeanRegistry.java ManagedMBeanRegistry.java
Log:
Allow generic data to be stored with an MBeans registration. Fixed the double
creation of the MBeanRegistry. Synchronized the long sequence numbers in the MBean
Registry
Revision Changes Path
1.16 +31 -12
jmx/src/main/org/jboss/mx/server/registry/BasicMBeanRegistry.java
Index: BasicMBeanRegistry.java
===================================================================
RCS file:
/cvsroot/jboss/jmx/src/main/org/jboss/mx/server/registry/BasicMBeanRegistry.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- BasicMBeanRegistry.java 15 Apr 2002 02:48:52 -0000 1.15
+++ BasicMBeanRegistry.java 20 Apr 2002 16:31:00 -0000 1.16
@@ -43,14 +43,13 @@
* directly, please check any changes for performance.
*
* @todo JMI_DOMAIN isn't very protected
- * @todo check race conditions for MT (un)registerMBean (uses long types)
*
* @see org.jboss.mx.server.registry.MBeanRegistry
*
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>.
* @author <a href="mailto:[EMAIL PROTECTED]">Trevor Squires</a>.
* @author <a href="mailto:[EMAIL PROTECTED]">Adrian Brock</a>.
- * @version $Revision: 1.15 $
+ * @version $Revision: 1.16 $
*/
public class BasicMBeanRegistry
implements MBeanRegistry
@@ -112,9 +111,6 @@
*/
public BasicMBeanRegistry(MBeanServer server, String defaultDomain)
{
- //Uncomment to see 2 instances being created
- //System.out.println("creating a BasicMBeanRegistry");
- //new Exception("STACK TRACE").printStackTrace();
// Stored the context
this.server = server;
this.defaultDomain = defaultDomain;
@@ -123,8 +119,10 @@
try
{
this.delegate = new MBeanServerDelegate();
+ HashMap valueMap = new HashMap();
+ valueMap.put(JMI_DOMAIN, JMI_DOMAIN);
registerMBean(delegate, new ObjectName(MBEAN_SERVER_DELEGATE),
- null, JMI_DOMAIN);
+ valueMap);
}
catch (MalformedObjectNameException e)
{
@@ -151,7 +149,9 @@
Class mbean = cl.loadClass(loaderClassMBeanName);
//there must be a class with the MBean extension.
ObjectName loaderName = new ObjectName(DEFAULT_LOADER_NAME);
- registerMBean(loaderRepository, loaderName, null, JMI_DOMAIN);
+ HashMap valueMap = new HashMap();
+ valueMap.put(JMI_DOMAIN, JMI_DOMAIN);
+ registerMBean(loaderRepository, loaderName, valueMap);
}
catch (Exception e)
{
@@ -166,7 +166,7 @@
// MBeanRegistry Implementation ----------------------------------
public ObjectInstance registerMBean(Object object, ObjectName name,
- ClassLoader cl, Object magicToken)
+ Map valueMap)
throws InstanceAlreadyExistsException,
MBeanRegistrationException,
NotCompliantMBeanException
@@ -228,7 +228,10 @@
}
// This is the final check of the name
- regName = validateAndQualifyName(regName, (String)magicToken);
+ String magicToken = null;
+ if (valueMap != null)
+ magicToken = (String) valueMap.remove(JMI_DOMAIN);
+ regName = validateAndQualifyName(regName, magicToken);
try
{
@@ -240,7 +243,7 @@
else
invoker = (DynamicMBean) object;
- MBeanEntry entry = new MBeanEntry(regName, invoker, object, cl);
+ MBeanEntry entry = new MBeanEntry(regName, invoker, object, valueMap);
add(entry);
try
@@ -251,10 +254,15 @@
try
{
+ long sequence;
+ synchronized (this)
+ {
+ sequence = registrationNotificationSequence++;
+ }
delegate.sendNotification(
new MBeanServerNotification(
MBeanServerNotification.REGISTRATION_NOTIFICATION,
- delegate, registrationNotificationSequence++, regName));
+ delegate, sequence, regName));
return new ServerObjectInstance(regName,
entry.getResourceClassName(),
delegate.getMBeanServerId());
@@ -373,11 +381,16 @@
// It is no longer registered
remove(name);
+ long sequence;
+ synchronized (this)
+ {
+ sequence = unregistrationNotificationSequence++;
+ }
delegate.sendNotification(
new MBeanServerNotification(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION,
delegate,
- unregistrationNotificationSequence++,
+ sequence,
name
)
);
@@ -423,6 +436,12 @@
return new ServerObjectInstance(qualifyName(name),
get(name).getResourceClassName(), delegate.getMBeanServerId());
+ }
+
+ public synchronized Object getValue(ObjectName name, String key)
+ throws InstanceNotFoundException
+ {
+ return get(name).getValue(key);
}
public synchronized boolean contains(ObjectName name)
1.8 +31 -4 jmx/src/main/org/jboss/mx/server/registry/MBeanEntry.java
Index: MBeanEntry.java
===================================================================
RCS file: /cvsroot/jboss/jmx/src/main/org/jboss/mx/server/registry/MBeanEntry.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- MBeanEntry.java 1 Mar 2002 19:25:58 -0000 1.7
+++ MBeanEntry.java 20 Apr 2002 16:31:00 -0000 1.8
@@ -6,10 +6,14 @@
*/
package org.jboss.mx.server.registry;
+import org.jboss.mx.server.ServerConstants;
+
import javax.management.DynamicMBean;
import javax.management.ObjectName;
import javax.management.MBeanRegistration;
+import java.util.Map;
+
/**
* info@todo this docs
*
@@ -17,9 +21,10 @@
* @see org.jboss.mx.server.MBeanServerImpl
*
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>.
- * @version $Revision: 1.7 $
+ * @version $Revision: 1.8 $
*/
public class MBeanEntry
+ implements ServerConstants
{
// Attributes ----------------------------------------------------
@@ -48,6 +53,11 @@
*/
private ClassLoader cl = null;
+ /**
+ * The value map of the mbean
+ */
+ private Map valueMap = null;
+
// Constructors --------------------------------------------------
/**
@@ -56,16 +66,20 @@
* @param objectName the name with which the mbean is registered
* @param invoker the dynamic mbean used to invoke the mbean
* @param object the mbean
- * @param cl the thread context classloader with which to invoke the mbean
+ * @param valueMap any other information to include in the registration
*/
public MBeanEntry(ObjectName objectName, DynamicMBean invoker,
- Object resource, ClassLoader cl)
+ Object resource, Map valueMap)
{
this.objectName = objectName;
this.invoker = invoker;
this.resourceClassName = resource.getClass().getName();
this.resource = resource;
- this.cl = cl;
+ this.valueMap = valueMap;
+
+ // Adrian: Unpack the classloader because this is used alot
+ if (valueMap != null)
+ this.cl = (ClassLoader) valueMap.get(CLASSLOADER);
}
// Public --------------------------------------------------------
@@ -118,5 +132,18 @@
public ClassLoader getClassLoader()
{
return cl;
+ }
+
+ /**
+ * Retrieve a value from the map.
+ *
+ * @return key the key to value
+ * @return the value or null if there is no entry
+ */
+ public Object getValue(String key)
+ {
+ if (valueMap != null)
+ return valueMap.get(key);
+ return null;
}
}
1.5 +29 -6 jmx/src/main/org/jboss/mx/server/registry/MBeanRegistry.java
Index: MBeanRegistry.java
===================================================================
RCS file:
/cvsroot/jboss/jmx/src/main/org/jboss/mx/server/registry/MBeanRegistry.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MBeanRegistry.java 14 Apr 2002 15:28:07 -0000 1.4
+++ MBeanRegistry.java 20 Apr 2002 16:31:00 -0000 1.5
@@ -15,6 +15,8 @@
import java.util.List;
+import java.util.Map;
+
import org.jboss.mx.server.ServerConstants;
/**
@@ -29,7 +31,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>.
* @author <a href="mailto:[EMAIL PROTECTED]">Trevor Squires</a>.
* @author <a href="mailto:[EMAIL PROTECTED]">Adrian Brock</a>.
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*
* @see MBeanEntry
*/
@@ -44,11 +46,22 @@
*
* The object name passed maybe unqualified.<p>
*
- * Pass {@link ServerConstants#JMI_DOMAIN JMI_DOMAIN} in the magic token to
- * get access to the reserved domain
+ * The map is a user definable string to value object map for holding
+ * information against a registered object.<p>
+ *
+ * Pass {@link ServerConstants#JMI_DOMAIN JMI_DOMAIN} in both the key and values
+ * of the values map to get access to the reserved domain. It is removed
+ * from the map during registration to save memory.<p>
+ * Pass {@link ServerConstants#CLASSLOADER CLASSLOADER} in the values map to
+ * set the context classloader<p>
+ *
+ * Other values are user definable and can be retrieved using the
+ * getValue(ObjectName,String) method.
*
* @param object the mbean to register.
* @param name the object name to assign to the mbean.
+ * @param valueMap a map of other information to include in the
+ * registry
* @param cl the thread classloader used to invoke the mbean
* @param magicToken used to get access to the JMImplementation domain
* @return an object instance for the registered mbean
@@ -62,8 +75,7 @@
* IllegalArgumentException for another problem with the name
* or a null object
*/
- ObjectInstance registerMBean(Object object, ObjectName name, ClassLoader cl,
- Object magicToken)
+ ObjectInstance registerMBean(Object object, ObjectName name, Map valueMap)
throws InstanceAlreadyExistsException,
MBeanRegistrationException,
NotCompliantMBeanException;
@@ -112,7 +124,6 @@
*/
String getDefaultDomain();
-
/**
* Retrieve the object instance for an object name.
*
@@ -122,6 +133,18 @@
* registered
*/
public ObjectInstance getObjectInstance(ObjectName name)
+ throws InstanceNotFoundException;
+
+ /**
+ * Retrieve a value from the registration.
+ *
+ * @param name the object name of the mbean
+ * @param key the key to the value
+ * @return the value or null if there is no such value
+ * @exception InstanceNotFoundException when the object name is not
+ * registered
+ */
+ public Object getValue(ObjectName name, String key)
throws InstanceNotFoundException;
/**
1.3 +43 -13
jmx/src/main/org/jboss/mx/server/registry/ManagedMBeanRegistry.java
Index: ManagedMBeanRegistry.java
===================================================================
RCS file:
/cvsroot/jboss/jmx/src/main/org/jboss/mx/server/registry/ManagedMBeanRegistry.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ManagedMBeanRegistry.java 14 Apr 2002 17:20:29 -0000 1.2
+++ ManagedMBeanRegistry.java 20 Apr 2002 16:31:00 -0000 1.3
@@ -25,12 +25,15 @@
import javax.management.modelmbean.ModelMBeanOperationInfo;
import javax.management.modelmbean.RequiredModelMBean;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* A managed version of the MBean registry. It registers itself as an
* mbean, exposing methods and attributes for management.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adrian Brock</a>.
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class ManagedMBeanRegistry
extends BasicMBeanRegistry
@@ -111,16 +114,10 @@
),
new MBeanParameterInfo
(
- "ClassLoader",
- ClassLoader.class.getName(),
- "The context classloader for the MBean"
+ "ValueMap",
+ Map.class.getName(),
+ "Values associated with the registration"
),
- new MBeanParameterInfo
- (
- "Magic",
- Object.class.getName(),
- "A magic token used to register into the JMImplementation Domain"
- )
};
ModelMBeanOperationInfo registerMBeanInfo =
new ModelMBeanOperationInfo
@@ -176,6 +173,37 @@
descGetSize
);
+ // getValue operation
+ DescriptorSupport descGetValue = new DescriptorSupport();
+ descGetValue.setField("name", "getValue");
+ descGetValue.setField("descriptorType", "operation");
+ descGetValue.setField("role", "operation");
+ MBeanParameterInfo[] getValueParms = new MBeanParameterInfo[]
+ {
+ new MBeanParameterInfo
+ (
+ "ObjectName",
+ ObjectName.class.getName(),
+ "The object name of the registered MBean"
+ ),
+ new MBeanParameterInfo
+ (
+ "Key",
+ String.class.getName(),
+ "The key to the value stored"
+ )
+ };
+ ModelMBeanOperationInfo getValueInfo =
+ new ModelMBeanOperationInfo
+ (
+ "getValue",
+ "Get a value stored in the MBean's registration",
+ getValueParms,
+ Object.class.getName(),
+ ModelMBeanOperationInfo.INFO,
+ descGetValue
+ );
+
// Construct the modelmbean
DescriptorSupport descMBean = new DescriptorSupport();
descMBean.setField("name", "MBeanRegistry");
@@ -194,7 +222,8 @@
{
registerMBeanInfo,
unregisterMBeanInfo,
- getSizeInfo
+ getSizeInfo,
+ getValueInfo
},
(ModelMBeanNotificationInfo[]) null,
descMBean
@@ -204,8 +233,9 @@
registry.setManagedResource(this, "ObjectReference");
// Register it
- registerMBean(registry, new ObjectName(MBEAN_REGISTRY), null,
- JMI_DOMAIN);
+ HashMap valueMap = new HashMap();
+ valueMap.put(JMI_DOMAIN, JMI_DOMAIN);
+ registerMBean(registry, new ObjectName(MBEAN_REGISTRY), valueMap);
}
catch (MalformedObjectNameException e)
{
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development