use of javax.management.AttributeList in project jdk8u_jdk by JetBrains.
the class MBeanServerDelegateImpl method getAttributes.
/**
* Makes it possible to get the values of several attributes of
* the MBeanServerDelegate.
*
* @param attributes A list of the attributes to be retrieved.
*
* @return The list of attributes retrieved.
*
*/
public AttributeList getAttributes(String[] attributes) {
// If attributes is null, the get all attributes.
//
final String[] attn = (attributes == null ? attributeNames : attributes);
// Prepare the result list.
//
final int len = attn.length;
final AttributeList list = new AttributeList(len);
//
for (int i = 0; i < len; i++) {
try {
final Attribute a = new Attribute(attn[i], getAttribute(attn[i]));
list.add(a);
} catch (Exception x) {
//
if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) {
MBEANSERVER_LOGGER.logp(Level.FINEST, MBeanServerDelegateImpl.class.getName(), "getAttributes", "Attribute " + attn[i] + " not found");
}
}
}
//
return list;
}
use of javax.management.AttributeList in project jdk8u_jdk by JetBrains.
the class SnmpGenericObjectServer method get.
/**
* Execute an SNMP GET request.
*
* <p>
* This method first builds the list of attributes that need to be
* retrieved from the MBean and then calls getAttributes() on the
* MBean server. Then it updates the SnmpMibSubRequest with the values
* retrieved from the MBean.
* </p>
*
* <p>
* The SNMP metadata information is obtained through the given
* <code>meta</code> object, which usually is an instance of a
* <code>mibgen</code> generated class.
* </p>
*
* <p><b><i>
* This method is called internally by <code>mibgen</code> generated
* objects and you should never need to call it directly.
* </i></b></p>
*
* @param meta The metadata object impacted by the subrequest
* @param name The ObjectName of the MBean impacted by this subrequest
* @param req The SNMP subrequest to execute on the MBean
* @param depth The depth of the SNMP object in the OID tree.
*
* @exception SnmpStatusException whenever an SNMP exception must be
* raised. Raising an exception will abort the request.<br>
* Exceptions should never be raised directly, but only by means of
* <code>
* req.registerGetException(<i>VariableId</i>,<i>SnmpStatusException</i>)
* </code>
**/
public void get(SnmpGenericMetaServer meta, ObjectName name, SnmpMibSubRequest req, int depth) throws SnmpStatusException {
// java.lang.System.out.println(">>>>>>>>> GET " + name);
final int size = req.getSize();
final Object data = req.getUserData();
final String[] nameList = new String[size];
final SnmpVarBind[] varList = new SnmpVarBind[size];
final long[] idList = new long[size];
int i = 0;
for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); ) {
final SnmpVarBind var = e.nextElement();
try {
final long id = var.oid.getOidArc(depth);
nameList[i] = meta.getAttributeName(id);
varList[i] = var;
idList[i] = id;
// Check the access rights according to the MIB.
// The MBean might be less restrictive (have a getter
// while the MIB defines the variable as AFN)
//
meta.checkGetAccess(id, data);
//java.lang.System.out.println(nameList[i] + " added.");
i++;
} catch (SnmpStatusException x) {
//java.lang.System.out.println("exception for " + nameList[i]);
//x.printStackTrace();
req.registerGetException(var, x);
}
}
AttributeList result = null;
int errorCode = SnmpStatusException.noSuchInstance;
try {
result = server.getAttributes(name, nameList);
} catch (InstanceNotFoundException f) {
//java.lang.System.out.println(name + ": instance not found.");
//f.printStackTrace();
result = new AttributeList();
} catch (ReflectionException r) {
//java.lang.System.out.println(name + ": reflexion error.");
//r.printStackTrace();
result = new AttributeList();
} catch (Exception x) {
result = new AttributeList();
}
final Iterator<?> it = result.iterator();
for (int j = 0; j < i; j++) {
if (!it.hasNext()) {
//java.lang.System.out.println(name + "variable[" + j +
// "] absent");
final SnmpStatusException x = new SnmpStatusException(errorCode);
req.registerGetException(varList[j], x);
continue;
}
final Attribute att = (Attribute) it.next();
while ((j < i) && (!nameList[j].equals(att.getName()))) {
//java.lang.System.out.println(name + "variable[" +j +
// "] not found");
final SnmpStatusException x = new SnmpStatusException(errorCode);
req.registerGetException(varList[j], x);
j++;
}
if (j == i)
break;
try {
varList[j].value = meta.buildSnmpValue(idList[j], att.getValue());
} catch (SnmpStatusException x) {
req.registerGetException(varList[j], x);
}
//java.lang.System.out.println(att.getName() + " retrieved.");
}
//java.lang.System.out.println(">>>>>>>>> END GET");
}
use of javax.management.AttributeList in project jdk8u_jdk by JetBrains.
the class SnmpGenericObjectServer method set.
/**
* Execute an SNMP SET request.
*
* <p>
* This method first builds the list of attributes that need to be
* set on the MBean and then calls setAttributes() on the
* MBean server. Then it updates the SnmpMibSubRequest with the new
* values retrieved from the MBean.
* </p>
*
* <p>
* The SNMP metadata information is obtained through the given
* <code>meta</code> object, which usually is an instance of a
* <code>mibgen</code> generated class.
* </p>
*
* <p><b><i>
* This method is called internally by <code>mibgen</code> generated
* objects and you should never need to call it directly.
* </i></b></p>
*
* @param meta The metadata object impacted by the subrequest
* @param name The ObjectName of the MBean impacted by this subrequest
* @param req The SNMP subrequest to execute on the MBean
* @param depth The depth of the SNMP object in the OID tree.
*
* @exception SnmpStatusException whenever an SNMP exception must be
* raised. Raising an exception will abort the request. <br>
* Exceptions should never be raised directly, but only by means of
* <code>
* req.registerGetException(<i>VariableId</i>,<i>SnmpStatusException</i>)
* </code>
**/
public void set(SnmpGenericMetaServer meta, ObjectName name, SnmpMibSubRequest req, int depth) throws SnmpStatusException {
final int size = req.getSize();
final AttributeList attList = new AttributeList(size);
final String[] nameList = new String[size];
final SnmpVarBind[] varList = new SnmpVarBind[size];
final long[] idList = new long[size];
int i = 0;
for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); ) {
final SnmpVarBind var = e.nextElement();
try {
final long id = var.oid.getOidArc(depth);
final String attname = meta.getAttributeName(id);
final Object attvalue = meta.buildAttributeValue(id, var.value);
final Attribute att = new Attribute(attname, attvalue);
attList.add(att);
nameList[i] = attname;
varList[i] = var;
idList[i] = id;
i++;
} catch (SnmpStatusException x) {
req.registerSetException(var, x);
}
}
AttributeList result;
int errorCode = SnmpStatusException.noAccess;
try {
result = server.setAttributes(name, attList);
} catch (InstanceNotFoundException f) {
result = new AttributeList();
errorCode = SnmpStatusException.snmpRspInconsistentName;
} catch (ReflectionException r) {
errorCode = SnmpStatusException.snmpRspInconsistentName;
result = new AttributeList();
} catch (Exception x) {
result = new AttributeList();
}
final Iterator<?> it = result.iterator();
for (int j = 0; j < i; j++) {
if (!it.hasNext()) {
final SnmpStatusException x = new SnmpStatusException(errorCode);
req.registerSetException(varList[j], x);
continue;
}
final Attribute att = (Attribute) it.next();
while ((j < i) && (!nameList[j].equals(att.getName()))) {
final SnmpStatusException x = new SnmpStatusException(SnmpStatusException.noAccess);
req.registerSetException(varList[j], x);
j++;
}
if (j == i)
break;
try {
varList[j].value = meta.buildSnmpValue(idList[j], att.getValue());
} catch (SnmpStatusException x) {
req.registerSetException(varList[j], x);
}
}
}
use of javax.management.AttributeList in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method setAttributes.
public AttributeList setAttributes(ObjectName name, AttributeList attributes) throws InstanceNotFoundException, ReflectionException {
if (name == null) {
throw new RuntimeOperationsException(new IllegalArgumentException("ObjectName name cannot be null"), "Exception occurred trying to invoke the setter on the MBean");
}
if (attributes == null) {
throw new RuntimeOperationsException(new IllegalArgumentException("AttributeList cannot be null"), "Exception occurred trying to invoke the setter on the MBean");
}
name = nonDefaultDomain(name);
final DynamicMBean instance = getMBean(name);
final AttributeList allowedAttributes;
final SecurityManager sm = System.getSecurityManager();
if (sm == null)
allowedAttributes = attributes;
else {
String classname = getClassName(instance);
// Check if the caller has the right to invoke 'setAttribute'
//
checkMBeanPermission(classname, null, name, "setAttribute");
// Check if the caller has the right to invoke 'setAttribute'
// on each specific attribute
//
allowedAttributes = new AttributeList(attributes.size());
for (Attribute attribute : attributes.asList()) {
try {
checkMBeanPermission(classname, attribute.getName(), name, "setAttribute");
allowedAttributes.add(attribute);
} catch (SecurityException e) {
// OK: Do not add this attribute to the list
}
}
}
try {
return instance.setAttributes(allowedAttributes);
} catch (Throwable t) {
rethrow(t);
throw new AssertionError();
}
}
use of javax.management.AttributeList in project jdk8u_jdk by JetBrains.
the class RequiredModelMBean method setAttributes.
/**
* Sets the values of an array of attributes of this ModelMBean.
* Executes the setAttribute() method for each attribute in the list.
*
* @param attributes A list of attributes: The identification of the
* attributes to be set and the values they are to be set to.
*
* @return The array of attributes that were set, with their new
* values in Attribute instances.
*
* @exception RuntimeOperationsException Wraps an
* {@link IllegalArgumentException}: The object name in parameter
* is null or attributes in parameter is null.
*
* @see #getAttributes
**/
public AttributeList setAttributes(AttributeList attributes) {
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), "setAttribute(Attribute)", "Entry");
}
if (attributes == null)
throw new RuntimeOperationsException(new IllegalArgumentException("attributes must not be null"), "Exception occurred trying to set attributes of a " + "RequiredModelMBean");
final AttributeList responseList = new AttributeList();
// Go through the list of attributes
for (Attribute attr : attributes.asList()) {
try {
setAttribute(attr);
responseList.add(attr);
} catch (Exception excep) {
responseList.remove(attr);
}
}
return responseList;
}
Aggregations