use of javax.management.openmbean.OpenType in project ddf by codice.
the class UndeliveredMessages method getMessages.
@Override
public List<CompositeData> getMessages(String address, String module) {
List<CompositeData> undeliveredMessages = new ArrayList<>();
Object compositeDatas = invokeMbean(createArtemisObjectName(address, module), GET_MESSAGES_OPERATION, new Object[] { "" }, new String[] { String.class.getName() });
if (!(compositeDatas instanceof CompositeData[])) {
return undeliveredMessages;
}
CompositeData[] messages = (CompositeData[]) compositeDatas;
for (CompositeData message : messages) {
Set<String> setMessageKeys = message.getCompositeType().keySet();
String[] messageKeysArray = setMessageKeys.toArray(new String[setMessageKeys.size()]);
Object[] messageValues = message.getAll(messageKeysArray);
CompositeType messageCompositeType = message.getCompositeType();
String[] itemDescription = new String[messageKeysArray.length];
OpenType<?>[] itemTypes = new OpenType[messageKeysArray.length];
try {
for (int i = 0; i < messageKeysArray.length; i++) {
String messageKey = messageKeysArray[i];
itemDescription[i] = messageCompositeType.getDescription(messageKey);
if (messageKeysArray[i].equals("body")) {
byte[] messageBodyBytes = (byte[]) message.get("body");
// Remove unprintable characters from the beginning of the string
messageValues[i] = removeNullCharacters(new String(Arrays.copyOfRange(messageBodyBytes, 5, messageBodyBytes.length), StandardCharsets.UTF_8));
itemTypes[i] = SimpleType.STRING;
} else {
itemTypes[i] = messageCompositeType.getType(messageKey);
}
}
undeliveredMessages.add(new CompositeDataSupport(new CompositeType(messageCompositeType.getTypeName(), messageCompositeType.getDescription(), messageKeysArray, itemDescription, itemTypes), messageKeysArray, messageValues));
} catch (OpenDataException e) {
LOGGER.warn("Unable to retrieve messages from the broker. For more information, set " + "logging level to DEBUG.");
LOGGER.debug("Unable to retrieve messages from the broker.", e);
}
}
return undeliveredMessages;
}
use of javax.management.openmbean.OpenType in project Payara by payara.
the class OpenMBeanUtil method getThrowableOpenType.
/**
* Get a CompositeType describing a CompositeData which has no elements.
*/
public static OpenType getThrowableOpenType(final Throwable t) throws OpenDataException {
final String[] itemNames = new String[] { "Message", "Cause", "StackTrace" };
final String[] descriptions = new String[] { "The message from the Throwable", "The cause (if any) from the Throwable", "The stack trace from the Throwable" };
final OpenType[] openTypes = new OpenType[itemNames.length];
openTypes[0] = SimpleType.STRING;
openTypes[1] = t.getCause() == null ? SimpleType.VOID : getThrowableOpenType(t.getCause());
openTypes[2] = newArrayType(t.getStackTrace().length, getStackTraceElementOpenType());
return (new CompositeType(t.getClass().getName(), "Throwable composite type", itemNames, descriptions, openTypes));
}
use of javax.management.openmbean.OpenType in project Payara by payara.
the class OpenMBeanUtil method mapToCompositeType.
/**
* Create a CompositeType from a Map. Each key in the map must be a String,
* and each value must be a type consistent with OpenTypes.
*
* @param typeName the arbitrary name of the OpenType to be used
* @param description the arbitrary description of the OpenType to be used
* @param map a Map keyed by String, whose values may not be null
*/
public static CompositeType mapToCompositeType(final String typeName, final String description, final Map<String, ?> map, CompositeTypeFromNameCallback callback) throws OpenDataException {
final String[] itemNames = new String[map.keySet().size()];
map.keySet().toArray(itemNames);
final String[] itemDescriptions = new String[itemNames.length];
final OpenType[] itemTypes = new OpenType[itemNames.length];
for (int i = 0; i < itemNames.length; ++i) {
final String name = itemNames[i];
final Object value = map.get(name);
itemDescriptions[i] = "value " + name;
if (value == null) {
// force nulls to type String
itemTypes[i] = callback.getOpenTypeFromName(name);
} else {
itemTypes[i] = getOpenType(value);
}
}
final CompositeType type = new CompositeType(typeName, description, itemNames, itemDescriptions, itemTypes);
return (type);
}
use of javax.management.openmbean.OpenType in project jdk8u_jdk by JetBrains.
the class DefaultMXBeanMappingFactory method makeCompositeMapping.
private MXBeanMapping makeCompositeMapping(Class<?> c, MXBeanMappingFactory factory) throws OpenDataException {
// For historical reasons GcInfo implements CompositeData but we
// shouldn't count its CompositeData.getCompositeType() field as
// an item in the computed CompositeType.
final boolean gcInfoHack = (c.getName().equals("com.sun.management.GcInfo") && c.getClassLoader() == null);
ReflectUtil.checkPackageAccess(c);
final List<Method> methods = MBeanAnalyzer.eliminateCovariantMethods(Arrays.asList(c.getMethods()));
final SortedMap<String, Method> getterMap = newSortedMap();
/* Select public methods that look like "T getX()" or "boolean
isX()", where T is not void and X is not the empty
string. Exclude "Class getClass()" inherited from Object. */
for (Method method : methods) {
final String propertyName = propertyName(method);
if (propertyName == null)
continue;
if (gcInfoHack && propertyName.equals("CompositeType"))
continue;
Method old = getterMap.put(decapitalize(propertyName), method);
if (old != null) {
final String msg = "Class " + c.getName() + " has method name clash: " + old.getName() + ", " + method.getName();
throw new OpenDataException(msg);
}
}
final int nitems = getterMap.size();
if (nitems == 0) {
throw new OpenDataException("Can't map " + c.getName() + " to an open data type");
}
final Method[] getters = new Method[nitems];
final String[] itemNames = new String[nitems];
final OpenType<?>[] openTypes = new OpenType<?>[nitems];
int i = 0;
for (Map.Entry<String, Method> entry : getterMap.entrySet()) {
itemNames[i] = entry.getKey();
final Method getter = entry.getValue();
getters[i] = getter;
final Type retType = getter.getGenericReturnType();
openTypes[i] = factory.mappingForType(retType, factory).getOpenType();
i++;
}
CompositeType compositeType = new CompositeType(c.getName(), c.getName(), // field names
itemNames, // field descriptions
itemNames, openTypes);
return new CompositeMapping(c, compositeType, itemNames, getters, factory);
}
use of javax.management.openmbean.OpenType in project tomee by apache.
the class LocalMBeanServer method tabularData.
public static TabularData tabularData(final String typeName, final String typeDescription, final String[] names, final Object[] values) {
if (names.length == 0) {
return null;
}
final OpenType<?>[] types = new OpenType<?>[names.length];
for (int i = 0; i < types.length; i++) {
types[i] = SimpleType.STRING;
}
try {
final CompositeType ct = new CompositeType(typeName, typeDescription, names, names, types);
final TabularType type = new TabularType(typeName, typeDescription, ct, names);
final TabularDataSupport data = new TabularDataSupport(type);
final CompositeData line = new CompositeDataSupport(ct, names, values);
data.put(line);
return data;
} catch (final OpenDataException e) {
return null;
}
}
Aggregations