public void unregister(Object statsProvider) {
    // Unregisters the statsProvider
    try {
      StatsProviderRegistryElement spre =
          statsProviderRegistry.getStatsProviderRegistryElement(statsProvider);
      if (spre == null) {
        logger.log(
            Level.INFO, invalidStatsProvider, new Object[] {statsProvider.getClass().getName()});
        return;
      }

      // get the Parent node and delete all children nodes (only that we know of)
      String parentNodePath = spre.getParentTreeNodePath();
      List<String> childNodeNames = spre.getChildTreeNodeNames();
      TreeNode rootNode = mrdr.get(instanceName);
      if ((rootNode != null) && (parentNodePath != null)) {
        // This has to return one node
        List<TreeNode> nodeList = rootNode.getNodes(parentNodePath, false, true);
        if (nodeList.size() > 0) {
          TreeNode parentNode = nodeList.get(0);
          // Remove each of the child nodes
          Collection<TreeNode> childNodes = parentNode.getChildNodes();
          for (TreeNode childNode : childNodes) {
            if (childNodeNames.contains(childNode.getName())) {
              parentNode.removeChild(childNode);
            }
          }
          if (!parentNode.hasChildNodes()) removeParentNode(parentNode);
        }
      }

      // get the handles and unregister the listeners from Flashlight
      Collection<ProbeClientMethodHandle> handles = spre.getHandles();
      if (handles != null) {
        for (ProbeClientMethodHandle handle : handles) {
          // handle.remove????? Mahesh?
          // TODO IMPLEMENTATION
          // For now disable the handle => remove the client from invokerlist
          handle.disable();
        }
      }

      // unregister the statsProvider from Gmbal
      if (spre.getManagedObjectManager() != null) unregisterGmbal(spre);

      // Unregister from the MonitoringDataTreeRegistry and the map entries
      statsProviderRegistry.unregisterStatsProvider(statsProvider);
    } catch (Exception ex) {
      String msg =
          MessageFormat.format(errorUnregisteringStatsProvider, statsProvider.getClass().getName());
      logger.log(Level.SEVERE, msg, ex);
    }
  }
 /* called from SPMD, when monitoring-enabled flag is turned off */
 public void disableAllStatsProviders() {
   // Looks like the monitoring-enabled flag is just turned OFF. Disable all the statsProviders
   // which were on
   for (String configElement : statsProviderRegistry.getConfigElementList()) {
     Collection<StatsProviderRegistryElement> spreList =
         statsProviderRegistry.getStatsProviderRegistryElement(configElement);
     for (StatsProviderRegistryElement spre : spreList) {
       if (spre.isEnabled) {
         disableStatsProvider(spre);
       }
     }
   }
 }
 /* called from SMPD, when monitoring level for a module is turned on */
 public void enableStatsProviders(String configElement) {
   // If monitoring-enabled is false, just return
   if (!getMonitoringEnabled()) return;
   String configLevel = getMonitoringLevel(configElement);
   // Enable all the StatsProviders for a given configElement
   if (logger.isLoggable(Level.FINE))
     logger.fine("Enabling all the statsProviders for - " + configElement);
   List<StatsProviderRegistryElement> spreList =
       statsProviderRegistry.getStatsProviderRegistryElement(configElement);
   if (spreList == null) return;
   for (StatsProviderRegistryElement spre : spreList) {
     // Check to see if the enable is allowed
     // Not allowed if statsProvider is registered for Low and configLevel is HIGH
     boolean isEnableAllowed = spre.isEnableAllowed(configLevel);
     if (!spre.isEnabled()) {
       // OFF->LOW, OFF->HIGH
       if (isEnableAllowed) {
         enableStatsProvider(spre);
       }
     } else {
       // Disable if the stats were enabled, but current level is not allowed for these
       // stats(HIGH->LOW) and
       // stats were registered at HIGH
       if (!isEnableAllowed) {
         disableStatsProvider(spre);
       } // else, Dont do anything LOW->HIGH (stats were registered at LOW)
     }
   }
 }
 // Called when AMX DomainRoot is loaded (when jconsole or gui is started)
 // Register statsProviders with gmbal whose configElement is enabled
 // Save mom in the spre.  Used in unregister with gmbal later for config change to OFF or undeploy
 // Set AMXReady flag to true
 @Override
 public void mbeanRegistered(final ObjectName objectName, final MBeanListener listener) {
   super.mbeanRegistered(objectName, listener);
   AMXReady = true;
   statsProviderRegistry.setAMXReady(true);
   if (this.getMbeanEnabledValue()) {
     for (StatsProviderRegistry.StatsProviderRegistryElement spre :
         statsProviderRegistry.getSpreList()) {
       if (spre.isEnabled()) {
         ManagedObjectManager mom = spre.getManagedObjectManager();
         if (mom == null) {
           mom = registerGmbal(spre.getStatsProvider(), spre.getMBeanName());
           spre.setManagedObjectManager(mom);
         }
       }
     }
   }
 }
  /* called from SPMD, when monitoring-enabled flag is turned on */
  public void updateAllStatsProviders() {
    // Looks like the monitoring-enabled flag is just turned ON. Lets do the catchup
    for (String configElement : statsProviderRegistry.getConfigElementList()) {
      Collection<StatsProviderRegistryElement> spreList =
          statsProviderRegistry.getStatsProviderRegistryElement(configElement);
      boolean isConfigEnabled = getEnabledValue(configElement);
      // Continue with the next configElement if this is not enabled
      if (!isConfigEnabled) continue;

      for (StatsProviderRegistryElement spre : spreList) {
        // Assuming the spre's are disabled to start with
        boolean isEnableAllowed = spre.isEnableAllowed(getMonitoringLevel(configElement));
        if (isEnableAllowed) {
          enableStatsProvider(spre);
        }
      }
    }
  }
  public void unregisterAllGmbal() {
    /* We do this when the mbean-enabled is turned off from on */

    if (logger.isLoggable(Level.FINE))
      logger.fine("Unregistering all the statsProviders whose enabled flag is 'off' with Gmbal");
    for (StatsProviderRegistryElement spre : statsProviderRegistry.getSpreList()) {
      if (spre.isEnabled()) {
        unregisterGmbal(spre);
      }
    }
  }
 public boolean isStatsProviderRegistered(Object statsProvider, String subTreePath) {
   boolean isStatsProviderRegistered = false;
   Collection<StatsProviderRegistry.StatsProviderRegistryElement> spreList =
       statsProviderRegistry.getSpreList();
   for (StatsProviderRegistry.StatsProviderRegistryElement spre : spreList) {
     if (spre.getStatsProvider().equals(statsProvider)
         && spre.getMBeanName().equals(subTreePath)) {
       isStatsProviderRegistered = true;
     }
   }
   return isStatsProviderRegistered;
 }
  /* throws RuntimeException maybe
   * note the default visibility so that MonitoringBootstrap can call it.
   */
  void tryToRegister(StatsProviderInfo spInfo) {
    final String configElement = spInfo.getConfigElement();
    Object statsProvider = spInfo.getStatsProvider();
    // register the statsProvider
    if (logger.isLoggable(Level.FINE)) logger.fine("registering a statsProvider");
    StatsProviderRegistryElement spre;
    // If configElement is null, create it
    if (monitoringService != null
        && monitoringService.getContainerMonitoring(configElement) == null
        && monitoringService.getMonitoringLevel(configElement) == null) {
      createConfigElement(configElement);
    }

    // First check if the configElement associated for statsProvider is 'ON'
    if (getMonitoringEnabled() && getEnabledValue(configElement)) {
      if (logger.isLoggable(Level.FINE)) logger.fine(" enabled is true ");
      spre = statsProviderRegistry.getStatsProviderRegistryElement(statsProvider);

      if (spre == null) {
        statsProviderRegistry.registerStatsProvider(spInfo);
        spre = statsProviderRegistry.getStatsProviderRegistryElement(statsProvider);
      }
      // Enable the StatsProvider if the enable is allowed
      if (spre.isEnableAllowed(getMonitoringLevel(configElement))) {
        enableStatsProvider(spre);
      }

    } else {
      if (logger.isLoggable(Level.FINE)) logger.fine(" enabled is false ");
      // Register with null values so to know that we need to register them individually and config
      // is on
      statsProviderRegistry.registerStatsProvider(spInfo);
      spre = statsProviderRegistry.getStatsProviderRegistryElement(statsProvider);
    }

    if (logger.isLoggable(Level.FINE)) {
      logger.fine(spre.toString());
      logger.fine("=========================================================");
    }
  }
  public void registerAllGmbal() {
    /* We do this when the mbean-enabled is turned on from off */

    if (logger.isLoggable(Level.FINE))
      logger.fine("Registering all the statsProviders whose enabled flag is 'on' with Gmbal");
    for (StatsProviderRegistryElement spre : statsProviderRegistry.getSpreList()) {
      if (spre.isEnabled()) {
        ManagedObjectManager mom = spre.getManagedObjectManager();
        if (mom == null) {
          mom = registerGmbal(spre.getStatsProvider(), spre.getMBeanName());
          spre.setManagedObjectManager(mom);
        }
      }
    }
  }
 /* called from SMPD, when monitoring level for a module is turned off */
 public void disableStatsProviders(String configElement) {
   // I think we should still disable even when monitoring-enabled is false
   /*
   //If monitoring-enabled is false, just return
   if (!getMonitoringEnabled())
   return;
   */
   // Disable all the StatsProviders for a given configElement
   if (logger.isLoggable(Level.FINE))
     logger.fine("Disabling all the statsProviders for - " + configElement);
   List<StatsProviderRegistryElement> spreList =
       statsProviderRegistry.getStatsProviderRegistryElement(configElement);
   if (spreList == null) return;
   for (StatsProviderRegistryElement spre : spreList) {
     if (spre.isEnabled()) disableStatsProvider(spre);
   }
 }