javax.management.ReflectionException Java Examples

The following examples show how to use javax.management.ReflectionException. 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: MBeanInstantiator.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Gets the class for the specified class name using the specified
 * class loader
 */
public Class<?> findClass(String className, ObjectName aLoader)
    throws ReflectionException, InstanceNotFoundException  {

    if (aLoader == null)
        throw new RuntimeOperationsException(new
            IllegalArgumentException(), "Null loader passed in parameter");

    // Retrieve the class loader from the repository
    ClassLoader loader = null;
    synchronized (this) {
        loader = getClassLoader(aLoader);
    }
    if (loader == null) {
        throw new InstanceNotFoundException("The loader named " +
                   aLoader + " is not registered in the MBeanServer");
    }
    return findClass(className,loader);
}
 
Example #2
Source File: JvmOptions.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void setAttribute(Attribute attribute) throws RemoteException, InstanceNotFoundException, AttributeNotFoundException,
 InvalidAttributeValueException, MBeanException, ReflectionException, java.io.IOException{
    if(attribute.getName().equals(this.JPDA_PORT)){
        if(attribute.getValue() != null){
            setAddressValue(attribute.getValue().toString());
        }
    }else if(attribute.getName().equals(this.SHARED_MEM)){
        if(attribute.getValue() != null){
                setAddressValue(attribute.getValue().toString());
        }
    }else if(attribute.getName().equals(this.DEBUG_OPTIONS)){
        //Fix for bug# 4989322 - solaris does not support shmem
        if((attribute.getValue() != null) && (attribute.getValue().toString().indexOf(ISMEM) == -1)){
            this.conn.setAttribute(this.configObjName, attribute);
        }else{
            if(isWindows()){
                this.conn.setAttribute(this.configObjName, attribute);
            }
          //ludo  else
          //ludo      Util.setStatusBar(bundle.getString("Msg_SolarisShmem"));
        }
    }else{
        this.conn.setAttribute(this.configObjName, attribute);
    }
}
 
Example #3
Source File: MetricsDynamicMBeanBase.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public Object invoke(String actionName, Object[] parms, String[] signature)
    throws MBeanException, ReflectionException {
  
  if (actionName == null || actionName.isEmpty()) 
    throw new IllegalArgumentException();
  
  
  // Right now we support only one fixed operation (if it applies)
  if (!(actionName.equals(RESET_ALL_MIN_MAX_OP)) || 
      mbeanInfo.getOperations().length != 1) {
    throw new ReflectionException(new NoSuchMethodException(actionName));
  }
  for (MetricsBase m : metricsRegistry.getMetricsList())  {
    if ( MetricsTimeVaryingRate.class.isInstance(m) ) {
      MetricsTimeVaryingRate.class.cast(m).resetMinMax();
    }
  }
  return null;
}
 
Example #4
Source File: DefaultMBeanServerInterceptor.java    From openjdk-jdk9 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 #5
Source File: PerInterface.java    From dragonwell8_jdk 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 #6
Source File: PluggableMBeanServerImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public ObjectInstance createMBean(String className, ObjectName name, Object[] params, String[] signature)
        throws ReflectionException, InstanceAlreadyExistsException, MBeanException,
        NotCompliantMBeanException {
    params = nullAsEmpty(params);
    signature = nullAsEmpty(signature);
    Throwable error = null;
    MBeanServerPlugin delegate = null;
    final boolean readOnly = false;
    try {
        delegate = findDelegateForNewObject(name);
        authorizeMBeanOperation(delegate, name, CREATE_MBEAN, null, JmxAction.Impact.WRITE);
        return checkNotAReservedDomainRegistrationIfObjectNameWasChanged(name, delegate.createMBean(className, name, params, signature), delegate);
    } catch (Exception e) {
        error = e;
        if (e instanceof ReflectionException) throw (ReflectionException)e;
        if (e instanceof InstanceAlreadyExistsException) throw (InstanceAlreadyExistsException)e;
        if (e instanceof MBeanException) throw (MBeanException)e;
        if (e instanceof NotCompliantMBeanException) throw (NotCompliantMBeanException)e;
        throw makeRuntimeException(e);
    } finally {
        if (shouldAuditLog(delegate, readOnly)) {
            new MBeanServerAuditLogRecordFormatter(this, error, readOnly).createMBean(className, name, params, signature);
        }
    }
}
 
Example #7
Source File: MdbContainer.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public Object invoke(final String actionName, final Object[] params, final String[] signature) throws MBeanException, ReflectionException {
    if (actionName.equals("stop")) {
        activationContext.stop();

    } else if (actionName.equals("start")) {
        try {
            activationContext.start();
        } catch (ResourceException e) {
            logger.error("Error invoking " + actionName + ": " + e.getMessage());
            throw new MBeanException(new IllegalStateException(e.getMessage(), e));
        }

    } else {
        throw new MBeanException(new IllegalStateException("unsupported operation: " + actionName));
    }
    return null;
}
 
Example #8
Source File: MBeanServerDelegateImpl.java    From JDKSourceCode1.8 with MIT License 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 #9
Source File: ProxyClient.java    From jvmtop with GNU General Public License v2.0 6 votes vote down vote up
private synchronized NameValueMap getCachedAttributes(
        ObjectName objName, Set<String> attrNames) throws
        InstanceNotFoundException, ReflectionException, IOException {
    NameValueMap values = cachedValues.get(objName);
    if (values != null && values.keySet().containsAll(attrNames)) {
        return values;
    }
    attrNames = new TreeSet<String>(attrNames);
    Set<String> oldNames = cachedNames.get(objName);
    if (oldNames != null) {
        attrNames.addAll(oldNames);
    }
    values = new NameValueMap();
    final AttributeList attrs = conn.getAttributes(
            objName,
            attrNames.toArray(new String[attrNames.size()]));
    for (Attribute attr : attrs.asList()) {
        values.put(attr.getName(), attr.getValue());
    }
    cachedValues.put(objName, values);
    cachedNames.put(objName, attrNames);
    return values;
}
 
Example #10
Source File: PerInterface.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
void setAttribute(Object resource, String attribute, Object value,
                  Object cookie)
        throws AttributeNotFoundException,
               InvalidAttributeValueException,
               MBeanException,
               ReflectionException {

    final M cm = setters.get(attribute);
    if (cm == null) {
        final String msg;
        if (getters.containsKey(attribute))
            msg = "Read-only attribute: " + attribute;
        else
            msg = "No such attribute: " + attribute;
        throw new AttributeNotFoundException(msg);
    }
    introspector.invokeSetter(attribute, cm, resource, value, cookie);
}
 
Example #11
Source File: MBeanInstantiator.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Gets the class for the specified class name using the specified
 * class loader
 */
public Class<?> findClass(String className, ObjectName aLoader)
    throws ReflectionException, InstanceNotFoundException  {

    if (aLoader == null)
        throw new RuntimeOperationsException(new
            IllegalArgumentException(), "Null loader passed in parameter");

    // Retrieve the class loader from the repository
    ClassLoader loader = null;
    synchronized (this) {
        loader = getClassLoader(aLoader);
    }
    if (loader == null) {
        throw new InstanceNotFoundException("The loader named " +
                   aLoader + " is not registered in the MBeanServer");
    }
    return findClass(className,loader);
}
 
Example #12
Source File: ROConnection.java    From scheduling with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * @see javax.management.MBeanServerConnection#invoke(javax.management.ObjectName, java.lang.String, java.lang.Object[], java.lang.String[])
 */
public Object invoke(final ObjectName name, final String operationName, final Object[] params,
        final String[] signature)
        throws InstanceNotFoundException, MBeanException, ReflectionException, IOException {
    if (this.subject == null) {
        return this.mbs.invoke(name, operationName, params, signature);
    }
    try {
        return Subject.doAsPrivileged(this.subject, new PrivilegedExceptionAction<Object>() {
            public final Object run() throws Exception {
                return mbs.invoke(name, operationName, params, signature);
            }
        }, this.context);
    } catch (final PrivilegedActionException pe) {
        final Exception e = JMXProviderUtils.extractException(pe);
        if (e instanceof InstanceNotFoundException)
            throw (InstanceNotFoundException) e;
        if (e instanceof MBeanException)
            throw (MBeanException) e;
        if (e instanceof ReflectionException)
            throw (ReflectionException) e;
        if (e instanceof IOException)
            throw (IOException) e;
        throw JMXProviderUtils.newIOException("Got unexpected server exception: " + e, e);
    }
}
 
Example #13
Source File: MBeanInstantiator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Load a class with the specified loader, or with this object
 * class loader if the specified loader is null.
 **/
static Class<?> loadClass(String className, ClassLoader loader)
    throws ReflectionException {
    Class<?> theClass;
    if (className == null) {
        throw new RuntimeOperationsException(new
            IllegalArgumentException("The class name cannot be null"),
                          "Exception occurred during object instantiation");
    }
    ReflectUtil.checkPackageAccess(className);
    try {
        if (loader == null)
            loader = MBeanInstantiator.class.getClassLoader();
        if (loader != null) {
            theClass = Class.forName(className, false, loader);
        } else {
            theClass = Class.forName(className);
        }
    } catch (ClassNotFoundException e) {
        throw new ReflectionException(e,
        "The MBean class could not be loaded");
    }
    return theClass;
}
 
Example #14
Source File: RMIConnector.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public AttributeList getAttributes(ObjectName name,
        String[] attributes)
        throws InstanceNotFoundException,
        ReflectionException,
        IOException {
    if (logger.debugOn()) logger.debug("getAttributes",
            "name=" + name + ", attributes="
            + strings(attributes));

    final ClassLoader old = pushDefaultClassLoader();
    try {
        return connection.getAttributes(name,
                attributes,
                delegationSubject);

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

        return connection.getAttributes(name,
                attributes,
                delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example #15
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,
                                  ObjectName loaderName)
    throws
    ReflectionException,
    InstanceAlreadyExistsException,
    MBeanRegistrationException,
    MBeanException,
    NotCompliantMBeanException,
    InstanceNotFoundException {
    checkCreate(className);
    SecurityManager sm = System.getSecurityManager();
    if (sm == null) {
        Object object = getMBeanServer().instantiate(className,
                                                     loaderName);
        checkClassLoader(object);
        return getMBeanServer().registerMBean(object, name);
    } else {
        return getMBeanServer().createMBean(className, name, loaderName);
    }
}
 
Example #16
Source File: DefaultMBeanServerInterceptor.java    From openjdk-jdk8u-backup 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 #17
Source File: StatisticsExposingMBean.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException, ReflectionException {
   if ("exposeTag".equals(actionName)) {
      this.exposeTag(params[0].toString());
      return null;
   } else if ("removeTag".equals(actionName)) {
      return this.removeTag(params[0].toString());
   } else {
      throw new UnsupportedOperationException("Unsupported operation: " + actionName);
   }
}
 
Example #18
Source File: ContextEnvironmentMBean.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * 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 {

    super.setAttribute(attribute);

    ContextEnvironment ce = doGetManagedResource();

    // cannot use side-effects.  It's removed and added back each time
    // there is a modification in a resource.
    NamingResources nr = ce.getNamingResources();
    nr.removeEnvironment(ce.getName());
    nr.addEnvironment(ce);
}
 
Example #19
Source File: ConfigurationManagerService.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
@Override
public Object getAttribute( String name )
    throws AttributeNotFoundException, MBeanException, ReflectionException
{
    UnitOfWork uow = uowf.newUnitOfWork();
    try
    {
        EntityComposite configuration = uow.get( EntityComposite.class, identity );
        AssociationStateHolder state = spi.stateOf( configuration );
        AccessibleObject accessor = propertyNames.get( name );
        Property<Object> property = state.propertyFor( accessor );
        Object object = property.get();
        if( object instanceof Enum )
        {
            object = object.toString();
        }
        return object;
    }
    catch( Exception ex )
    {
        throw new ReflectionException( ex, "Could not get attribute " + name );
    }
    finally
    {
        uow.discard();
    }
}
 
Example #20
Source File: ProxyClient.java    From jmxmon with Apache License 2.0 5 votes vote down vote up
private AttributeList getAttributes(
        ObjectName objName, String[] attrNames) throws
        InstanceNotFoundException, ReflectionException, IOException {
    final NameValueMap values = getCachedAttributes(
            objName,
            new TreeSet<String>(Arrays.asList(attrNames)));
    final AttributeList list = new AttributeList();
    for (String attrName : attrNames) {
        final Object value = values.get(attrName);
        if (value != null || values.containsKey(attrName)) {
            list.add(new Attribute(attrName, value));
        }
    }
    return list;
}
 
Example #21
Source File: MBeanServerAccessController.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Call <code>checkRead()</code>, then forward this method to the
 * wrapped object.
 */
public MBeanInfo getMBeanInfo(ObjectName name)
    throws
    InstanceNotFoundException,
    IntrospectionException,
    ReflectionException {
    checkRead();
    return getMBeanServer().getMBeanInfo(name);
}
 
Example #22
Source File: MBeanServerAccessController.java    From openjdk-jdk8u-backup 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 #23
Source File: IgniteSnapshotMXBeanTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**

     * @param mBean Ignite snapshot MBean.
     * @return Value of snapshot end time.
     */
    private static long getLastSnapshotEndTime(DynamicMBean mBean) {
        try {
            return (long)mBean.getAttribute("LastSnapshotEndTime");
        }
        catch (MBeanException | ReflectionException | AttributeNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
 
Example #24
Source File: MBeanServerAccessController.java    From hottub 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 AttributeList setAttributes(ObjectName name,
                                   AttributeList attributes)
    throws InstanceNotFoundException, ReflectionException {
    checkWrite();
    return getMBeanServer().setAttributes(name, attributes);
}
 
Example #25
Source File: MBeanServerAccessController.java    From jdk8u-jdk 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 Object invoke(ObjectName name, String operationName,
                     Object params[], String signature[])
    throws
    InstanceNotFoundException,
    MBeanException,
    ReflectionException {
    checkWrite();
    checkMLetMethods(name, operationName);
    return getMBeanServer().invoke(name, operationName, params, signature);
}
 
Example #26
Source File: RemoteResourceMonitor.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public Object invoke(final String actionName, final Object[] params, final String[] signature) throws MBeanException, ReflectionException {
    if (hosts.contains(actionName)) {
        return ping(actionName);
    } else if (PING.equals(actionName) && params != null && params.length == 1) {
        return ping((String) params[0]);
    }
    throw new MBeanException(new IllegalArgumentException(), actionName + " doesn't exist");
}
 
Example #27
Source File: MBeanServerAccessController.java    From jdk8u60 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: MBeanTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void validateTableIntAttr(String tableName, MBeanServerConnection mBeanServer, ObjectName name, Attribute attribute, Number value) throws AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException, IOException {
  int actual = ((Integer)mBeanServer.getAttribute(name, attribute.getName())).intValue();
 
  if(actual - value.intValue() < 0) {
    saveError(attribute.getName() + " attribute did not match for " + tableName + " where expected = " + value + " and actuals : " + actual);
  } else {
    Log.getLogWriter().info(attribute.getName() + " attribute match for " + tableName + " where expected = " + value + " and actuals : " + actual);
  }
}
 
Example #29
Source File: MBeanServerAccessController.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Call <code>checkRead()</code>, then forward this method to the
 * wrapped object.
 */
@Deprecated
public ObjectInputStream deserialize(String className, byte[] data)
    throws OperationsException, ReflectionException {
    checkRead();
    return getMBeanServer().deserialize(className, data);
}
 
Example #30
Source File: RMIConnector.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public ObjectInstance createMBean(String className,
        ObjectName name,
        Object params[],
        String signature[])
        throws ReflectionException,
        InstanceAlreadyExistsException,
        MBeanRegistrationException,
        MBeanException,
        NotCompliantMBeanException,
        IOException {
    if (logger.debugOn())
        logger.debug("createMBean(String,ObjectName,Object[],String[])",
                "className=" + className + ", name="
                + name + ", params="
                + objects(params) + ", signature="
                + strings(signature));

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

        return connection.createMBean(className,
                name,
                sParams,
                signature,
                delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}