Java Code Examples for javax.management.MBeanAttributeInfo

The following are top voted examples for showing how to use javax.management.MBeanAttributeInfo. 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: lazycat   File: Registry.java   Source Code and License 6 votes vote down vote up
/**
 * Get the type of an attribute of the object, from the metadata.
 *
 * @param oname
 * @param attName
 * @return null if metadata about the attribute is not found
 * @since 1.1
 */
public String getType(ObjectName oname, String attName) {
	String type = null;
	MBeanInfo info = null;
	try {
		info = server.getMBeanInfo(oname);
	} catch (Exception e) {
		log.info("Can't find metadata for object" + oname);
		return null;
	}

	MBeanAttributeInfo attInfo[] = info.getAttributes();
	for (int i = 0; i < attInfo.length; i++) {
		if (attName.equals(attInfo[i].getName())) {
			type = attInfo[i].getType();
			return type;
		}
	}
	return null;
}
 
Example 2
Project: phone-simulator   File: TestCheckImeiServerStandardManMBean.java   Source Code and License 6 votes vote down vote up
@Override
public MBeanInfo getMBeanInfo() {

    MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[] {

            new MBeanAttributeInfo("AutoEquipmentStatus", EquipmentStatusType.class.getName(), "EquipmentStatus parameter to be automatically send in CheckImeiResponse", true, true, false),
            new MBeanAttributeInfo("AutoEquipmentStatus_Value", String.class.getName(), "EquipmentStatus parameter to be automatically send in CheckImeiResponse", true, false, false),
            new MBeanAttributeInfo("OneNotificationFor100Dialogs", boolean.class.getName(),
                    "If true there will be only one notification per every 100 sent dialogs", true, true, true),
            new MBeanAttributeInfo("CurrentRequestDef", String.class.getName(), "Definition of the current request Dialog",
                    true, false, false),

    };

    MBeanParameterInfo[] putAutoEquipmentStatusParam = new MBeanParameterInfo[] { new MBeanParameterInfo("val", String.class.getName(), "EquipmentStatus value") };

    MBeanOperationInfo[] operations = new MBeanOperationInfo[] {
            new MBeanOperationInfo(
                    "putAutoEquipmentStatus",
                    "EquipmentStatus parameter to be automatically send in CheckImeiResponse: "
                            + "0:whiteListed,1:blackListed,2:greyListed",
                    putAutoEquipmentStatusParam, Void.TYPE.getName(), MBeanOperationInfo.ACTION),
            new MBeanOperationInfo("closeCurrentDialog", "Closing the current dialog", null, String.class.getName(), MBeanOperationInfo.ACTION)
    };
    return new MBeanInfo(TestCheckImeiServerMan.class.getName(), "CheckImeiServer test parameters management", attributes, null, operations, null);
}
 
Example 3
Project: phone-simulator   File: TestMapLcsServerStandardManMBean.java   Source Code and License 6 votes vote down vote up
@Override
public MBeanInfo getMBeanInfo() {

    MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[] {
            new MBeanAttributeInfo("NetworkNodeNumberAddress", String.class.getName(),
                                   "NetworkNodeNumber address parameter for response",
                                   true, true, false), };

    MBeanParameterInfo[] performSRIResponseParam = new MBeanParameterInfo[] { };

    MBeanOperationInfo[] operations = new MBeanOperationInfo[] {
            new MBeanOperationInfo("performSendRoutingInfoForLCSResponse", "Send Routing Information for LCS response",
                                   performSRIResponseParam, String.class.getName(), MBeanOperationInfo.ACTION),
             };

    return new MBeanInfo(TestMapLcsServerMan.class.getName(), "MapLcsServer test parameters management", attributes, null, operations, null);
}
 
Example 4
Project: phone-simulator   File: TestMapLcsClientStandardManMBean.java   Source Code and License 6 votes vote down vote up
@Override
public MBeanInfo getMBeanInfo() {

    // TODO: Put real attributes and operations

    MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[] {
            new MBeanAttributeInfo("AddressNature", AddressNatureType.class.getName(),
                                   "AddressNature parameter for mlcNumber creating",
                                   true, true, false),
            new MBeanAttributeInfo("NumberingPlanType", NumberingPlanMapType.class.getName(),
                                   "NumberingPlanType parameter for mlcNumber creating",
                                   true, true, false),
            new MBeanAttributeInfo("NumberingPlan", String.class.getName(),
                                   "NumberingPlan parameter for mlcNumber creating",
                                   true, true, false), };

    MBeanParameterInfo[] performSRIRequestParam = new MBeanParameterInfo[] {
                   new MBeanParameterInfo("addressIMSI", String.class.getName(), "Address for IMSI") };

    MBeanOperationInfo[] operations = new MBeanOperationInfo[] {
            new MBeanOperationInfo("performSendRoutingInfoForLCSRequest", "Send Routing Information for LCS request",
                                   performSRIRequestParam, String.class.getName(), MBeanOperationInfo.ACTION),
             };

    return new MBeanInfo(TestMapLcsClientMan.class.getName(), "MapLcsClient test parameters management", attributes, null, operations, null);
}
 
Example 5
Project: hadoop-oss   File: MBeanInfoBuilder.java   Source Code and License 6 votes vote down vote up
MBeanInfo get() {
  curRecNo = 0;
  for (MetricsRecordImpl rec : recs) {
    for (MetricsTag t : rec.tags()) {
      attrs.add(newAttrInfo("tag."+ t.name(), t.description(),
                "java.lang.String"));
    }
    for (AbstractMetric m : rec.metrics()) {
      m.visit(this);
    }
    ++curRecNo;
  }
  MetricsSystemImpl.LOG.debug(attrs);
  MBeanAttributeInfo[] attrsArray = new MBeanAttributeInfo[attrs.size()];
  return new MBeanInfo(name, description, attrs.toArray(attrsArray),
                       null, null, null); // no ops/ctors/notifications
}
 
Example 6
Project: eZooKeeper   File: MBeanAttributeDoc.java   Source Code and License 6 votes vote down vote up
@Override
public String getName() {
    if (_Name == null) {

        _Name = super.getName();

        if (_Name == null) {
            return _Name;
        }

        MBeanAttributeInfo info = getInfo();
        String prefix = NAME_PREFIX_GET;
        if (info.isIs()) {
            prefix = NAME_PREFIX_IS;
        }

        _Name = prefix + _Name;
    }

    return _Name;
}
 
Example 7
Project: eZooKeeper   File: MBeanDoc.java   Source Code and License 6 votes vote down vote up
public List<MBeanAttributeDoc> getAttributes() {

        if (_Attributes == null) {
            MBeanAttributeInfo[] attributeInfos = getInfo().getAttributes();

            if (attributeInfos == null || attributeInfos.length == 0) {
                return Collections.emptyList();
            }

            _Attributes = new ArrayList<MBeanAttributeDoc>(attributeInfos.length);

            for (MBeanAttributeInfo attributeInfo : attributeInfos) {
                MBeanAttributeDoc attributeDoc = new MBeanAttributeDoc(attributeInfo);
                _Attributes.add(attributeDoc);
            }
        }

        return _Attributes;
    }
 
Example 8
Project: truevfs   File: JmxBufferView.java   Source Code and License 6 votes vote down vote up
@Override
protected String getDescription(final MBeanAttributeInfo info) {
    switch (info.getName()) {
    case "Name":
        return "The name of this buffer.";
    case "SizeOfData":
        return "The data size of this buffer.";
    case "SizeOfStorage":
        return "The storage size of this buffer.";
    case "TimeCreatedDate":
        return "The time this buffer has been created.";
    case "TimeCreatedMillis":
        return "The time this buffer has been created in milliseconds.";
    case "TimeReadDate":
        return "The last time this buffer has been read or accessed.";
    case "TimeReadMillis":
        return "The last time this buffer has been read or accessed in milliseconds.";
    case "TimeWrittenDate":
        return "The last time this buffer has been written.";
    case "TimeWrittenMillis":
        return "The last time this buffer has been written in milliseconds.";
    default:
        return null;
    }
}
 
Example 9
Project: tomcat7   File: Registry.java   Source Code and License 6 votes vote down vote up
/** Get the type of an attribute of the object, from the metadata.
 *
 * @param oname
 * @param attName
 * @return null if metadata about the attribute is not found
 * @since 1.1
 */
public String getType( ObjectName oname, String attName )
{
    String type=null;
    MBeanInfo info=null;
    try {
        info=server.getMBeanInfo(oname);
    } catch (Exception e) {
        log.info( "Can't find metadata for object" + oname );
        return null;
    }

    MBeanAttributeInfo attInfo[]=info.getAttributes();
    for( int i=0; i<attInfo.length; i++ ) {
        if( attName.equals(attInfo[i].getName())) {
            type=attInfo[i].getType();
            return type;
        }
    }
    return null;
}
 
Example 10
Project: monarch   File: MX4JModelMBean.java   Source Code and License 6 votes vote down vote up
public void addAttributeChangeNotificationListener(NotificationListener listener,
    String attributeName, Object handback)
    throws MBeanException, RuntimeOperationsException, IllegalArgumentException {
  if (listener == null)
    throw new RuntimeOperationsException(new IllegalArgumentException(
        LocalizedStrings.MX4JModelMBean_LISTENER_CANNOT_BE_NULL.toLocalizedString()));
  AttributeChangeNotificationFilter filter = new AttributeChangeNotificationFilter();
  if (attributeName != null) {
    filter.enableAttribute(attributeName);
  } else {
    MBeanAttributeInfo[] ai = m_modelMBeanInfo.getAttributes();
    for (int i = 0; i < ai.length; i++) {
      Descriptor d = ((ModelMBeanAttributeInfo) ai[i]).getDescriptor();
      filter.enableAttribute((String) d.getFieldValue("name"));
    }
  }

  getAttributeChangeBroadcaster().addNotificationListener(listener, filter, handback);

  Logger logger = getLogger();
  if (logger.isEnabledFor(Logger.DEBUG))
    logger.debug("Listener " + listener + " for attribute " + attributeName
        + " added successfully, handback is " + handback);
}
 
Example 11
Project: monarch   File: MX4JModelMBean.java   Source Code and License 6 votes vote down vote up
private void removeAttributeChangeNotificationListener(NotificationListener listener,
    String attributeName, Object handback)
    throws MBeanException, RuntimeOperationsException, ListenerNotFoundException {
  if (listener == null)
    throw new RuntimeOperationsException(new IllegalArgumentException(
        LocalizedStrings.MX4JModelMBean_LISTENER_CANNOT_BE_NULL.toLocalizedString()));
  AttributeChangeNotificationFilter filter = new AttributeChangeNotificationFilter();
  if (attributeName != null) {
    filter.enableAttribute(attributeName);
  } else {
    MBeanAttributeInfo[] ai = m_modelMBeanInfo.getAttributes();
    for (int i = 0; i < ai.length; i++) {
      Descriptor d = ((ModelMBeanAttributeInfo) ai[i]).getDescriptor();
      filter.enableAttribute((String) d.getFieldValue("name"));
    }
  }

  getAttributeChangeBroadcaster().removeNotificationListener(listener, filter, handback);

  Logger logger = getLogger();
  if (logger.isEnabledFor(Logger.DEBUG))
    logger.debug("Listener " + listener + " for attribute " + attributeName
        + " removed successfully, handback is " + handback);
}
 
Example 12
Project: apache-tomcat-7.0.73-with-comment   File: Registry.java   Source Code and License 6 votes vote down vote up
/** Get the type of an attribute of the object, from the metadata.
 *
 * @param oname
 * @param attName
 * @return null if metadata about the attribute is not found
 * @since 1.1
 */
public String getType( ObjectName oname, String attName )
{
    String type=null;
    MBeanInfo info=null;
    try {
        info=server.getMBeanInfo(oname);
    } catch (Exception e) {
        log.info( "Can't find metadata for object" + oname );
        return null;
    }

    MBeanAttributeInfo attInfo[]=info.getAttributes();
    for( int i=0; i<attInfo.length; i++ ) {
        if( attName.equals(attInfo[i].getName())) {
            type=attInfo[i].getType();
            return type;
        }
    }
    return null;
}
 
Example 13
Project: hadoop   File: JMXGet.java   Source Code and License 6 votes vote down vote up
/**
 * print all attributes' values
 */
public void printAllValues() throws Exception {
  err("List of all the available keys:");

  Object val = null;

  for (ObjectName oname : hadoopObjectNames) {
    err(">>>>>>>>jmx name: " + oname.getCanonicalKeyPropertyListString());
    MBeanInfo mbinfo = mbsc.getMBeanInfo(oname);
    MBeanAttributeInfo[] mbinfos = mbinfo.getAttributes();

    for (MBeanAttributeInfo mb : mbinfos) {
      val = mbsc.getAttribute(oname, mb.getName());
      System.out.format(format, mb.getName(), (val==null)?"":val.toString());
    }
  }
}
 
Example 14
Project: hadoop   File: JMXGet.java   Source Code and License 6 votes vote down vote up
public void printAllMatchedAttributes(String attrRegExp) throws Exception {
  err("List of the keys matching " + attrRegExp + " :");
  Object val = null;
  Pattern p = Pattern.compile(attrRegExp);
  for (ObjectName oname : hadoopObjectNames) {
    err(">>>>>>>>jmx name: " + oname.getCanonicalKeyPropertyListString());
    MBeanInfo mbinfo = mbsc.getMBeanInfo(oname);
    MBeanAttributeInfo[] mbinfos = mbinfo.getAttributes();
    for (MBeanAttributeInfo mb : mbinfos) {
      if (p.matcher(mb.getName()).lookingAt()) {
        val = mbsc.getAttribute(oname, mb.getName());
        System.out.format(format, mb.getName(), (val == null) ? "" : val.toString());
      }
    }
  }
}
 
Example 15
Project: openjdk-jdk10   File: MXBeanInteropTest2.java   Source Code and License 6 votes vote down vote up
private void printMBeanInfo(MBeanInfo mbInfo) {
    System.out.println("Description " + mbInfo.getDescription());

    for (MBeanConstructorInfo ctor : mbInfo.getConstructors()) {
        System.out.println("Constructor " + ctor.getName());
    }

    for (MBeanAttributeInfo att : mbInfo.getAttributes()) {
        System.out.println("Attribute " + att.getName()
        + " [" + att.getType() + "]");
    }

    for (MBeanOperationInfo oper : mbInfo.getOperations()) {
        System.out.println("Operation " + oper.getName());
    }

    for (MBeanNotificationInfo notif : mbInfo.getNotifications()) {
        System.out.println("Notification " + notif.getName());
    }
}
 
Example 16
Project: hadoop   File: MBeanInfoBuilder.java   Source Code and License 6 votes vote down vote up
MBeanInfo get() {
  curRecNo = 0;
  for (MetricsRecordImpl rec : recs) {
    for (MetricsTag t : rec.tags()) {
      attrs.add(newAttrInfo("tag."+ t.name(), t.description(),
                "java.lang.String"));
    }
    for (AbstractMetric m : rec.metrics()) {
      m.visit(this);
    }
    ++curRecNo;
  }
  MetricsSystemImpl.LOG.debug(attrs);
  MBeanAttributeInfo[] attrsArray = new MBeanAttributeInfo[attrs.size()];
  return new MBeanInfo(name, description, attrs.toArray(attrsArray),
                       null, null, null); // no ops/ctors/notifications
}
 
Example 17
Project: doctorkafka   File: MetricsFetcher.java   Source Code and License 6 votes vote down vote up
private static void fetchKafkaMetrics(String host, String jmxPort, String metric)
    throws Exception {

  Map<String, String[]> env = new HashMap<>();
  JMXServiceURL address = new JMXServiceURL(
      "service:jmx:rmi://" + host + "/jndi/rmi://" + host + ":" + jmxPort + "/jmxrmi");
  JMXConnector connector = JMXConnectorFactory.connect(address, env);
  MBeanServerConnection mbs = connector.getMBeanServerConnection();


  ObjectName name = ObjectName.getInstance(metric);
  MBeanInfo beanInfo = mbs.getMBeanInfo(name);
  for (MBeanAttributeInfo attributeInfo : beanInfo.getAttributes()) {
    Object obj = mbs.getAttribute(name, attributeInfo.getName());
    System.out.println(" attributeName = " + attributeInfo.getName() + " " + obj.toString());
  }
}
 
Example 18
Project: jdk8u-jdk   File: MustBeValidCommand.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Instantiate the MBean server
    //
    final MBeanAttributeInfo[]    atts   = makeAttInfos(attributes);
    final MBeanConstructorInfo[]  ctors  = makeCtorInfos(constructors);
    final MBeanOperationInfo[]    ops    = makeOpInfos(operations);
    final MBeanNotificationInfo[] notifs =
        makeNotifInfos(notificationclasses);

    for (int i=0; i<mbeanclasses.length;i++) {
        System.out.println("Create an MBeanInfo: " + mbeanclasses[i][0]);
        final MBeanInfo mbi =
            new MBeanInfo(mbeanclasses[i][1],mbeanclasses[i][0],
                          atts, ctors, ops, notifs);
    }

    // Test OK!
    //
    System.out.println("All MBeanInfo successfuly created!");
    System.out.println("Bye! Bye!");
}
 
Example 19
Project: jdk8u-jdk   File: MXBeanInteropTest2.java   Source Code and License 6 votes vote down vote up
private void printMBeanInfo(MBeanInfo mbInfo) {
    System.out.println("Description " + mbInfo.getDescription());

    for (MBeanConstructorInfo ctor : mbInfo.getConstructors()) {
        System.out.println("Constructor " + ctor.getName());
    }

    for (MBeanAttributeInfo att : mbInfo.getAttributes()) {
        System.out.println("Attribute " + att.getName()
        + " [" + att.getType() + "]");
    }

    for (MBeanOperationInfo oper : mbInfo.getOperations()) {
        System.out.println("Operation " + oper.getName());
    }

    for (MBeanNotificationInfo notif : mbInfo.getNotifications()) {
        System.out.println("Notification " + notif.getName());
    }
}
 
Example 20
Project: metrics-tomcat   File: AnnotatedStandardMBean.java   Source Code and License 6 votes vote down vote up
/** {@inheritDoc} */
@Override
protected String getDescription(final MBeanAttributeInfo info) {
	String descr = info.getDescription();
	Method m = getMethod(getMBeanInterface(),
			"get" + info.getName().substring(0, 1).toUpperCase() + info.getName().substring(1));
	if (m == null) {
		m = getMethod(getMBeanInterface(),
				"is" + info.getName().substring(0, 1).toUpperCase() + info.getName().substring(1));
	}
	if (m == null) {
		m = getMethod(getMBeanInterface(),
				"does" + info.getName().substring(0, 1).toUpperCase() + info.getName().substring(1));
	}
	if (m != null) {
		Description d = m.getAnnotation(Description.class);
		if (d != null) {
			descr = d.value();
		}
	}
	return descr;
}
 
Example 21
Project: openjdk-jdk10   File: AnnotationTest.java   Source Code and License 5 votes vote down vote up
private static void check(MBeanServer mbs, ObjectName on) throws Exception {
    MBeanInfo mbi = mbs.getMBeanInfo(on);

    // check the MBean itself
    check(mbi);

    // check attributes
    MBeanAttributeInfo[] attrs = mbi.getAttributes();
    for (MBeanAttributeInfo attr : attrs) {
        check(attr);
        if (attr.getName().equals("ReadOnly"))
            check("@Full", attr.getDescriptor(), expectedFullDescriptor);
    }

    // check operations
    MBeanOperationInfo[] ops = mbi.getOperations();
    for (MBeanOperationInfo op : ops) {
        check(op);
        check(op.getSignature());
    }

    MBeanConstructorInfo[] constrs = mbi.getConstructors();
    for (MBeanConstructorInfo constr : constrs) {
        check(constr);
        check(constr.getSignature());
    }
}
 
Example 22
Project: phone-simulator   File: TestCheckImeiClientStandardManMBean.java   Source Code and License 5 votes vote down vote up
@Override
public MBeanInfo getMBeanInfo() {

    MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[] {
            // TODO mnowa: add/correct attributes here
            new MBeanAttributeInfo("Imei", String.class.getName(), "IMEI's digits string", true, true, false),
            new MBeanAttributeInfo("MapProtocolVersion", MapProtocolVersion.class.getName(), "MAP protocol version", true, true, false),
            new MBeanAttributeInfo("MapProtocolVersion_Value", String.class.getName(), "MAP protocol version", true, false, false),
            new MBeanAttributeInfo(
                    "CheckImeiClientAction",
                    CheckImeiClientAction.class.getName(),
                    "The mode of CheckImeiClient work. When manual response user can manually send CheckImei request, when VAL_AUTO_SendCheckImeiRequest the tester sends CheckImei requests without dealay (load test)",
                    true, true, false),
            new MBeanAttributeInfo(
                    "CheckImeiClientAction_Value",
                    String.class.getName(),
                    "The mode of CheckImeiClient work. When manual response user can manually send CheckImei request, when VAL_AUTO_SendCheckImeiRequest the tester sends CheckImei requests without dealay (load test)",
                    true, false, false),
            new MBeanAttributeInfo("MaxConcurrentDialogs", int.class.getName(), "The count of maximum active MAP dialogs when the auto sending mode", true,
                    true, false),
            new MBeanAttributeInfo("OneNotificationFor100Dialogs", boolean.class.getName(),
                    "If true there will be only one notification per every 100 sent dialogs (recommended for the auto sending mode)", true, true, true),

    };

    MBeanParameterInfo[] performCheckImeiParam = new MBeanParameterInfo[] { new MBeanParameterInfo("imei", String.class.getName(), "IMEI's digits string")};
    MBeanParameterInfo[] signString = new MBeanParameterInfo[] { new MBeanParameterInfo("val", String.class.getName(), "Index number or value") };

    MBeanOperationInfo[] operations = new MBeanOperationInfo[] {
            new MBeanOperationInfo("performCheckImeiRequest", "Send CheckIMEI request for provided IMEI", performCheckImeiParam/*signString*/ , String.class.getName(), MBeanOperationInfo.ACTION),
            new MBeanOperationInfo("putMapProtocolVersion", "MAP protocol version: " + "1, 2 or 3", signString, Void.TYPE.getName(),
                    MBeanOperationInfo.ACTION),
            new MBeanOperationInfo("closeCurrentDialog", "Closing the current dialog", null, String.class.getName(), MBeanOperationInfo.ACTION),

            new MBeanOperationInfo("putCheckImeiClientAction",
                    "The mode of CheckImeiClient work. 1:VAL_MANUAL_OPERATION,2:VAL_AUTO_SendCheckImeiRequest", signString, Void.TYPE.getName(),
                    MBeanOperationInfo.ACTION),
    };
    return new MBeanInfo(TestCheckImeiClientMan.class.getName(), "CheckImeiClient test parameters management", attributes, null, operations, null);
}
 
Example 23
Project: Pogamut3   File: DynamicMBeanToFolderAdapter.java   Source Code and License 5 votes vote down vote up
@Override
protected Property[] computeProperties(DynamicProxy object) {
    MBeanInfo nfo = object.getMBeanInfo();
    MBeanAttributeInfo[] attrs = nfo.getAttributes();
    List<Property> props = new ArrayList<Property>();
    for (MBeanAttributeInfo attr : attrs) {
        props.add(new AttributeToPropertyAdapter(attr, object));
    }
    return props.toArray(new Property[0]);
}
 
Example 24
Project: openjdk-jdk10   File: MustBeValidCommand.java   Source Code and License 5 votes vote down vote up
static private MBeanAttributeInfo[] makeAttInfos(String[][] spec) {
    final MBeanAttributeInfo[] result =
        new MBeanAttributeInfo[spec.length];
    for (int i=0;i<result.length;i++) {
        System.out.println("\tCreate an MBeanAttributeInfo: " +
                           spec[i][0]);
        final MBeanAttributeInfo item =
            new MBeanAttributeInfo(spec[i][2],spec[i][1],spec[i][0],
                                   true,true,false);
        result[i]=item;
    }
    return result;
}
 
Example 25
Project: hadoop-oss   File: TestMetricsSourceAdapter.java   Source Code and License 5 votes vote down vote up
@Override
public void run() {
  try {
    // This will trigger updateJmxCache().
    MBeanInfo info = sa.getMBeanInfo();
    final String key = src.getKey();
    for (MBeanAttributeInfo mBeanAttributeInfo : info.getAttributes()) {
      // Found the new key, update the metric source and move on.
      if (mBeanAttributeInfo.getName().equals(key)) {
        LOG.info("found key/val=" + cnt + "/" + cnt);
        cnt++;
        src.setKV("key" + cnt, cnt);
        return;
      }
    }
    LOG.error("key=" + key + " not found. Stopping now.");
    hasError.set(true);
  } catch (Exception e) {
    // catch other errors
    hasError.set(true);
    LOG.error(e.getStackTrace());
  } finally {
    if (hasError.get()) {
      future.cancel(false);
    }
  }
}
 
Example 26
Project: eZooKeeper   File: JmxConnection.java   Source Code and License 5 votes vote down vote up
public MBeanAttribute getMBeanAttribute(MBean mbean, String attributeName) {

        if (mbean == null) {
            throw new IllegalArgumentException("null MBean");
        }

        if (attributeName == null) {
            throw new IllegalArgumentException("null attributeName");
        }

        // TODO: Handle connection errors and try to reconnect.

        MBeanAttributeInfo attributeInfo = mbean.getAttributeInfo(attributeName);
        MBeanAttribute mbeanAttribute = new MBeanAttribute(attributeName);
        mbeanAttribute.setInfo(attributeInfo);

        Object value = null;

        try {
            value = _MBeanServerConnection.getAttribute(mbean.getObjectName(), attributeName);
        }
        catch (Throwable t) {
            String errorMessage = t.getLocalizedMessage();
            mbeanAttribute.setValueRetrievalErrorMessage(errorMessage);
        }

        mbeanAttribute.setValue(value);
        return mbeanAttribute;
    }
 
Example 27
Project: eZooKeeper   File: MBean.java   Source Code and License 5 votes vote down vote up
/**
 * TODO: Comment.
 * 
 * @param attributeName
 * @return
 */
public MBeanAttributeInfo getAttributeInfo(String attributeName) {
    if (_AttributeInfoMap == null) {
        initAttributeCollections();
    }
    return _AttributeInfoMap.get(attributeName);
}
 
Example 28
Project: lazycat   File: JMXAccessorSetTask.java   Source Code and License 5 votes vote down vote up
/**
 * Get MBean Attribute from Mbean Server
 * 
 * @param jmxServerConnection
 * @param name
 * @param attribute
 * @return The type
 * @throws Exception
 */
protected String getMBeanAttributeType(MBeanServerConnection jmxServerConnection, String name, String attribute)
		throws Exception {
	ObjectName oname = new ObjectName(name);
	String mattrType = null;
	MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
	MBeanAttributeInfo attrs[] = minfo.getAttributes();
	for (int i = 0; mattrType == null && i < attrs.length; i++) {
		if (attribute.equals(attrs[i].getName()))
			mattrType = attrs[i].getType();
	}
	return mattrType;
}
 
Example 29
Project: openjdk-jdk10   File: ModelMBeanInfoSupport.java   Source Code and License 5 votes vote down vote up
/**
 * Deserializes a {@link ModelMBeanInfoSupport} from an {@link ObjectInputStream}.
 */
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
    if (compat) {
        // Read an object serialized in the old serial form
        //
        ObjectInputStream.GetField fields = in.readFields();
        modelMBeanDescriptor =
                (Descriptor) fields.get("modelMBeanDescriptor", null);
        if (fields.defaulted("modelMBeanDescriptor")) {
            throw new NullPointerException("modelMBeanDescriptor");
        }
        modelMBeanAttributes =
                (MBeanAttributeInfo[]) fields.get("mmbAttributes", null);
        if (fields.defaulted("mmbAttributes")) {
            throw new NullPointerException("mmbAttributes");
        }
        modelMBeanConstructors =
                (MBeanConstructorInfo[]) fields.get("mmbConstructors", null);
        if (fields.defaulted("mmbConstructors")) {
            throw new NullPointerException("mmbConstructors");
        }
        modelMBeanNotifications =
                (MBeanNotificationInfo[]) fields.get("mmbNotifications", null);
        if (fields.defaulted("mmbNotifications")) {
            throw new NullPointerException("mmbNotifications");
        }
        modelMBeanOperations =
                (MBeanOperationInfo[]) fields.get("mmbOperations", null);
        if (fields.defaulted("mmbOperations")) {
            throw new NullPointerException("mmbOperations");
        }
    } else {
        // Read an object serialized in the new serial form
        //
        in.defaultReadObject();
    }
}
 
Example 30
Project: eZooKeeper   File: MBeanAttributeModelElementType.java   Source Code and License 5 votes vote down vote up
@Override
public String getColumnText(Object element, int columnIndex) {

    // 0:Name | 1:Value | 2:Type | 3:Description

    MBeanAttributeModel model = (MBeanAttributeModel) element;
    MBeanAttribute mbeanAttribute = model.getData();
    MBeanAttributeInfo info = mbeanAttribute.getInfo();
    switch (columnIndex) {

    case 0:
        return mbeanAttribute.getName();

    case 1:

        String valueError = mbeanAttribute.getValueRetrievalErrorMessage();
        if (valueError != null) {
            return valueError;
        }
        else {
            return mbeanAttribute.getValueAsString();
        }

    case 2:
        return info.getType();

    case 3:
        return info.getDescription();

    }

    return null;
}
 
Example 31
Project: alfresco-repository   File: JmxDumpUtil.java   Source Code and License 5 votes vote down vote up
/**
 * Dumps the details of a single MBean.
 * 
 * @param connection
 *            the server connection (or server itself)
 * @param objectName
 *            the object name
 * @param out
 *            PrintWriter to write the output to
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws JMException
 *             Signals a JMX error
 */
private static void printMBeanInfo(MBeanServerConnection connection, ObjectName objectName, PrintWriter out)
        throws IOException, JMException
{
    Map<String, Object> attributes = new TreeMap<String, Object>();
    MBeanInfo info = connection.getMBeanInfo(objectName);
    attributes.put("** Object Name", objectName.toString());
    attributes.put("** Object Type", info.getClassName());
    for (MBeanAttributeInfo element : info.getAttributes())
    {
        Object value;
        if (element.isReadable())
        {
            try
            {
                value = connection.getAttribute(objectName, element.getName());
            }
            catch (Exception e)
            {
                value = JmxDumpUtil.PROTECTED_VALUE;
            }
        }
        else
        {
            value = JmxDumpUtil.PROTECTED_VALUE;
        }
        attributes.put(element.getName(), value);
    }
    if (objectName.getCanonicalName().equals("Alfresco:Name=SystemProperties"))
    {
        String osName = (String) attributes.get(OS_NAME);
        if (osName != null && osName.toLowerCase().startsWith("linux"))
        {
            attributes.put(OS_NAME, updateOSNameAttributeForLinux(osName));
        }
    }
    tabulate(JmxDumpUtil.NAME_HEADER, JmxDumpUtil.VALUE_HEADER, attributes, out, 0);
}
 
Example 32
Project: truevfs   File: JmxManagerView.java   Source Code and License 5 votes vote down vote up
@Override
protected String getDescription(final MBeanAttributeInfo info) {
    switch (info.getName()) {
    case "FileSystemsMounted":
        return "The number of file systems which have been mounted.";
    case "FileSystemsTotal":
        return "The total number of file systems.";
    case "TopLevelArchiveFileSystemsMounted":
        return "The number of top level archive file systems which have been mounted.";
    case "TopLevelArchiveFileSystemsTotal":
        return "The total number of top level archive file systems.";
    default:
        return null;
    }
}
 
Example 33
Project: truevfs   File: JmxModelView.java   Source Code and License 5 votes vote down vote up
@Override
protected String getDescription(final MBeanAttributeInfo info) {
    switch (info.getName()) {
    case "Mounted":
        return "Whether or not this file system is mounted.";
    case "MountPoint":
        return "The mount point URI of this file system.";
    case "MountPointOfParent":
        return "The mount point URI of the parent file system.";
    case "SizeOfData":
        return "The data size of this file system.";
    case "SizeOfStorage":
        return "The storage size of this file system.";
    case "TimeCreatedDate":
        return "The time this file system has been created.";
    case "TimeCreatedMillis":
        return "The time this file system has been created in milliseconds.";
    case "TimeReadDate":
        return "The last time this file system has been read or accessed.";
    case "TimeReadMillis":
        return "The last time this file system has been read or accessed in milliseconds.";
    case "TimeWrittenDate":
        return "The last time this file system has been written.";
    case "TimeWrittenMillis":
        return "The last time this file system has been written in milliseconds.";
    default:
        return null;
    }
}
 
Example 34
Project: tomcat7   File: JMXAccessorSetTask.java   Source Code and License 5 votes vote down vote up
/**
 * Get MBean Attribute from Mbean Server
 * @param jmxServerConnection
 * @param name
 * @param attribute
 * @return The type
 * @throws Exception
 */
protected String getMBeanAttributeType(
        MBeanServerConnection jmxServerConnection,
        String name,
        String attribute) throws Exception {
    ObjectName oname = new ObjectName(name);
    String mattrType = null;
    MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
    MBeanAttributeInfo attrs[] = minfo.getAttributes();
    for (int i = 0; mattrType == null && i < attrs.length; i++) {
        if (attribute.equals(attrs[i].getName()))
            mattrType = attrs[i].getType();
    }
    return mattrType;
}
 
Example 35
Project: flume-release-1.7.0   File: JMXPollUtil.java   Source Code and License 5 votes vote down vote up
public static Map<String, Map<String, String>> getAllMBeans() {
  Map<String, Map<String, String>> mbeanMap = Maps.newHashMap();
  Set<ObjectInstance> queryMBeans = null;
  try {
    queryMBeans = mbeanServer.queryMBeans(null, null);
  } catch (Exception ex) {
    LOG.error("Could not get Mbeans for monitoring", ex);
    Throwables.propagate(ex);
  }
  for (ObjectInstance obj : queryMBeans) {
    try {
      if (!obj.getObjectName().toString().startsWith("org.apache.flume")) {
        continue;
      }
      MBeanAttributeInfo[] attrs = mbeanServer.getMBeanInfo(obj.getObjectName()).getAttributes();
      String[] strAtts = new String[attrs.length];
      for (int i = 0; i < strAtts.length; i++) {
        strAtts[i] = attrs[i].getName();
      }
      AttributeList attrList = mbeanServer.getAttributes(obj.getObjectName(), strAtts);
      String component = obj.getObjectName().toString().substring(
          obj.getObjectName().toString().indexOf('=') + 1);
      Map<String, String> attrMap = Maps.newHashMap();

      for (Object attr : attrList) {
        Attribute localAttr = (Attribute) attr;
        if (localAttr.getName().equalsIgnoreCase("type")) {
          component = localAttr.getValue() + "." + component;
        }
        attrMap.put(localAttr.getName(), localAttr.getValue().toString());
      }
      mbeanMap.put(component, attrMap);
    } catch (Exception e) {
      LOG.error("Unable to poll JMX for metrics.", e);
    }
  }
  return mbeanMap;
}
 
Example 36
Project: lams   File: MBeanClientInterceptor.java   Source Code and License 5 votes vote down vote up
private Object invokeAttribute(PropertyDescriptor pd, MethodInvocation invocation)
		throws JMException, IOException {

	String attributeName = JmxUtils.getAttributeName(pd, this.useStrictCasing);
	MBeanAttributeInfo inf = this.allowedAttributes.get(attributeName);
	// If no attribute is returned, we know that it is not defined in the
	// management interface.
	if (inf == null) {
		throw new InvalidInvocationException(
				"Attribute '" + pd.getName() + "' is not exposed on the management interface");
	}
	if (invocation.getMethod().equals(pd.getReadMethod())) {
		if (inf.isReadable()) {
			return this.serverToUse.getAttribute(this.objectName, attributeName);
		}
		else {
			throw new InvalidInvocationException("Attribute '" + attributeName + "' is not readable");
		}
	}
	else if (invocation.getMethod().equals(pd.getWriteMethod())) {
		if (inf.isWritable()) {
			this.serverToUse.setAttribute(this.objectName, new Attribute(attributeName, invocation.getArguments()[0]));
			return null;
		}
		else {
			throw new InvalidInvocationException("Attribute '" + attributeName + "' is not writable");
		}
	}
	else {
		throw new IllegalStateException(
				"Method [" + invocation.getMethod() + "] is neither a bean property getter nor a setter");
	}
}
 
Example 37
Project: lams   File: JMXAccessorSetTask.java   Source Code and License 5 votes vote down vote up
/**
 * Get MBean Attriute from Mbean Server
 * @param jmxServerConnection
 * @param name
 * @param attribute
 * @return The type
 * @throws Exception
 */
protected String getMBeanAttributeType(
        MBeanServerConnection jmxServerConnection,
        String name,
        String attribute) throws Exception {
    ObjectName oname = new ObjectName(name);
    String mattrType = null;
    MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
    MBeanAttributeInfo attrs[] = minfo.getAttributes();
    if (attrs != null) {
        for (int i = 0; mattrType == null && i < attrs.length; i++) {
            if (attribute.equals(attrs[i].getName()))
                mattrType = attrs[i].getType();
        }
    }
    return mattrType;
}
 
Example 38
Project: hashsdn-controller   File: AbstractDynamicWrapper.java   Source Code and License 5 votes vote down vote up
private static MBeanInfo generateMBeanInfo(final Module module,
        final Map<String, AttributeHolder> attributeHolderMap, final MBeanOperationInfo[] operations,
        final Set<Class<?>> jmxInterfaces) {

    String description = findDescription(module.getClass(), jmxInterfaces);
    MBeanConstructorInfo[] constructors = new MBeanConstructorInfo[0];
    List<MBeanAttributeInfo> attributes = new ArrayList<>(attributeHolderMap.size());
    for (AttributeHolder attributeHolder : attributeHolderMap.values()) {
        attributes.add(attributeHolder.toMBeanAttributeInfo());
    }
    return new MBeanInfo(module.getClass().getName(), description, attributes.toArray(new MBeanAttributeInfo[0]),
            constructors, operations, new MBeanNotificationInfo[0]);
}
 
Example 39
Project: OpenJSharp   File: StandardMBeanIntrospector.java   Source Code and License 5 votes vote down vote up
@Override
MBeanAttributeInfo getMBeanAttributeInfo(String attributeName,
        Method getter, Method setter) {

    final String description = "Attribute exposed for management";
    try {
        return new MBeanAttributeInfo(attributeName, description,
                                      getter, setter);
    } catch (IntrospectionException e) {
        throw new RuntimeException(e); // should not happen
    }
}
 
Example 40
Project: OpenJSharp   File: MBeanIntrospector.java   Source Code and License 5 votes vote down vote up
public void visitAttribute(String attributeName,
        M getter,
        M setter) {
    MBeanAttributeInfo mbai =
            getMBeanAttributeInfo(attributeName, getter, setter);

    attrs.add(mbai);
}
 
Example 41
Project: OpenJSharp   File: MBeanIntrospector.java   Source Code and License 5 votes vote down vote up
/** Make an MBeanInfo based on the attributes and operations
 *  found in the interface. */
MBeanInfo makeMBeanInfo(Class<?> mbeanInterface,
        String description) {
    final MBeanAttributeInfo[] attrArray =
            attrs.toArray(new MBeanAttributeInfo[0]);
    final MBeanOperationInfo[] opArray =
            ops.toArray(new MBeanOperationInfo[0]);
    final String interfaceClassName =
            "interfaceClassName=" + mbeanInterface.getName();
    final Descriptor classNameDescriptor =
            new ImmutableDescriptor(interfaceClassName);
    final Descriptor mbeanDescriptor = getBasicMBeanDescriptor();
    final Descriptor annotatedDescriptor =
            Introspector.descriptorForElement(mbeanInterface);
    final Descriptor descriptor =
        DescriptorCache.getInstance().union(
            classNameDescriptor,
            mbeanDescriptor,
            annotatedDescriptor);

    return new MBeanInfo(mbeanInterface.getName(),
            description,
            attrArray,
            null,
            opArray,
            null,
            descriptor);
}
 
Example 42
Project: OpenJSharp   File: ModelMBeanInfoSupport.java   Source Code and License 5 votes vote down vote up
/**
 * Deserializes a {@link ModelMBeanInfoSupport} from an {@link ObjectInputStream}.
 */
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
    if (compat) {
        // Read an object serialized in the old serial form
        //
        ObjectInputStream.GetField fields = in.readFields();
        modelMBeanDescriptor =
                (Descriptor) fields.get("modelMBeanDescriptor", null);
        if (fields.defaulted("modelMBeanDescriptor")) {
            throw new NullPointerException("modelMBeanDescriptor");
        }
        modelMBeanAttributes =
                (MBeanAttributeInfo[]) fields.get("mmbAttributes", null);
        if (fields.defaulted("mmbAttributes")) {
            throw new NullPointerException("mmbAttributes");
        }
        modelMBeanConstructors =
                (MBeanConstructorInfo[]) fields.get("mmbConstructors", null);
        if (fields.defaulted("mmbConstructors")) {
            throw new NullPointerException("mmbConstructors");
        }
        modelMBeanNotifications =
                (MBeanNotificationInfo[]) fields.get("mmbNotifications", null);
        if (fields.defaulted("mmbNotifications")) {
            throw new NullPointerException("mmbNotifications");
        }
        modelMBeanOperations =
                (MBeanOperationInfo[]) fields.get("mmbOperations", null);
        if (fields.defaulted("mmbOperations")) {
            throw new NullPointerException("mmbOperations");
        }
    } else {
        // Read an object serialized in the new serial form
        //
        in.defaultReadObject();
    }
}
 
Example 43
Project: OpenJSharp   File: OpenMBeanInfoSupport.java   Source Code and License 5 votes vote down vote up
private static MBeanAttributeInfo[]
        attributeArray(OpenMBeanAttributeInfo[] src) {
    if (src == null)
        return null;
    MBeanAttributeInfo[] dst = new MBeanAttributeInfo[src.length];
    System.arraycopy(src, 0, dst, 0, src.length);
    // may throw an ArrayStoreException
    return dst;
}
 
Example 44
Project: ChronoBike   File: MBeanAttributeInfoWrapper.java   Source Code and License 5 votes vote down vote up
public MBeanAttributeInfoWrapper(String csName, String csDescription, Method getter, Method setter)
{
	try
	{
		m_attribute = new MBeanAttributeInfo(csName, csDescription, getter, setter);
	} 
	catch (IntrospectionException e)
	{
		e.printStackTrace();
	}
	m_getter = getter;
	m_setter = setter;
}
 
Example 45
Project: apache-tomcat-7.0.73-with-comment   File: JMXAccessorSetTask.java   Source Code and License 5 votes vote down vote up
/**
 * Get MBean Attribute from Mbean Server
 * @param jmxServerConnection
 * @param name
 * @param attribute
 * @return The type
 * @throws Exception
 */
protected String getMBeanAttributeType(
        MBeanServerConnection jmxServerConnection,
        String name,
        String attribute) throws Exception {
    ObjectName oname = new ObjectName(name);
    String mattrType = null;
    MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
    MBeanAttributeInfo attrs[] = minfo.getAttributes();
    for (int i = 0; mattrType == null && i < attrs.length; i++) {
        if (attribute.equals(attrs[i].getName()))
            mattrType = attrs[i].getType();
    }
    return mattrType;
}
 
Example 46
Project: jmx-prometheus-exporter   File: MBean.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("StaticMethodNamingConvention")
public static @NotNull Optional<MBean> of(@NotNull ObjectName name, @NotNull MBeanAttributeInfo info) {
  final Map<String, String> properties = name.getKeyPropertyList();
  final String type = properties.get(TYPE_PROPERTY_NAME);
  if (type == null) {
    return Optional.empty();
  }

  final Map<String, String> labels = properties.entrySet().stream()
      .filter(entry -> !entry.getKey().equals(TYPE_PROPERTY_NAME))
      .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

  return Optional.of(new MBean(name.getDomain() + ':' + type, info.getName(), labels));
}
 
Example 47
Project: openjdk-jdk10   File: MXBeanTest.java   Source Code and License 5 votes vote down vote up
private static void testMXBean(MBeanServer mbs, ObjectName on)
        throws Exception {
    MBeanInfo mbi = mbs.getMBeanInfo(on);
    MBeanAttributeInfo[] attrs = mbi.getAttributes();
    int nattrs = attrs.length;
    if (mbi.getAttributes().length != 1)
        failure("wrong number of attributes: " + attrs);
    else {
        MBeanAttributeInfo mbai = attrs[0];
        if (mbai.getName().equals("Ints")
            && mbai.isReadable() && !mbai.isWritable()
            && mbai.getDescriptor().getFieldValue("openType")
                .equals(new ArrayType<int[]>(SimpleType.INTEGER, true))
            && attrs[0].getType().equals("[I"))
            success("MBeanAttributeInfo");
        else
            failure("MBeanAttributeInfo: " + mbai);
    }

    int[] ints = (int[]) mbs.getAttribute(on, "Ints");
    if (equal(ints, new int[] {1, 2, 3}, null))
        success("getAttribute");
    else
        failure("getAttribute: " + Arrays.toString(ints));

    ExplicitMXBean proxy =
        JMX.newMXBeanProxy(mbs, on, ExplicitMXBean.class);
    int[] pints = proxy.getInts();
    if (equal(pints, new int[] {1, 2, 3}, null))
        success("getAttribute through proxy");
    else
        failure("getAttribute through proxy: " + Arrays.toString(pints));
}
 
Example 48
Project: jdk8u-jdk   File: StandardMBeanIntrospector.java   Source Code and License 5 votes vote down vote up
@Override
MBeanAttributeInfo getMBeanAttributeInfo(String attributeName,
        Method getter, Method setter) {

    final String description = "Attribute exposed for management";
    try {
        return new MBeanAttributeInfo(attributeName, description,
                                      getter, setter);
    } catch (IntrospectionException e) {
        throw new RuntimeException(e); // should not happen
    }
}
 
Example 49
Project: jdk8u-jdk   File: MBeanIntrospector.java   Source Code and License 5 votes vote down vote up
public void visitAttribute(String attributeName,
        M getter,
        M setter) {
    MBeanAttributeInfo mbai =
            getMBeanAttributeInfo(attributeName, getter, setter);

    attrs.add(mbai);
}
 
Example 50
Project: jdk8u-jdk   File: MBeanIntrospector.java   Source Code and License 5 votes vote down vote up
/** Make an MBeanInfo based on the attributes and operations
 *  found in the interface. */
MBeanInfo makeMBeanInfo(Class<?> mbeanInterface,
        String description) {
    final MBeanAttributeInfo[] attrArray =
            attrs.toArray(new MBeanAttributeInfo[0]);
    final MBeanOperationInfo[] opArray =
            ops.toArray(new MBeanOperationInfo[0]);
    final String interfaceClassName =
            "interfaceClassName=" + mbeanInterface.getName();
    final Descriptor classNameDescriptor =
            new ImmutableDescriptor(interfaceClassName);
    final Descriptor mbeanDescriptor = getBasicMBeanDescriptor();
    final Descriptor annotatedDescriptor =
            Introspector.descriptorForElement(mbeanInterface);
    final Descriptor descriptor =
        DescriptorCache.getInstance().union(
            classNameDescriptor,
            mbeanDescriptor,
            annotatedDescriptor);

    return new MBeanInfo(mbeanInterface.getName(),
            description,
            attrArray,
            null,
            opArray,
            null,
            descriptor);
}
 
Example 51
Project: jdk8u-jdk   File: ModelMBeanInfoSupport.java   Source Code and License 5 votes vote down vote up
/**
 * Deserializes a {@link ModelMBeanInfoSupport} from an {@link ObjectInputStream}.
 */
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
    if (compat) {
        // Read an object serialized in the old serial form
        //
        ObjectInputStream.GetField fields = in.readFields();
        modelMBeanDescriptor =
                (Descriptor) fields.get("modelMBeanDescriptor", null);
        if (fields.defaulted("modelMBeanDescriptor")) {
            throw new NullPointerException("modelMBeanDescriptor");
        }
        modelMBeanAttributes =
                (MBeanAttributeInfo[]) fields.get("mmbAttributes", null);
        if (fields.defaulted("mmbAttributes")) {
            throw new NullPointerException("mmbAttributes");
        }
        modelMBeanConstructors =
                (MBeanConstructorInfo[]) fields.get("mmbConstructors", null);
        if (fields.defaulted("mmbConstructors")) {
            throw new NullPointerException("mmbConstructors");
        }
        modelMBeanNotifications =
                (MBeanNotificationInfo[]) fields.get("mmbNotifications", null);
        if (fields.defaulted("mmbNotifications")) {
            throw new NullPointerException("mmbNotifications");
        }
        modelMBeanOperations =
                (MBeanOperationInfo[]) fields.get("mmbOperations", null);
        if (fields.defaulted("mmbOperations")) {
            throw new NullPointerException("mmbOperations");
        }
    } else {
        // Read an object serialized in the new serial form
        //
        in.defaultReadObject();
    }
}
 
Example 52
Project: jdk8u-jdk   File: OpenMBeanInfoSupport.java   Source Code and License 5 votes vote down vote up
private static MBeanAttributeInfo[]
        attributeArray(OpenMBeanAttributeInfo[] src) {
    if (src == null)
        return null;
    MBeanAttributeInfo[] dst = new MBeanAttributeInfo[src.length];
    System.arraycopy(src, 0, dst, 0, src.length);
    // may throw an ArrayStoreException
    return dst;
}
 
Example 53
Project: jdk8u-jdk   File: MustBeValidCommand.java   Source Code and License 5 votes vote down vote up
static private MBeanAttributeInfo[] makeAttInfos(String[][] spec) {
    final MBeanAttributeInfo[] result =
        new MBeanAttributeInfo[spec.length];
    for (int i=0;i<result.length;i++) {
        System.out.println("\tCreate an MBeanAttributeInfo: " +
                           spec[i][0]);
        final MBeanAttributeInfo item =
            new MBeanAttributeInfo(spec[i][2],spec[i][1],spec[i][0],
                                   true,true,false);
        result[i]=item;
    }
    return result;
}
 
Example 54
Project: jdk8u-jdk   File: MXBeanTest.java   Source Code and License 5 votes vote down vote up
private static void testMXBean(MBeanServer mbs, ObjectName on)
        throws Exception {
    MBeanInfo mbi = mbs.getMBeanInfo(on);
    MBeanAttributeInfo[] attrs = mbi.getAttributes();
    int nattrs = attrs.length;
    if (mbi.getAttributes().length != 1)
        failure("wrong number of attributes: " + attrs);
    else {
        MBeanAttributeInfo mbai = attrs[0];
        if (mbai.getName().equals("Ints")
            && mbai.isReadable() && !mbai.isWritable()
            && mbai.getDescriptor().getFieldValue("openType")
                .equals(new ArrayType<int[]>(SimpleType.INTEGER, true))
            && attrs[0].getType().equals("[I"))
            success("MBeanAttributeInfo");
        else
            failure("MBeanAttributeInfo: " + mbai);
    }

    int[] ints = (int[]) mbs.getAttribute(on, "Ints");
    if (equal(ints, new int[] {1, 2, 3}, null))
        success("getAttribute");
    else
        failure("getAttribute: " + Arrays.toString(ints));

    ExplicitMXBean proxy =
        JMX.newMXBeanProxy(mbs, on, ExplicitMXBean.class);
    int[] pints = proxy.getInts();
    if (equal(pints, new int[] {1, 2, 3}, null))
        success("getAttribute through proxy");
    else
        failure("getAttribute through proxy: " + Arrays.toString(pints));
}
 
Example 55
Project: jdk8u-jdk   File: AnnotationTest.java   Source Code and License 5 votes vote down vote up
private static void check(MBeanServer mbs, ObjectName on) throws Exception {
    MBeanInfo mbi = mbs.getMBeanInfo(on);

    // check the MBean itself
    check(mbi);

    // check attributes
    MBeanAttributeInfo[] attrs = mbi.getAttributes();
    for (MBeanAttributeInfo attr : attrs) {
        check(attr);
        if (attr.getName().equals("ReadOnly"))
            check("@Full", attr.getDescriptor(), expectedFullDescriptor);
    }

    // check operations
    MBeanOperationInfo[] ops = mbi.getOperations();
    for (MBeanOperationInfo op : ops) {
        check(op);
        check(op.getSignature());
    }

    MBeanConstructorInfo[] constrs = mbi.getConstructors();
    for (MBeanConstructorInfo constr : constrs) {
        check(constr);
        check(constr.getSignature());
    }
}
 
Example 56
Project: jdk8u-jdk   File: OldMBeanServerTest.java   Source Code and License 5 votes vote down vote up
private static void printAttrs(
        MBeanServerConnection mbsc1, Class<? extends Exception> expectX)
throws Exception {
    Set<ObjectName> names = mbsc1.queryNames(null, null);
    for (ObjectName name : names) {
        System.out.println(name + ":");
        MBeanInfo mbi = mbsc1.getMBeanInfo(name);
        MBeanAttributeInfo[] mbais = mbi.getAttributes();
        for (MBeanAttributeInfo mbai : mbais) {
            String attr = mbai.getName();
            Object value;
            try {
                value = mbsc1.getAttribute(name, attr);
            } catch (Exception e) {
                if (expectX != null && expectX.isInstance(e))
                    value = "<" + e + ">";
                else
                    throw e;
            }
            String s = "  " + attr + " = " + value;
            if (s.length() > 80)
                s = s.substring(0, 77) + "...";
            System.out.println(s);
        }
    }
}
 
Example 57
Project: openjdk-jdk10   File: HotSpotGraalMBeanTest.java   Source Code and License 5 votes vote down vote up
@Test
public void readBeanInfo() throws Exception {
    ObjectName name;

    assertNotNull("Server is started", ManagementFactory.getPlatformMBeanServer());

    HotSpotGraalMBean realBean = HotSpotGraalMBean.create(null);
    assertNotNull("Bean is registered", name = realBean.ensureRegistered(false));
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();

    ObjectInstance bean = server.getObjectInstance(name);
    assertNotNull("Bean is registered", bean);
    MBeanInfo info = server.getMBeanInfo(name);
    assertNotNull("Info is found", info);

    MBeanAttributeInfo printCompilation = (MBeanAttributeInfo) findAttributeInfo("PrintCompilation", info);
    assertNotNull("PrintCompilation found", printCompilation);
    assertEquals("true/false", Boolean.class.getName(), printCompilation.getType());

    Attribute printOn = new Attribute(printCompilation.getName(), Boolean.TRUE);

    Object before = server.getAttribute(name, printCompilation.getName());
    server.setAttribute(name, printOn);
    Object after = server.getAttribute(name, printCompilation.getName());

    assertNull("Default value was not set", before);
    assertEquals("Changed to on", Boolean.TRUE, after);
}
 
Example 58
Project: openjdk-jdk10   File: HotSpotGraalMBeanTest.java   Source Code and License 5 votes vote down vote up
private static Object findAttributeInfo(String attrName, Object info) {
    MBeanAttributeInfo printCompilation = null;
    for (MBeanAttributeInfo attr : ((MBeanInfo) info).getAttributes()) {
        if (attr.getName().equals(attrName)) {
            assertTrue("Readable", attr.isReadable());
            assertTrue("Writable", attr.isWritable());
            printCompilation = attr;
            break;
        }
    }
    return printCompilation;
}
 
Example 59
Project: openjdk-jdk10   File: StandardMBeanIntrospector.java   Source Code and License 5 votes vote down vote up
@Override
MBeanAttributeInfo getMBeanAttributeInfo(String attributeName,
        Method getter, Method setter) {

    final String description = "Attribute exposed for management";
    try {
        return new MBeanAttributeInfo(attributeName, description,
                                      getter, setter);
    } catch (IntrospectionException e) {
        throw new RuntimeException(e); // should not happen
    }
}
 
Example 60
Project: openjdk-jdk10   File: MBeanIntrospector.java   Source Code and License 5 votes vote down vote up
public void visitAttribute(String attributeName,
        M getter,
        M setter) {
    MBeanAttributeInfo mbai =
            getMBeanAttributeInfo(attributeName, getter, setter);

    attrs.add(mbai);
}