use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.
the class RelationService method checkRoleInt.
// Checks that given role conforms to given role info.
//
// -param chkType type of check:
// - 1: read, just check read access
// - 2: write, check value and write access if writeChkFlag
// -param roleName role name
// -param roleValue role value
// -param roleInfo corresponding role info
// -param writeChkFlag boolean to specify a current write access and
// to check it
//
// -return Integer with value:
// - 0: ok
// - RoleStatus.NO_ROLE_WITH_NAME
// - RoleStatus.ROLE_NOT_READABLE
// - RoleStatus.ROLE_NOT_WRITABLE
// - RoleStatus.LESS_THAN_MIN_ROLE_DEGREE
// - RoleStatus.MORE_THAN_MAX_ROLE_DEGREE
// - RoleStatus.REF_MBEAN_OF_INCORRECT_CLASS
// - RoleStatus.REF_MBEAN_NOT_REGISTERED
//
// -exception IllegalArgumentException if null parameter
private Integer checkRoleInt(int chkType, String roleName, List<ObjectName> roleValue, RoleInfo roleInfo, boolean writeChkFlag) throws IllegalArgumentException {
if (roleName == null || roleInfo == null || (chkType == 2 && roleValue == null)) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(), "checkRoleInt", new Object[] { chkType, roleName, roleValue, roleInfo, writeChkFlag });
// Compares names
String expName = roleInfo.getName();
if (!(roleName.equals(expName))) {
RELATION_LOGGER.exiting(RelationService.class.getName(), "checkRoleInt");
return Integer.valueOf(RoleStatus.NO_ROLE_WITH_NAME);
}
// Checks read access if required
if (chkType == 1) {
boolean isReadable = roleInfo.isReadable();
if (!isReadable) {
RELATION_LOGGER.exiting(RelationService.class.getName(), "checkRoleInt");
return Integer.valueOf(RoleStatus.ROLE_NOT_READABLE);
} else {
// End of check :)
RELATION_LOGGER.exiting(RelationService.class.getName(), "checkRoleInt");
return new Integer(0);
}
}
// Checks write access if required
if (writeChkFlag) {
boolean isWritable = roleInfo.isWritable();
if (!isWritable) {
RELATION_LOGGER.exiting(RelationService.class.getName(), "checkRoleInt");
return new Integer(RoleStatus.ROLE_NOT_WRITABLE);
}
}
int refNbr = roleValue.size();
// Checks minimum cardinality
boolean chkMinFlag = roleInfo.checkMinDegree(refNbr);
if (!chkMinFlag) {
RELATION_LOGGER.exiting(RelationService.class.getName(), "checkRoleInt");
return new Integer(RoleStatus.LESS_THAN_MIN_ROLE_DEGREE);
}
// Checks maximum cardinality
boolean chkMaxFlag = roleInfo.checkMaxDegree(refNbr);
if (!chkMaxFlag) {
RELATION_LOGGER.exiting(RelationService.class.getName(), "checkRoleInt");
return new Integer(RoleStatus.MORE_THAN_MAX_ROLE_DEGREE);
}
// Verifies that each referenced MBean is registered in the MBean
// Server and that it is an instance of the class specified in the
// role info, or of a subclass of it
// Note that here again this is under the assumption that
// referenced MBeans, relation MBeans and the Relation Service are
// registered in the same MBean Server.
String expClassName = roleInfo.getRefMBeanClassName();
for (ObjectName currObjName : roleValue) {
// Checks it is registered
if (currObjName == null) {
RELATION_LOGGER.exiting(RelationService.class.getName(), "checkRoleInt");
return new Integer(RoleStatus.REF_MBEAN_NOT_REGISTERED);
}
// Can throw an InstanceNotFoundException, if MBean not registered
try {
boolean classSts = myMBeanServer.isInstanceOf(currObjName, expClassName);
if (!classSts) {
RELATION_LOGGER.exiting(RelationService.class.getName(), "checkRoleInt");
return new Integer(RoleStatus.REF_MBEAN_OF_INCORRECT_CLASS);
}
} catch (InstanceNotFoundException exc) {
RELATION_LOGGER.exiting(RelationService.class.getName(), "checkRoleInt");
return new Integer(RoleStatus.REF_MBEAN_NOT_REGISTERED);
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(), "checkRoleInt");
return new Integer(0);
}
use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method isInstanceOf.
public boolean isInstanceOf(ObjectName name, String className) throws InstanceNotFoundException {
final DynamicMBean instance = getMBean(name);
checkMBeanPermission(instance, null, name, "isInstanceOf");
try {
Object resource = getResource(instance);
final String resourceClassName = (resource instanceof DynamicMBean) ? getClassName((DynamicMBean) resource) : resource.getClass().getName();
if (resourceClassName.equals(className))
return true;
final ClassLoader cl = resource.getClass().getClassLoader();
final Class<?> classNameClass = Class.forName(className, false, cl);
if (classNameClass.isInstance(resource))
return true;
final Class<?> resourceClass = Class.forName(resourceClassName, false, cl);
return classNameClass.isAssignableFrom(resourceClass);
} catch (Exception x) {
/* Could be SecurityException or ClassNotFoundException */
if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) {
MBEANSERVER_LOGGER.logp(Level.FINEST, DefaultMBeanServerInterceptor.class.getName(), "isInstanceOf", "Exception calling isInstanceOf", x);
}
return false;
}
}
use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method getListener.
private NotificationListener getListener(ObjectName listener) throws ListenerNotFoundException {
// ----------------
// Get listener object
// ----------------
DynamicMBean instance;
try {
instance = getMBean(listener);
} catch (InstanceNotFoundException e) {
throw EnvHelp.initCause(new ListenerNotFoundException(e.getMessage()), e);
}
Object resource = getResource(instance);
if (!(resource instanceof NotificationListener)) {
final RuntimeException exc = new IllegalArgumentException(listener.getCanonicalName());
final String msg = "MBean " + listener.getCanonicalName() + " does not " + "implement " + NotificationListener.class.getName();
throw new RuntimeOperationsException(exc, msg);
}
return (NotificationListener) resource;
}
use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.
the class ManagementFactory method newPlatformMXBeanProxy.
/**
* Returns a proxy for a platform MXBean interface of a
* given <a href="#MXBeanNames">MXBean name</a>
* that forwards its method calls through the given
* <tt>MBeanServerConnection</tt>.
*
* <p>This method is equivalent to:
* <blockquote>
* {@link java.lang.reflect.Proxy#newProxyInstance
* Proxy.newProxyInstance}<tt>(mxbeanInterface.getClassLoader(),
* new Class[] { mxbeanInterface }, handler)</tt>
* </blockquote>
*
* where <tt>handler</tt> is an {@link java.lang.reflect.InvocationHandler
* InvocationHandler} to which method invocations to the MXBean interface
* are dispatched. This <tt>handler</tt> converts an input parameter
* from an MXBean data type to its mapped open type before forwarding
* to the <tt>MBeanServer</tt> and converts a return value from
* an MXBean method call through the <tt>MBeanServer</tt>
* from an open type to the corresponding return type declared in
* the MXBean interface.
*
* <p>
* If the MXBean is a notification emitter (i.e.,
* it implements
* {@link javax.management.NotificationEmitter NotificationEmitter}),
* both the <tt>mxbeanInterface</tt> and <tt>NotificationEmitter</tt>
* will be implemented by this proxy.
*
* <p>
* <b>Notes:</b>
* <ol>
* <li>Using an MXBean proxy is a convenience remote access to
* a platform MXBean of a running virtual machine. All method
* calls to the MXBean proxy are forwarded to an
* <tt>MBeanServerConnection</tt> where
* {@link java.io.IOException IOException} may be thrown
* when the communication problem occurs with the connector server.
* An application remotely accesses the platform MXBeans using
* proxy should prepare to catch <tt>IOException</tt> as if
* accessing with the <tt>MBeanServerConnector</tt> interface.</li>
*
* <li>When a client application is designed to remotely access MXBeans
* for a running virtual machine whose version is different than
* the version on which the application is running,
* it should prepare to catch
* {@link java.io.InvalidObjectException InvalidObjectException}
* which is thrown when an MXBean proxy receives a name of an
* enum constant which is missing in the enum class loaded in
* the client application. </li>
*
* <li>{@link javax.management.MBeanServerInvocationHandler
* MBeanServerInvocationHandler} or its
* {@link javax.management.MBeanServerInvocationHandler#newProxyInstance
* newProxyInstance} method cannot be used to create
* a proxy for a platform MXBean. The proxy object created
* by <tt>MBeanServerInvocationHandler</tt> does not handle
* the properties of the platform MXBeans described in
* the <a href="#MXBean">class specification</a>.
*</li>
* </ol>
*
* @param connection the <tt>MBeanServerConnection</tt> to forward to.
* @param mxbeanName the name of a platform MXBean within
* <tt>connection</tt> to forward to. <tt>mxbeanName</tt> must be
* in the format of {@link ObjectName ObjectName}.
* @param mxbeanInterface the MXBean interface to be implemented
* by the proxy.
* @param <T> an {@code mxbeanInterface} type parameter
*
* @return a proxy for a platform MXBean interface of a
* given <a href="#MXBeanNames">MXBean name</a>
* that forwards its method calls through the given
* <tt>MBeanServerConnection</tt>, or {@code null} if not exist.
*
* @throws IllegalArgumentException if
* <ul>
* <li><tt>mxbeanName</tt> is not with a valid
* {@link ObjectName ObjectName} format, or</li>
* <li>the named MXBean in the <tt>connection</tt> is
* not a MXBean provided by the platform, or</li>
* <li>the named MXBean is not registered in the
* <tt>MBeanServerConnection</tt>, or</li>
* <li>the named MXBean is not an instance of the given
* <tt>mxbeanInterface</tt></li>
* </ul>
*
* @throws java.io.IOException if a communication problem
* occurred when accessing the <tt>MBeanServerConnection</tt>.
*/
public static <T> T newPlatformMXBeanProxy(MBeanServerConnection connection, String mxbeanName, Class<T> mxbeanInterface) throws java.io.IOException {
// Only allow MXBean interfaces from rt.jar loaded by the
// bootstrap class loader
final Class<?> cls = mxbeanInterface;
ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
public ClassLoader run() {
return cls.getClassLoader();
}
});
if (!sun.misc.VM.isSystemDomainLoader(loader)) {
throw new IllegalArgumentException(mxbeanName + " is not a platform MXBean");
}
try {
final ObjectName objName = new ObjectName(mxbeanName);
// skip the isInstanceOf check for LoggingMXBean
String intfName = mxbeanInterface.getName();
if (!connection.isInstanceOf(objName, intfName)) {
throw new IllegalArgumentException(mxbeanName + " is not an instance of " + mxbeanInterface);
}
final Class[] interfaces;
// check if the registered MBean is a notification emitter
boolean emitter = connection.isInstanceOf(objName, NOTIF_EMITTER);
// create an MXBean proxy
return JMX.newMXBeanProxy(connection, objName, mxbeanInterface, emitter);
} catch (InstanceNotFoundException | MalformedObjectNameException e) {
throw new IllegalArgumentException(e);
}
}
use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.
the class RelationService method addRelation.
/**
* Adds an MBean created by the user (and registered by him in the MBean
* Server) as a relation in the Relation Service.
* <P>To be added as a relation, the MBean must conform to the
* following:
* <P>- implement the Relation interface
* <P>- have for RelationService ObjectName the ObjectName of current
* Relation Service
* <P>- have a relation id unique and unused in current Relation Service
* <P>- have for relation type a relation type created in the Relation
* Service
* <P>- have roles conforming to the role info provided in the relation
* type.
*
* @param relationObjectName ObjectName of the relation MBean to be added.
*
* @exception IllegalArgumentException if null parameter
* @exception RelationServiceNotRegisteredException if the Relation
* Service is not registered in the MBean Server
* @exception NoSuchMethodException If the MBean does not implement the
* Relation interface
* @exception InvalidRelationIdException if:
* <P>- no relation identifier in MBean
* <P>- the relation identifier is already used in the Relation Service
* @exception InstanceNotFoundException if the MBean for given ObjectName
* has not been registered
* @exception InvalidRelationServiceException if:
* <P>- no Relation Service name in MBean
* <P>- the Relation Service name in the MBean is not the one of the
* current Relation Service
* @exception RelationTypeNotFoundException if:
* <P>- no relation type name in MBean
* <P>- the relation type name in MBean does not correspond to a relation
* type created in the Relation Service
* @exception InvalidRoleValueException if:
* <P>- the number of referenced MBeans in a role is less than
* expected minimum degree
* <P>- the number of referenced MBeans in a role exceeds expected
* maximum degree
* <P>- one referenced MBean in the value is not an Object of the MBean
* class expected for that role
* <P>- an MBean provided for a role does not exist
* @exception RoleNotFoundException if a value is provided for a role
* that does not exist in the relation type
*/
public void addRelation(ObjectName relationObjectName) throws IllegalArgumentException, RelationServiceNotRegisteredException, NoSuchMethodException, InvalidRelationIdException, InstanceNotFoundException, InvalidRelationServiceException, RelationTypeNotFoundException, RoleNotFoundException, InvalidRoleValueException {
if (relationObjectName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(), "addRelation", relationObjectName);
// Can throw RelationServiceNotRegisteredException
isActive();
// registered MBean (else will throw an InstanceNotFoundException)
if ((!(myMBeanServer.isInstanceOf(relationObjectName, "javax.management.relation.Relation")))) {
String excMsg = "This MBean does not implement the Relation interface.";
throw new NoSuchMethodException(excMsg);
}
// Checks there is a relation id in the relation MBean (its uniqueness
// is checked in addRelationInt())
// Can throw InstanceNotFoundException (but detected above)
// No MBeanException as no exception raised by this method, and no
// ReflectionException
String relId;
try {
relId = (String) (myMBeanServer.getAttribute(relationObjectName, "RelationId"));
} catch (MBeanException exc1) {
throw new RuntimeException((exc1.getTargetException()).getMessage());
} catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (AttributeNotFoundException exc3) {
throw new RuntimeException(exc3.getMessage());
}
if (relId == null) {
String excMsg = "This MBean does not provide a relation id.";
throw new InvalidRelationIdException(excMsg);
}
// Checks that the Relation Service where the relation MBean is
// expected to be added is the current one
// Can throw InstanceNotFoundException (but detected above)
// No MBeanException as no exception raised by this method, no
// ReflectionException
ObjectName relServObjName;
try {
relServObjName = (ObjectName) (myMBeanServer.getAttribute(relationObjectName, "RelationServiceName"));
} catch (MBeanException exc1) {
throw new RuntimeException((exc1.getTargetException()).getMessage());
} catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (AttributeNotFoundException exc3) {
throw new RuntimeException(exc3.getMessage());
}
boolean badRelServFlag = false;
if (relServObjName == null) {
badRelServFlag = true;
} else if (!(relServObjName.equals(myObjName))) {
badRelServFlag = true;
}
if (badRelServFlag) {
String excMsg = "The Relation Service referenced in the MBean is not the current one.";
throw new InvalidRelationServiceException(excMsg);
}
// Checks that a relation type has been specified for the relation
// Can throw InstanceNotFoundException (but detected above)
// No MBeanException as no exception raised by this method, no
// ReflectionException
String relTypeName;
try {
relTypeName = (String) (myMBeanServer.getAttribute(relationObjectName, "RelationTypeName"));
} catch (MBeanException exc1) {
throw new RuntimeException((exc1.getTargetException()).getMessage());
} catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (AttributeNotFoundException exc3) {
throw new RuntimeException(exc3.getMessage());
}
if (relTypeName == null) {
String excMsg = "No relation type provided.";
throw new RelationTypeNotFoundException(excMsg);
}
// Retrieves all roles without considering read mode
// Can throw InstanceNotFoundException (but detected above)
// No MBeanException as no exception raised by this method, no
// ReflectionException
RoleList roleList;
try {
roleList = (RoleList) (myMBeanServer.invoke(relationObjectName, "retrieveAllRoles", null, null));
} catch (MBeanException exc1) {
throw new RuntimeException((exc1.getTargetException()).getMessage());
} catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
}
// Can throw RoleNotFoundException, InvalidRelationIdException,
// RelationTypeNotFoundException, InvalidRoleValueException
addRelationInt(false, null, relationObjectName, relId, relTypeName, roleList);
// Adds relation MBean ObjectName in map
synchronized (myRelMBeanObjName2RelIdMap) {
myRelMBeanObjName2RelIdMap.put(relationObjectName, relId);
}
// of the Relation interface, so may be not supported.
try {
myMBeanServer.setAttribute(relationObjectName, new Attribute("RelationServiceManagementFlag", Boolean.TRUE));
} catch (Exception exc) {
// OK : The flag is not supported.
}
// Updates listener information to received notification for
// unregistration of this MBean
List<ObjectName> newRefList = new ArrayList<ObjectName>();
newRefList.add(relationObjectName);
updateUnregistrationListener(newRefList, null);
RELATION_LOGGER.exiting(RelationService.class.getName(), "addRelation");
return;
}
Aggregations