Java Code Examples for javax.management.openmbean.TabularData

The following are top voted examples for showing how to use javax.management.openmbean.TabularData. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: openjdk-jdk10   File: XMBeanNotifications.java   Source Code and License 7 votes vote down vote up
@Override
public String toString() {
    if (userData == null) {
        return null;
    }
    if (userData.getClass().isArray()) {
        String name =
                Utils.getArrayClassName(userData.getClass().getName());
        int length = Array.getLength(userData);
        return name + "[" + length + "]";
    }

    if (userData instanceof CompositeData ||
            userData instanceof TabularData) {
        return userData.getClass().getName();
    }

    return userData.toString();
}
 
Example 2
Project: quartz-web   File: JSONWriter.java   Source Code and License 6 votes vote down vote up
public void writeTabularData(TabularData tabularData) {
    if (tabularData == null) {
        writeNull();
        return;
    }

    int entryIndex = 0;
    write('[');

    for (Object item : tabularData.values()) {
        if (entryIndex != 0) {
            write(',');
        }
        CompositeData row = (CompositeData) item;
        writeCompositeData(row);

        entryIndex++;
    }
    write(']');
}
 
Example 3
Project: asura   File: QuartzSchedulerMBeanImpl.java   Source Code and License 6 votes vote down vote up
public TabularData getAllTriggers(String instanceId)
		throws SchedulerException {
	SchedulingContext cntx = new SchedulingContext(instanceId);
	List<Trigger> triggerList = new ArrayList<Trigger>();

	for (String triggerGroupName : scheduler.getTriggerGroupNames(cntx)) {
		for (String triggerName : scheduler.getTriggerNames(cntx,
				triggerGroupName)) {
			triggerList.add(scheduler.getTrigger(cntx, triggerName,
					triggerGroupName));
		}
	}

	return TriggerSupport.toTabularData(triggerList
			.toArray(new Trigger[triggerList.size()]));
}
 
Example 4
Project: asura   File: JobDetailSupport.java   Source Code and License 6 votes vote down vote up
/**
 * @param cData
 * @return JobDetail
 */
public static JobDetail newJobDetail(CompositeData cData) {
	JobDetail jobDetail = new JobDetail();

	int i = 0;
	jobDetail.setName((String) cData.get(ITEM_NAMES[i++]));
	jobDetail.setGroup((String) cData.get(ITEM_NAMES[i++]));
	jobDetail.setDescription((String) cData.get(ITEM_NAMES[i++]));
	try {
		Class c = Class.forName((String) cData.get(ITEM_NAMES[i++]));
		jobDetail.setJobClass(c);
	} catch (ClassNotFoundException cnfe) {
		/**/
	}
	jobDetail.setJobDataMap(JobDataMapSupport
			.newJobDataMap((TabularData) cData.get(ITEM_NAMES[i++])));
	jobDetail.setVolatility((Boolean) cData.get(ITEM_NAMES[i++]));
	jobDetail.setDurability((Boolean) cData.get(ITEM_NAMES[i++]));
	jobDetail.setRequestsRecovery((Boolean) cData.get(ITEM_NAMES[i++]));

	return jobDetail;
}
 
Example 5
Project: OpenJSharp   File: XMBeanNotifications.java   Source Code and License 6 votes vote down vote up
@Override
public String toString() {
    if (userData == null) {
        return null;
    }
    if (userData.getClass().isArray()) {
        String name =
                Utils.getArrayClassName(userData.getClass().getName());
        int length = Array.getLength(userData);
        return name + "[" + length + "]";
    }

    if (userData instanceof CompositeData ||
            userData instanceof TabularData) {
        return userData.getClass().getName();
    }

    return userData.toString();
}
 
Example 6
Project: OpenJSharp   File: XMBeanAttributes.java   Source Code and License 6 votes vote down vote up
@Override
public String toString() {

    if(value == null) return null;

    if(value.getClass().isArray()) {
        String name =
            Utils.getArrayClassName(value.getClass().getName());
        int length = Array.getLength(value);
        return name + "[" + length +"]";
    }

    if(value instanceof CompositeData ||
       value instanceof TabularData)
        return value.getClass().getName();

    return value.toString();
}
 
Example 7
Project: OpenJSharp   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
@Override
final Object fromNonNullOpenValue(Object openValue)
        throws InvalidObjectException {
    final TabularData table = (TabularData) openValue;
    final Collection<CompositeData> rows = cast(table.values());
    final Map<Object, Object> valueMap =
        sortedMap ? newSortedMap() : newInsertionOrderMap();
    for (CompositeData row : rows) {
        final Object key =
            keyMapping.fromOpenValue(row.get("key"));
        final Object value =
            valueMapping.fromOpenValue(row.get("value"));
        if (valueMap.put(key, value) != null) {
            final String msg =
                "Duplicate entry in TabularData: key=" + key;
            throw new InvalidObjectException(msg);
        }
    }
    return valueMap;
}
 
Example 8
Project: jdk8u-jdk   File: XMBeanNotifications.java   Source Code and License 6 votes vote down vote up
@Override
public String toString() {
    if (userData == null) {
        return null;
    }
    if (userData.getClass().isArray()) {
        String name =
                Utils.getArrayClassName(userData.getClass().getName());
        int length = Array.getLength(userData);
        return name + "[" + length + "]";
    }

    if (userData instanceof CompositeData ||
            userData instanceof TabularData) {
        return userData.getClass().getName();
    }

    return userData.toString();
}
 
Example 9
Project: jdk8u-jdk   File: XMBeanAttributes.java   Source Code and License 6 votes vote down vote up
@Override
public String toString() {

    if(value == null) return null;

    if(value.getClass().isArray()) {
        String name =
            Utils.getArrayClassName(value.getClass().getName());
        int length = Array.getLength(value);
        return name + "[" + length +"]";
    }

    if(value instanceof CompositeData ||
       value instanceof TabularData)
        return value.getClass().getName();

    return value.toString();
}
 
Example 10
Project: jdk8u-jdk   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
@Override
final Object fromNonNullOpenValue(Object openValue)
        throws InvalidObjectException {
    final TabularData table = (TabularData) openValue;
    final Collection<CompositeData> rows = cast(table.values());
    final Map<Object, Object> valueMap =
        sortedMap ? newSortedMap() : newInsertionOrderMap();
    for (CompositeData row : rows) {
        final Object key =
            keyMapping.fromOpenValue(row.get("key"));
        final Object value =
            valueMapping.fromOpenValue(row.get("value"));
        if (valueMap.put(key, value) != null) {
            final String msg =
                "Duplicate entry in TabularData: key=" + key;
            throw new InvalidObjectException(msg);
        }
    }
    return valueMap;
}
 
Example 11
Project: openjdk-jdk10   File: XMBeanAttributes.java   Source Code and License 6 votes vote down vote up
@Override
public String toString() {

    if(value == null) return null;

    if(value.getClass().isArray()) {
        String name =
            Utils.getArrayClassName(value.getClass().getName());
        int length = Array.getLength(value);
        return name + "[" + length +"]";
    }

    if(value instanceof CompositeData ||
       value instanceof TabularData)
        return value.getClass().getName();

    return value.toString();
}
 
Example 12
Project: openjdk-jdk10   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
@Override
final Object fromNonNullOpenValue(Object openValue)
        throws InvalidObjectException {
    final TabularData table = (TabularData) openValue;
    final Collection<CompositeData> rows = cast(table.values());
    final Map<Object, Object> valueMap =
        sortedMap ? newSortedMap() : newInsertionOrderMap();
    for (CompositeData row : rows) {
        final Object key =
            keyMapping.fromOpenValue(row.get("key"));
        final Object value =
            valueMapping.fromOpenValue(row.get("value"));
        if (valueMap.put(key, value) != null) {
            final String msg =
                "Duplicate entry in TabularData: key=" + key;
            throw new InvalidObjectException(msg);
        }
    }
    return valueMap;
}
 
Example 13
Project: openjdk9   File: XMBeanNotifications.java   Source Code and License 6 votes vote down vote up
@Override
public String toString() {
    if (userData == null) {
        return null;
    }
    if (userData.getClass().isArray()) {
        String name =
                Utils.getArrayClassName(userData.getClass().getName());
        int length = Array.getLength(userData);
        return name + "[" + length + "]";
    }

    if (userData instanceof CompositeData ||
            userData instanceof TabularData) {
        return userData.getClass().getName();
    }

    return userData.toString();
}
 
Example 14
Project: openjdk9   File: XMBeanAttributes.java   Source Code and License 6 votes vote down vote up
@Override
public String toString() {

    if(value == null) return null;

    if(value.getClass().isArray()) {
        String name =
            Utils.getArrayClassName(value.getClass().getName());
        int length = Array.getLength(value);
        return name + "[" + length +"]";
    }

    if(value instanceof CompositeData ||
       value instanceof TabularData)
        return value.getClass().getName();

    return value.toString();
}
 
Example 15
Project: openjdk9   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
@Override
final Object fromNonNullOpenValue(Object openValue)
        throws InvalidObjectException {
    final TabularData table = (TabularData) openValue;
    final Collection<CompositeData> rows = cast(table.values());
    final Map<Object, Object> valueMap =
        sortedMap ? newSortedMap() : newInsertionOrderMap();
    for (CompositeData row : rows) {
        final Object key =
            keyMapping.fromOpenValue(row.get("key"));
        final Object value =
            valueMapping.fromOpenValue(row.get("value"));
        if (valueMap.put(key, value) != null) {
            final String msg =
                "Duplicate entry in TabularData: key=" + key;
            throw new InvalidObjectException(msg);
        }
    }
    return valueMap;
}
 
Example 16
Project: djigger   File: MBeanCollector.java   Source Code and License 6 votes vote down vote up
private void recursive(GenericObject object, String key, Object value) {
	if (value instanceof CompositeData) {
		CompositeData composite = (CompositeData) value;
		object.put(key, toGenericObject(composite));
	} else if (value instanceof TabularData) {
		TabularData tabularData = (TabularData) value;
		@SuppressWarnings("unchecked")
		Collection<CompositeData> values = (Collection<CompositeData>) tabularData.values();
		GenericArray array = new GenericArray();
		for (CompositeData data : values) {
			array.add(toGenericObject(data));
		}
		object.put(key, array);
	} else if (value instanceof Number || value instanceof Boolean || value instanceof String){
		object.put(key, value);
	} else {
		// todo log
	}
}
 
Example 17
Project: jdk8u_jdk   File: XMBeanNotifications.java   Source Code and License 6 votes vote down vote up
@Override
public String toString() {
    if (userData == null) {
        return null;
    }
    if (userData.getClass().isArray()) {
        String name =
                Utils.getArrayClassName(userData.getClass().getName());
        int length = Array.getLength(userData);
        return name + "[" + length + "]";
    }

    if (userData instanceof CompositeData ||
            userData instanceof TabularData) {
        return userData.getClass().getName();
    }

    return userData.toString();
}
 
Example 18
Project: jdk8u_jdk   File: XMBeanAttributes.java   Source Code and License 6 votes vote down vote up
@Override
public String toString() {

    if(value == null) return null;

    if(value.getClass().isArray()) {
        String name =
            Utils.getArrayClassName(value.getClass().getName());
        int length = Array.getLength(value);
        return name + "[" + length +"]";
    }

    if(value instanceof CompositeData ||
       value instanceof TabularData)
        return value.getClass().getName();

    return value.toString();
}
 
Example 19
Project: jdk8u_jdk   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
@Override
final Object fromNonNullOpenValue(Object openValue)
        throws InvalidObjectException {
    final TabularData table = (TabularData) openValue;
    final Collection<CompositeData> rows = cast(table.values());
    final Map<Object, Object> valueMap =
        sortedMap ? newSortedMap() : newInsertionOrderMap();
    for (CompositeData row : rows) {
        final Object key =
            keyMapping.fromOpenValue(row.get("key"));
        final Object value =
            valueMapping.fromOpenValue(row.get("value"));
        if (valueMap.put(key, value) != null) {
            final String msg =
                "Duplicate entry in TabularData: key=" + key;
            throw new InvalidObjectException(msg);
        }
    }
    return valueMap;
}
 
Example 20
Project: lookaside_java-1.8.0-openjdk   File: XMBeanNotifications.java   Source Code and License 6 votes vote down vote up
@Override
public String toString() {
    if (userData == null) {
        return null;
    }
    if (userData.getClass().isArray()) {
        String name =
                Utils.getArrayClassName(userData.getClass().getName());
        int length = Array.getLength(userData);
        return name + "[" + length + "]";
    }

    if (userData instanceof CompositeData ||
            userData instanceof TabularData) {
        return userData.getClass().getName();
    }

    return userData.toString();
}
 
Example 21
Project: lookaside_java-1.8.0-openjdk   File: XMBeanAttributes.java   Source Code and License 6 votes vote down vote up
@Override
public String toString() {

    if(value == null) return null;

    if(value.getClass().isArray()) {
        String name =
            Utils.getArrayClassName(value.getClass().getName());
        int length = Array.getLength(value);
        return name + "[" + length +"]";
    }

    if(value instanceof CompositeData ||
       value instanceof TabularData)
        return value.getClass().getName();

    return value.toString();
}
 
Example 22
Project: lookaside_java-1.8.0-openjdk   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
@Override
final Object fromNonNullOpenValue(Object openValue)
        throws InvalidObjectException {
    final TabularData table = (TabularData) openValue;
    final Collection<CompositeData> rows = cast(table.values());
    final Map<Object, Object> valueMap =
        sortedMap ? newSortedMap() : newInsertionOrderMap();
    for (CompositeData row : rows) {
        final Object key =
            keyMapping.fromOpenValue(row.get("key"));
        final Object value =
            valueMapping.fromOpenValue(row.get("value"));
        if (valueMap.put(key, value) != null) {
            final String msg =
                "Duplicate entry in TabularData: key=" + key;
            throw new InvalidObjectException(msg);
        }
    }
    return valueMap;
}
 
Example 23
Project: cuba   File: AttributeHelper.java   Source Code and License 6 votes vote down vote up
public static String convertToString(Object value) {
    if (value == null) {
        return null;
    }

    if (value.getClass().isArray()) {
        StringBuilder b = new StringBuilder("[");
        int length = Array.getLength(value);
        for (int i = 0; i < length; i++) {
            Object o = Array.get(value, i);
            b.append(convertToString(o));
            if (i < length - 1) {
                b.append(", ");
            }
        }
        return b.append("]").toString();
    }
    else if (value instanceof CompositeData) {
        return compositeToString((CompositeData) value);
    }
    else if (value instanceof TabularData) {
        return tabularToString((TabularData) value);
    }
    return value.toString();
}
 
Example 24
Project: Camel   File: ManagedInflightRepository.java   Source Code and License 6 votes vote down vote up
@Override
public TabularData browse(String routeId, int limit, boolean sortByLongestDuration) {
    try {
        TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.listInflightExchangesTabularType());
        Collection<InflightRepository.InflightExchange> exchanges = inflightRepository.browse(routeId, limit, sortByLongestDuration);

        for (InflightRepository.InflightExchange entry : exchanges) {
            CompositeType ct = CamelOpenMBeanTypes.listInflightExchangesCompositeType();
            String exchangeId = entry.getExchange().getExchangeId();
            String fromRouteId = entry.getFromRouteId();
            String atRouteId = entry.getAtRouteId();
            String nodeId = entry.getNodeId();
            String elapsed = "" + entry.getElapsed();
            String duration = "" + entry.getDuration();

            CompositeData data = new CompositeDataSupport(ct,
                    new String[]{"exchangeId", "fromRouteId", "routeId", "nodeId", "elapsed", "duration"},
                    new Object[]{exchangeId, fromRouteId, atRouteId, nodeId, elapsed, duration});
            answer.put(data);
        }
        return answer;
    } catch (Exception e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
}
 
Example 25
Project: Camel   File: ManagedSendProcessor.java   Source Code and License 6 votes vote down vote up
@Override
public TabularData extendedInformation() {
    try {
        TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.endpointsUtilizationTabularType());

        // we only have 1 endpoint

        CompositeType ct = CamelOpenMBeanTypes.endpointsUtilizationCompositeType();
        String url = getDestination();
        Long hits = processor.getCounter();

        CompositeData data = new CompositeDataSupport(ct, new String[]{"url", "hits"}, new Object[]{url, hits});
        answer.put(data);
        return answer;
    } catch (Exception e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
}
 
Example 26
Project: Camel   File: ManagedEndpointRegistry.java   Source Code and License 6 votes vote down vote up
@SuppressWarnings("unchecked")
public TabularData listEndpoints() {
    try {
        TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.listEndpointsTabularType());
        Collection<Endpoint> endpoints = endpointRegistry.values();
        for (Endpoint endpoint : endpoints) {
            CompositeType ct = CamelOpenMBeanTypes.listEndpointsCompositeType();
            String url = endpoint.getEndpointUri();
            if (sanitize) {
                url = URISupport.sanitizeUri(url);
            }

            boolean fromStatic = endpointRegistry.isStatic(url);
            boolean fromDynamic = endpointRegistry.isDynamic(url);

            CompositeData data = new CompositeDataSupport(ct, new String[]{"url", "static", "dynamic"}, new Object[]{url, fromStatic, fromDynamic});
            answer.put(data);
        }
        return answer;
    } catch (Exception e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
}
 
Example 27
Project: Camel   File: ManagedAsyncProcessorAwaitManager.java   Source Code and License 6 votes vote down vote up
@Override
public TabularData browse() {
    try {
        TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.listAwaitThreadsTabularType());
        Collection<AsyncProcessorAwaitManager.AwaitThread> threads = manager.browse();
        for (AsyncProcessorAwaitManager.AwaitThread entry : threads) {
            CompositeType ct = CamelOpenMBeanTypes.listAwaitThreadsCompositeType();
            String id = "" + entry.getBlockedThread().getId();
            String name = entry.getBlockedThread().getName();
            String exchangeId = entry.getExchange().getExchangeId();
            String routeId = entry.getRouteId();
            String nodeId = entry.getNodeId();
            String duration = "" + entry.getWaitDuration();

            CompositeData data = new CompositeDataSupport(ct,
                    new String[]{"id", "name", "exchangeId", "routeId", "nodeId", "duration"},
                    new Object[]{id, name, exchangeId, routeId, nodeId, duration});
            answer.put(data);
        }
        return answer;
    } catch (Exception e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
}
 
Example 28
Project: Camel   File: ManagedTypeConverterRegistry.java   Source Code and License 6 votes vote down vote up
public TabularData listTypeConverters() {
    try {
        TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.listTypeConvertersTabularType());
        List<Class<?>[]> converters = registry.listAllTypeConvertersFromTo();
        for (Class<?>[] entry : converters) {
            CompositeType ct = CamelOpenMBeanTypes.listTypeConvertersCompositeType();
            String from = entry[0].getCanonicalName();
            String to = entry[1].getCanonicalName();
            CompositeData data = new CompositeDataSupport(ct, new String[]{"from", "to"}, new Object[]{from, to});
            answer.put(data);
        }
        return answer;
    } catch (Exception e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
}
 
Example 29
Project: Camel   File: ManagedCamelContext.java   Source Code and License 6 votes vote down vote up
public TabularData listEips() throws Exception {
    try {
        // find all EIPs
        Map<String, Properties> eips = context.findEips();

        TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.listEipsTabularType());

        // gather EIP detail for each eip
        for (Map.Entry<String, Properties> entry : eips.entrySet()) {
            String name = entry.getKey();
            String title = (String) entry.getValue().get("title");
            String description = (String) entry.getValue().get("description");
            String label = (String) entry.getValue().get("label");
            String type = (String) entry.getValue().get("class");
            String status = CamelContextHelper.isEipInUse(context, name) ? "in use" : "on classpath";
            CompositeType ct = CamelOpenMBeanTypes.listEipsCompositeType();
            CompositeData data = new CompositeDataSupport(ct, new String[]{"name", "title", "description", "label", "status", "type"},
                    new Object[]{name, title, description, label, status, type});
            answer.put(data);
        }
        return answer;
    } catch (Exception e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
}
 
Example 30
Project: Camel   File: SpringManagedCamelContextTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testListEips() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }

    MBeanServer mbeanServer = getMBeanServer();

    ObjectName on = ObjectName.getInstance("org.apache.camel:context=19-camel-1,type=context,name=\"camel-1\"");

    assertTrue("Should be registered", mbeanServer.isRegistered(on));

    @SuppressWarnings("unchecked")
    TabularData data = (TabularData) mbeanServer.invoke(on, "listEips", null, null);
    assertNotNull(data);
    assertTrue(data.size() > 150);
}
 
Example 31
Project: scylla-jmx   File: FailureDetector.java   Source Code and License 6 votes vote down vote up
@Override
public TabularData getPhiValues() throws OpenDataException {
    final CompositeType ct = new CompositeType("Node", "Node", new String[] { "Endpoint", "PHI" },
            new String[] { "IP of the endpoint", "PHI value" },
            new OpenType[] { SimpleType.STRING, SimpleType.DOUBLE });
    final TabularDataSupport results = new TabularDataSupport(
            new TabularType("PhiList", "PhiList", ct, new String[] { "Endpoint" }));
    final JsonArray arr = client.getJsonArray("/failure_detector/endpoint_phi_values");

    for (JsonValue v : arr) {
        JsonObject o = (JsonObject) v;
        String endpoint = o.getString("endpoint");
        double phi = Double.parseDouble(o.getString("phi"));

        if (phi != Double.MIN_VALUE) {
            // returned values are scaled by PHI_FACTOR so that the are on
            // the same scale as PhiConvictThreshold
            final CompositeData data = new CompositeDataSupport(ct, new String[] { "Endpoint", "PHI" },
                    new Object[] { endpoint, phi * PHI_FACTOR });
            results.put(data);
        }
    }

    return results;
}
 
Example 32
Project: scylla-jmx   File: APIClient.java   Source Code and License 6 votes vote down vote up
public Map<String, TabularData> getMapStringSnapshotTabularDataValue(String string,
        MultivaluedMap<String, String> queryParams) {
    if (string.equals("")) {
        return null;
    }
    JsonReader reader = getReader(string, queryParams);
    JsonArray arr = reader.readArray();
    Map<String, TabularData> map = new HashMap<>();

    for (int i = 0; i < arr.size(); i++) {
        JsonObject obj = arr.getJsonObject(i);
        if (obj.containsKey("key") && obj.containsKey("value")) {
            String key = obj.getString("key");
            map.put(key, getSnapshotData(key, obj.getJsonArray("value")));
        }
    }
    reader.close();
    return map;
}
 
Example 33
Project: cassandra-kmean   File: NodeTool.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(NodeProbe probe)
{
    System.out.println("Compaction History: ");

    TabularData tabularData = probe.getCompactionHistory();
    if (tabularData.isEmpty())
    {
        System.out.printf("There is no compaction history");
        return;
    }

    String format = "%-41s%-19s%-29s%-26s%-15s%-15s%s%n";
    List<String> indexNames = tabularData.getTabularType().getIndexNames();
    System.out.printf(format, toArray(indexNames, Object.class));

    Set<?> values = tabularData.keySet();
    for (Object eachValue : values)
    {
        List<?> value = (List<?>) eachValue;
        System.out.printf(format, toArray(value, Object.class));
    }
}
 
Example 34
Project: parfait   File: JmxInProgressMonitor.java   Source Code and License 6 votes vote down vote up
@Override
public TabularData apply(InProgressSnapshot from) {
    List<OpenType<?>> types = Lists.transform(from.getColumnClasses(), CLASS_TO_OPENTYPE);

    CompositeType rowType;
    try {
        int columnCount = from.getColumnCount();
        rowType = new CompositeType("Snapshot row", "Snapshot row", from.getColumnNames()
                .toArray(new String[columnCount]), from.getColumnDescriptions().toArray(
                new String[columnCount]), types.toArray(new OpenType<?>[columnCount]));
        TabularType type = new TabularType("Snapshot", "Snapshot", rowType,
                new String[] { "Thread name" });
        TabularData data = new TabularDataSupport(type);

        for (Map<String, Object> dataRow : from.getValues()) {
            CompositeData row = new CompositeDataSupport(rowType, dataRow);
            data.put(row);
        }
        return data;
    } catch (OpenDataException e) {
        throw new RuntimeException(e);
    }
}
 
Example 35
Project: boon   File: MBeans.java   Source Code and License 6 votes vote down vote up
private static Object convertFromTabularDataToMap( Object value ) {
    final TabularData data = ( TabularData ) value;

    final Set<List<?>> keys = ( Set<List<?>> ) data.keySet();

    final Map<String, Object> map = new HashMap<>();
    for ( final List<?> key : keys ) {
        final Object subValue = convertValue( data.get( key.toArray() ) );

        if ( key.size() == 1 ) {
            map.put( convertValue( key.get( 0 ) ).toString(), subValue );
        } else {
            map.put( convertValue( key ).toString(), subValue );
        }
    }

    value = map;
    return value;
}
 
Example 36
Project: tnt4j-stream-jmx   File: DefaultSampleListener.java   Source Code and License 6 votes vote down vote up
/**
 * Process/extract value from a given MBean attribute
 *
 * @param snapshot instance where extracted attribute is stored
 * @param mbAttrInfo MBean attribute info
 * @param propName name to be assigned to given attribute value
 * @param value associated with attribute
 * @return snapshot instance where all attributes are contained
 */
protected PropertySnapshot processAttrValue(PropertySnapshot snapshot, MBeanAttributeInfo mbAttrInfo,
		PropertyNameBuilder propName, Object value) {
	if (value instanceof CompositeData) {
		CompositeData cdata = (CompositeData) value;
		Set<String> keys = cdata.getCompositeType().keySet();
		for (String key : keys) {
			Object cVal = cdata.get(key);
			processAttrValue(snapshot, mbAttrInfo, propName.append(key), cVal);
			propName.popLevel();
		}
	} else if (value instanceof TabularData) {
		TabularData tData = (TabularData) value;
		Collection<?> values = tData.values();
		int row = 0;
		for (Object tVal : values) {
			processAttrValue(snapshot, mbAttrInfo, propName.append(padNumber(++row)), tVal);
			propName.popLevel();
		}
	} else {
		snapshot.add(propName.propString(), value);
	}
	return snapshot;
}
 
Example 37
Project: infobip-open-jdk-8   File: XMBeanNotifications.java   Source Code and License 6 votes vote down vote up
@Override
public String toString() {
    if (userData == null) {
        return null;
    }
    if (userData.getClass().isArray()) {
        String name =
                Utils.getArrayClassName(userData.getClass().getName());
        int length = Array.getLength(userData);
        return name + "[" + length + "]";
    }

    if (userData instanceof CompositeData ||
            userData instanceof TabularData) {
        return userData.getClass().getName();
    }

    return userData.toString();
}
 
Example 38
Project: infobip-open-jdk-8   File: XMBeanAttributes.java   Source Code and License 6 votes vote down vote up
@Override
public String toString() {

    if(value == null) return null;

    if(value.getClass().isArray()) {
        String name =
            Utils.getArrayClassName(value.getClass().getName());
        int length = Array.getLength(value);
        return name + "[" + length +"]";
    }

    if(value instanceof CompositeData ||
       value instanceof TabularData)
        return value.getClass().getName();

    return value.toString();
}
 
Example 39
Project: infobip-open-jdk-8   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
@Override
final Object fromNonNullOpenValue(Object openValue)
        throws InvalidObjectException {
    final TabularData table = (TabularData) openValue;
    final Collection<CompositeData> rows = cast(table.values());
    final Map<Object, Object> valueMap =
        sortedMap ? newSortedMap() : newInsertionOrderMap();
    for (CompositeData row : rows) {
        final Object key =
            keyMapping.fromOpenValue(row.get("key"));
        final Object value =
            valueMapping.fromOpenValue(row.get("value"));
        if (valueMap.put(key, value) != null) {
            final String msg =
                "Duplicate entry in TabularData: key=" + key;
            throw new InvalidObjectException(msg);
        }
    }
    return valueMap;
}
 
Example 40
Project: jdk8u-dev-jdk   File: XMBeanNotifications.java   Source Code and License 6 votes vote down vote up
@Override
public String toString() {
    if (userData == null) {
        return null;
    }
    if (userData.getClass().isArray()) {
        String name =
                Utils.getArrayClassName(userData.getClass().getName());
        int length = Array.getLength(userData);
        return name + "[" + length + "]";
    }

    if (userData instanceof CompositeData ||
            userData instanceof TabularData) {
        return userData.getClass().getName();
    }

    return userData.toString();
}
 
Example 41
Project: jdk8u-dev-jdk   File: XMBeanAttributes.java   Source Code and License 6 votes vote down vote up
@Override
public String toString() {

    if(value == null) return null;

    if(value.getClass().isArray()) {
        String name =
            Utils.getArrayClassName(value.getClass().getName());
        int length = Array.getLength(value);
        return name + "[" + length +"]";
    }

    if(value instanceof CompositeData ||
       value instanceof TabularData)
        return value.getClass().getName();

    return value.toString();
}
 
Example 42
Project: jdk8u-dev-jdk   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
@Override
final Object fromNonNullOpenValue(Object openValue)
        throws InvalidObjectException {
    final TabularData table = (TabularData) openValue;
    final Collection<CompositeData> rows = cast(table.values());
    final Map<Object, Object> valueMap =
        sortedMap ? newSortedMap() : newInsertionOrderMap();
    for (CompositeData row : rows) {
        final Object key =
            keyMapping.fromOpenValue(row.get("key"));
        final Object value =
            valueMapping.fromOpenValue(row.get("value"));
        if (valueMap.put(key, value) != null) {
            final String msg =
                "Duplicate entry in TabularData: key=" + key;
            throw new InvalidObjectException(msg);
        }
    }
    return valueMap;
}
 
Example 43
Project: activemq-artemis   File: JobSchedulerJmxManagementTests.java   Source Code and License 6 votes vote down vote up
@Test
public void testRemvoeJob() throws Exception {
   JobSchedulerViewMBean view = getJobSchedulerMBean();
   assertNotNull(view);
   assertTrue(view.getAllJobs().isEmpty());
   scheduleMessage(60000, -1, -1);
   assertFalse(view.getAllJobs().isEmpty());
   TabularData jobs = view.getAllJobs();
   assertEquals(1, jobs.size());
   for (Object key : jobs.keySet()) {
      String jobId = ((List<?>) key).get(0).toString();
      LOG.info("Attempting to remove Job: {}", jobId);
      view.removeJob(jobId);
   }
   assertTrue(view.getAllJobs().isEmpty());
}
 
Example 44
Project: activemq-artemis   File: JobSchedulerJmxManagementTests.java   Source Code and License 6 votes vote down vote up
@Test
public void testGetExecutionCount() throws Exception {
   final JobSchedulerViewMBean view = getJobSchedulerMBean();
   assertNotNull(view);
   assertTrue(view.getAllJobs().isEmpty());
   scheduleMessage(10000, 1000, 10);
   assertFalse(view.getAllJobs().isEmpty());
   TabularData jobs = view.getAllJobs();
   assertEquals(1, jobs.size());
   String jobId = null;
   for (Object key : jobs.keySet()) {
      jobId = ((List<?>) key).get(0).toString();
   }

   final String fixedJobId = jobId;
   LOG.info("Attempting to get execution count for Job: {}", jobId);
   assertEquals(0, view.getExecutionCount(jobId));

   assertTrue("Should execute again", Wait.waitFor(new Wait.Condition() {

      @Override
      public boolean isSatisified() throws Exception {
         return view.getExecutionCount(fixedJobId) > 0;
      }
   }));
}
 
Example 45
Project: scylla-tools-java   File: CompactionHistory.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(NodeProbe probe)
{
    System.out.println("Compaction History: ");

    TabularData tabularData = probe.getCompactionHistory();
    if (tabularData.isEmpty())
    {
        System.out.printf("There is no compaction history");
        return;
    }

    String format = "%-41s%-19s%-29s%-26s%-15s%-15s%s%n";
    List<String> indexNames = tabularData.getTabularType().getIndexNames();
    System.out.printf(format, toArray(indexNames, Object.class));

    Set<?> values = tabularData.keySet();
    for (Object eachValue : values)
    {
        List<?> value = (List<?>) eachValue;
        System.out.printf(format, toArray(value, Object.class));
    }
}
 
Example 46
Project: jdk7-jdk   File: XMBeanNotifications.java   Source Code and License 6 votes vote down vote up
@Override
public String toString() {
    if (userData == null) {
        return null;
    }
    if (userData.getClass().isArray()) {
        String name =
                Utils.getArrayClassName(userData.getClass().getName());
        int length = Array.getLength(userData);
        return name + "[" + length + "]";
    }

    if (userData instanceof CompositeData ||
            userData instanceof TabularData) {
        return userData.getClass().getName();
    }

    return userData.toString();
}
 
Example 47
Project: jdk7-jdk   File: XMBeanAttributes.java   Source Code and License 6 votes vote down vote up
@Override
public String toString() {

    if(value == null) return null;

    if(value.getClass().isArray()) {
        String name =
            Utils.getArrayClassName(value.getClass().getName());
        int length = Array.getLength(value);
        return name + "[" + length +"]";
    }

    if(value instanceof CompositeData ||
       value instanceof TabularData)
        return value.getClass().getName();

    return value.toString();
}
 
Example 48
Project: jdk7-jdk   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
@Override
final Object fromNonNullOpenValue(Object openValue)
        throws InvalidObjectException {
    final TabularData table = (TabularData) openValue;
    final Collection<CompositeData> rows = cast(table.values());
    final Map<Object, Object> valueMap =
        sortedMap ? newSortedMap() : newInsertionOrderMap();
    for (CompositeData row : rows) {
        final Object key =
            keyMapping.fromOpenValue(row.get("key"));
        final Object value =
            valueMapping.fromOpenValue(row.get("value"));
        if (valueMap.put(key, value) != null) {
            final String msg =
                "Duplicate entry in TabularData: key=" + key;
            throw new InvalidObjectException(msg);
        }
    }
    return valueMap;
}
 
Example 49
Project: openjdk-jdk7u-jdk   File: DefaultMXBeanMappingFactory.java   Source Code and License 6 votes vote down vote up
@Override
final Object fromNonNullOpenValue(Object openValue)
        throws InvalidObjectException {
    final TabularData table = (TabularData) openValue;
    final Collection<CompositeData> rows = cast(table.values());
    final Map<Object, Object> valueMap =
        sortedMap ? newSortedMap() : newInsertionOrderMap();
    for (CompositeData row : rows) {
        final Object key =
            keyMapping.fromOpenValue(row.get("key"));
        final Object value =
            valueMapping.fromOpenValue(row.get("value"));
        if (valueMap.put(key, value) != null) {
            final String msg =
                "Duplicate entry in TabularData: key=" + key;
            throw new InvalidObjectException(msg);
        }
    }
    return valueMap;
}
 
Example 50
Project: bagri   File: SchemaFeatureManagement.java   Source Code and License 6 votes vote down vote up
protected TabularData getSeriesStatistics(Callable<TabularData> statsTask, StatsAggregator aggregator) {
	logger.trace("getSeriesStatistics.enter; going to collect stats for schema: {}", schemaName);

	int cnt = 0;
	TabularData result = null;
	Map<Member, Future<TabularData>> futures = execService.submitToAllMembers(statsTask);
	for (Map.Entry<Member, Future<TabularData>> entry: futures.entrySet()) {
		try {
			TabularData stats = entry.getValue().get();
			logger.trace("getSeriesStatistics; got stats: {}, from member {}", stats, entry.getKey());
			result = JMXUtils.aggregateStats(stats, result, aggregator);
			logger.trace("getSeriesStatistics; got aggregated result: {}", result);
			cnt++;
		} catch (InterruptedException | ExecutionException ex) {
			logger.error("getSeriesStatistics.error: " + ex.getMessage(), ex);
		}
	}
	logger.trace("getSeriesStatistics.exit; got stats from {} nodes", cnt);
	return result;
}
 
Example 51
Project: bagri   File: SchemaFeatureManagement.java   Source Code and License 6 votes vote down vote up
protected TabularData getTabularFeatures(String name, String desc, String key) {

		logger.trace("getTabularFeatures.enter; schemaManager: {}", schemaManager);
		Schema schema = schemaManager.getEntity();
		Collection<Entity> features = getSchemaFeatures(schema); 
		if (features == null || features.size() == 0) {
			return null;
		}
		
        TabularData result = null;
        for (Entity feature: features) {
            try {
                Map<String, Object> def = feature.convert();
                CompositeData data = JMXUtils.mapToComposite(name, desc, def);
                result = JMXUtils.compositeToTabular(name, desc, key, result, data);
            } catch (Exception ex) {
                logger.error("getTabularFeatures; error", ex);
            }
        }
        return result;
    }
 
Example 52
Project: bagri   File: QueryManagement.java   Source Code and License 6 votes vote down vote up
@ManagedAttribute(description="Return aggregated query usage statistics, per cached query")
public TabularData getQueryCacheStatistics() {
	if (qcAggregator == null) {
		qcAggregator = new StatsAggregator() {

			@Override
			@SuppressWarnings({ "unchecked", "rawtypes" })
			public Object[] aggregateStats(Object[] source, Object[] target) {
				target[0] = (Integer) source[0] + (Integer) target[0]; // accessed
				target[1] = (Integer) source[1] + (Integer) target[1]; // cached results
				target[2] = ((Comparable) source[2]).compareTo((Comparable) target[2]) < 0 ? source[2] : target[2]; // first  
				target[3] = (Integer) source[3] + (Integer) target[3]; // hits
				target[4] = ((Comparable) source[4]).compareTo((Comparable) target[4]) > 0 ? source[4] : target[4]; // last  
				target[5] = (Integer) source[5] + (Integer) target[5]; // miss
				target[6] = source[6]; // query
				target[7] = (Integer) source[7] + (Integer) target[7]; // result hits
				target[8] = (Integer) source[8] + (Integer) target[8]; // result miss
				return target;
			}
			
		};
	}
	
	return super.getUsageStatistics(new StatisticSeriesCollector(schemaName, "queryCacheStats"), qcAggregator);
}
 
Example 53
Project: bagri   File: EntityManagement.java   Source Code and License 6 votes vote down vote up
protected TabularData getEntities(String name, String desc) {
Collection<E> entities = entityCache.values();
if (entities.size() == 0) {
	return null;
}

      TabularData result = null;
      for (Entity entity: entities) {
          try {
              Map<String, Object> def = entity.convert();
              CompositeData data = JMXUtils.mapToComposite(name, desc, def);
              result = JMXUtils.compositeToTabular(name, desc, "name", result, data);
          } catch (Exception ex) {
              logger.error("getEntities; error", ex);
          }
      }
      return result;
  }
 
Example 54
Project: wildfly-core   File: ExpressionTypeConverterUnitTestCase.java   Source Code and License 6 votes vote down vote up
@Test
public void testSimpleTypeObjectExpressions() throws Exception {
    ModelNode description = createDescription(ModelType.OBJECT, ModelType.LONG);
    description.get(EXPRESSIONS_ALLOWED).set(true);
    TypeConverter converter = getConverter(description);

    assertMapType(assertCast(TabularType.class, converter.getOpenType()), SimpleType.STRING, SimpleType.STRING);

    ModelNode node = new ModelNode();
    node.get("one").set(new ValueExpression("${this.should.not.exist.!!!!!:1}"));
    node.get("two").set(new ValueExpression("${this.should.not.exist.!!!!!:2}"));

    TabularData tabularData = assertCast(TabularData.class, converter.fromModelNode(node));
    Assert.assertEquals(2, tabularData.size());
    Assert.assertEquals("${this.should.not.exist.!!!!!:1}", tabularData.get(new Object[] {"one"}).get("value"));
    Assert.assertEquals("${this.should.not.exist.!!!!!:2}", tabularData.get(new Object[] {"two"}).get("value"));

    Assert.assertEquals(node, converter.toModelNode(tabularData));
}
 
Example 55
Project: wildfly-core   File: ExpressionTypeConverterUnitTestCase.java   Source Code and License 6 votes vote down vote up
@Test
public void testByteArrayObject() throws Exception {
    ModelNode description = createDescription(ModelType.OBJECT, ModelType.BYTES);
    TypeConverter converter = getConverter(description);

    assertMapType(assertCast(TabularType.class, converter.getOpenType()), SimpleType.STRING, ArrayType.getPrimitiveArrayType(byte[].class));

    ModelNode node = new ModelNode();
    node.get("one").set(new byte[] {1,2});
    node.get("two").set(new byte[] {3,4});

    TabularData tabularData = assertCast(TabularData.class, converter.fromModelNode(node));
    Assert.assertEquals(2, tabularData.size());
    Assert.assertTrue(Arrays.equals(new byte[] {1,2}, (byte[])tabularData.get(new Object[] {"one"}).get("value")));
    Assert.assertTrue(Arrays.equals(new byte[] {3,4}, (byte[])tabularData.get(new Object[] {"two"}).get("value")));

    //Allow plain map as well? Yeah why not!
    Map<String, byte[]> map = new HashMap<String, byte[]>();
    map.put("one", new byte[] {1,2});
    map.put("two", new byte[] {3,4});
    Assert.assertEquals(node, converter.toModelNode(map));
}
 
Example 56
Project: bagri   File: ClientManagement.java   Source Code and License 6 votes vote down vote up
@ManagedAttribute(description="Return client connection properties, per client")
public TabularData getClientProperties() {
	TabularData result = null;
  		HazelcastClientProxy hzProxy = (com.hazelcast.client.impl.HazelcastClientProxy) schemaManager.getHazelcastClient();
	try {
		for (Map.Entry<String, Properties> e: clientCache.entrySet()) {
			Properties props = e.getValue();
			props.setProperty("client", e.getKey());
			props.remove(pn_schema_password);
			CompositeData data = propsToComposite("clients", "client props", props);
			result = compositeToTabular("clients", "client props", "client", result, data);
		}
	} catch (OpenDataException ex) {
		logger.error("getClientProperties.error: ", ex);
	}
	return result;
}
 
Example 57
Project: andes   File: ExchangeMBeanTest.java   Source Code and License 6 votes vote down vote up
/**
 * Test for "topic" exchange mbean
 * @throws Exception
 */

public void testTopicExchangeMBean() throws Exception
{
    TopicExchange exchange = new TopicExchange();
    exchange.initialise(_virtualHost,ExchangeDefaults.TOPIC_EXCHANGE_NAME, false, 0, true);
    ManagedObject managedObj = exchange.getManagedObject();
    ManagedExchange mbean = (ManagedExchange)managedObj;

    mbean.createNewBinding(_queue.getNameShortString().toString(), "binding1");
    mbean.createNewBinding(_queue.getNameShortString().toString(), "binding2");

    TabularData data = mbean.bindings();
    ArrayList<Object> list = new ArrayList<Object>(data.values());
    assertTrue(list.size() == 2);

    // test general exchange properties
    assertEquals(mbean.getName(), "amq.topic");
    assertEquals(mbean.getExchangeType(), "topic");
    assertTrue(mbean.getTicketNo() == 0);
    assertTrue(!mbean.isDurable());
    assertTrue(mbean.isAutoDelete());
}
 
Example 58
Project: bagri   File: StatisticsCollector.java   Source Code and License 6 votes vote down vote up
public String getStatistics(String kind, String method) throws Exception {
       ObjectName mName = new ObjectName("com.bagri.db:type=Schema,name=" + schema + ",kind=" + kind); 
	TabularData data = (TabularData) mbsc.getAttribute(mName, "InvocationStatistics");
	if (data != null) {
		CompositeData stats = data.get(new String[] {method});
		if (stats != null) {
			StringBuilder buff = new StringBuilder();
			for (String key: stats.getCompositeType().keySet()) {
				buff.append(key).append("=").append(stats.get(key));
				buff.append("; ");
			}
			return buff.toString();
		}
	}
	return "";
}
 
Example 59
Project: bagri   File: StatisticsCollector.java   Source Code and License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public TabularData getStatisticSeries() {
       TabularData result = null;
       for (Map.Entry<String, Statistics> entry: series.entrySet()) {
       	Statistics stats = entry.getValue();
       	if (reportStatistics(stats)) {
            try {
            	String desc = stats.getDescription();
            	String name = stats.getName();
            	String header = stats.getHeader();
                Map<String, Object> sts = stats.toMap();
                sts.put(header, entry.getKey());
                CompositeData data = JMXUtils.mapToComposite(name, desc, sts);
                result = JMXUtils.compositeToTabular(name, desc, header, result, data);
            } catch (Exception ex) {
                logger.error("getStatisticSeries; error", ex);
            }
       	}
       }
       return result;
   }
 
Example 60
Project: andes   File: ExchangeMBeanTest.java   Source Code and License 6 votes vote down vote up
/**
 * Test for direct exchange mbean
 * @throws Exception
 */

public void testDirectExchangeMBean() throws Exception
{
    DirectExchange exchange = new DirectExchange();
    exchange.initialise(_virtualHost, ExchangeDefaults.DIRECT_EXCHANGE_NAME, false, 0, true);
    ManagedObject managedObj = exchange.getManagedObject();
    ManagedExchange mbean = (ManagedExchange)managedObj;

    mbean.createNewBinding(_queue.getNameShortString().toString(), "binding1");
    mbean.createNewBinding(_queue.getNameShortString().toString(), "binding2");

    TabularData data = mbean.bindings();
    ArrayList<Object> list = new ArrayList<Object>(data.values());
    assertTrue(list.size() == 2);

    // test general exchange properties
    assertEquals(mbean.getName(), "amq.direct");
    assertEquals(mbean.getExchangeType(), "direct");
    assertTrue(mbean.getTicketNo() == 0);
    assertTrue(!mbean.isDurable());
    assertTrue(mbean.isAutoDelete());
}