Search in sources :

Example 81 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project scylla-jmx by scylladb.

the class CompactionHistoryTabularData method from.

public static TabularData from(JsonArray resultSet) throws OpenDataException {
    TabularDataSupport result = new TabularDataSupport(TABULAR_TYPE);
    for (int i = 0; i < resultSet.size(); i++) {
        JsonObject row = resultSet.getJsonObject(i);
        String id = row.getString("id");
        String ksName = row.getString("ks");
        String cfName = row.getString("cf");
        long compactedAt = row.getJsonNumber("compacted_at").longValue();
        long bytesIn = row.getJsonNumber("bytes_in").longValue();
        long bytesOut = row.getJsonNumber("bytes_out").longValue();
        JsonArray merged = row.getJsonArray("rows_merged");
        StringBuilder sb = new StringBuilder();
        if (merged != null) {
            sb.append('{');
            for (int m = 0; m < merged.size(); m++) {
                JsonObject entry = merged.getJsonObject(m);
                if (m > 0) {
                    sb.append(',');
                }
                sb.append(entry.getString("key")).append(':').append(entry.getString("value"));
            }
            sb.append('}');
        }
        result.put(new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES, new Object[] { id, ksName, cfName, compactedAt, bytesIn, bytesOut, sb.toString() }));
    }
    return result;
}
Also used : JsonArray(javax.json.JsonArray) TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) JsonObject(javax.json.JsonObject) JsonObject(javax.json.JsonObject)

Example 82 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project Payara by payara.

the class JMXMonitoringJob method getValueString.

/**
 * Gets the attribute value as a string.
 *
 * @param attributeName Name of the attribute.
 * @param attributeObj The object representing the attribute.
 * @return Returns a string containing the key-value pair(s) for the
 * attribute.
 */
private String getValueString(String attributeName, Object attributeObj) {
    StringBuilder attributeString = new StringBuilder();
    if (attributeObj.getClass() == CompositeDataSupport.class) {
        CompositeDataSupport compositeObj = (CompositeDataSupport) attributeObj;
        String[] attributeToks = attributeName.split("\\.");
        switch(attributeToks.length) {
            case 1:
                String compositeString = getCompositeString(attributeToks[0], compositeObj);
                attributeString.append(compositeString);
                break;
            case 2:
                String attributeValue = compositeObj.get(attributeToks[1]).toString();
                attributeString.append(attributeToks[1]);
                attributeString.append(attributeToks[0]);
                attributeString.append("=");
                attributeString.append(attributeValue);
                attributeString.append(" ");
                break;
            default:
                Logger.getLogger(JMXMonitoringJob.class.getCanonicalName()).log(Level.WARNING, "Could not parse attribute `{0}`" + " it should be of the form `AttributeName` or" + "`AttributeName.property`", attributeName);
        }
    } else {
        attributeString.append(attributeName);
        attributeString.append("=");
        attributeString.append(attributeObj.toString());
        attributeString.append(" ");
    }
    return attributeString.toString();
}
Also used : CompositeDataSupport(javax.management.openmbean.CompositeDataSupport)

Example 83 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project hazelcast by hazelcast.

the class JVMUtil method isHotSpotCompressedOopsOrNull.

// not private for testing
@SuppressFBWarnings("NP_BOOLEAN_RETURN_NULL")
static Boolean isHotSpotCompressedOopsOrNull() {
    try {
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        ObjectName mbean = new ObjectName("com.sun.management:type=HotSpotDiagnostic");
        Object[] objects = { "UseCompressedOops" };
        String[] strings = { "java.lang.String" };
        String operation = "getVMOption";
        CompositeDataSupport compressedOopsValue = (CompositeDataSupport) server.invoke(mbean, operation, objects, strings);
        return Boolean.valueOf(compressedOopsValue.get("value").toString());
    } catch (Exception e) {
        getLogger(JVMUtil.class).fine("Failed to read HotSpot specific configuration: " + e.getMessage());
    }
    return null;
}
Also used : CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 84 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project neo4j by neo4j.

the class JmxQueryProcedureTest method shouldHandleCompositeAttributes.

@Test
public void shouldHandleCompositeAttributes() throws Throwable {
    // given
    ObjectName beanName = new ObjectName("org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference");
    when(jmxServer.queryNames(new ObjectName("*:*"), null)).thenReturn(asSet(beanName));
    when(jmxServer.getMBeanInfo(beanName)).thenReturn(new MBeanInfo("org.neo4j.SomeMBean", "This is a description", new MBeanAttributeInfo[] { new MBeanAttributeInfo("name", "differenceMaker", "Who makes the difference?", true, false, false) }, null, null, null));
    when(jmxServer.getAttribute(beanName, "name")).thenReturn(new CompositeDataSupport(new CompositeType("myComposite", "Composite description", new String[] { "key1", "key2" }, new String[] { "Can't be empty", "Also can't be empty" }, new OpenType<?>[] { SimpleType.STRING, SimpleType.INTEGER }), map("key1", "Hello", "key2", 123)));
    JmxQueryProcedure procedure = new JmxQueryProcedure(ProcedureSignature.procedureName("bob"), jmxServer);
    // when
    RawIterator<Object[], ProcedureException> result = procedure.apply(null, new Object[] { "*:*" });
    // then
    assertThat(asList(result), contains(equalTo(new Object[] { "org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference", "This is a description", map(attributeName, map("description", "Who makes the difference?", "value", map("description", "Composite description", "properties", map("key1", "Hello", "key2", 123)))) })));
}
Also used : MBeanInfo(javax.management.MBeanInfo) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) CompositeType(javax.management.openmbean.CompositeType) Test(org.junit.Test)

Example 85 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport 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)

Aggregations

CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)166 CompositeData (javax.management.openmbean.CompositeData)107 CompositeType (javax.management.openmbean.CompositeType)105 TabularDataSupport (javax.management.openmbean.TabularDataSupport)78 OpenDataException (javax.management.openmbean.OpenDataException)66 TabularData (javax.management.openmbean.TabularData)46 HashMap (java.util.HashMap)36 TabularType (javax.management.openmbean.TabularType)30 Map (java.util.Map)26 OpenType (javax.management.openmbean.OpenType)15 ObjectName (javax.management.ObjectName)12 MBeanServer (javax.management.MBeanServer)8 Test (org.junit.Test)8 IOException (java.io.IOException)7 EndpointUtilizationStatistics (org.apache.camel.spi.EndpointUtilizationStatistics)7 MBeanException (javax.management.MBeanException)6 JsonArray (javax.json.JsonArray)5 JsonObject (javax.json.JsonObject)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 ArrayList (java.util.ArrayList)4