Refine search
ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(attrName, description, getter, setter); Descriptor desc = info.getDescriptor(); if (getter != null) { desc.setField(FIELD_GET_METHOD, getter.getName()); desc.setField(FIELD_SET_METHOD, setter.getName()); info.setDescriptor(desc); infos.add(info);
logger.debug("Attribute info is: " + attrInfo); if (!attrInfo.isWritable()) throw new AttributeNotFoundException( String.format("Attribute %s is not writable", attrName)); Descriptor attributeDescriptor = attrInfo.getDescriptor(); if (attributeDescriptor == null) throw new AttributeNotFoundException( String method = (String) attributeDescriptor.getFieldValue("setMethod"); if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("setMethod field is: " + method); if (method != null) { Class declared = loadClassWithContextClassLoader(attrInfo.getType()); if (attrValue != null) { Class parameter = attrValue.getClass(); attributeDescriptor.setField("value", attrValue); attributeDescriptor.setField(lastUpdateField, Long.valueOf(System.currentTimeMillis())); if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Attribute's value has been cached"); if (attrValue != null) { Class parameter = attrValue.getClass(); Class declared = loadClassWithContextClassLoader(attrInfo.getType());
if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Attribute info is: " + attrInfo); if (!attrInfo.isReadable()) throw new AttributeNotFoundException( String.format("Attribute %s is not readable", attribute)); Descriptor attributeDescriptor = attrInfo.getDescriptor(); if (attributeDescriptor == null) throw new AttributeNotFoundException( logger.trace("Value is stale"); String getter = (String) attributeDescriptor.getFieldValue("getMethod"); if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("getMethod field is: " + getter); if (getter == null) { returnValue = attributeDescriptor.getFieldValue("default"); Class declared = loadClassWithContextClassLoader(attrInfo.getType()); Class declared = loadClassWithContextClassLoader(attrInfo.getType()); attributeDescriptor.setField("value", returnValue); attributeDescriptor.setField(lastUpdateField, Long.valueOf(System.currentTimeMillis())); if (logger.isEnabledFor(Logger.TRACE)) Class declared = loadClassWithContextClassLoader(attrInfo.getType());
@Test public void testGetAgeIsReadOnly() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); ModelMBeanAttributeInfo attr = info.getAttribute(AGE_ATTRIBUTE); assertTrue(attr.isReadable()); assertFalse(attr.isWritable()); }
@Test public void testAttributeDescriptor() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); Descriptor desc = info.getAttribute(NAME_ATTRIBUTE).getDescriptor(); assertEquals("Default value should be foo", "foo", desc.getFieldValue("default")); assertEquals("Currency Time Limit should be 20", "20", desc.getFieldValue("currencyTimeLimit")); assertEquals("Persist Policy should be OnUpdate", "OnUpdate", desc.getFieldValue("persistPolicy")); assertEquals("Persist Period should be 300", "300", desc.getFieldValue("persistPeriod")); }
/** * Generates a setter signature string for a ModelMBean attribute by checking the * descriptor for setMethod. */ public static String setterSignature(ModelMBeanAttributeInfo info) { if (null == info) { throw new IllegalArgumentException("ModelMBeanAttributeInfo cannot be null"); } String methodName = (String) info.getDescriptor().getFieldValue("setMethod"); if (null == methodName) { throw new IllegalArgumentException("setMethod not defined in ModelMBeanAttributeInfo descriptor"); } return methodSignature(Void.TYPE.getName(), methodName, new String[]{info.getType()}); }
@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; } }
private void populateFullCheckpointTime(List<MBeanAttributeInfo> performanceAttributes) { final MBeanAttributeInfo fullCheckpointTime = new ModelMBeanAttributeInfo(FULL_CHECKPOINT_TIME, long.class.getName(), "Time which is spent on each full checkpoint", true, false, false); performanceAttributes.add(fullCheckpointTime); }
if (attributes[i].isReadable() && (attributes[i].getDescriptor().getFieldValue("getMethod") != null)) String role = (String) opinfo.getDescriptor().getFieldValue("role"); if ("getter".equals(role) || stripAllRoles) if (attributes[i].isWritable() && (attributes[i].getDescriptor().getFieldValue("setMethod") != null))
log.trace(" attr (#" + i + ") - " + attributeInfo); if (attributeInfo.isWritable()) { Descriptor attrDesc = attributeInfo.getDescriptor(); Object name = attrDesc.getFieldValue(ModelMBeanConstants.NAME); Object value = attrDesc.getFieldValue(ModelMBeanConstants.ATTRIBUTE_VALUE); Object updated = attrDesc.getFieldValue(ModelMBeanConstants.LAST_UPDATED_TIME_STAMP2); Object pPolicy = attrDesc.getFieldValue(ModelMBeanConstants.PERSIST_POLICY);
@Test public void testRegistrationOnInterface() throws Exception { Object bean = getContext().getBean("testInterfaceBean"); ModelMBeanInfo inf = getAssembler().getMBeanInfo(bean, "bean:name=interfaceTestBean"); assertNotNull(inf); assertEquals("My Managed Bean", inf.getDescription()); ModelMBeanOperationInfo op = inf.getOperation("foo"); assertNotNull("foo operation not exposed", op); assertEquals("invoke foo", op.getDescription()); assertNull("doNotExpose operation should not be exposed", inf.getOperation("doNotExpose")); ModelMBeanAttributeInfo attr = inf.getAttribute("Bar"); assertNotNull("bar attribute not exposed", attr); assertEquals("Bar description", attr.getDescription()); ModelMBeanAttributeInfo attr2 = inf.getAttribute("CacheEntries"); assertNotNull("cacheEntries attribute not exposed", attr2); assertEquals("Metric Type should be COUNTER", "COUNTER", attr2.getDescriptor().getFieldValue("metricType")); }
protected void doCollectAttributes(Class<?> clazz, BeanInfo beanInfo) { for (PropertyDescriptor propertyInfo : beanInfo.getPropertyDescriptors()) { if (propertyInfo.isHidden()) { continue; } ModelMBeanAttributeInfo attributeInfo = null; try { Descriptor descriptor = doGetDescriptor(propertyInfo, "attribute"); Method readMethod = propertyInfo.getReadMethod(); Method writeMethod = propertyInfo.getWriteMethod(); if (readMethod != null) { descriptor.setField("getMethod", readMethod.getName()); } if (writeMethod != null) { descriptor.setField("setMethod", writeMethod.getName()); } attributeInfo = new ModelMBeanAttributeInfo(propertyInfo.getName(), propertyInfo.getShortDescription(), propertyInfo.getReadMethod(), propertyInfo.getWriteMethod(), descriptor); } catch (IntrospectionException e) { continue; } attributesInfo.put(attributeInfo.getName(), attributeInfo); } }
javax.management.Descriptor descr = attribInfo.getDescriptor(); String value = descr.getFieldValue("default").toString(); String persistAttrValue = value; if ( isPassword(attribInfo.getName()) ) persistAttrValue = ksUtil.encrypt(value); updater.setAttribute("domain", mCategory, attribInfo.getName(), persistAttrValue);
protected void initAttributeContexts(MBeanAttributeInfo[] attributes) { super.initAttributeContexts(attributes); for (int i = 0; i < attributes.length; ++i) { ModelMBeanAttributeInfo info = (ModelMBeanAttributeInfo) attributes[i]; String name = info.getName(); InvocationContext ctx = (InvocationContext) attributeContextMap.get(name); ctx.setDescriptor(info.getDescriptor()); ctx.setReadable(info.isReadable()); ctx.setWritable(info.isWritable()); } }
String name=attrInfo.getName(); String uName=name.substring(0,1).toUpperCase()+name.substring(1); Class oClass=_object.getClass(); Class type=TypeUtil.fromName(attrInfo.getType()); if (type==null) type=Thread.currentThread().getContextClassLoader().loadClass(attrInfo.getType()); if (attrInfo.isReadable()) getter=oClass.getMethod((attrInfo.isIs()?"is":"get")+uName,(java.lang.Class[])null); if (attrInfo.isWritable()) setter=oClass.getMethod("set"+uName,new Class[] {type});
descrMap.put(modelAttrInfo.getName(), modelAttrInfo.getDescriptor());
protected JmxAttribute buildProperty(Class<?> managedClass, BeanProperty property) { MBeanProperty jmxAttribute = new MBeanProperty( property, getPropertyExportName(managedClass, property), getPropertyDescription(managedClass, property), getPropertyAccess(managedClass, property)); Descriptor desc = jmxAttribute.getMetadata().getDescriptor(); populatePropertyDescriptor(managedClass, property, desc); jmxAttribute.getMetadata().setDescriptor(desc); return jmxAttribute; }
Descriptor descr = attribInfo.getDescriptor(); String[] params = new String[]{attribInfo.getName()}; String errMsg = getTranslator().getString( LocalStringKeys.CS_ATTRIBUTE_DESCR_NULL, if ( !descr.isValid() ) String[] params = new String[]{attribInfo.getName()}; String errMsg = getTranslator().getString( LocalStringKeys.CS_ATTRIBUTE_DESCR_INVALID,
/** * Tests the situation where the attribute is only defined on the getter. */ @Test public void testReadOnlyAttribute() throws Exception { ModelMBeanInfo inf = getMBeanInfoFromAssembler(); ModelMBeanAttributeInfo attr = inf.getAttribute(AGE_ATTRIBUTE); assertFalse("The age attribute should not be writable", attr.isWritable()); }
public ModelMBeanAttributeInfo getAttribute(String name) { for (ModelMBeanAttributeInfo attribute : attributes) { if (attribute.getName().equals(name)) return attribute; } return null; }