Skip to content

Commit

Permalink
Merge pull request #5477 from keithc-ca/management-0.14
Browse files Browse the repository at this point in the history
(v0.14.0) Remove ManagementUtils.convertToOpenType()
  • Loading branch information
pshipton authored Apr 13, 2019
2 parents 0727b85 + 70a5c72 commit 27df834
Show file tree
Hide file tree
Showing 27 changed files with 127 additions and 300 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF Sidecar17]*/
/*******************************************************************************
* Copyright (c) 2008, 2018 IBM Corp. and others
* Copyright (c) 2008, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -379,87 +379,6 @@ private static MemoryType convertStringToMemoryType(String data) {
return result;
}

private static final Map<Class<?>, Function<Object, CompositeData>> compositeConverterMap = new ConcurrentHashMap<>();

static {
// Register converters for all types in this module.
addCompositeConverter(LockInfo.class, LockInfoUtil::toCompositeData);
addCompositeConverter(MemoryNotificationInfo.class, MemoryNotificationInfoUtil::toCompositeData);
addCompositeConverter(MemoryUsage.class, MemoryUsageUtil::toCompositeData);
addCompositeConverter(MonitorInfo.class, MonitorInfoUtil::toCompositeData);
addCompositeConverter(StackTraceElement.class, StackTraceElementUtil::toCompositeData);
addCompositeConverter(ThreadInfo.class, ThreadInfoUtil::toCompositeData);
}

public static <T> void addCompositeConverter(Class<T> clazz, Function<T, CompositeData> object) {
// This cast is safe because we use the runtime class of the data
// to locate the entry in the map before applying the function.
@SuppressWarnings("unchecked")
Function<Object, CompositeData> converter = (Function<Object, CompositeData>) object;

compositeConverterMap.put(clazz, converter);
}

/**
* Convenience method to convert an object, <code>data</code> from its
* Java type <code>realClass</code> to the specified open MBean type
* <code>openClass</code>.
*
* @param <T>
* the open MBean class
* @param data
* the object to be converted
* @param openClass
* the open MBean class
* @param realClass
* the real Java type of <code>data</code>
* @return a new instance of type <code>openClass</code>
*/
@SuppressWarnings("unchecked")
public static <T> T convertToOpenType(Object data, Class<T> openClass, Class<?> realClass) {
// Bail out early on null input.
if (data == null) {
return null;
}

T result = null;

if (openClass.isArray() && realClass.isArray()) {
Class<?> openElementClass = openClass.getComponentType();
Class<?> realElementClass = realClass.getComponentType();
Object[] dataArray = (Object[]) data;
int length = dataArray.length;

result = (T) Array.newInstance(openElementClass, length);

for (int i = 0; i < length; ++i) {
Array.set(result, i, convertToOpenType(dataArray[i], openElementClass, realElementClass));
}
} else if (openClass.equals(CompositeData.class)) {
Function<Object, CompositeData> converter = compositeConverterMap.get(realClass);

if (converter != null) {
result = (T) converter.apply(data);
}
} else if (openClass.equals(TabularData.class)) {
if (realClass.equals(Map.class)) {
result = (T) toSystemPropertiesTabularData((Map<String, String>) data);
}
} else if (openClass.equals(String[].class)) {
if (realClass.equals(List.class)) {
List<?> list = (List<?>) data;

result = (T) list.toArray(new String[list.size()]);
}
} else if (openClass.equals(String.class)) {
if (realClass.isEnum()) {
result = (T) ((Enum<?>) data).name();
}
}

return result;
}

/**
* @param propsMap
* a <code>Map&lt;String, String%gt;</code> of the system
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF Sidecar17 & !Sidecar19-SE]*/
/*******************************************************************************
* Copyright (c) 2005, 2017 IBM Corp. and others
* Copyright (c) 2005, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -473,34 +473,44 @@ private static final class ServerHolder {
static {
platformServer = MBeanServerFactory.createMBeanServer();

PrivilegedAction<?> action = (PrivilegedAction<?>) ServerHolder::registerPlatformBeans;
final class Registration implements PrivilegedAction<Void> {

AccessController.doPrivileged(action);
}

private static Void registerPlatformBeans() {
for (PlatformManagedObject bean : ManagementUtils.getAllAvailableMXBeans()) {
ObjectName objectName = bean.getObjectName();
private final MBeanServer server;

if (platformServer.isRegistered(objectName)) {
continue;
Registration(MBeanServer server) {
super();
this.server = server;
}

try {
platformServer.registerMBean(bean, objectName);
} catch (InstanceAlreadyExistsException | MBeanRegistrationException | NullPointerException e) {
if (ManagementUtils.VERBOSE_MODE) {
e.printStackTrace(System.err);
}
} catch (NotCompliantMBeanException e) {
e.printStackTrace();
if (ManagementUtils.VERBOSE_MODE) {
e.printStackTrace(System.err);
@Override
public Void run() {
for (PlatformManagedObject bean : ManagementUtils.getAllAvailableMXBeans()) {
ObjectName objectName = bean.getObjectName();

if (server.isRegistered(objectName)) {
continue;
}

try {
server.registerMBean(bean, objectName);
} catch (InstanceAlreadyExistsException | MBeanRegistrationException | NullPointerException e) {
if (ManagementUtils.VERBOSE_MODE) {
e.printStackTrace(System.err);
}
} catch (NotCompliantMBeanException e) {
e.printStackTrace();
if (ManagementUtils.VERBOSE_MODE) {
e.printStackTrace(System.err);
}
}
}

return null;
}

}

return null;
AccessController.doPrivileged(new Registration(platformServer));
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF Sidecar17]*/
/*******************************************************************************
* Copyright (c) 2005, 2016 IBM Corp. and others
* Copyright (c) 2005, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand All @@ -25,7 +25,6 @@
import javax.management.openmbean.CompositeData;

import com.ibm.java.lang.management.internal.ManagementUtils;
import com.ibm.lang.management.internal.AvailableProcessorsNotificationInfoUtil;

/**
* Encapsulates the details of a DLPAR notification emitted by a
Expand All @@ -41,10 +40,6 @@ public class AvailableProcessorsNotificationInfo {

public static final String AVAILABLE_PROCESSORS_CHANGE = "com.ibm.management.available.processors.change"; //$NON-NLS-1$

static {
AvailableProcessorsNotificationInfoUtil.registerConverters();
}

private final int newAvailableProcessors;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF Sidecar17]*/
/*******************************************************************************
* Copyright (c) 2014, 2016 IBM Corp. and others
* Copyright (c) 2014, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -39,10 +39,6 @@ public final class JvmCpuMonitorInfo {
private static final int HASHMASK = 0x0FFFFFFF;
private static final int NUM_USER_DEFINED_CATEGORY = 5;

static {
JvmCpuMonitorInfoUtil.registerConverters();
}

private long timestamp;
private long applicationCpuTime;
private long resourceMonitorCpuTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF Sidecar17]*/
/*******************************************************************************
* Copyright (c) 2012, 2016 IBM Corp. and others
* Copyright (c) 2012, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -38,10 +38,6 @@ public class MemoryUsage {

private static final int HASHMASK = 0x0FFFFFFF;

static {
MemoryUsageUtil.registerConverters();
}

private long total;
private long free;
private long swapTotal;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF Sidecar17]*/
/*******************************************************************************
* Copyright (c) 2005, 2016 IBM Corp. and others
* Copyright (c) 2005, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand All @@ -25,7 +25,6 @@
import javax.management.openmbean.CompositeData;

import com.ibm.java.lang.management.internal.ManagementUtils;
import com.ibm.lang.management.internal.ProcessingCapacityNotificationInfoUtil;

/**
* Encapsulates the details of a DLPAR notification emitted by a
Expand All @@ -41,10 +40,6 @@ public class ProcessingCapacityNotificationInfo {

public static final String PROCESSING_CAPACITY_CHANGE = "com.ibm.management.processing.capacity.change"; //$NON-NLS-1$

static {
ProcessingCapacityNotificationInfoUtil.registerConverters();
}

private final int newProcessingCapacity;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF Sidecar18-SE]*/
/*******************************************************************************
* Copyright (c) 2013, 2016 IBM Corp. and others
* Copyright (c) 2013, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -41,10 +41,6 @@ public class ProcessorUsage {

private static final int HASHMASK = 0x0FFFFFFF;

static {
ProcessorUsageUtil.registerConverters();
}

private long user;
private long system;
private long idle;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF Sidecar17]*/
/*******************************************************************************
* Copyright (c) 2016, 2018 IBM Corp. and others
* Copyright (c) 2016, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -63,14 +63,6 @@ private static CompositeType getCompositeType() {
return compositeType;
}

/**
* Register converters for the {@link AvailableProcessorsNotificationInfo} class.
*/
public static void registerConverters() {
ManagementUtils.addCompositeConverter(AvailableProcessorsNotificationInfo.class,
AvailableProcessorsNotificationInfoUtil::toCompositeData);
}

/**
* @param info a {@link AvailableProcessorsNotificationInfo} object
* @return a {@link CompositeData} object that represents the supplied <code>info</code> object
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF Sidecar17]*/
/*******************************************************************************
* Copyright (c) 2016, 2016 IBM Corp. and others
* Copyright (c) 2016, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -71,13 +71,6 @@ public static CompositeType getCompositeType() {
return compositeType;
}

/**
* Register converters for the {@link JvmCpuMonitorInfo} class.
*/
public static void registerConverters() {
ManagementUtils.addCompositeConverter(JvmCpuMonitorInfo.class, JvmCpuMonitorInfoUtil::toCompositeData);
}

/**
* @param info a {@link JvmCpuMonitorInfo} object
* @return a {@link CompositeData} object that represents the supplied <code>info</code> object
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF Sidecar17]*/
/*******************************************************************************
* Copyright (c) 2016, 2016 IBM Corp. and others
* Copyright (c) 2016, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -66,13 +66,6 @@ public static CompositeType getCompositeType() {
return compositeType;
}

/**
* Register converters for the {@link MemoryUsage} class.
*/
public static void registerConverters() {
ManagementUtils.addCompositeConverter(MemoryUsage.class, MemoryUsageUtil::toCompositeData);
}

/**
* @param usage a {@link MemoryUsage} object
* @return a {@link CompositeData} object that represents the supplied <code>usage</code> object
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF Sidecar17]*/
/*******************************************************************************
* Copyright (c) 2016, 2018 IBM Corp. and others
* Copyright (c) 2016, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -63,14 +63,6 @@ private static CompositeType getCompositeType() {
return compositeType;
}

/**
* Register converters for the {@link ProcessingCapacityNotificationInfo} class.
*/
public static void registerConverters() {
ManagementUtils.addCompositeConverter(ProcessingCapacityNotificationInfo.class,
ProcessingCapacityNotificationInfoUtil::toCompositeData);
}

/**
* @param info a {@link ProcessingCapacityNotificationInfo} object
* @return a {@link CompositeData} object that represents the supplied <code>info</code> object
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF Sidecar17]*/
/*******************************************************************************
* Copyright (c) 2016, 2016 IBM Corp. and others
* Copyright (c) 2016, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -70,13 +70,6 @@ public static CompositeType getCompositeType() {
return compositeType;
}

/**
* Register converters for the {@link ProcessorUsage} class.
*/
public static void registerConverters() {
ManagementUtils.addCompositeConverter(ProcessorUsage.class, ProcessorUsageUtil::toCompositeData);
}

/**
* @param usage a {@link ProcessorUsage} object
* @return a {@link CompositeData} object that represents the supplied <code>usage</code> object
Expand Down
Loading

0 comments on commit 27df834

Please sign in to comment.