javax.management.openmbean.CompositeData Java Examples

The following examples show how to use javax.management.openmbean.CompositeData. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultMXBeanMappingFactory.java    From jdk8u-jdk with GNU General Public License v2.0 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 #2
Source File: DefaultMXBeanMappingFactory.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
Object fromCompositeData(CompositeData cd,
                         String[] itemNames,
                         MXBeanMapping[] converters)
        throws InvalidObjectException {
    Object o;
    try {
        final Class<?> targetClass = getTargetClass();
        ReflectUtil.checkPackageAccess(targetClass);
        o = targetClass.newInstance();
        for (int i = 0; i < itemNames.length; i++) {
            if (cd.containsKey(itemNames[i])) {
                Object openItem = cd.get(itemNames[i]);
                Object javaItem =
                    converters[i].fromOpenValue(openItem);
                MethodUtil.invoke(setters[i], o, new Object[] {javaItem});
            }
        }
    } catch (Exception e) {
        throw invalidObjectException(e);
    }
    return o;
}
 
Example #3
Source File: GarbageCollectorImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
void createGCNotification(long timestamp,
                          String gcName,
                          String gcAction,
                          String gcCause,
                          GcInfo gcInfo)  {

    if (!hasListeners()) {
        return;
    }

    Notification notif = new Notification(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION,
                                          getObjectName(),
                                          getNextSeqNumber(),
                                          timestamp,
                                          gcName);
    GarbageCollectionNotificationInfo info =
        new GarbageCollectionNotificationInfo(gcName,
                                              gcAction,
                                              gcCause,
                                              gcInfo);

    CompositeData cd =
        GarbageCollectionNotifInfoCompositeData.toCompositeData(info);
    notif.setUserData(cd);
    sendNotification(notif);
}
 
Example #4
Source File: MemoryImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
static void createNotification(String notifType,
                               String poolName,
                               MemoryUsage usage,
                               long count) {
    MemoryImpl mbean = (MemoryImpl) ManagementFactory.getMemoryMXBean();
    if (!mbean.hasListeners()) {
        // if no listener is registered.
        return;
    }
    long timestamp = System.currentTimeMillis();
    String msg = getNotifMsg(notifType);
    Notification notif = new Notification(notifType,
                                          mbean.getObjectName(),
                                          getNextSeqNumber(),
                                          timestamp,
                                          msg);
    MemoryNotificationInfo info =
        new MemoryNotificationInfo(poolName,
                                   usage,
                                   count);
    CompositeData cd =
        MemoryNotifInfoCompositeData.toCompositeData(info);
    notif.setUserData(cd);
    mbean.sendNotification(notif);
}
 
Example #5
Source File: MemoryUsageCompositeData.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // memoryUsageItemNames!
    final Object[] memoryUsageItemValues = {
        new Long(usage.getInit()),
        new Long(usage.getUsed()),
        new Long(usage.getCommitted()),
        new Long(usage.getMax()),
    };

    try {
        return new CompositeDataSupport(memoryUsageCompositeType,
                                        memoryUsageItemNames,
                                        memoryUsageItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example #6
Source File: DefaultMXBeanMappingFactory.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
Object fromCompositeData(CompositeData cd,
                         String[] itemNames,
                         MXBeanMapping[] converters)
        throws InvalidObjectException {
    Object o;
    try {
        final Class<?> targetClass = getTargetClass();
        ReflectUtil.checkPackageAccess(targetClass);
        o = targetClass.newInstance();
        for (int i = 0; i < itemNames.length; i++) {
            if (cd.containsKey(itemNames[i])) {
                Object openItem = cd.get(itemNames[i]);
                Object javaItem =
                    converters[i].fromOpenValue(openItem);
                MethodUtil.invoke(setters[i], o, new Object[] {javaItem});
            }
        }
    } catch (Exception e) {
        throw invalidObjectException(e);
    }
    return o;
}
 
Example #7
Source File: MemoryNotifInfoCompositeData.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // memoryNotifInfoItemNames!
    final Object[] memoryNotifInfoItemValues = {
        memoryNotifInfo.getPoolName(),
        MemoryUsageCompositeData.toCompositeData(memoryNotifInfo.getUsage()),
        new Long(memoryNotifInfo.getCount()),
    };

    try {
        return new CompositeDataSupport(memoryNotifInfoCompositeType,
                                        memoryNotifInfoItemNames,
                                        memoryNotifInfoItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example #8
Source File: StackTraceElementCompositeData.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // stackTraceElementItemNames!
    final Object[] stackTraceElementItemValues = {
        ste.getClassName(),
        ste.getMethodName(),
        ste.getFileName(),
        new Integer(ste.getLineNumber()),
        new Boolean(ste.isNativeMethod()),
    };
    try {
        return new CompositeDataSupport(stackTraceElementCompositeType,
                                        stackTraceElementItemNames,
                                        stackTraceElementItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example #9
Source File: MemoryUsageCompositeData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // memoryUsageItemNames!
    final Object[] memoryUsageItemValues = {
        new Long(usage.getInit()),
        new Long(usage.getUsed()),
        new Long(usage.getCommitted()),
        new Long(usage.getMax()),
    };

    try {
        return new CompositeDataSupport(memoryUsageCompositeType,
                                        memoryUsageItemNames,
                                        memoryUsageItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example #10
Source File: JmxExporterSpiTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** */
private void checkContinuousQueryView(IgniteEx origNode, IgniteEx checkNode) {
    TabularDataSupport qrys = systemView(checkNode, CQ_SYS_VIEW);

    assertEquals(1, qrys.size());

    for (int i = 0; i < qrys.size(); i++) {
        CompositeData cq = qrys.get(new Object[] {i});

        assertEquals("cache-1", cq.get("cacheName"));
        assertEquals(100, cq.get("bufferSize"));
        assertEquals(1000L, cq.get("interval"));
        assertEquals(origNode.localNode().id().toString(), cq.get("nodeId"));

        if (origNode.localNode().id().equals(checkNode.localNode().id()))
            assertTrue(cq.get("localListener").toString().startsWith(getClass().getName()));
        else
            assertNull(cq.get("localListener"));

        assertTrue(cq.get("remoteFilter").toString().startsWith(getClass().getName()));
        assertNull(cq.get("localTransformedListener"));
        assertNull(cq.get("remoteTransformer"));
    }
}
 
Example #11
Source File: MXBeanTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static boolean compositeDataEqual(CompositeData cd1,
                                          CompositeData cd2,
                                          NamedMXBeans namedMXBeans) {
    if (cd1 == cd2)
        return true;
    if (!cd1.getCompositeType().equals(cd2.getCompositeType()))
        return false;
    Collection v1 = cd1.values();
    Collection v2 = cd2.values();
    if (v1.size() != v2.size())
        return false; // should not happen
    for (Iterator i1 = v1.iterator(), i2 = v2.iterator();
         i1.hasNext(); ) {
        if (!equal(i1.next(), i2.next(), namedMXBeans))
            return false;
    }
    return true;
}
 
Example #12
Source File: VMOptionCompositeData.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // vmOptionItemNames!
    final Object[] vmOptionItemValues = {
        option.getName(),
        option.getValue(),
        new Boolean(option.isWriteable()),
        option.getOrigin().toString(),
    };

    try {
        return new CompositeDataSupport(vmOptionCompositeType,
                                        vmOptionItemNames,
                                        vmOptionItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example #13
Source File: XMBeanNotifications.java    From openjdk-jdk8u with GNU General Public License v2.0 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
Source File: MemoryPoolAdapter.java    From baratine with GNU General Public License v2.0 5 votes vote down vote up
public long getCodeCacheFree()
  throws JMException
{
  CompositeData data
    = (CompositeData) _mbeanServer.getAttribute(getCodeCacheName(), "Usage");

  MemoryUsage usage = MemoryUsage.from(data);

  return usage.getMax() - usage.getUsed();
}
 
Example #15
Source File: AttributeArbitraryDataTypeTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public CompositeData getCompositeDataAttribute()
    throws OpenDataException {
    CompositeType ct = new CompositeType("CompositeDataAttribute",
                                         "Composite Data Attribute",
                                         itemNames,
                                         itemDescriptions,
                                         itemTypes);
    Object itemValues[] = { ia, da, sa };
    return new CompositeDataSupport(ct, itemNames, itemValues);
}
 
Example #16
Source File: AttributeArbitraryDataTypeTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public CompositeData getCompositeDataAttribute()
    throws OpenDataException {
    CompositeType ct = new CompositeType("CompositeDataAttribute",
                                         "Composite Data Attribute",
                                         itemNames,
                                         itemDescriptions,
                                         itemTypes);
    Object itemValues[] = { ia, da, sa };
    return new CompositeDataSupport(ct, itemNames, itemValues);
}
 
Example #17
Source File: MonitorInfoCompositeData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static StackTraceElement getLockedStackFrame(CompositeData cd) {
    CompositeData ste = (CompositeData) cd.get(LOCKED_STACK_FRAME);
    if (ste != null) {
        return StackTraceElementCompositeData.from(ste);
    } else {
        return null;
    }
}
 
Example #18
Source File: MemoryNotifInfoCompositeData.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static String getPoolName(CompositeData cd) {
    String poolname = getString(cd, POOL_NAME);
    if (poolname == null) {
        throw new IllegalArgumentException("Invalid composite data: " +
            "Attribute " + POOL_NAME + " has null value");
    }
    return poolname;
}
 
Example #19
Source File: DefaultMXBeanMappingFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
final Object fromCompositeData(CompositeData cd,
                               String[] itemNames,
                               MXBeanMapping[] converters)
        throws InvalidObjectException {
    try {
        return MethodUtil.invoke(fromMethod, null, new Object[] {cd});
    } catch (Exception e) {
        final String msg = "Failed to invoke from(CompositeData)";
        throw invalidObjectException(msg, e);
    }
}
 
Example #20
Source File: JavaMailJMSStatistics.java    From javamail with Apache License 2.0 5 votes vote down vote up
private static CompositeData convert(MessageAndAddresses maa) {
    if (maa == null) {
        return null;
    }
    try {
        TabularData addrData = new TabularDataSupport(TAB_ADDR_TYPE);
        for(Address addr : maa.getAddresses()) {
            addrData.put(new CompositeDataSupport(ROW_ADDR_TYPE, new String[]{"addressType", "address"}, new Object[]{addr.getType(), addr.toString()}));
        }
        TabularData headerData = new TabularDataSupport(TAB_HEADER_TYPE);
        Enumeration en = maa.getMessage().getAllHeaders();
        while (en.hasMoreElements()) {
            Header header = (Header) en.nextElement();
            headerData.put(new CompositeDataSupport(ROW_HEADER_TYPE, new String[]{"header-name", "header-value"}, new Object[]{header.getName(), header.getValue()}));
        }
        String error = null;
        if (maa.getException() != null) {
            StringWriter sw = new StringWriter();
            sw.append(maa.getException().toString());
            maa.getException().printStackTrace(new PrintWriter(sw));
            sw.flush();
            error = sw.toString();
        }
        return new CompositeDataSupport(MAIL_INFO_TYPE,
                new String[] {"messageId", "date", "subject", "toAddresses", "headers", "errorDescription"},
                new Object[]{maa.getMessage().getMessageID(), new Date(maa.getTimestamp()), maa.getMessage().getSubject(), addrData, headerData, error}
        );
    } catch (OpenDataException | MessagingException e) {
        throw new IllegalArgumentException("cannot convert MessageAndAddresses to CompositeData", e);
    }
}
 
Example #21
Source File: ThreadInfoCompositeData.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isCurrentVersion(CompositeData cd) {
    if (cd == null) {
        throw new NullPointerException("Null CompositeData");
    }

    return isTypeMatched(threadInfoCompositeType, cd.getCompositeType());
}
 
Example #22
Source File: JMXProxyServlet.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public void getAttribute(PrintWriter writer, String onameStr, String att, String key) {
    try {
        ObjectName oname = new ObjectName(onameStr);
        Object value = mBeanServer.getAttribute(oname, att);

        if(null != key && value instanceof CompositeData)
          value = ((CompositeData)value).get(key);

        String valueStr;
        if (value != null) {
            valueStr = value.toString();
        } else {
            valueStr = "<null>";
        }

        writer.print("OK - Attribute get '");
        writer.print(onameStr);
        writer.print("' - ");
        writer.print(att);

        if(null != key) {
            writer.print(" - key '");
            writer.print(key);
            writer.print("'");
        }

        writer.print(" = ");

        writer.println(MBeanDumper.escape(valueStr));
    } catch (Exception ex) {
        writer.println("Error - " + ex.toString());
        ex.printStackTrace(writer);
    }
}
 
Example #23
Source File: MBeanCompositeDataQueryTest.java    From netdata-java-orchestrator with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testQueryInteger() throws AttributeNotFoundException, MBeanException, ReflectionException,
		InstanceNotFoundException, IOException, JmxMBeanServerQueryException {
	final CompositeData compositeData = mock(CompositeData.class);
	when(compositeData.get("key")).thenReturn(1234);

	when(mBeanServer.getAttribute(ObjectName.WILDCARD, "Attribute")).thenReturn(compositeData);

	final Dimension dim = new Dimension();
	query.addDimension(dim, "Attribute.key");

	query.query();

	assertEquals((Long) 1234L, dim.getCurrentValue());
}
 
Example #24
Source File: MXBeanTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
static boolean equal(Object o1, Object o2, NamedMXBeans namedMXBeans) {
        if (o1 == o2)
            return true;
        if (o1 == null || o2 == null)
            return false;
        if (o1.getClass().isArray()) {
            if (!o2.getClass().isArray())
                return false;
            return deepEqual(o1, o2, namedMXBeans);
        }
        if (o1 instanceof Map) {
            if (!(o2 instanceof Map))
                return false;
            return equalMap((Map) o1, (Map) o2, namedMXBeans);
        }
        if (o1 instanceof CompositeData && o2 instanceof CompositeData) {
            return compositeDataEqual((CompositeData) o1, (CompositeData) o2,
                                      namedMXBeans);
        }
        if (Proxy.isProxyClass(o1.getClass())) {
            if (Proxy.isProxyClass(o2.getClass()))
                return proxyEqual(o1, o2, namedMXBeans);
            InvocationHandler ih = Proxy.getInvocationHandler(o1);
//            if (ih instanceof MXBeanInvocationHandler) {
//                return proxyEqualsObject((MXBeanInvocationHandler) ih,
//                                         o2, namedMXBeans);
            if (ih instanceof MBeanServerInvocationHandler) {
                return true;
            } else if (ih instanceof CompositeDataInvocationHandler) {
                return o2.equals(o1);
                // We assume the other object has a reasonable equals method
            }
        } else if (Proxy.isProxyClass(o2.getClass()))
            return equal(o2, o1, namedMXBeans);
        return o1.equals(o2);
    }
 
Example #25
Source File: LowMemoryTest2.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void handleNotification(Notification notif, Object handback) {
    String type = notif.getType();
    if (type.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED) ||
        type.equals(MemoryNotificationInfo.
            MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) {
        listenerInvoked = true;
        MemoryNotificationInfo minfo = MemoryNotificationInfo.
            from((CompositeData) notif.getUserData());

        System.out.print("Notification for " + minfo.getPoolName());
        System.out.print(" [type = " + type);
        System.out.println(" count = " + minfo.getCount() + "]");
        System.out.println(INDENT + "usage = " + minfo.getUsage());
    }
}
 
Example #26
Source File: VMOption.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a <tt>VMOption</tt> object from a
 * {@link CompositeData CompositeData}.
 */
private VMOption(CompositeData cd) {
    // validate the input composite data
    VMOptionCompositeData.validateCompositeData(cd);

    this.name = VMOptionCompositeData.getName(cd);
    this.value = VMOptionCompositeData.getValue(cd);
    this.writeable = VMOptionCompositeData.isWriteable(cd);
    this.origin = VMOptionCompositeData.getOrigin(cd);
}
 
Example #27
Source File: GcHelper.java    From actframework with Apache License 2.0 5 votes vote down vote up
public static void registerGcEventListener(final $.Visitor<GcInfo> listener) {
    for (java.lang.management.GarbageCollectorMXBean mxBean : gcBeans) {
        NotificationEmitter emitter = (NotificationEmitter) mxBean;
        emitter.addNotificationListener(new NotificationListener() {
            @Override
            public void handleNotification(Notification notification, Object handback) {
                if (notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
                    GarbageCollectionNotificationInfo gcInfo = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());
                    listener.visit(gcInfo.getGcInfo());
                }
            }
        }, null, null);
    }
}
 
Example #28
Source File: MemoryPoolAdapter.java    From baratine with GNU General Public License v2.0 5 votes vote down vote up
public long getTenuredCommitted()
  throws JMException
{
  CompositeData data
    = (CompositeData) _mbeanServer.getAttribute(getTenuredName(), "Usage");

  MemoryUsage usage = MemoryUsage.from(data);

  return usage.getCommitted();
}
 
Example #29
Source File: JMXTest.java    From incubator-batchee with Apache License 2.0 5 votes vote down vote up
@Test
public void jobInstances() throws Exception {
    final TabularData instance = TabularData.class.cast(result("getJobInstances", "jmx", 0, 1));
    assertEquals(1, instance.size());

    final CompositeData cd = instance.get(new Object[]{"jmx", id});
    assertEquals(id, cd.get("instanceId"));
    assertEquals("jmx", cd.get("jobName"));
}
 
Example #30
Source File: TriggerSupport.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static OperableTrigger newTrigger(CompositeData cData) throws ParseException {
    OperableTrigger result = null;
    if(cData.containsKey("cronExpression")) {
        result = CronTriggerSupport.newTrigger(cData);
    } else {
        result = SimpleTriggerSupport.newTrigger(cData);
    }
    return result;
}