javax.management.MBeanException Java Examples

The following examples show how to use javax.management.MBeanException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JMXProxyServlet.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Invokes an operation on an MBean.
 *
 * @param onameStr The name of the MBean.
 * @param operation The name of the operation to invoke.
 * @param parameters An array of Strings containing the parameters to the
 *            operation. They will be converted to the appropriate types to
 *            call the requested operation.
 * @return The value returned by the requested operation.
 */
private Object invokeOperationInternal(String onameStr, String operation, String[] parameters)
        throws OperationsException, MBeanException, ReflectionException {
    ObjectName oname = new ObjectName(onameStr);
    MBeanOperationInfo methodInfo = registry.getMethodInfo(oname, operation);
    MBeanParameterInfo[] signature = methodInfo.getSignature();
    String[] signatureTypes = new String[signature.length];
    Object[] values = new Object[signature.length];
    for (int i = 0; i < signature.length; i++) {
        MBeanParameterInfo pi = signature[i];
        signatureTypes[i] = pi.getType();
        values[i] = registry.convertValue(pi.getType(), parameters[i]);
    }

    return mBeanServer.invoke(oname, operation, values, signatureTypes);
}
 
Example #2
Source File: MBeanServerAccessController.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public ObjectInstance createMBean(String className, ObjectName name)
    throws
    ReflectionException,
    InstanceAlreadyExistsException,
    MBeanRegistrationException,
    MBeanException,
    NotCompliantMBeanException {
    checkCreate(className);
    SecurityManager sm = System.getSecurityManager();
    if (sm == null) {
        Object object = getMBeanServer().instantiate(className);
        checkClassLoader(object);
        return getMBeanServer().registerMBean(object, name);
    } else {
        return getMBeanServer().createMBean(className, name);
    }
}
 
Example #3
Source File: PerInterface.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
Object getAttribute(Object resource, String attribute, Object cookie)
        throws AttributeNotFoundException,
               MBeanException,
               ReflectionException {

    final M cm = getters.get(attribute);
    if (cm == null) {
        final String msg;
        if (setters.containsKey(attribute))
            msg = "Write-only attribute: " + attribute;
        else
            msg = "No such attribute: " + attribute;
        throw new AttributeNotFoundException(msg);
    }
    return introspector.invokeM(cm, resource, (Object[]) null, cookie);
}
 
Example #4
Source File: MBeanServerAccessController.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public ObjectInstance createMBean(String className, ObjectName name)
    throws
    ReflectionException,
    InstanceAlreadyExistsException,
    MBeanRegistrationException,
    MBeanException,
    NotCompliantMBeanException {
    checkCreate(className);
    SecurityManager sm = System.getSecurityManager();
    if (sm == null) {
        Object object = getMBeanServer().instantiate(className);
        checkClassLoader(object);
        return getMBeanServer().registerMBean(object, name);
    } else {
        return getMBeanServer().createMBean(className, name);
    }
}
 
Example #5
Source File: DefaultMBeanServerInterceptor.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public Object invoke(ObjectName name, String operationName,
                     Object params[], String signature[])
        throws InstanceNotFoundException, MBeanException,
               ReflectionException {

    name = nonDefaultDomain(name);

    DynamicMBean instance = getMBean(name);
    checkMBeanPermission(instance, operationName, name, "invoke");
    try {
        return instance.invoke(operationName, params, signature);
    } catch (Throwable t) {
        rethrowMaybeMBeanException(t);
        throw new AssertionError();
    }
}
 
Example #6
Source File: MBeanServerDelegateImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Always fails since the MBeanServerDelegate MBean has no operation.
 *
 * @param actionName The name of the action to be invoked.
 * @param params An array containing the parameters to be set when the
 *        action is invoked.
 * @param signature An array containing the signature of the action.
 *
 * @return  The object returned by the action, which represents
 *          the result of invoking the action on the MBean specified.
 *
 * @exception MBeanException  Wraps a <CODE>java.lang.Exception</CODE>
 *         thrown by the MBean's invoked method.
 * @exception ReflectionException  Wraps a
 *      <CODE>java.lang.Exception</CODE> thrown while trying to invoke
 *      the method.
 */
public Object invoke(String actionName, Object params[],
                     String signature[])
    throws MBeanException, ReflectionException {
    // Check that operation name is not null.
    //
    if (actionName == null) {
        final RuntimeException r =
          new IllegalArgumentException("Operation name  cannot be null");
        throw new RuntimeOperationsException(r,
        "Exception occurred trying to invoke the operation on the MBean");
    }

    throw new ReflectionException(
                      new NoSuchMethodException(actionName),
                      "The operation with name " + actionName +
                      " could not be found");
}
 
Example #7
Source File: PerInterface.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
Object getAttribute(Object resource, String attribute, Object cookie)
        throws AttributeNotFoundException,
               MBeanException,
               ReflectionException {

    final M cm = getters.get(attribute);
    if (cm == null) {
        final String msg;
        if (setters.containsKey(attribute))
            msg = "Write-only attribute: " + attribute;
        else
            msg = "No such attribute: " + attribute;
        throw new AttributeNotFoundException(msg);
    }
    return introspector.invokeM(cm, resource, (Object[]) null, cookie);
}
 
Example #8
Source File: MBeanServerAccessController.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public ObjectInstance createMBean(String className, ObjectName name,
                                  Object params[], String signature[])
    throws
    ReflectionException,
    InstanceAlreadyExistsException,
    MBeanRegistrationException,
    MBeanException,
    NotCompliantMBeanException {
    checkCreate(className);
    SecurityManager sm = System.getSecurityManager();
    if (sm == null) {
        Object object = getMBeanServer().instantiate(className,
                                                     params,
                                                     signature);
        checkClassLoader(object);
        return getMBeanServer().registerMBean(object, name);
    } else {
        return getMBeanServer().createMBean(className, name,
                                            params, signature);
    }
}
 
Example #9
Source File: MBeanServerAccessController.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public ObjectInstance createMBean(String className, ObjectName name)
    throws
    ReflectionException,
    InstanceAlreadyExistsException,
    MBeanRegistrationException,
    MBeanException,
    NotCompliantMBeanException {
    checkCreate(className);
    SecurityManager sm = System.getSecurityManager();
    if (sm == null) {
        Object object = getMBeanServer().instantiate(className);
        checkClassLoader(object);
        return getMBeanServer().registerMBean(object, name);
    } else {
        return getMBeanServer().createMBean(className, name);
    }
}
 
Example #10
Source File: DefaultMBeanServerInterceptor.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public ObjectInstance createMBean(String className, ObjectName name,
                                  Object[] params, String[] signature)
    throws ReflectionException, InstanceAlreadyExistsException,
           MBeanRegistrationException, MBeanException,
           NotCompliantMBeanException  {

    try {
        return createMBean(className, name, null, true,
                           params, signature);
    } catch (InstanceNotFoundException e) {
        /* Can only happen if loaderName doesn't exist, but we just
           passed null, so we shouldn't get this exception.  */
        throw EnvHelp.initCause(
            new IllegalArgumentException("Unexpected exception: " + e), e);
    }
}
 
Example #11
Source File: MBeanServerAccessController.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public ObjectInstance createMBean(String className, ObjectName name,
                                  Object params[], String signature[])
    throws
    ReflectionException,
    InstanceAlreadyExistsException,
    MBeanRegistrationException,
    MBeanException,
    NotCompliantMBeanException {
    checkCreate(className);
    SecurityManager sm = System.getSecurityManager();
    if (sm == null) {
        Object object = getMBeanServer().instantiate(className,
                                                     params,
                                                     signature);
        checkClassLoader(object);
        return getMBeanServer().registerMBean(object, name);
    } else {
        return getMBeanServer().createMBean(className, name,
                                            params, signature);
    }
}
 
Example #12
Source File: FlightRecorderMXBeanImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private Notification createNotication(Recording recording) {
    try {
        Long id = recording.getId();
        Object oldValue = changes.get(recording.getId());
        Object newValue = getAttribute(ATTRIBUTE_RECORDINGS);
        if (recording.getState() != RecordingState.CLOSED) {
            changes.put(id, newValue);
        } else {
            changes.remove(id);
        }
        return new AttributeChangeNotification(getObjectName(), sequenceNumber.incrementAndGet(), System.currentTimeMillis(), "Recording " + recording.getName() + " is "
                + recording.getState(), ATTRIBUTE_RECORDINGS, newValue.getClass().getName(), oldValue, newValue);
    } catch (AttributeNotFoundException | MBeanException | ReflectionException e) {
        throw new RuntimeException("Could not create notifcation for FlightRecorderMXBean. " + e.getMessage(), e);
    }
}
 
Example #13
Source File: MBeanServerAccessController.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public Object instantiate(String className, ObjectName loaderName,
                          Object params[], String signature[])
    throws ReflectionException, MBeanException, InstanceNotFoundException {
    checkCreate(className);
    return getMBeanServer().instantiate(className, loaderName,
                                        params, signature);
}
 
Example #14
Source File: ModelMBeanInfoSupport.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void setMBeanDescriptor(Descriptor inMBeanDescriptor)
throws MBeanException, RuntimeOperationsException {
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                ModelMBeanInfoSupport.class.getName(),
                "setMBeanDescriptor(Descriptor)", "Entry");
    }
    modelMBeanDescriptor = validDescriptor(inMBeanDescriptor);
}
 
Example #15
Source File: OldMBeanServerTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public ObjectInstance createMBean(
        String className, ObjectName name, ObjectName loaderName)
throws ReflectionException, InstanceAlreadyExistsException,
        MBeanRegistrationException, MBeanException,
        NotCompliantMBeanException, InstanceNotFoundException {
    return createMBean(className, name, loaderName, null, null);
}
 
Example #16
Source File: MXBeanIntrospector.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
Object invokeM2(ConvertingMethod m, Object target, Object[] args,
                Object cookie)
        throws InvocationTargetException, IllegalAccessException,
               MBeanException {
    return m.invokeWithOpenReturn((MXBeanLookup) cookie, target, args);
}
 
Example #17
Source File: ModelMBeanInfoSupport.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public ModelMBeanNotificationInfo getNotification(String inName)
throws MBeanException, RuntimeOperationsException {
    ModelMBeanNotificationInfo retInfo = null;
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                ModelMBeanInfoSupport.class.getName(),
                "getNotification(String)", "Entry");
    }
    if (inName == null) {
        throw new RuntimeOperationsException(
                new IllegalArgumentException("Notification name is null"),
                "Exception occurred trying to get the " +
                "ModelMBeanNotificationInfo of the MBean");
    }
    MBeanNotificationInfo[] notifList = modelMBeanNotifications; //this.getNotifications();
    int numNotifs = 0;
    if (notifList != null) numNotifs = notifList.length;

    for (int i=0; (i < numNotifs) && (retInfo == null); i++) {
        if (inName.equals(notifList[i].getName())) {
            retInfo = ((ModelMBeanNotificationInfo) notifList[i].clone());
        }
    }
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                ModelMBeanInfoSupport.class.getName(),
                "getNotification(String)", "Exit");
    }

    return retInfo;
}
 
Example #18
Source File: ConvertingMethod.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
Object invokeWithOpenReturn(MXBeanLookup lookup,
                            Object obj, Object[] params)
        throws MBeanException, IllegalAccessException,
               InvocationTargetException {
    MXBeanLookup old = MXBeanLookup.getLookup();
    try {
        MXBeanLookup.setLookup(lookup);
        return invokeWithOpenReturn(obj, params);
    } finally {
        MXBeanLookup.setLookup(old);
    }
}
 
Example #19
Source File: ModelMBeanInfoSupport.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public ModelMBeanOperationInfo getOperation(String inName)
throws MBeanException, RuntimeOperationsException {
    ModelMBeanOperationInfo retInfo = null;
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                ModelMBeanInfoSupport.class.getName(),
                "getOperation(String)", "Entry");
    }
    if (inName == null) {
        throw new RuntimeOperationsException(
                new IllegalArgumentException("inName is null"),
                "Exception occurred trying to get the " +
                "ModelMBeanOperationInfo of the MBean");
    }
    MBeanOperationInfo[] operList = modelMBeanOperations; //this.getOperations();
    int numOpers = 0;
    if (operList != null) numOpers = operList.length;

    for (int i=0; (i < numOpers) && (retInfo == null); i++) {
        if (inName.equals(operList[i].getName())) {
            retInfo = ((ModelMBeanOperationInfo) operList[i].clone());
        }
    }
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                ModelMBeanInfoSupport.class.getName(),
                "getOperation(String)", "Exit");
    }

    return retInfo;
}
 
Example #20
Source File: PerfCounters.java    From java-svc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Object getAttribute(String attribute)
		throws AttributeNotFoundException, MBeanException, ReflectionException {
	if (attribute == null) {
		throw new RuntimeOperationsException(new IllegalArgumentException("The attribute name cannot be null."),
				"Cannot invoke getAttribute on " + MBEAN_OBJECT_NAME + " with null as attribute name.");
	}
	Counter c = counterMap.get(attribute);
	if (c == null) {
		throw new AttributeNotFoundException("Could not find the attribute " + attribute);
	}
	return c.getValue();
}
 
Example #21
Source File: ConvertingMethod.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
Object invokeWithOpenReturn(MXBeanLookup lookup,
                            Object obj, Object[] params)
        throws MBeanException, IllegalAccessException,
               InvocationTargetException {
    MXBeanLookup old = MXBeanLookup.getLookup();
    try {
        MXBeanLookup.setLookup(lookup);
        return invokeWithOpenReturn(obj, params);
    } finally {
        MXBeanLookup.setLookup(old);
    }
}
 
Example #22
Source File: MBeanServerAccessController.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public ObjectInstance createMBean(String className,
                                  ObjectName name,
                                  ObjectName loaderName,
                                  Object params[],
                                  String signature[])
    throws
    ReflectionException,
    InstanceAlreadyExistsException,
    MBeanRegistrationException,
    MBeanException,
    NotCompliantMBeanException,
    InstanceNotFoundException {
    checkCreate(className);
    SecurityManager sm = System.getSecurityManager();
    if (sm == null) {
        Object object = getMBeanServer().instantiate(className,
                                                     loaderName,
                                                     params,
                                                     signature);
        checkClassLoader(object);
        return getMBeanServer().registerMBean(object, name);
    } else {
        return getMBeanServer().createMBean(className, name, loaderName,
                                            params, signature);
    }
}
 
Example #23
Source File: RMIConnector.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public Object invoke(ObjectName name,
        String operationName,
        Object params[],
        String signature[])
        throws InstanceNotFoundException,
        MBeanException,
        ReflectionException,
        IOException {

    if (logger.debugOn()) logger.debug("invoke",
            "name=" + name
            + ", operationName=" + operationName
            + ", signature=" + strings(signature));

    final MarshalledObject<Object[]> sParams =
            new MarshalledObject<Object[]>(params);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        return connection.invoke(name,
                operationName,
                sParams,
                signature,
                delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        return connection.invoke(name,
                operationName,
                sParams,
                signature,
                delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example #24
Source File: MXBeanIntrospector.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
Object invokeM2(ConvertingMethod m, Object target, Object[] args,
                Object cookie)
        throws InvocationTargetException, IllegalAccessException,
               MBeanException {
    return m.invokeWithOpenReturn((MXBeanLookup) cookie, target, args);
}
 
Example #25
Source File: RMIConnector.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public ObjectInstance createMBean(String className,
        ObjectName name,
        ObjectName loaderName,
        Object params[],
        String signature[])
        throws ReflectionException,
        InstanceAlreadyExistsException,
        MBeanRegistrationException,
        MBeanException,
        NotCompliantMBeanException,
        InstanceNotFoundException,
        IOException {
    if (logger.debugOn()) logger.debug(
            "createMBean(String,ObjectName,ObjectName,Object[],String[])",
            "className=" + className + ", name=" + name + ", loaderName="
            + loaderName + ", signature=" + strings(signature));

    final MarshalledObject<Object[]> sParams =
            new MarshalledObject<Object[]>(params);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        return connection.createMBean(className,
                name,
                loaderName,
                sParams,
                signature,
                delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        return connection.createMBean(className,
                name,
                loaderName,
                sParams,
                signature,
                delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example #26
Source File: DefaultMBeanServerInterceptor.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public Object getAttribute(ObjectName name, String attribute)
    throws MBeanException, AttributeNotFoundException,
           InstanceNotFoundException, ReflectionException {

    if (name == null) {
        throw new RuntimeOperationsException(new
            IllegalArgumentException("Object name cannot be null"),
            "Exception occurred trying to invoke the getter on the MBean");
    }
    if (attribute == null) {
        throw new RuntimeOperationsException(new
            IllegalArgumentException("Attribute cannot be null"),
            "Exception occurred trying to invoke the getter on the MBean");
    }

    name = nonDefaultDomain(name);

    if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
        MBEANSERVER_LOGGER.logp(Level.FINER,
                DefaultMBeanServerInterceptor.class.getName(),
                "getAttribute",
                "Attribute = " + attribute + ", ObjectName = " + name);
    }

    final DynamicMBean instance = getMBean(name);
    checkMBeanPermission(instance, attribute, name, "getAttribute");

    try {
        return instance.getAttribute(attribute);
    } catch (AttributeNotFoundException e) {
        throw e;
    } catch (Throwable t) {
        rethrowMaybeMBeanException(t);
        throw new AssertionError(); // not reached
    }
}
 
Example #27
Source File: MBeanServerAccessController.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Call <code>checkWrite()</code>, then forward this method to the
 * wrapped object.
 */
public void setAttribute(ObjectName name, Attribute attribute)
    throws
    InstanceNotFoundException,
    AttributeNotFoundException,
    InvalidAttributeValueException,
    MBeanException,
    ReflectionException {
    checkWrite();
    getMBeanServer().setAttribute(name, attribute);
}
 
Example #28
Source File: DefaultMBeanServerInterceptor.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public Object getAttribute(ObjectName name, String attribute)
    throws MBeanException, AttributeNotFoundException,
           InstanceNotFoundException, ReflectionException {

    if (name == null) {
        throw new RuntimeOperationsException(new
            IllegalArgumentException("Object name cannot be null"),
            "Exception occurred trying to invoke the getter on the MBean");
    }
    if (attribute == null) {
        throw new RuntimeOperationsException(new
            IllegalArgumentException("Attribute cannot be null"),
            "Exception occurred trying to invoke the getter on the MBean");
    }

    name = nonDefaultDomain(name);

    if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
        MBEANSERVER_LOGGER.logp(Level.FINER,
                DefaultMBeanServerInterceptor.class.getName(),
                "getAttribute",
                "Attribute = " + attribute + ", ObjectName = " + name);
    }

    final DynamicMBean instance = getMBean(name);
    checkMBeanPermission(instance, attribute, name, "getAttribute");

    try {
        return instance.getAttribute(attribute);
    } catch (AttributeNotFoundException e) {
        throw e;
    } catch (Throwable t) {
        rethrowMaybeMBeanException(t);
        throw new AssertionError(); // not reached
    }
}
 
Example #29
Source File: RMIConnector.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public ObjectInstance createMBean(String className,
        ObjectName name,
        ObjectName loaderName)
        throws ReflectionException,
        InstanceAlreadyExistsException,
        MBeanRegistrationException,
        MBeanException,
        NotCompliantMBeanException,
        InstanceNotFoundException,
        IOException {

    if (logger.debugOn())
        logger.debug("createMBean(String,ObjectName,ObjectName)",
                "className=" + className + ", name="
                + name + ", loaderName="
                + loaderName + ")");

    final ClassLoader old = pushDefaultClassLoader();
    try {
        return connection.createMBean(className,
                name,
                loaderName,
                delegationSubject);

    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        return connection.createMBean(className,
                name,
                loaderName,
                delegationSubject);

    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example #30
Source File: MBeanExceptionTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Object invoke(String opName, Object[] params, String[] sig)
        throws MBeanException {
    assert params == null && sig == null;
    if (opName.equals("UncheckedException"))
        throw theUncheckedException;
    else
        throw new AssertionError();
}