protected void initDescriptorSectionFromModel() {
Descriptor descriptor = getJmxDescriptor();
if (descriptor == null) {
return;
}
Table table = getDescriptorTable();
if (table == null) {
return;
}
table.removeAll();
for (String fieldName : descriptor.getFieldNames()) {
TableItem item = new TableItem(table, SWT.NONE);
Object value = descriptor.getFieldValue(fieldName);
item.setText(0, fieldName);
item.setText(1, String.valueOf(value));
}
packTable(table, DEFAULT_NAME_VALUE_COLUMN_WIDTHS);
}
java类javax.management.Descriptor的实例源码
BaseJmxModelMainFormPage.java 文件源码
项目:eZooKeeper
阅读 21
收藏 0
点赞 0
评论 0
MetadataMBeanInfoAssembler.java 文件源码
项目:lams
阅读 21
收藏 0
点赞 0
评论 0
private void populateMetricDescriptor(Descriptor desc, ManagedMetric metric) {
applyCurrencyTimeLimit(desc, metric.getCurrencyTimeLimit());
if (StringUtils.hasLength(metric.getPersistPolicy())) {
desc.setField(FIELD_PERSIST_POLICY, metric.getPersistPolicy());
}
if (metric.getPersistPeriod() >= 0) {
desc.setField(FIELD_PERSIST_PERIOD, Integer.toString(metric.getPersistPeriod()));
}
if (StringUtils.hasLength(metric.getDisplayName())) {
desc.setField(FIELD_DISPLAY_NAME, metric.getDisplayName());
}
if(StringUtils.hasLength(metric.getUnit())) {
desc.setField(FIELD_UNITS, metric.getUnit());
}
if(StringUtils.hasLength(metric.getCategory())) {
desc.setField(FIELD_METRIC_CATEGORY, metric.getCategory());
}
String metricType = (metric.getMetricType() == null) ? MetricType.GAUGE.toString() : metric.getMetricType().toString();
desc.setField(FIELD_METRIC_TYPE, metricType);
}
RequiredModelMBean.java 文件源码
项目:openjdk-jdk10
阅读 24
收藏 0
点赞 0
评论 0
/**
* Creates a default ModelMBeanNotificationInfo for GENERIC
* notification. (bug 4744667)
**/
private static final ModelMBeanNotificationInfo makeGenericInfo() {
final Descriptor genericDescriptor = new DescriptorSupport( new
String[] {
"name=GENERIC",
"descriptorType=notification",
"log=T",
"severity=6",
"displayName=jmx.modelmbean.generic"} );
return new ModelMBeanNotificationInfo(new
String[] {"jmx.modelmbean.generic"},
"GENERIC",
"A text notification has been issued by the managed resource",
genericDescriptor);
}
OpenMBeanAttributeInfoSupport.java 文件源码
项目:jdk8u-jdk
阅读 30
收藏 0
点赞 0
评论 0
static <T> Descriptor makeDescriptor(OpenType<T> openType,
T defaultValue,
T[] legalValues,
Comparable<T> minValue,
Comparable<T> maxValue) {
Map<String, Object> map = new HashMap<String, Object>();
if (defaultValue != null)
map.put("defaultValue", defaultValue);
if (legalValues != null) {
Set<T> set = new HashSet<T>();
for (T v : legalValues)
set.add(v);
set = Collections.unmodifiableSet(set);
map.put("legalValues", set);
}
if (minValue != null)
map.put("minValue", minValue);
if (maxValue != null)
map.put("maxValue", maxValue);
if (map.isEmpty()) {
return openType.getDescriptor();
} else {
map.put("openType", openType);
return new ImmutableDescriptor(map);
}
}
ModelMBeanNotificationInfo.java 文件源码
项目:openjdk-jdk10
阅读 20
收藏 0
点赞 0
评论 0
/**
* Returns a copy of the associated Descriptor for the
* ModelMBeanNotificationInfo.
*
* @return Descriptor associated with the
* ModelMBeanNotificationInfo object.
*
* @see #setDescriptor
**/
public Descriptor getDescriptor() {
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
}
if (notificationDescriptor == null) {
// Dead code. Should never happen.
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
MODELMBEAN_LOGGER.log(Level.TRACE,
"Descriptor value is null, " +
"setting descriptor to default values");
}
notificationDescriptor = validDescriptor(null);
}
return((Descriptor)notificationDescriptor.clone());
}
ModelMBeanConstructorInfo.java 文件源码
项目:OpenJSharp
阅读 24
收藏 0
点赞 0
评论 0
/**
* Returns a copy of the associated Descriptor.
*
* @return Descriptor associated with the
* ModelMBeanConstructorInfo object.
*
* @see #setDescriptor
*/
@Override
public Descriptor getDescriptor()
{
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
ModelMBeanConstructorInfo.class.getName(),
"getDescriptor()", "Entry");
}
if (consDescriptor == null){
consDescriptor = validDescriptor(null);
}
return((Descriptor)consDescriptor.clone());
}
OpenMBeanParameterInfoSupport.java 文件源码
项目:openjdk-jdk10
阅读 23
收藏 0
点赞 0
评论 0
private <T> OpenMBeanParameterInfoSupport(String name,
String description,
OpenType<T> openType,
T defaultValue,
T[] legalValues,
Comparable<T> minValue,
Comparable<T> maxValue)
throws OpenDataException {
super(name,
(openType == null) ? null : openType.getClassName(),
description,
makeDescriptor(openType,
defaultValue, legalValues, minValue, maxValue));
this.openType = openType;
Descriptor d = getDescriptor();
this.defaultValue = defaultValue;
this.minValue = minValue;
this.maxValue = maxValue;
// We already converted the array into an unmodifiable Set
// in the descriptor.
this.legalValues = (Set<?>) d.getFieldValue("legalValues");
check(this);
}
ModelMBeanInfoSupport.java 文件源码
项目:OpenJSharp
阅读 25
收藏 0
点赞 0
评论 0
private Descriptor getMBeanDescriptorNoException() {
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
ModelMBeanInfoSupport.class.getName(),
"getMBeanDescriptorNoException()", "Entry");
}
if (modelMBeanDescriptor == null)
modelMBeanDescriptor = validDescriptor(null);
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
ModelMBeanInfoSupport.class.getName(),
"getMBeanDescriptorNoException()",
"Exit, returning: " + modelMBeanDescriptor);
}
return (Descriptor) modelMBeanDescriptor.clone();
}
RequiredModelMBean.java 文件源码
项目:OpenJSharp
阅读 22
收藏 0
点赞 0
评论 0
/**
* Creates a default ModelMBeanNotificationInfo for GENERIC
* notification. (bug 4744667)
**/
private static final ModelMBeanNotificationInfo makeGenericInfo() {
final Descriptor genericDescriptor = new DescriptorSupport( new
String[] {
"name=GENERIC",
"descriptorType=notification",
"log=T",
"severity=6",
"displayName=jmx.modelmbean.generic"} );
return new ModelMBeanNotificationInfo(new
String[] {"jmx.modelmbean.generic"},
"GENERIC",
"A text notification has been issued by the managed resource",
genericDescriptor);
}
RequiredModelMBean.java 文件源码
项目:OpenJSharp
阅读 23
收藏 0
点赞 0
评论 0
/**
* Creates a default ModelMBeanNotificationInfo for ATTRIBUTE_CHANGE
* notification. (bug 4744667)
**/
private static final
ModelMBeanNotificationInfo makeAttributeChangeInfo() {
final Descriptor attributeDescriptor = new DescriptorSupport(new
String[] {
"name=ATTRIBUTE_CHANGE",
"descriptorType=notification",
"log=T",
"severity=6",
"displayName=jmx.attribute.change"});
return new ModelMBeanNotificationInfo(new
String[] {"jmx.attribute.change"},
"ATTRIBUTE_CHANGE",
"Signifies that an observed MBean attribute value has changed",
attributeDescriptor );
}
OpenMBeanParameterInfoSupport.java 文件源码
项目:OpenJSharp
阅读 22
收藏 0
点赞 0
评论 0
private <T> OpenMBeanParameterInfoSupport(String name,
String description,
OpenType<T> openType,
T defaultValue,
T[] legalValues,
Comparable<T> minValue,
Comparable<T> maxValue)
throws OpenDataException {
super(name,
(openType == null) ? null : openType.getClassName(),
description,
makeDescriptor(openType,
defaultValue, legalValues, minValue, maxValue));
this.openType = openType;
Descriptor d = getDescriptor();
this.defaultValue = defaultValue;
this.minValue = minValue;
this.maxValue = maxValue;
// We already converted the array into an unmodifiable Set
// in the descriptor.
this.legalValues = (Set<?>) d.getFieldValue("legalValues");
check(this);
}
AnnotationTest.java 文件源码
项目:jdk8u-jdk
阅读 32
收藏 0
点赞 0
评论 0
private static void check(Object x, Descriptor d, Descriptor expect) {
String fail = null;
try {
Descriptor u = ImmutableDescriptor.union(d, expect);
if (!u.equals(d))
fail = "should contain " + expect + "; is " + d;
} catch (IllegalArgumentException e) {
fail = e.getMessage();
}
if (fail == null) {
System.out.println("OK: " + x);
} else {
failed = "NOT OK: Incorrect descriptor for: " + x;
System.out.println(failed);
System.out.println("..." + fail);
}
}
ModelMBeanInfoSupport.java 文件源码
项目:jdk8u-jdk
阅读 20
收藏 0
点赞 0
评论 0
private Descriptor getMBeanDescriptorNoException() {
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
ModelMBeanInfoSupport.class.getName(),
"getMBeanDescriptorNoException()", "Entry");
}
if (modelMBeanDescriptor == null)
modelMBeanDescriptor = validDescriptor(null);
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
ModelMBeanInfoSupport.class.getName(),
"getMBeanDescriptorNoException()",
"Exit, returning: " + modelMBeanDescriptor);
}
return (Descriptor) modelMBeanDescriptor.clone();
}
MX4JModelMBean.java 文件源码
项目:monarch
阅读 24
收藏 0
点赞 0
评论 0
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);
}
MX4JModelMBean.java 文件源码
项目:monarch
阅读 28
收藏 0
点赞 0
评论 0
private boolean shouldPersistNow(Descriptor attribute, Descriptor mbean, String lastUpdateField) {
int persist = getPersistPolicy(attribute, mbean);
if (persist == PERSIST_NO_MORE_OFTEN_THAN) {
Long period = getFieldTimeValue(attribute, mbean, "persistPeriod");
long now = System.currentTimeMillis();
Long lastUpdate = (Long) attribute.getFieldValue(lastUpdateField);
if (now - lastUpdate.longValue() < period.longValue())
return false;
else
return true;
} else if (persist == PERSIST_NEVER) {
return false;
} else if (persist == PERSIST_ON_TIMER) {
return false;
} else if (persist == PERSIST_ON_UPDATE) {
return true;
} else {
throw new ImplementationException(
LocalizedStrings.MX4JModelMBean_INVALID_PERSIST_VALUE.toLocalizedString());
}
}
ImmutableNotificationInfoTest.java 文件源码
项目:jdk8u-jdk
阅读 23
收藏 0
点赞 0
评论 0
private static boolean test(Object mbean, boolean expectImmutable)
throws Exception {
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
ObjectName on = new ObjectName("a:b=c");
mbs.registerMBean(mbean, on);
MBeanInfo mbi = mbs.getMBeanInfo(on);
Descriptor d = mbi.getDescriptor();
String immutableValue = (String) d.getFieldValue("immutableInfo");
boolean immutable = ("true".equals(immutableValue));
if (immutable != expectImmutable) {
System.out.println("FAILED: " + mbean.getClass().getName() +
" -> " + immutableValue);
return false;
} else {
System.out.println("OK: " + mbean.getClass().getName());
return true;
}
}
StatisticAttributeInfo.java 文件源码
项目:monarch
阅读 18
收藏 0
点赞 0
评论 0
@Override
public ModelMBeanAttributeInfo createAttributeInfo() {
Descriptor desc = new DescriptorSupport(new String[] {"name=" + this.displayName,
"descriptorType=attribute", "currencyTimeLimit=-1", // always stale
"displayName=" + this.displayName, "getMethod=getValue"});
Assert.assertTrue(this.stat != null, "Stat target object is null!");
desc.setField("targetObject", this.stat);
ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(this.displayName, // name
this.type, // type
this.description, // description
this.readable, // isReadable
this.writeable, // isWritable
this.is, // isIs
desc);
return info;
}
OpenMBeanAttributeInfoSupport.java 文件源码
项目:openjdk-jdk10
阅读 24
收藏 0
点赞 0
评论 0
private <T> OpenMBeanAttributeInfoSupport(String name,
String description,
OpenType<T> openType,
boolean isReadable,
boolean isWritable,
boolean isIs,
T defaultValue,
T[] legalValues,
Comparable<T> minValue,
Comparable<T> maxValue)
throws OpenDataException {
super(name,
(openType==null) ? null : openType.getClassName(),
description,
isReadable,
isWritable,
isIs,
makeDescriptor(openType,
defaultValue, legalValues, minValue, maxValue));
this.openType = openType;
Descriptor d = getDescriptor();
this.defaultValue = defaultValue;
this.minValue = minValue;
this.maxValue = maxValue;
// We already converted the array into an unmodifiable Set
// in the descriptor.
this.legalValues = (Set<?>) d.getFieldValue("legalValues");
check(this);
}
DiagnosticCommandImpl.java 文件源码
项目:openjdk-jdk10
阅读 18
收藏 0
点赞 0
评论 0
private Descriptor commandDescriptor(Wrapper w) throws IllegalArgumentException {
HashMap<String, Object> map = new HashMap<>();
map.put("dcmd.name", w.info.getName());
map.put("dcmd.description", w.info.getDescription());
map.put("dcmd.vmImpact", w.info.getImpact());
map.put("dcmd.permissionClass", w.info.getPermissionClass());
map.put("dcmd.permissionName", w.info.getPermissionName());
map.put("dcmd.permissionAction", w.info.getPermissionAction());
map.put("dcmd.enabled", w.info.isEnabled());
StringBuilder sb = new StringBuilder();
sb.append("help ");
sb.append(w.info.getName());
map.put("dcmd.help", executeDiagnosticCommand(sb.toString()));
if (w.info.getArgumentsInfo() != null && !w.info.getArgumentsInfo().isEmpty()) {
HashMap<String, Object> allargmap = new HashMap<>();
for (DiagnosticCommandArgumentInfo arginfo : w.info.getArgumentsInfo()) {
HashMap<String, Object> argmap = new HashMap<>();
argmap.put("dcmd.arg.name", arginfo.getName());
argmap.put("dcmd.arg.type", arginfo.getType());
argmap.put("dcmd.arg.description", arginfo.getDescription());
argmap.put("dcmd.arg.isMandatory", arginfo.isMandatory());
argmap.put("dcmd.arg.isMultiple", arginfo.isMultiple());
boolean isOption = arginfo.isOption();
argmap.put("dcmd.arg.isOption", isOption);
if(!isOption) {
argmap.put("dcmd.arg.position", arginfo.getPosition());
} else {
argmap.put("dcmd.arg.position", -1);
}
allargmap.put(arginfo.getName(), new ImmutableDescriptor(argmap));
}
map.put("dcmd.arguments", new ImmutableDescriptor(allargmap));
}
return new ImmutableDescriptor(map);
}
MetadataMBeanInfoAssembler.java 文件源码
项目:lams
阅读 21
收藏 0
点赞 0
评论 0
/**
* Adds descriptor fields from the {@code ManagedResource} attribute
* to the MBean descriptor. Specifically, adds the {@code currencyTimeLimit},
* {@code persistPolicy}, {@code persistPeriod}, {@code persistLocation}
* and {@code persistName} descriptor fields if they are present in the metadata.
*/
@Override
protected void populateMBeanDescriptor(Descriptor desc, Object managedBean, String beanKey) {
ManagedResource mr = this.attributeSource.getManagedResource(getClassToExpose(managedBean));
if (mr == null) {
throw new InvalidMetadataException(
"No ManagedResource attribute found for class: " + getClassToExpose(managedBean));
}
applyCurrencyTimeLimit(desc, mr.getCurrencyTimeLimit());
if (mr.isLog()) {
desc.setField(FIELD_LOG, "true");
}
if (StringUtils.hasLength(mr.getLogFile())) {
desc.setField(FIELD_LOG_FILE, mr.getLogFile());
}
if (StringUtils.hasLength(mr.getPersistPolicy())) {
desc.setField(FIELD_PERSIST_POLICY, mr.getPersistPolicy());
}
if (mr.getPersistPeriod() >= 0) {
desc.setField(FIELD_PERSIST_PERIOD, Integer.toString(mr.getPersistPeriod()));
}
if (StringUtils.hasLength(mr.getPersistName())) {
desc.setField(FIELD_PERSIST_NAME, mr.getPersistName());
}
if (StringUtils.hasLength(mr.getPersistLocation())) {
desc.setField(FIELD_PERSIST_LOCATION, mr.getPersistLocation());
}
}
MetadataMBeanInfoAssembler.java 文件源码
项目:lams
阅读 18
收藏 0
点赞 0
评论 0
/**
* Adds descriptor fields from the {@code ManagedAttribute} attribute or the {@code ManagedMetric} attribute
* to the attribute descriptor.
*/
@Override
protected void populateAttributeDescriptor(Descriptor desc, Method getter, Method setter, String beanKey) {
if(getter != null && hasManagedMetric(getter)) {
populateMetricDescriptor(desc, this.attributeSource.getManagedMetric(getter));
}
else {
ManagedAttribute gma =
(getter == null) ? ManagedAttribute.EMPTY : this.attributeSource.getManagedAttribute(getter);
ManagedAttribute sma =
(setter == null) ? ManagedAttribute.EMPTY : this.attributeSource.getManagedAttribute(setter);
populateAttributeDescriptor(desc,gma,sma);
}
}
StandardMBeanIntrospector.java 文件源码
项目:OpenJSharp
阅读 23
收藏 0
点赞 0
评论 0
@Override
Descriptor getBasicMBeanDescriptor() {
/* We don't bother saying mxbean=false, and we can't know whether
the info is immutable until we know whether the MBean class
(not interface) is a NotificationBroadcaster. */
return ImmutableDescriptor.EMPTY_DESCRIPTOR;
}
ModelMBeanOperationInfo.java 文件源码
项目:openjdk-jdk10
阅读 21
收藏 0
点赞 0
评论 0
/**
* Returns a copy of the associated Descriptor of the
* ModelMBeanOperationInfo.
*
* @return Descriptor associated with the
* ModelMBeanOperationInfo object.
*
* @see #setDescriptor
*/
public Descriptor getDescriptor()
{
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
}
if (operationDescriptor == null) {
operationDescriptor = validDescriptor(null);
}
return((Descriptor) operationDescriptor.clone());
}
OpenMBeanAttributeInfoSupport.java 文件源码
项目:jdk8u-jdk
阅读 32
收藏 0
点赞 0
评论 0
static String toString(OpenMBeanParameterInfo info) {
Descriptor d = (info instanceof DescriptorRead) ?
((DescriptorRead) info).getDescriptor() : null;
return
info.getClass().getName() +
"(name=" + info.getName() +
",openType=" + info.getOpenType() +
",default=" + info.getDefaultValue() +
",minValue=" + info.getMinValue() +
",maxValue=" + info.getMaxValue() +
",legalValues=" + info.getLegalValues() +
((d == null) ? "" : ",descriptor=" + d) +
")";
}
ModelMBeanInfoSupport.java 文件源码
项目:openjdk-jdk10
阅读 19
收藏 0
点赞 0
评论 0
private Descriptor getMBeanDescriptorNoException() {
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
}
if (modelMBeanDescriptor == null)
modelMBeanDescriptor = validDescriptor(null);
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
MODELMBEAN_LOGGER.log(Level.TRACE,
"Exit, returning: " + modelMBeanDescriptor);
}
return (Descriptor) modelMBeanDescriptor.clone();
}
StandardMBeanIntrospector.java 文件源码
项目:openjdk-jdk10
阅读 35
收藏 0
点赞 0
评论 0
@Override
Descriptor getBasicMBeanDescriptor() {
/* We don't bother saying mxbean=false, and we can't know whether
the info is immutable until we know whether the MBean class
(not interface) is a NotificationBroadcaster. */
return ImmutableDescriptor.EMPTY_DESCRIPTOR;
}
ModelMBeanInfoSupport.java 文件源码
项目:openjdk-jdk10
阅读 21
收藏 0
点赞 0
评论 0
/**
* Constructs a ModelMBeanInfoSupport which is a duplicate of the given
* ModelMBeanInfo. The returned object is a shallow copy of the given
* object. Neither the Descriptor nor the contained arrays
* ({@code ModelMBeanAttributeInfo[]} etc) are cloned. This method is
* chiefly of interest to modify the Descriptor of the returned instance
* via {@link #setDescriptor setDescriptor} without affecting the
* Descriptor of the original object.
*
* @param mbi the ModelMBeanInfo instance from which the ModelMBeanInfo
* being created is initialized.
*/
public ModelMBeanInfoSupport(ModelMBeanInfo mbi) {
super(mbi.getClassName(),
mbi.getDescription(),
mbi.getAttributes(),
mbi.getConstructors(),
mbi.getOperations(),
mbi.getNotifications());
modelMBeanAttributes = mbi.getAttributes();
modelMBeanConstructors = mbi.getConstructors();
modelMBeanOperations = mbi.getOperations();
modelMBeanNotifications = mbi.getNotifications();
try {
Descriptor mbeandescriptor = mbi.getMBeanDescriptor();
modelMBeanDescriptor = validDescriptor(mbeandescriptor);
} catch (MBeanException mbe) {
modelMBeanDescriptor = validDescriptor(null);
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
MODELMBEAN_LOGGER.log(Level.TRACE,
"ModelMBeanInfo(ModelMBeanInfo) " +
"Could not get a valid modelMBeanDescriptor, " +
"setting a default Descriptor");
}
}
if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
}
}
AnnotationTest.java 文件源码
项目:openjdk-jdk10
阅读 30
收藏 0
点赞 0
评论 0
public static void main(String[] args) throws Exception {
System.out.println("Testing that annotations are correctly " +
"reflected in Descriptor entries");
MBeanServer mbs =
java.lang.management.ManagementFactory.getPlatformMBeanServer();
ObjectName on = new ObjectName("a:b=c");
Thing thing = new Thing();
mbs.registerMBean(thing, on);
check(mbs, on);
mbs.unregisterMBean(on);
ThingImpl thingImpl = new ThingImpl();
mbs.registerMBean(thingImpl, on);
Descriptor d = mbs.getMBeanInfo(on).getDescriptor();
if (!d.getFieldValue("mxbean").equals("true")) {
System.out.println("NOT OK: expected MXBean");
failed = "Expected MXBean";
}
check(mbs, on);
if (failed == null)
System.out.println("Test passed");
else
throw new Exception("TEST FAILED: " + failed);
}
ModelMBeanOperationInfo.java 文件源码
项目:OpenJSharp
阅读 19
收藏 0
点赞 0
评论 0
/**
* Returns a copy of the associated Descriptor of the
* ModelMBeanOperationInfo.
*
* @return Descriptor associated with the
* ModelMBeanOperationInfo object.
*
* @see #setDescriptor
*/
public Descriptor getDescriptor()
{
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
ModelMBeanOperationInfo.class.getName(),
"getDescriptor()", "Entry");
}
if (operationDescriptor == null) {
operationDescriptor = validDescriptor(null);
}
return((Descriptor) operationDescriptor.clone());
}
DcmdMBeanPermissionsTest.java 文件源码
项目:jdk8u-jdk
阅读 26
收藏 0
点赞 0
评论 0
static void testOperation(MBeanServer mbs, CustomSecurityManager sm,
ObjectName on, MBeanOperationInfo opInfo) {
System.out.println("Testing " + opInfo.getName());
Descriptor desc = opInfo.getDescriptor();
if (desc.getFieldValue("dcmd.permissionClass") == null) {
// No special permission required, execution should not trigger
// any security exception
if (invokeOperation(mbs, on, opInfo)) {
throw new RuntimeException("TEST FAILED");
}
} else {
// Building the required permission
Permission reqPerm = createPermission(
(String)desc.getFieldValue("dcmd.permissionClass"),
(String)desc.getFieldValue("dcmd.permissionName"),
(String)desc.getFieldValue("dcmd.permissionAction"));
// Paranoid mode: check that the SecurityManager has not already
// been granted the permission
sm.denyPermission(reqPerm);
// A special permission is required for this operation,
// invoking it without the permission granted must trigger
// a security exception
if(!invokeOperation(mbs, on, opInfo)) {
throw new RuntimeException("TEST FAILED");
}
// grant the permission and re-try invoking the operation
sm.grantPermission(reqPerm);
if(invokeOperation(mbs, on, opInfo)) {
throw new RuntimeException("TEST FAILED");
}
// Clean up
sm.denyPermission(reqPerm);
}
}