use of javax.management.openmbean.OpenDataException in project jdk8u_jdk by JetBrains.
the class GcInfoBuilder method getGcInfoCompositeType.
// Returns the CompositeType for the GcInfo including
// the extension attributes
synchronized CompositeType getGcInfoCompositeType() {
if (gcInfoCompositeType != null)
return gcInfoCompositeType;
// First, fill with the attributes in the GcInfo
String[] gcInfoItemNames = GcInfoCompositeData.getBaseGcInfoItemNames();
OpenType[] gcInfoItemTypes = GcInfoCompositeData.getBaseGcInfoItemTypes();
int numGcInfoItems = gcInfoItemNames.length;
int itemCount = numGcInfoItems + gcExtItemCount;
allItemNames = new String[itemCount];
String[] allItemDescs = new String[itemCount];
OpenType<?>[] allItemTypes = new OpenType<?>[itemCount];
System.arraycopy(gcInfoItemNames, 0, allItemNames, 0, numGcInfoItems);
System.arraycopy(gcInfoItemNames, 0, allItemDescs, 0, numGcInfoItems);
System.arraycopy(gcInfoItemTypes, 0, allItemTypes, 0, numGcInfoItems);
// Then fill with the extension GC-specific attributes, if any.
if (gcExtItemCount > 0) {
fillGcAttributeInfo(gc, gcExtItemCount, gcExtItemNames, gcExtItemTypes, gcExtItemDescs);
System.arraycopy(gcExtItemNames, 0, allItemNames, numGcInfoItems, gcExtItemCount);
System.arraycopy(gcExtItemDescs, 0, allItemDescs, numGcInfoItems, gcExtItemCount);
for (int i = numGcInfoItems, j = 0; j < gcExtItemCount; i++, j++) {
switch(gcExtItemTypes[j]) {
case 'Z':
allItemTypes[i] = SimpleType.BOOLEAN;
break;
case 'B':
allItemTypes[i] = SimpleType.BYTE;
break;
case 'C':
allItemTypes[i] = SimpleType.CHARACTER;
break;
case 'S':
allItemTypes[i] = SimpleType.SHORT;
break;
case 'I':
allItemTypes[i] = SimpleType.INTEGER;
break;
case 'J':
allItemTypes[i] = SimpleType.LONG;
break;
case 'F':
allItemTypes[i] = SimpleType.FLOAT;
break;
case 'D':
allItemTypes[i] = SimpleType.DOUBLE;
break;
default:
throw new AssertionError("Unsupported type [" + gcExtItemTypes[i] + "]");
}
}
}
CompositeType gict = null;
try {
final String typeName = "sun.management." + gc.getName() + ".GcInfoCompositeType";
gict = new CompositeType(typeName, "CompositeType for GC info for " + gc.getName(), allItemNames, allItemDescs, allItemTypes);
} catch (OpenDataException e) {
// shouldn't reach here
throw Util.newException(e);
}
gcInfoCompositeType = gict;
return gcInfoCompositeType;
}
use of javax.management.openmbean.OpenDataException in project jdk8u_jdk by JetBrains.
the class GarbageCollectionNotifInfoCompositeData method getCompositeData.
protected CompositeData getCompositeData() {
// CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
// gcNotifInfoItemNames!
final Object[] gcNotifInfoItemValues;
gcNotifInfoItemValues = new Object[] { gcNotifInfo.getGcName(), gcNotifInfo.getGcAction(), gcNotifInfo.getGcCause(), GcInfoCompositeData.toCompositeData(gcNotifInfo.getGcInfo()) };
CompositeType gict = getCompositeTypeByBuilder();
try {
return new CompositeDataSupport(gict, gcNotifInfoItemNames, gcNotifInfoItemValues);
} catch (OpenDataException e) {
// Should never reach here
throw new AssertionError(e);
}
}
use of javax.management.openmbean.OpenDataException in project jdk8u_jdk by JetBrains.
the class GarbageCollectionNotifInfoCompositeData method getCompositeTypeByBuilder.
private CompositeType getCompositeTypeByBuilder() {
final GcInfoBuilder builder = AccessController.doPrivileged(new PrivilegedAction<GcInfoBuilder>() {
public GcInfoBuilder run() {
try {
Class cl = Class.forName("com.sun.management.GcInfo");
Field f = cl.getDeclaredField("builder");
f.setAccessible(true);
return (GcInfoBuilder) f.get(gcNotifInfo.getGcInfo());
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
return null;
}
}
});
CompositeType gict = null;
synchronized (compositeTypeByBuilder) {
gict = compositeTypeByBuilder.get(builder);
if (gict == null) {
OpenType<?>[] gcNotifInfoItemTypes = new OpenType<?>[] { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, builder.getGcInfoCompositeType() };
try {
final String typeName = "sun.management.GarbageCollectionNotifInfoCompositeType";
gict = new CompositeType(typeName, "CompositeType for GC notification info", gcNotifInfoItemNames, gcNotifInfoItemNames, gcNotifInfoItemTypes);
compositeTypeByBuilder.put(builder, gict);
} catch (OpenDataException e) {
// shouldn't reach here
throw Util.newException(e);
}
}
}
return gict;
}
use of javax.management.openmbean.OpenDataException 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.OpenDataException in project nhin-d by DirectProject.
the class FileAuditor method getEvent.
/*
* Get the event prior to the file position
*/
private CompositeData getEvent(long position) {
CompositeData retVal = null;
try {
long currentPosition = position;
if (getEventCount() > 0 && currentPosition >= RECORD_METADATA_SIZE) {
int size = this.getRecordSize(position);
if (size > 0) {
// go to the beginning of the record
auditFile.seek(currentPosition - RECORD_METADATA_SIZE - size);
byte[] message = new byte[size];
// read the message
auditFile.read(message);
String strMessage = new String(message);
// split into an array using the event delimiter
String[] eventTags = strMessage.split(EVENT_TAG_DELIMITER);
String id = "";
String time = "";
String principal = "";
String name = "";
String type = "";
String[] contexts = null;
for (String tag : eventTags) {
tag = tag.trim();
if (tag.startsWith(EVENT_ID))
id = getItemText(tag);
else if (tag.startsWith(EVENT_TIME))
time = getItemText(tag);
else if (tag.startsWith(EVENT_PRINCIPAL))
principal = getItemText(tag);
else if (tag.startsWith(EVENT_NAME))
name = getItemText(tag);
else if (tag.startsWith(EVENT_TYPE))
type = getItemText(tag);
else if (tag.startsWith(EVENT_CTX)) {
// need to add the \r\n back on the end
tag += "\r\n";
String[] ctx = tag.split(CONTEXT_TAG_DELIMITER);
if (ctx.length > 1) {
contexts = new String[ctx.length - 1];
for (int i = 1; i < ctx.length; ++i) contexts[i - 1] = ctx[i].trim();
}
}
}
if (contexts == null)
contexts = new String[] { " " };
Object[] eventValues = { id, time, principal, name, type, contexts };
try {
// create the record to be returned
retVal = new CompositeDataSupport(eventType, itemNames, eventValues);
} catch (OpenDataException e) {
LOGGER.error("Error create composit data for audit event.", e);
}
}
}
} catch (IOException e) {
LOGGER.error("Error reading audit file to create audit event composite data.", e);
} finally {
try {
// put the file pointer back in the original position
auditFile.seek(position);
} catch (IOException e) {
/* no-op */
}
}
return retVal;
}
Aggregations