@Override
  protected void executeReadAttribute(OperationContext context, ModelNode operation)
      throws OperationFailedException {

    final String gcName =
        PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR))
            .getLastElement()
            .getValue();
    final String name = operation.require(ModelDescriptionConstants.NAME).asString();

    GarbageCollectorMXBean gcMBean = null;

    for (GarbageCollectorMXBean mbean : ManagementFactory.getGarbageCollectorMXBeans()) {
      if (gcName.equals(escapeMBeanName(mbean.getName()))) {
        gcMBean = mbean;
      }
    }

    if (gcMBean == null) {
      throw PlatformMBeanLogger.ROOT_LOGGER.unknownGarbageCollector(gcName);
    }

    if (PlatformMBeanConstants.OBJECT_NAME.getName().equals(name)) {
      final String objName =
          PlatformMBeanUtil.getObjectNameStringWithNameKey(
              ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE, gcName);
      context.getResult().set(objName);
    } else if (ModelDescriptionConstants.NAME.equals(name)) {
      context.getResult().set(escapeMBeanName(gcMBean.getName()));
    } else if (PlatformMBeanConstants.VALID.getName().equals(name)) {
      context.getResult().set(gcMBean.isValid());
    } else if (PlatformMBeanConstants.MEMORY_POOL_NAMES.equals(name)) {
      final ModelNode result = context.getResult();
      result.setEmptyList();
      for (String pool : gcMBean.getMemoryPoolNames()) {
        result.add(escapeMBeanName(pool));
      }
    } else if (PlatformMBeanConstants.COLLECTION_COUNT.equals(name)) {
      context.getResult().set(gcMBean.getCollectionCount());
    } else if (PlatformMBeanConstants.COLLECTION_TIME.equals(name)) {
      context.getResult().set(gcMBean.getCollectionTime());
    } else if (GarbageCollectorResourceDefinition.GARBAGE_COLLECTOR_READ_ATTRIBUTES.contains(name)
        || GarbageCollectorResourceDefinition.GARBAGE_COLLECTOR_METRICS.contains(name)) {
      // Bug
      throw PlatformMBeanLogger.ROOT_LOGGER.badReadAttributeImpl(name);
    } else {
      // Shouldn't happen; the global handler should reject
      throw unknownAttribute(operation);
    }
  }
  @Override
  protected void executeReadAttribute(OperationContext context, ModelNode operation)
      throws OperationFailedException {

    final String mmName =
        PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR))
            .getLastElement()
            .getValue();
    final String name = operation.require(ModelDescriptionConstants.NAME).asString();

    MemoryManagerMXBean memoryManagerMXBean = null;

    for (MemoryManagerMXBean mbean : ManagementFactory.getMemoryManagerMXBeans()) {
      if (mmName.equals(escapeMBeanName(mbean.getName()))) {
        memoryManagerMXBean = mbean;
      }
    }

    if (memoryManagerMXBean == null) {
      throw PlatformMBeanMessages.MESSAGES.unknownMemoryManager(mmName);
    }

    if (PlatformMBeanUtil.JVM_MAJOR_VERSION > 6
        && PlatformMBeanConstants.OBJECT_NAME.equals(name)) {
      final String objName =
          PlatformMBeanUtil.getObjectNameStringWithNameKey(
              ManagementFactory.MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE, mmName);
      context.getResult().set(objName);
    } else if (ModelDescriptionConstants.NAME.equals(name)) {
      context.getResult().set(escapeMBeanName(memoryManagerMXBean.getName()));
    } else if (PlatformMBeanConstants.VALID.equals(name)) {
      context.getResult().set(memoryManagerMXBean.isValid());
    } else if (PlatformMBeanConstants.MEMORY_POOL_NAMES.equals(name)) {
      final ModelNode result = context.getResult();
      result.setEmptyList();
      for (String pool : memoryManagerMXBean.getMemoryPoolNames()) {
        result.add(escapeMBeanName(pool));
      }
    } else if (PlatformMBeanConstants.MEMORY_MANAGER_READ_ATTRIBUTES.contains(name)) {
      // Bug
      throw PlatformMBeanMessages.MESSAGES.badReadAttributeImpl5(name);
    } else {
      // Shouldn't happen; the global handler should reject
      throw unknownAttribute(operation);
    }
  }