static ObjectName createMBean(ManagedResource resource, ManagedBean managed) {

    try {
      DynamicManagedBean mb = new DynamicManagedBean(managed);
      resource.setModelMBean(mb.createMBean(resource));

      // create the ObjectName and register the MBean...
      final ObjectName objName;
      try {
        objName = ObjectName.getInstance(resource.getMBeanName());
      } catch (MalformedObjectNameException e) {
        throw new MalformedObjectNameException(String.format("%s in '%s'",
            e.getMessage(), resource.getMBeanName()));
      }

      synchronized (MBeanUtils.class) {
        // Only register a bean once. Otherwise, you risk race
        // conditions with things like the RMI connector accessing it.

        if (mbeanServer != null && !mbeanServer.isRegistered(objName)) {
          mbeanServer.registerMBean(resource.getModelMBean(), objName);
          synchronized (managedResources) {
            managedResources.put(objName, resource);
          }
        }
      }
      return objName;
    } catch (java.lang.Exception e) {
      throw new RuntimeAdminException(
          String.format("Failed to create MBean representation for resource %s.",
              resource.getMBeanName()),
          e);
    }
  }
Creates and registers a <code>ModelMBean</code> for the specified <code>ManagedResource</code>.
State changing callbacks into the <code>ManagedResource</code> will also be made.

@param resource the ManagedResource to create a managing MBean for
@param managed the ManagedBean definition to create the MBean with
@see ManagedResource#setModelMBean
geode-core/src/main/java/org/apache/geode/admin/jmx/internal/MBeanUtils.java