下面列出了javax.management.Attribute#getValue ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Send an <code>AttributeChangeNotification</code> to all registered
* listeners.
*
* @param oldValue The original value of the <code>Attribute</code>
* @param newValue The new value of the <code>Attribute</code>
*
* @exception MBeanException if an object initializer throws an
* exception
* @exception RuntimeOperationsException wraps IllegalArgumentException
* when the specified notification is <code>null</code> or invalid
*/
@Override
public void sendAttributeChangeNotification
(Attribute oldValue, Attribute newValue)
throws MBeanException, RuntimeOperationsException {
// Calculate the class name for the change notification
String type = null;
if (newValue.getValue() != null)
type = newValue.getValue().getClass().getName();
else if (oldValue.getValue() != null)
type = oldValue.getValue().getClass().getName();
else
return; // Old and new are both null == no change
AttributeChangeNotification notification =
new AttributeChangeNotification
(this, 1, System.currentTimeMillis(),
"Attribute value has changed",
oldValue.getName(), type,
oldValue.getValue(), newValue.getValue());
sendAttributeChangeNotification(notification);
}
/**
* Set the value of a specific attribute of this MBean.
*
* @param attribute The identification of the attribute to be set
* and the new value
*
* @exception AttributeNotFoundException if this attribute is not
* supported by this MBean
* @exception MBeanException if the initializer of an object
* throws an exception
* @exception ReflectionException if a Java reflection exception
* occurs when invoking the getter
*/
@Override
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException,
ReflectionException {
// Validate the input parameters
if (attribute == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute is null"),
"Attribute is null");
}
String name = attribute.getName();
Object value = attribute.getValue();
if (name == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute name is null"),
"Attribute name is null");
}
ContextResourceLink crl = doGetManagedResource();
if ("global".equals(name)) {
crl.setGlobal((String) value);
} else if ("description".equals(name)) {
crl.setDescription((String) value);
} else if ("name".equals(name)) {
crl.setName((String) value);
} else if ("type".equals(name)) {
crl.setType((String) value);
} else {
crl.setProperty(name, "" + value);
}
// cannot use side-effects. It's removed and added back each time
// there is a modification in a resource.
NamingResources nr = crl.getNamingResources();
nr.removeResourceLink(crl.getName());
nr.addResourceLink(crl);
}
/**
* Clone attribute.
*/
private Attribute cloneAttribute(Attribute attribute) {
if (attribute != null) {
if (!attribute.getClass().equals(Attribute.class)) {
return new Attribute(attribute.getName(), attribute.getValue());
}
}
return attribute;
}
public final void setAttribute(Attribute attribute)
throws AttributeNotFoundException,
InvalidAttributeValueException,
MBeanException,
ReflectionException {
final String name = attribute.getName();
final Object value = attribute.getValue();
perInterface.setAttribute(resource, name, value, getCookie());
}
public final void setAttribute(Attribute attribute)
throws AttributeNotFoundException,
InvalidAttributeValueException,
MBeanException,
ReflectionException {
final String name = attribute.getName();
final Object value = attribute.getValue();
perInterface.setAttribute(resource, name, value, getCookie());
}
public final void setAttribute(Attribute attribute)
throws AttributeNotFoundException,
InvalidAttributeValueException,
MBeanException,
ReflectionException {
final String name = attribute.getName();
final Object value = attribute.getValue();
perInterface.setAttribute(resource, name, value, getCookie());
}
/**
* Clone attribute.
*/
private Attribute cloneAttribute(Attribute attribute) {
if (attribute != null) {
if (!attribute.getClass().equals(Attribute.class)) {
return new Attribute(attribute.getName(), attribute.getValue());
}
}
return attribute;
}
/**
* Clone attribute.
*/
private Attribute cloneAttribute(Attribute attribute) {
if (attribute != null) {
if (!attribute.getClass().equals(Attribute.class)) {
return new Attribute(attribute.getName(), attribute.getValue());
}
}
return attribute;
}
public final void setAttribute(Attribute attribute)
throws AttributeNotFoundException,
InvalidAttributeValueException,
MBeanException,
ReflectionException {
final String name = attribute.getName();
final Object value = attribute.getValue();
perInterface.setAttribute(resource, name, value, getCookie());
}
/**
* Clone attribute.
*/
private Attribute cloneAttribute(Attribute attribute) {
if (attribute != null) {
if (!attribute.getClass().equals(Attribute.class)) {
return new Attribute(attribute.getName(), attribute.getValue());
}
}
return attribute;
}
public final void setAttribute(Attribute attribute)
throws AttributeNotFoundException,
InvalidAttributeValueException,
MBeanException,
ReflectionException {
final String name = attribute.getName();
final Object value = attribute.getValue();
perInterface.setAttribute(resource, name, value, getCookie());
}
public void sendAttributeChangeNotification(Attribute inOldVal,
Attribute inNewVal)
throws MBeanException, RuntimeOperationsException {
final String mth =
"sendAttributeChangeNotification(Attribute, Attribute)";
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
RequiredModelMBean.class.getName(),mth,
"Entry");
}
// do we really want to do this?
if ((inOldVal == null) || (inNewVal == null))
throw new RuntimeOperationsException(new
IllegalArgumentException("Attribute object must not be null"),
"Exception occurred trying to send " +
"attribute change notification of a ModelMBean");
if (!(inOldVal.getName().equals(inNewVal.getName())))
throw new RuntimeOperationsException(new
IllegalArgumentException("Attribute names are not the same"),
"Exception occurred trying to send " +
"attribute change notification of a ModelMBean");
Object newVal = inNewVal.getValue();
Object oldVal = inOldVal.getValue();
String className = "unknown";
if (newVal != null)
className = newVal.getClass().getName();
if (oldVal != null)
className = oldVal.getClass().getName();
AttributeChangeNotification myNtfyObj = new
AttributeChangeNotification(this,
1,
((new Date()).getTime()),
"AttributeChangeDetected",
inOldVal.getName(),
className,
inOldVal.getValue(),
inNewVal.getValue());
sendAttributeChangeNotification(myNtfyObj);
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
RequiredModelMBean.class.getName(),mth,
"Exit");
}
}
/**
* Set the value of a specific attribute of this MBean.
*
* @param attribute The identification of the attribute to be set
* and the new value
*
* @exception AttributeNotFoundException if this attribute is not
* supported by this MBean
* @exception MBeanException if the initializer of an object
* throws an exception
* @exception ReflectionException if a Java reflection exception
* occurs when invoking the getter
*/
@Override
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException,
ReflectionException {
// Validate the input parameters
if (attribute == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute is null"),
"Attribute is null");
}
String name = attribute.getName();
Object value = attribute.getValue();
if (name == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute name is null"),
"Attribute name is null");
}
ContextResource cr = doGetManagedResource();
if ("auth".equals(name)) {
cr.setAuth((String)value);
} else if ("description".equals(name)) {
cr.setDescription((String)value);
} else if ("name".equals(name)) {
cr.setName((String)value);
} else if ("scope".equals(name)) {
cr.setScope((String)value);
} else if ("type".equals(name)) {
cr.setType((String)value);
} else {
cr.setProperty(name, "" + value);
}
// cannot use side-effects. It's removed and added back each time
// there is a modification in a resource.
NamingResources nr = cr.getNamingResources();
nr.removeResource(cr.getName());
nr.addResource(cr);
}
public void sendAttributeChangeNotification(Attribute inOldVal,
Attribute inNewVal)
throws MBeanException, RuntimeOperationsException {
final String mth =
"sendAttributeChangeNotification(Attribute, Attribute)";
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
RequiredModelMBean.class.getName(),mth,
"Entry");
}
// do we really want to do this?
if ((inOldVal == null) || (inNewVal == null))
throw new RuntimeOperationsException(new
IllegalArgumentException("Attribute object must not be null"),
"Exception occurred trying to send " +
"attribute change notification of a ModelMBean");
if (!(inOldVal.getName().equals(inNewVal.getName())))
throw new RuntimeOperationsException(new
IllegalArgumentException("Attribute names are not the same"),
"Exception occurred trying to send " +
"attribute change notification of a ModelMBean");
Object newVal = inNewVal.getValue();
Object oldVal = inOldVal.getValue();
String className = "unknown";
if (newVal != null)
className = newVal.getClass().getName();
if (oldVal != null)
className = oldVal.getClass().getName();
AttributeChangeNotification myNtfyObj = new
AttributeChangeNotification(this,
1,
((new Date()).getTime()),
"AttributeChangeDetected",
inOldVal.getName(),
className,
inOldVal.getValue(),
inNewVal.getValue());
sendAttributeChangeNotification(myNtfyObj);
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
RequiredModelMBean.class.getName(),mth,
"Exit");
}
}
private boolean isViewable(Attribute attribute) {
Object data = attribute.getValue();
return XDataViewer.isViewableValue(data);
}
private boolean isViewable(Attribute attribute) {
Object data = attribute.getValue();
return XDataViewer.isViewableValue(data);
}
private boolean isViewable(Attribute attribute) {
Object data = attribute.getValue();
return XDataViewer.isViewableValue(data);
}
public void sendAttributeChangeNotification(Attribute inOldVal,
Attribute inNewVal)
throws MBeanException, RuntimeOperationsException {
final String mth =
"sendAttributeChangeNotification(Attribute, Attribute)";
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
RequiredModelMBean.class.getName(),mth,
"Entry");
}
// do we really want to do this?
if ((inOldVal == null) || (inNewVal == null))
throw new RuntimeOperationsException(new
IllegalArgumentException("Attribute object must not be null"),
"Exception occurred trying to send " +
"attribute change notification of a ModelMBean");
if (!(inOldVal.getName().equals(inNewVal.getName())))
throw new RuntimeOperationsException(new
IllegalArgumentException("Attribute names are not the same"),
"Exception occurred trying to send " +
"attribute change notification of a ModelMBean");
Object newVal = inNewVal.getValue();
Object oldVal = inOldVal.getValue();
String className = "unknown";
if (newVal != null)
className = newVal.getClass().getName();
if (oldVal != null)
className = oldVal.getClass().getName();
AttributeChangeNotification myNtfyObj = new
AttributeChangeNotification(this,
1,
((new Date()).getTime()),
"AttributeChangeDetected",
inOldVal.getName(),
className,
inOldVal.getValue(),
inNewVal.getValue());
sendAttributeChangeNotification(myNtfyObj);
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
RequiredModelMBean.class.getName(),mth,
"Exit");
}
}
public void sendAttributeChangeNotification(Attribute inOldVal,
Attribute inNewVal)
throws MBeanException, RuntimeOperationsException {
final String mth =
"sendAttributeChangeNotification(Attribute, Attribute)";
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
RequiredModelMBean.class.getName(),mth,
"Entry");
}
// do we really want to do this?
if ((inOldVal == null) || (inNewVal == null))
throw new RuntimeOperationsException(new
IllegalArgumentException("Attribute object must not be null"),
"Exception occurred trying to send " +
"attribute change notification of a ModelMBean");
if (!(inOldVal.getName().equals(inNewVal.getName())))
throw new RuntimeOperationsException(new
IllegalArgumentException("Attribute names are not the same"),
"Exception occurred trying to send " +
"attribute change notification of a ModelMBean");
Object newVal = inNewVal.getValue();
Object oldVal = inOldVal.getValue();
String className = "unknown";
if (newVal != null)
className = newVal.getClass().getName();
if (oldVal != null)
className = oldVal.getClass().getName();
AttributeChangeNotification myNtfyObj = new
AttributeChangeNotification(this,
1,
((new Date()).getTime()),
"AttributeChangeDetected",
inOldVal.getName(),
className,
inOldVal.getValue(),
inNewVal.getValue());
sendAttributeChangeNotification(myNtfyObj);
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
RequiredModelMBean.class.getName(),mth,
"Exit");
}
}
public void sendAttributeChangeNotification(Attribute inOldVal,
Attribute inNewVal)
throws MBeanException, RuntimeOperationsException {
final String mth =
"sendAttributeChangeNotification(Attribute, Attribute)";
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
RequiredModelMBean.class.getName(),mth,
"Entry");
}
// do we really want to do this?
if ((inOldVal == null) || (inNewVal == null))
throw new RuntimeOperationsException(new
IllegalArgumentException("Attribute object must not be null"),
"Exception occurred trying to send " +
"attribute change notification of a ModelMBean");
if (!(inOldVal.getName().equals(inNewVal.getName())))
throw new RuntimeOperationsException(new
IllegalArgumentException("Attribute names are not the same"),
"Exception occurred trying to send " +
"attribute change notification of a ModelMBean");
Object newVal = inNewVal.getValue();
Object oldVal = inOldVal.getValue();
String className = "unknown";
if (newVal != null)
className = newVal.getClass().getName();
if (oldVal != null)
className = oldVal.getClass().getName();
AttributeChangeNotification myNtfyObj = new
AttributeChangeNotification(this,
1,
((new Date()).getTime()),
"AttributeChangeDetected",
inOldVal.getName(),
className,
inOldVal.getValue(),
inNewVal.getValue());
sendAttributeChangeNotification(myNtfyObj);
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
RequiredModelMBean.class.getName(),mth,
"Exit");
}
}