Search in sources :

Example 61 with OpenDataException

use of javax.management.openmbean.OpenDataException in project openj9 by eclipse.

the class TestThreadInfo method createGoodStackTraceCompositeData.

/**
 * @return new array of <code>CompositeData</code> representing an array
 *         of <code>StackTraceElement</code>.
 */
protected static CompositeData[] createGoodStackTraceCompositeData() {
    // Let's make the array have three elements. Doesn't matter that
    // they are all identical.
    CompositeData[] result = new CompositeData[3];
    CompositeType cType = createGoodStackTraceElementCompositeType();
    String[] names = TestMisc.getJava9STEMethodNames();
    Object[] values = { new String("foo.bar.Blobby"), new String("takeOverWorld"), new String("Blobby.java"), Integer.valueOf(2100), Boolean.valueOf(false), new String("myModuleName"), new String("myModuleVersion"), new String("myClassLoaderName") };
    for (int i = 0; i < result.length; i++) {
        try {
            result[i] = new CompositeDataSupport(cType, names, values);
        } catch (OpenDataException e) {
            e.printStackTrace();
        }
    }
    // end for
    return result;
}
Also used : OpenDataException(javax.management.openmbean.OpenDataException) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) CompositeType(javax.management.openmbean.CompositeType)

Example 62 with OpenDataException

use of javax.management.openmbean.OpenDataException in project openj9 by eclipse.

the class TestThreadInfo method createBadCompositeData.

/**
 * Returns a new <code>CompositeData</code> instance which has been
 * intentionally constructed with attributes that <i>should</i> prevent the
 * creation of a new <code>ThreadInfo</code>.
 *
 * @return a new <code>CompositeData</code> instance representing a
 *         <code>ThreadInfo</code>.
 */
protected static CompositeData createBadCompositeData() {
    CompositeData result = null;
    CompositeType cType = createBadThreadInfoCompositeType();
    try {
        result = new CompositeDataSupport(cType, badTypeNames, valuesCompositeDataGlobal);
    } catch (OpenDataException e) {
        e.printStackTrace();
    }
    return result;
}
Also used : OpenDataException(javax.management.openmbean.OpenDataException) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) CompositeType(javax.management.openmbean.CompositeType)

Example 63 with OpenDataException

use of javax.management.openmbean.OpenDataException in project openj9 by eclipse.

the class TestThreadInfo method createGoodCompositeData.

/**
 * @return a new <code>CompositeData</code> instance representing a
 *         <code>ThreadInfo</code>.
 */
protected static CompositeData createGoodCompositeData() {
    CompositeData result = null;
    CompositeType cType = createGoodThreadInfoCompositeType();
    try {
        result = new CompositeDataSupport(cType, typeNamesGlobal, valuesCompositeDataGlobal);
    } catch (OpenDataException e) {
        e.printStackTrace();
    }
    return result;
}
Also used : OpenDataException(javax.management.openmbean.OpenDataException) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) CompositeType(javax.management.openmbean.CompositeType)

Example 64 with OpenDataException

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;
}
Also used : OpenDataException(javax.management.openmbean.OpenDataException) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) IOException(java.io.IOException)

Example 65 with OpenDataException

use of javax.management.openmbean.OpenDataException in project nhin-d by DirectProject.

the class FileAuditor method registerMBean.

/*
	 * Register the MBean
	 */
private void registerMBean() {
    LOGGER.info("Registering FileAuditor MBean");
    try {
        itemNames = new String[] { "Event Id", "Event Time", "Event Principal", "Event Name", "Event Type", "Contexts" };
        OpenType<?>[] types = { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, ArrayType.getArrayType(SimpleType.STRING) };
        eventType = new CompositeType("AuditEvent", "Direct Auditable Event", itemNames, itemNames, types);
    } catch (OpenDataException e) {
        LOGGER.error("Failed to create settings composite type: " + e.getLocalizedMessage(), e);
        return;
    }
    Class<?> clazz = this.getClass();
    final StringBuilder objectNameBuilder = new StringBuilder(clazz.getPackage().getName());
    objectNameBuilder.append(":type=").append(clazz.getSimpleName());
    objectNameBuilder.append(",name=").append(UUID.randomUUID());
    try {
        final StandardMBean mbean = new StandardMBean(this, AuditorMBean.class);
        final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
        mbeanServer.registerMBean(mbean, new ObjectName(objectNameBuilder.toString()));
    } catch (JMException e) {
        LOGGER.error("Unable to register the FileAuditor MBean", e);
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) OpenDataException(javax.management.openmbean.OpenDataException) StandardMBean(javax.management.StandardMBean) JMException(javax.management.JMException) CompositeType(javax.management.openmbean.CompositeType) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Aggregations

OpenDataException (javax.management.openmbean.OpenDataException)139 CompositeType (javax.management.openmbean.CompositeType)94 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)67 CompositeData (javax.management.openmbean.CompositeData)54 OpenType (javax.management.openmbean.OpenType)52 TabularType (javax.management.openmbean.TabularType)33 TabularDataSupport (javax.management.openmbean.TabularDataSupport)32 HashMap (java.util.HashMap)14 Map (java.util.Map)12 TabularData (javax.management.openmbean.TabularData)11 ObjectName (javax.management.ObjectName)8 ArrayType (javax.management.openmbean.ArrayType)8 Type (java.lang.reflect.Type)5 ArrayList (java.util.ArrayList)5 Method (java.lang.reflect.Method)4 Comparator (java.util.Comparator)4 MBeanServer (javax.management.MBeanServer)4 SimpleType (javax.management.openmbean.SimpleType)4 IOException (java.io.IOException)3 InvalidObjectException (java.io.InvalidObjectException)3