Search in sources :

Example 91 with OpenDataException

use of javax.management.openmbean.OpenDataException in project spf4j by zolyfarkas.

the class SpecificRecordOpenTypeMapping method typeFromSpecificRecord.

private static CompositeType typeFromSpecificRecord(final SpecificRecordBase r, final JMXBeanMappingSupplier typeMapper) throws NotSerializableException {
    Schema schema = r.getSchema();
    List<Schema.Field> fields = schema.getFields();
    int size = fields.size();
    String[] names = new String[size];
    String[] descriptions = new String[size];
    OpenType<?>[] types = new OpenType<?>[size];
    for (Schema.Field field : fields) {
        int pos = field.pos();
        names[pos] = field.name();
        descriptions[pos] = field.doc();
        types[pos] = typeMapper.get(getGenericType(field.schema())).getOpenType();
    }
    try {
        return new CompositeType(schema.getFullName(), schema.getDoc(), names, descriptions, types);
    } catch (OpenDataException ex) {
        throw new UncheckedExecutionException(ex);
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) OpenDataException(javax.management.openmbean.OpenDataException) Schema(org.apache.avro.Schema) CompositeType(javax.management.openmbean.CompositeType)

Example 92 with OpenDataException

use of javax.management.openmbean.OpenDataException in project acs-aem-commons by Adobe-Consulting-Services.

the class AbstractCacheMBean method getCacheContents.

@Override
public final TabularData getCacheContents() throws CacheMBeanException {
    try {
        final CompositeType cacheEntryType = getCacheEntryType();
        final TabularDataSupport tabularData = new TabularDataSupport(new TabularType("Cache Entries", "Cache Entries", cacheEntryType, new String[] { JMX_PN_CACHEKEY }));
        Map<K, V> cacheAsMap = getCacheAsMap();
        for (final Map.Entry<K, V> entry : cacheAsMap.entrySet()) {
            final Map<String, Object> data = new HashMap<String, Object>();
            data.put(JMX_PN_CACHEKEY, entry.getKey().toString());
            V cacheObj = entry.getValue();
            if (cacheObj != null) {
                addCacheData(data, cacheObj);
            }
            tabularData.put(new CompositeDataSupport(cacheEntryType, data));
        }
        return tabularData;
    } catch (OpenDataException ex) {
        throw new CacheMBeanException("Error getting the cache contents", ex);
    }
}
Also used : HashMap(java.util.HashMap) TabularType(javax.management.openmbean.TabularType) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport) CacheMBeanException(com.adobe.acs.commons.util.impl.exception.CacheMBeanException) HashMap(java.util.HashMap) Map(java.util.Map) CompositeType(javax.management.openmbean.CompositeType)

Example 93 with OpenDataException

use of javax.management.openmbean.OpenDataException in project acs-aem-commons by Adobe-Consulting-Services.

the class ThrottledTaskRunnerImpl method getStatistics.

@Override
public TabularDataSupport getStatistics() {
    try {
        TabularDataSupport stats = new TabularDataSupport(RunningStatistic.getStaticsTableType());
        stats.put(waitTime.getStatistics());
        stats.put(throttleTime.getStatistics());
        stats.put(processingTime.getStatistics());
        return stats;
    } catch (OpenDataException ex) {
        LOG.error("Error generating statistics", ex);
        return null;
    }
}
Also used : OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport)

Example 94 with OpenDataException

use of javax.management.openmbean.OpenDataException in project motech by motech.

the class MBeanService method getQueueMessages.

/**
 * Retrieves a list of messages for the given JMS queue.
 *
 * @param queueName The name of the queue for which messages should be retrieved.
 * @return {@link List} of messages for the given queue.
 */
@PreAuthorize(SecurityConstants.MANAGE_ACTIVEMQ)
public List<QueueMessage> getQueueMessages(String queueName) {
    try {
        ArrayList<QueueMessage> queueMessages = new ArrayList<>();
        QueueViewMBean queueViewMBean = mBeanServer.getQueueViewMBean(queueName);
        for (CompositeData compositeData : queueViewMBean.browse()) {
            if (compositeData != null) {
                String messageId = (String) compositeData.get(JMS_MESSAGE_ID);
                Boolean redelivered = (Boolean) compositeData.get(JMS_REDELIVERED);
                Date timestamp = (Date) compositeData.get(JMS_TIMESTAMP);
                queueMessages.add(new QueueMessage(messageId, redelivered, DateUtil.newDateTime(timestamp)));
            }
        }
        return queueMessages;
    } catch (OpenDataException openDataException) {
        throw new MotechException(String.format("Could not Browse MBean for queue %s", queueName), openDataException);
    } catch (IOException ioException) {
        throw new MotechException(String.format("Could not access MBean for queue %s", queueName), ioException);
    }
}
Also used : MotechException(org.motechproject.commons.api.MotechException) QueueMessage(org.motechproject.admin.domain.QueueMessage) OpenDataException(javax.management.openmbean.OpenDataException) CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) QueueViewMBean(org.apache.activemq.broker.jmx.QueueViewMBean) IOException(java.io.IOException) Date(java.util.Date) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 95 with OpenDataException

use of javax.management.openmbean.OpenDataException 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;
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) CompositeType(javax.management.openmbean.CompositeType)

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