@Override Set<String> getChildrenNames() { final Set<String> result = new LinkedHashSet<String>(); for (GarbageCollectorMXBean mbean : ManagementFactory.getGarbageCollectorMXBeans()) { result.add(escapeMBeanName(mbean.getName())); } return result; }
private static ModelNode getDetypedMonitorInfo(final MonitorInfo monitorInfo) { final ModelNode result = getDetypedLockInfo(monitorInfo); if (monitorInfo != null) { result.get(PlatformMBeanConstants.LOCKED_STACK_DEPTH).set(monitorInfo.getLockedStackDepth()); final ModelNode frame = getDetypedStackTraceElement(monitorInfo.getLockedStackFrame()); result.get(PlatformMBeanConstants.LOCKED_STACK_FRAME).set(frame); } return result; }
public static ObjectName getObjectNameWithNameKey(final String base, final String escapedValue) throws OperationFailedException { try { return new ObjectName(getObjectNameStringWithNameKey(base, escapedValue)); } catch (MalformedObjectNameException e) { throw new OperationFailedException(new ModelNode().set(e.toString())); } }
result.get(PlatformMBeanConstants.WAITED_TIME).set(threadInfo.getWaitedTime()); result.get(PlatformMBeanConstants.WAITED_COUNT).set(threadInfo.getWaitedCount()); result.get(PlatformMBeanConstants.LOCK_INFO).set(getDetypedLockInfo(threadInfo.getLockInfo())); nullSafeSet(result.get(PlatformMBeanConstants.LOCK_NAME), threadInfo.getLockName()); result.get(PlatformMBeanConstants.LOCK_OWNER_ID).set(threadInfo.getLockOwnerId()); nullSafeSet(result.get(PlatformMBeanConstants.LOCK_OWNER_NAME), threadInfo.getLockOwnerName()); final ModelNode stack = result.get(PlatformMBeanConstants.STACK_TRACE); stack.setEmptyList(); for (StackTraceElement ste : threadInfo.getStackTrace()) { stack.add(getDetypedStackTraceElement(ste)); monitors.setEmptyList(); for (MonitorInfo monitor : threadInfo.getLockedMonitors()) { monitors.add(getDetypedMonitorInfo(monitor)); synchronizers.add(getDetypedLockInfo(lock));
static void storeResult(final String name, final ModelNode store, final MemoryPoolMXBean memoryPoolMXBean, final String memPoolName) { final String objName = PlatformMBeanUtil.getObjectNameStringWithNameKey(ManagementFactory.MEMORY_POOL_MXBEAN_DOMAIN_TYPE, memPoolName); store.set(objName); } else if (ModelDescriptionConstants.NAME.equals(name)) { store.set(escapeMBeanName(memoryPoolMXBean.getName())); } else if (PlatformMBeanConstants.TYPE.equals(name)) { store.set(memoryPoolMXBean.getType().name()); } else if (PlatformMBeanConstants.USAGE.equals(name)) { final ModelNode usage = PlatformMBeanUtil.getDetypedMemoryUsage(memoryPoolMXBean.getUsage()); store.set(usage); } else if (PlatformMBeanConstants.PEAK_USAGE.equals(name)) { final ModelNode usage = PlatformMBeanUtil.getDetypedMemoryUsage(memoryPoolMXBean.getPeakUsage()); store.set(usage); } else if (PlatformMBeanConstants.VALID.equals(name)) { store.setEmptyList(); for (String mgr : memoryPoolMXBean.getMemoryManagerNames()) { store.add(escapeMBeanName(mgr)); store.set(memoryPoolMXBean.isCollectionUsageThresholdSupported()); } else if (PlatformMBeanConstants.COLLECTION_USAGE.equals(name)) { final ModelNode usage = PlatformMBeanUtil.getDetypedMemoryUsage(memoryPoolMXBean.getCollectionUsage()); store.set(usage); } else if (PlatformMBeanConstants.MEMORY_POOL_READ_ATTRIBUTES.contains(name)
if (gcName.equals(escapeMBeanName(mbean.getName()))) { gcMBean = mbean; 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.equals(name)) { context.getResult().set(gcMBean.isValid()); result.setEmptyList(); for (String pool : gcMBean.getMemoryPoolNames()) { result.add(escapeMBeanName(pool));
@Override protected void executeReadAttribute(OperationContext context, ModelNode operation) throws OperationFailedException { final String bpName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue(); final ObjectName objectName = PlatformMBeanUtil.getObjectNameWithNameKey(PlatformMBeanConstants.BUFFER_POOL_MXBEAN_DOMAIN_TYPE, bpName); if (!ManagementFactory.getPlatformMBeanServer().isRegistered(objectName)) { throw PlatformMBeanMessages.MESSAGES.unknownBufferPool(bpName); } final String name = operation.require(ModelDescriptionConstants.NAME).asString(); if (PlatformMBeanConstants.OBJECT_NAME.equals(name)) { context.getResult().set(objectName.toString()); } else if (ModelDescriptionConstants.NAME.equals(name)) { context.getResult().set(PlatformMBeanUtil.getMBeanAttribute(objectName, "Name").toString()); } else if (PlatformMBeanConstants.COUNT.equals(name)) { context.getResult().set(Long.class.cast(PlatformMBeanUtil.getMBeanAttribute(objectName, "Count"))); } else if (PlatformMBeanConstants.MEMORY_USED.equals(name)) { context.getResult().set(Long.class.cast(PlatformMBeanUtil.getMBeanAttribute(objectName, "MemoryUsed"))); } else if (PlatformMBeanConstants.TOTAL_CAPACITY.equals(name)) { context.getResult().set(Long.class.cast(PlatformMBeanUtil.getMBeanAttribute(objectName, "TotalCapacity"))); } else if (PlatformMBeanConstants.BUFFER_POOL_METRICS.contains(name)) { // Bug throw PlatformMBeanMessages.MESSAGES.badReadAttributeImpl1(name); } else { // Shouldn't happen; the global handler should reject throw unknownAttribute(operation); } }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { lockedValidator.validate(operation); ThreadMXBean mbean = ManagementFactory.getThreadMXBean(); try { ThreadInfo[] infos = mbean.dumpAllThreads( operation.require(PlatformMBeanConstants.LOCKED_MONITORS).asBoolean(), operation.require(PlatformMBeanConstants.LOCKED_SYNCHRONIZERS).asBoolean()); final ModelNode result = context.getResult(); if (infos != null) { result.setEmptyList(); for (ThreadInfo info : infos) { result.add(PlatformMBeanUtil.getDetypedThreadInfo(info, mbean.isThreadCpuTimeSupported())); } } } catch (SecurityException e) { throw new OperationFailedException(new ModelNode().set(e.toString())); } catch (UnsupportedOperationException e) { throw new OperationFailedException(new ModelNode().set(e.toString())); } context.stepCompleted(); }
private static ModelNode getDetypedStackTraceElement(final StackTraceElement stackTraceElement) { final ModelNode result = new ModelNode(); if (stackTraceElement != null) { nullSafeSet(result.get(PlatformMBeanConstants.FILE_NAME), stackTraceElement.getFileName()); result.get(PlatformMBeanConstants.LINE_NUMBER).set(stackTraceElement.getLineNumber()); result.get(PlatformMBeanConstants.CLASS_NAME).set(stackTraceElement.getClassName()); result.get(PlatformMBeanConstants.METHOD_NAME).set(stackTraceElement.getMethodName()); result.get(PlatformMBeanConstants.NATIVE_METHOD).set(stackTraceElement.isNativeMethod()); } return result; }
@Override protected void executeReadAttribute(OperationContext context, ModelNode operation) throws OperationFailedException { final String name = operation.require(ModelDescriptionConstants.NAME).asString(); if (PlatformMBeanUtil.JVM_MAJOR_VERSION > 6 && PlatformMBeanConstants.OBJECT_NAME.equals(name)) { context.getResult().set(ManagementFactory.MEMORY_MXBEAN_NAME); } else if (PlatformMBeanConstants.OBJECT_PENDING_FINALIZATION_COUNT.equals(name)) { context.getResult().set(ManagementFactory.getMemoryMXBean().getObjectPendingFinalizationCount()); } else if (PlatformMBeanConstants.HEAP_MEMORY_USAGE.equals(name)) { final ModelNode mu = PlatformMBeanUtil.getDetypedMemoryUsage(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage()); context.getResult().set(mu); } else if (PlatformMBeanConstants.NON_HEAP_MEMORY_USAGE.equals(name)) { final ModelNode mu = PlatformMBeanUtil.getDetypedMemoryUsage(ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage()); context.getResult().set(mu); } else if (PlatformMBeanConstants.VERBOSE.equals(name)) { context.getResult().set(ManagementFactory.getMemoryMXBean().isVerbose()); } else if (PlatformMBeanConstants.MEMORY_METRICS.contains(name) || PlatformMBeanConstants.MEMORY_READ_WRITE_ATTRIBUTES.contains(name)) { // Bug throw PlatformMBeanMessages.MESSAGES.badReadAttributeImpl6(name); } else { // Shouldn't happen; the global handler should reject throw unknownAttribute(operation); } }
@Override protected void executeReadAttribute(OperationContext context, ModelNode operation) throws OperationFailedException { /** * Implementation note: This implementation uses indirect access to the mbean (i.e. via the * {@code MBeanServerConnection} API) in order to avoid adding a compile time dependency on JDK 7. If the base * JDK requirement for JBoss AS ever moves to JDK 7, this implementation can be updated to use the * {@code java.lang.management.PlatformLoggingMXBean} interface. */ final String name = operation.require(ModelDescriptionConstants.NAME).asString(); if (PlatformMBeanConstants.OBJECT_NAME.equals(name)) { context.getResult().set(PlatformMBeanConstants.PLATFORM_LOGGING_MXBEAN_NAME); } else if (PlatformMBeanConstants.LOGGER_NAMES.equals(name)) { String[] names = (String[]) PlatformMBeanUtil.getMBeanAttribute(PlatformMBeanConstants.PLATFORM_LOGGING_OBJECT_NAME, "LoggerNames"); final ModelNode result = context.getResult(); result.setEmptyList(); for (String loggerName : names) { result.add(loggerName); } } else if (PlatformMBeanConstants.LOGGING_READ_ATTRIBUTES.contains(name)) { // Bug throw PlatformMBeanMessages.MESSAGES.badReadAttributeImpl9(name); } else { // Shouldn't happen; the global handler should reject throw unknownAttribute(operation); } }
result.get(PlatformMBeanConstants.WAITED_TIME).set(threadInfo.getWaitedTime()); result.get(PlatformMBeanConstants.WAITED_COUNT).set(threadInfo.getWaitedCount()); result.get(PlatformMBeanConstants.LOCK_INFO).set(getDetypedLockInfo(threadInfo.getLockInfo())); nullSafeSet(result.get(PlatformMBeanConstants.LOCK_NAME), threadInfo.getLockName()); result.get(PlatformMBeanConstants.LOCK_OWNER_ID).set(threadInfo.getLockOwnerId()); nullSafeSet(result.get(PlatformMBeanConstants.LOCK_OWNER_NAME), threadInfo.getLockOwnerName()); final ModelNode stack = result.get(PlatformMBeanConstants.STACK_TRACE); stack.setEmptyList(); for (StackTraceElement ste : threadInfo.getStackTrace()) { stack.add(getDetypedStackTraceElement(ste)); monitors.setEmptyList(); for (MonitorInfo monitor : threadInfo.getLockedMonitors()) { monitors.add(getDetypedMonitorInfo(monitor)); synchronizers.add(getDetypedLockInfo(lock));
static void storeResult(final String name, final ModelNode store, final MemoryPoolMXBean memoryPoolMXBean, final String memPoolName) { final String objName = PlatformMBeanUtil.getObjectNameStringWithNameKey(ManagementFactory.MEMORY_POOL_MXBEAN_DOMAIN_TYPE, memPoolName); store.set(objName); } else if (ModelDescriptionConstants.NAME.equals(name)) { store.set(escapeMBeanName(memoryPoolMXBean.getName())); } else if (PlatformMBeanConstants.TYPE.equals(name)) { store.set(memoryPoolMXBean.getType().name()); } else if (PlatformMBeanConstants.USAGE.equals(name)) { final ModelNode usage = PlatformMBeanUtil.getDetypedMemoryUsage(memoryPoolMXBean.getUsage()); store.set(usage); } else if (PlatformMBeanConstants.PEAK_USAGE.equals(name)) { final ModelNode usage = PlatformMBeanUtil.getDetypedMemoryUsage(memoryPoolMXBean.getPeakUsage()); store.set(usage); } else if (PlatformMBeanConstants.VALID.getName().equals(name)) { store.setEmptyList(); for (String mgr : memoryPoolMXBean.getMemoryManagerNames()) { store.add(escapeMBeanName(mgr)); store.set(memoryPoolMXBean.isCollectionUsageThresholdSupported()); } else if (PlatformMBeanConstants.COLLECTION_USAGE.equals(name)) { final ModelNode usage = PlatformMBeanUtil.getDetypedMemoryUsage(memoryPoolMXBean.getCollectionUsage()); store.set(usage); } else if (MemoryPoolResourceDefinition.MEMORY_POOL_READ_ATTRIBUTES.contains(name)
if (gcName.equals(escapeMBeanName(mbean.getName()))) { gcMBean = mbean; 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()); result.setEmptyList(); for (String pool : gcMBean.getMemoryPoolNames()) { result.add(escapeMBeanName(pool));
@Override protected void executeReadAttribute(OperationContext context, ModelNode operation) throws OperationFailedException { final String bpName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue(); final ObjectName objectName = PlatformMBeanUtil.getObjectNameWithNameKey(PlatformMBeanConstants.BUFFER_POOL_MXBEAN_DOMAIN_TYPE, bpName); if (!ManagementFactory.getPlatformMBeanServer().isRegistered(objectName)) { throw PlatformMBeanLogger.ROOT_LOGGER.unknownBufferPool(bpName); } final String name = operation.require(ModelDescriptionConstants.NAME).asString(); if (PlatformMBeanConstants.OBJECT_NAME.getName().equals(name)) { context.getResult().set(objectName.toString()); } else if (ModelDescriptionConstants.NAME.equals(name)) { context.getResult().set(PlatformMBeanUtil.getMBeanAttribute(objectName, "Name").toString()); } else if (PlatformMBeanConstants.COUNT.equals(name)) { context.getResult().set(Long.class.cast(PlatformMBeanUtil.getMBeanAttribute(objectName, "Count"))); } else if (PlatformMBeanConstants.MEMORY_USED_NAME.equals(name)) { context.getResult().set(Long.class.cast(PlatformMBeanUtil.getMBeanAttribute(objectName, "MemoryUsed"))); } else if (PlatformMBeanConstants.TOTAL_CAPACITY.equals(name)) { context.getResult().set(Long.class.cast(PlatformMBeanUtil.getMBeanAttribute(objectName, "TotalCapacity"))); } else if (BufferPoolResourceDefinition.BUFFER_POOL_METRICS.contains(name)) { // Bug throw PlatformMBeanLogger.ROOT_LOGGER.badReadAttributeImpl(name); } else { // Shouldn't happen; the global handler should reject throw unknownAttribute(operation); } }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { validator.validate(operation); ThreadMXBean mbean = ManagementFactory.getThreadMXBean(); try { long id = operation.require(PlatformMBeanConstants.ID).asLong(); ThreadInfo info; if (operation.hasDefined(PlatformMBeanConstants.MAX_DEPTH)) { info = mbean.getThreadInfo(id, operation.require(PlatformMBeanConstants.MAX_DEPTH).asInt()); } else { info = mbean.getThreadInfo(id); } final ModelNode result = context.getResult(); if (info != null) { result.set(PlatformMBeanUtil.getDetypedThreadInfo(info, mbean.isThreadCpuTimeSupported())); } } catch (SecurityException e) { throw new OperationFailedException(new ModelNode().set(e.toString())); } context.stepCompleted(); }
private static ModelNode getDetypedStackTraceElement(final StackTraceElement stackTraceElement) { final ModelNode result = new ModelNode(); if (stackTraceElement != null) { nullSafeSet(result.get(PlatformMBeanConstants.FILE_NAME), stackTraceElement.getFileName()); result.get(PlatformMBeanConstants.LINE_NUMBER).set(stackTraceElement.getLineNumber()); result.get(PlatformMBeanConstants.CLASS_NAME).set(stackTraceElement.getClassName()); result.get(PlatformMBeanConstants.METHOD_NAME).set(stackTraceElement.getMethodName()); result.get(PlatformMBeanConstants.NATIVE_METHOD).set(stackTraceElement.isNativeMethod()); } return result; }
@Override protected void executeReadAttribute(OperationContext context, ModelNode operation) throws OperationFailedException { final String name = operation.require(ModelDescriptionConstants.NAME).asString(); if (PlatformMBeanConstants.OBJECT_NAME.getName().equals(name)) { context.getResult().set(ManagementFactory.MEMORY_MXBEAN_NAME); } else if (PlatformMBeanConstants.OBJECT_PENDING_FINALIZATION_COUNT.equals(name)) { context.getResult().set(ManagementFactory.getMemoryMXBean().getObjectPendingFinalizationCount()); } else if (PlatformMBeanConstants.HEAP_MEMORY_USAGE.equals(name)) { final ModelNode mu = PlatformMBeanUtil.getDetypedMemoryUsage(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage()); context.getResult().set(mu); } else if (PlatformMBeanConstants.NON_HEAP_MEMORY_USAGE.equals(name)) { final ModelNode mu = PlatformMBeanUtil.getDetypedMemoryUsage(ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage()); context.getResult().set(mu); } else if (PlatformMBeanConstants.VERBOSE.equals(name)) { context.getResult().set(ManagementFactory.getMemoryMXBean().isVerbose()); } else if (MemoryResourceDefinition.MEMORY_METRICS.contains(name) || MemoryResourceDefinition.MEMORY_READ_WRITE_ATTRIBUTES.contains(name)) { // Bug throw PlatformMBeanLogger.ROOT_LOGGER.badReadAttributeImpl(name); } else { // Shouldn't happen; the global handler should reject throw unknownAttribute(operation); } }
result.get(PlatformMBeanConstants.WAITED_TIME).set(threadInfo.getWaitedTime()); result.get(PlatformMBeanConstants.WAITED_COUNT).set(threadInfo.getWaitedCount()); result.get(PlatformMBeanConstants.LOCK_INFO).set(getDetypedLockInfo(threadInfo.getLockInfo())); nullSafeSet(result.get(PlatformMBeanConstants.LOCK_NAME), threadInfo.getLockName()); result.get(PlatformMBeanConstants.LOCK_OWNER_ID).set(threadInfo.getLockOwnerId()); nullSafeSet(result.get(PlatformMBeanConstants.LOCK_OWNER_NAME), threadInfo.getLockOwnerName()); final ModelNode stack = result.get(PlatformMBeanConstants.STACK_TRACE); stack.setEmptyList(); for (StackTraceElement ste : threadInfo.getStackTrace()) { stack.add(getDetypedStackTraceElement(ste)); monitors.setEmptyList(); for (MonitorInfo monitor : threadInfo.getLockedMonitors()) { monitors.add(getDetypedMonitorInfo(monitor)); synchronizers.add(getDetypedLockInfo(lock));
@Override Set<String> getChildrenNames() { final Set<String> result = new LinkedHashSet<String>(); for (GarbageCollectorMXBean mbean : ManagementFactory.getGarbageCollectorMXBeans()) { result.add(escapeMBeanName(mbean.getName())); } return result; }