use of javax.management.InstanceNotFoundException in project wildfly by wildfly.
the class LogStoreTransactionDeleteHandler method execute.
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
MBeanServer mbs = TransactionExtension.getMBeanServer(context);
final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
try {
final ObjectName on = LogStoreResource.getObjectName(resource);
// Invoke operation
Object res = mbs.invoke(on, "remove", null, null);
try {
// validate that the MBean was removed:
mbs.getObjectInstance(on);
String reason = res != null ? res.toString() : LOG_DELETE_FAILURE_MESSAGE;
throw new OperationFailedException(reason);
} catch (InstanceNotFoundException e) {
// success, the MBean was deleted
final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
final PathElement element = address.getLastElement();
logStoreResource.removeChild(element);
}
} catch (OperationFailedException e) {
throw e;
} catch (Exception e) {
throw new OperationFailedException(e.getMessage());
}
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method getClassLoader.
/**
* <p>Return the named {@link java.lang.ClassLoader}.
* @param loaderName The ObjectName of the ClassLoader.
* @return The named ClassLoader.
* @exception InstanceNotFoundException if the named ClassLoader
* is not found.
*/
public ClassLoader getClassLoader(ObjectName loaderName) throws InstanceNotFoundException {
if (loaderName == null) {
checkMBeanPermission((String) null, null, null, "getClassLoader");
return server.getClass().getClassLoader();
}
DynamicMBean instance = getMBean(loaderName);
checkMBeanPermission(instance, null, loaderName, "getClassLoader");
Object resource = getResource(instance);
/* Check if the given MBean is a ClassLoader */
if (!(resource instanceof ClassLoader))
throw new InstanceNotFoundException(loaderName.toString() + " is not a classloader");
return (ClassLoader) resource;
}
use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.
the class SnmpGenericObjectServer method set.
/**
* Set the value of an SNMP variable.
*
* <p><b><i>
* You should never need to use this method directly.
* </i></b></p>
*
* @param meta The impacted metadata object
* @param name The ObjectName of the impacted MBean
* @param x The new requested SnmpValue
* @param id The OID arc identifying the variable we're trying to set.
* @param data User contextual data allocated through the
* {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}
*
* @return The new value of the variable after the operation.
*
* @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.registerSetException(<i>VariableId</i>,<i>SnmpStatusException</i>)
* </code>
**/
public SnmpValue set(SnmpGenericMetaServer meta, ObjectName name, SnmpValue x, long id, Object data) throws SnmpStatusException {
final String attname = meta.getAttributeName(id);
final Object attvalue = meta.buildAttributeValue(id, x);
final Attribute att = new Attribute(attname, attvalue);
Object result = null;
try {
server.setAttribute(name, att);
result = server.getAttribute(name, attname);
} catch (InvalidAttributeValueException iv) {
throw new SnmpStatusException(SnmpStatusException.snmpRspWrongValue);
} catch (InstanceNotFoundException f) {
throw new SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
} catch (ReflectionException r) {
throw new SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
} catch (MBeanException m) {
Exception t = m.getTargetException();
if (t instanceof SnmpStatusException)
throw (SnmpStatusException) t;
throw new SnmpStatusException(SnmpStatusException.noAccess);
} catch (Exception e) {
throw new SnmpStatusException(SnmpStatusException.noAccess);
}
return meta.buildSnmpValue(id, result);
}
use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.
the class SnmpGenericObjectServer method check.
/**
* Checks whether a SET operation can be performed on a given SNMP
* variable.
*
* @param meta The impacted metadata object
* @param name The ObjectName of the impacted MBean
* @param x The new requested SnmpValue
* @param id The OID arc identifying the variable we're trying to set.
* @param data User contextual data allocated through the
* {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}
*
* <p>
* This method calls checkSetAccess() on the meta object, and then
* tries to invoke the check<i>AttributeName</i>() method on the MBean.
* If this method is not defined then it is assumed that the SET
* won't fail.
* </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>
*
* @exception SnmpStatusException if the requested SET operation must
* be rejected. Raising an exception will abort the request. <br>
* Exceptions should never be raised directly, but only by means of
* <code>
* req.registerCheckException(<i>VariableId</i>,<i>SnmpStatusException</i>)
* </code>
*
**/
// XXX xxx ZZZ zzz Maybe we should go through the MBeanInfo here?
public void check(SnmpGenericMetaServer meta, ObjectName name, SnmpValue x, long id, Object data) throws SnmpStatusException {
meta.checkSetAccess(x, id, data);
try {
final String attname = meta.getAttributeName(id);
final Object attvalue = meta.buildAttributeValue(id, x);
final Object[] params = new Object[1];
final String[] signature = new String[1];
params[0] = attvalue;
signature[0] = attvalue.getClass().getName();
server.invoke(name, "check" + attname, params, signature);
} catch (SnmpStatusException e) {
throw e;
} catch (InstanceNotFoundException i) {
throw new SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
} catch (ReflectionException r) {
// checkXXXX() not defined => do nothing
} catch (MBeanException m) {
Exception t = m.getTargetException();
if (t instanceof SnmpStatusException)
throw (SnmpStatusException) t;
throw new SnmpStatusException(SnmpStatusException.noAccess);
} catch (Exception e) {
throw new SnmpStatusException(SnmpStatusException.noAccess);
}
}
use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.
the class SnmpMibAgent method setSnmpAdaptorName.
/**
* Sets the reference to the SNMP protocol adaptor through which the MIB
* will be SNMP accessible and add this new MIB in the SNMP MIB handler
* associated to the specified <CODE>name</CODE>.
*
* @param name The name of the SNMP protocol adaptor.
*
* @exception InstanceNotFoundException The SNMP protocol adaptor does
* not exist in the MBean server.
*
* @exception ServiceNotFoundException This SNMP MIB is not registered
* in the MBean server or the requested service is not supported.
*/
@Override
public void setSnmpAdaptorName(ObjectName name) throws InstanceNotFoundException, ServiceNotFoundException {
if (server == null) {
throw new ServiceNotFoundException(mibName + " is not registered in the MBean server");
}
//
if (adaptor != null) {
adaptor.removeMib(this);
}
// Then update the reference to the new adaptor server.
//
Object[] params = { this };
String[] signature = { "com.sun.jmx.snmp.agent.SnmpMibAgent" };
try {
adaptor = (SnmpMibHandler) (server.invoke(name, "addMib", params, signature));
} catch (InstanceNotFoundException e) {
throw new InstanceNotFoundException(name.toString());
} catch (ReflectionException e) {
throw new ServiceNotFoundException(name.toString());
} catch (MBeanException e) {
// Should never occur...
}
adaptorName = name;
}
Aggregations