Java Code Examples for javax.management.ReflectionException

The following are top voted examples for showing how to use javax.management.ReflectionException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Shadbot   File: Utils.java   Source Code and License 6 votes vote down vote up
public static double getProcessCpuLoad() {
	double cpuLoad;
	try {
		MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
		ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem");
		AttributeList list = mbs.getAttributes(name, new String[] { "ProcessCpuLoad" });

		if(list.isEmpty()) {
			return Double.NaN;
		}

		Attribute att = (Attribute) list.get(0);
		Double value = (Double) att.getValue();

		if(value == -1.0) {
			return Double.NaN;
		}

		cpuLoad = value * 100d;
	} catch (InstanceNotFoundException | ReflectionException | MalformedObjectNameException err) {
		cpuLoad = Double.NaN;
	}

	return cpuLoad;
}
 
Example 2
Project: monarch   File: MBeanSecurityJUnitTest.java   Source Code and License 6 votes vote down vote up
/**
 * No user can call createBean or unregisterBean of GemFire Domain
 */
@Test
@ConnectionConfiguration(user = "super-user", password = "1234567")
public void testNoAccessWithWhoever() throws Exception {
  MBeanServerConnection con = connectionRule.getMBeanServerConnection();
  assertThatThrownBy(
      () -> con.createMBean("FakeClassName", new ObjectName("GemFire", "name", "foo")))
          .isInstanceOf(SecurityException.class);

  assertThatThrownBy(() -> con.unregisterMBean(new ObjectName("GemFire", "name", "foo")))
      .isInstanceOf(SecurityException.class);

  // user is allowed to create beans of other domains
  assertThatThrownBy(
      () -> con.createMBean("FakeClassName", new ObjectName("OtherDomain", "name", "foo")))
          .isInstanceOf(ReflectionException.class);
}
 
Example 3
Project: doctorkafka   File: BrokerStatsRetriever.java   Source Code and License 6 votes vote down vote up
public static double getProcessCpuLoad(MBeanServerConnection mbs)
    throws MalformedObjectNameException, NullPointerException, InstanceNotFoundException,
           ReflectionException, IOException {
  ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem");
  AttributeList list = mbs.getAttributes(name, new String[]{"ProcessCpuLoad"});

  if (list.isEmpty()) {
    return 0.0;
  }

  Attribute att = (Attribute) list.get(0);
  Double value = (Double) att.getValue();

  // usually takes a couple of seconds before we get real values
  if (value == -1.0) {
    return 0.0;
  }
  // returns a percentage value with 1 decimal point precision
  return ((int) (value * 1000) / 10.0);
}
 
Example 4
Project: jdk8u-jdk   File: MBeanInstantiator.java   Source Code and License 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 5
Project: openjdk-jdk10   File: MBeanServerDelegateImpl.java   Source Code and 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 6
Project: openjdk-jdk10   File: MBeanServerAccessController.java   Source Code and 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 7
Project: hashsdn-controller   File: DynamicWritableWrapper.java   Source Code and License 6 votes vote down vote up
@Override
public AttributeList setAttributes(final AttributeList attributes) {
    AttributeList result = new AttributeList();
    for (Object attributeObject : attributes) {
        Attribute attribute = (Attribute) attributeObject;
        try {
            setAttribute(attribute);
            result.add(attribute);
        } catch (final InvalidAttributeValueException | AttributeNotFoundException | MBeanException
                | ReflectionException e) {
            LOG.warn("Setting attribute {} failed on {}", attribute.getName(), moduleIdentifier, e);
            throw new IllegalArgumentException(
                    "Setting attribute failed - " + attribute.getName() + " on " + moduleIdentifier, e);
        }
    }
    return result;
}
 
Example 8
Project: OpenJSharp   File: MBeanInstantiator.java   Source Code and License 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 9
Project: OpenJSharp   File: PerInterface.java   Source Code and License 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 10
Project: OpenJSharp   File: MBeanServerAccessController.java   Source Code and 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 11
Project: lazycat   File: JMXProxyServlet.java   Source Code and 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 12
Project: Pogamut3   File: DynamicProxy.java   Source Code and License 5 votes vote down vote up
public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
    try {
        return mbsc.getAttribute(objectName, attribute);
    } catch (Exception ex) {
        throw new MBeanException(ex);
    }
}
 
Example 13
Project: Pogamut3   File: FolderMBean.java   Source Code and License 5 votes vote down vote up
@Override
public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
    try {
        return folder.getProperty(attribute).getValue();
    } catch (IntrospectionException ex) {
        throw new MBeanException(ex);
    }
}
 
Example 14
Project: Pogamut3   File: FolderMBean.java   Source Code and License 5 votes vote down vote up
@Override
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    try {
        folder.getProperty(attribute.getName()).setValue(attribute.getValue());
    } catch (IntrospectionException ex) {
        throw new MBeanException(ex);
    }
}
 
Example 15
Project: Pogamut3   File: PogamutMBeanServer.java   Source Code and License 5 votes vote down vote up
@Override
public synchronized ObjectInstance createMBean(String className, ObjectName name,
		Object[] params, String[] signature) throws ReflectionException,
		InstanceAlreadyExistsException, MBeanRegistrationException,
		MBeanException, NotCompliantMBeanException {
	throw new UnsupportedOperationException("Not supported by PogamutMBeanServer yet...");
}
 
Example 16
Project: Pogamut3   File: PogamutMBeanServer.java   Source Code and License 5 votes vote down vote up
@Override
public synchronized ObjectInstance createMBean(String className, ObjectName name,
		ObjectName loaderName, Object[] params, String[] signature)
		throws ReflectionException, InstanceAlreadyExistsException,
		MBeanRegistrationException, MBeanException,
		NotCompliantMBeanException, InstanceNotFoundException {
	throw new UnsupportedOperationException("Not supported by PogamutMBeanServer yet...");		
}
 
Example 17
Project: jdk8u-jdk   File: MBeanServerAccessController.java   Source Code and License 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 18
Project: jdk8u-jdk   File: MBeanServerAccessController.java   Source Code and License 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 19
Project: OpenJSharp   File: MBeanServerAccessController.java   Source Code and License 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 20
Project: openjdk-jdk10   File: MBeanServerAccessController.java   Source Code and License 5 votes vote down vote up
/**
 * Call <code>checkRead()</code>, then forward this method to the
 * wrapped object.
 */
@Deprecated
public ObjectInputStream deserialize(String className,
                                     ObjectName loaderName,
                                     byte[] data)
    throws
    InstanceNotFoundException,
    OperationsException,
    ReflectionException {
    checkRead();
    return getMBeanServer().deserialize(className, loaderName, data);
}
 
Example 21
Project: tomcat7   File: JMXProxyServlet.java   Source Code and License 5 votes vote down vote up
/**
 * Sets an MBean attribute's value.
 */
private void setAttributeInternal(String onameStr,
                                  String attributeName,
                                  String value)
    throws OperationsException, MBeanException, ReflectionException {
    ObjectName oname=new ObjectName( onameStr );
    String type=registry.getType(oname, attributeName);
    Object valueObj=registry.convertValue(type, value );
    mBeanServer.setAttribute( oname, new Attribute(attributeName, valueObj));
}
 
Example 22
Project: InventoryAPI   File: NMSUtils.java   Source Code and License 5 votes vote down vote up
public static Object getNMSPlayer( Player player ) throws ReflectionException
{
    try
    {
        Method method = player.getClass().getMethod( "getHandle" );
        return method.invoke( player );
    }
    catch ( NoSuchMethodException | IllegalAccessException | InvocationTargetException e )
    {
        throw new ReflectionException( e, "can't get EntityPlayer" );
    }
}
 
Example 23
Project: lams   File: SpringModelMBean.java   Source Code and License 5 votes vote down vote up
/**
 * Switches the {@link Thread#getContextClassLoader() context ClassLoader} for the
 * managed resources {@link ClassLoader} before allowing the invocation to occur.
 * @see javax.management.modelmbean.ModelMBean#invoke
 */
@Override
public Object invoke(String opName, Object[] opArgs, String[] sig)
		throws MBeanException, ReflectionException {

	ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
	try {
		Thread.currentThread().setContextClassLoader(this.managedResourceClassLoader);
		return super.invoke(opName, opArgs, sig);
	}
	finally {
		Thread.currentThread().setContextClassLoader(currentClassLoader);
	}
}
 
Example 24
Project: OpenJSharp   File: MBeanServerAccessController.java   Source Code and License 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 25
Project: hadoop   File: MetricsSourceAdapter.java   Source Code and License 5 votes vote down vote up
@Override
public Object getAttribute(String attribute)
    throws AttributeNotFoundException, MBeanException, ReflectionException {
  updateJmxCache();
  synchronized(this) {
    Attribute a = attrCache.get(attribute);
    if (a == null) {
      throw new AttributeNotFoundException(attribute +" not found");
    }
    if (LOG.isDebugEnabled()) {
      LOG.debug(attribute +": "+ a);
    }
    return a.getValue();
  }
}
 
Example 26
Project: OpenJSharp   File: MBeanServerAccessController.java   Source Code and License 5 votes vote down vote up
/**
 * Call <code>checkRead()</code>, then forward this method to the
 * wrapped object.
 */
public Object getAttribute(ObjectName name, String attribute)
    throws
    MBeanException,
    AttributeNotFoundException,
    InstanceNotFoundException,
    ReflectionException {
    checkRead();
    return getMBeanServer().getAttribute(name, attribute);
}
 
Example 27
Project: hashsdn-controller   File: DynamicWritableWrapper.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("IllegalCatch")
@Override
public Object invoke(final String actionName, final Object[] params, final String[] signature)
        throws MBeanException, ReflectionException {
    if ("validate".equals(actionName) && (params == null || params.length == 0)
            && (signature == null || signature.length == 0)) {
        try {
            validate();
        } catch (final Exception e) {
            throw new MBeanException(ValidationException.createForSingleException(moduleIdentifier, e));
        }
        return Void.TYPE;
    }
    return super.invoke(actionName, params, signature);
}
 
Example 28
Project: OpenJSharp   File: DefaultMBeanServerInterceptor.java   Source Code and License 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, (Object[]) null,
                       (String[]) null);
}
 
Example 29
Project: OpenJSharp   File: DefaultMBeanServerInterceptor.java   Source Code and License 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 30
Project: openjdk-jdk10   File: MBeanServerAccessController.java   Source Code and License 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 31
Project: apache-tomcat-7.0.73-with-comment   File: JMXProxyServlet.java   Source Code and License 5 votes vote down vote up
/**
 * Sets an MBean attribute's value.
 */
private void setAttributeInternal(String onameStr,
                                  String attributeName,
                                  String value)
    throws OperationsException, MBeanException, ReflectionException {
    ObjectName oname=new ObjectName( onameStr );
    String type=registry.getType(oname, attributeName);
    Object valueObj=registry.convertValue(type, value );
    mBeanServer.setAttribute( oname, new Attribute(attributeName, valueObj));
}
 
Example 32
Project: OpenJSharp   File: MBeanServerAccessController.java   Source Code and License 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 33
Project: openjdk-jdk10   File: MBeanServerAccessController.java   Source Code and License 5 votes vote down vote up
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public Object instantiate(String className,
                          Object params[],
                          String signature[])
    throws ReflectionException, MBeanException {
    checkCreate(className);
    return getMBeanServer().instantiate(className, params, signature);
}
 
Example 34
Project: jdk8u-jdk   File: RMIConnectorLogAttributesTest.java   Source Code and License 5 votes vote down vote up
private JMXConnector connectToServer(JMXConnectorServer server) throws IOException, MalformedObjectNameException, NullPointerException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException, ReflectionException, MBeanException {
    JMXServiceURL url = server.getAddress();
    Map<String, Object> env = new HashMap<String, Object>();
    JMXConnector connector = JMXConnectorFactory.connect(url, env);

    System.out.println("DEBUG: Client connected to RMI at: " + url);

    return connector;
}
 
Example 35
Project: jwala   File: JwalaAuthenticationProvider.java   Source Code and License 5 votes vote down vote up
/**
 *
 * @param authentication
 * @return Authentication
 */
@Override
public Authentication authenticate(Authentication authentication) {
    Realm realm;
    Set<GrantedAuthority> auths = new HashSet<>();
    try {
        realm = getTomcatContextRealm();
        if(realm instanceof NullRealm) {
            throw new ProviderNotFoundException("No Realms configured for Jwala to Authenticate");
        }
        Principal principal = realm.authenticate(authentication.getName(),
                authentication.getCredentials().toString());
        if (principal == null) {
            throw new BadCredentialsException("Username or Password not found.");
        } else {
            if (principal instanceof GenericPrincipal) {
                String[] roles = ((GenericPrincipal) principal).getRoles();
                for (String role : roles) {
                    auths.add(new SimpleGrantedAuthority(role));
                }
            }
            GrantedAuthoritiesMapperImpl grantedAuthoritiesMapper = new GrantedAuthoritiesMapperImpl();
            return new UsernamePasswordAuthenticationToken(authentication.getName(),
                    authentication.getCredentials(), grantedAuthoritiesMapper.mapAuthorities(auths));
        }
    } catch (AttributeNotFoundException | InstanceNotFoundException | MBeanException | ReflectionException e) {
        LOGGER.error("Error getting realms", e);
        throw new ProviderNotFoundException(e.getMessage());
    }
}
 
Example 36
Project: OpenJSharp   File: MBeanServerAccessController.java   Source Code and License 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 37
Project: OpenJSharp   File: MBeanServerAccessController.java   Source Code and License 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 38
Project: jwala   File: JwalaAuthenticationProvider.java   Source Code and License 5 votes vote down vote up
/**
 *
 * @return Tomcat Realms
 * @throws AttributeNotFoundException
 * @throws InstanceNotFoundException
 * @throws MBeanException
 * @throws ReflectionException
 */
public Realm getTomcatContextRealm() throws AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException {
    try {
        ObjectName name = new ObjectName("Catalina", "type", "Engine");
        Engine engine = (Engine) JwalaAuthenticationProvider.getmBeanServer().getAttribute(name, "managedResource");
        return engine.getRealm();
    } catch (MalformedObjectNameException ex) {
        LOGGER.error("Invalid Realm", ex);
    }
    return null;
}
 
Example 39
Project: jdk8u-jdk   File: DefaultMBeanServerInterceptor.java   Source Code and License 4 votes vote down vote up
public Object instantiate(String className) throws ReflectionException,
                                                   MBeanException {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
Example 40
Project: Pogamut3   File: FolderMBean.java   Source Code and License 4 votes vote down vote up
@Override
public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException, ReflectionException {
    // there are no methods to be invoked
    return null;
}
 
Example 41
Project: openjdk-jdk10   File: GmbalMBeanNOPImpl.java   Source Code and License 4 votes vote down vote up
public Object invoke(String actionName, Object[] params, String[] signature)
    throws MBeanException, ReflectionException {

    return null ;
}
 
Example 42
Project: Android_Code_Arbiter   File: OgnlReflectionProvider.java   Source Code and License 4 votes vote down vote up
public Method getGetMethod(Class targetClass, String propertyName)
        throws IntrospectionException, ReflectionException {

    return null;
}
 
Example 43
Project: Pogamut3   File: PogamutMBeanServer.java   Source Code and License 4 votes vote down vote up
@Override
public AttributeList getAttributes(ObjectName name, String[] attributes)
		throws InstanceNotFoundException, ReflectionException {
	return mbs.getAttributes(name, attributes);
}
 
Example 44
Project: openjdk-jdk10   File: RelationSupport.java   Source Code and License 4 votes vote down vote up
private void updateRelationServiceMap(Role newRole,
                                      List<ObjectName> oldRoleValue,
                                      boolean relationServCallFlg,
                                      RelationService relationServ)
    throws IllegalArgumentException,
           RelationServiceNotRegisteredException,
           RelationNotFoundException {

    if (newRole == null ||
        oldRoleValue == null ||
        (relationServCallFlg && relationServ == null)) {
        String excMsg = "Invalid parameter.";
        throw new IllegalArgumentException(excMsg);
    }

    RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1} {2} {3}",
                        newRole, oldRoleValue, relationServCallFlg,
                        relationServ);

    if (relationServCallFlg) {
        // Direct call to the Relation Service
        // Shall not throw a RelationNotFoundException
        try {
            relationServ.updateRoleMap(myRelId,
                                     newRole,
                                     oldRoleValue);
        } catch (RelationNotFoundException exc) {
            throw new RuntimeException(exc.getMessage());
        }

    } else {
        Object[] params = new Object[3];
        params[0] = myRelId;
        params[1] = newRole;
        params[2] = oldRoleValue;
        String[] signature = new String[3];
        signature[0] = "java.lang.String";
        signature[1] = "javax.management.relation.Role";
        signature[2] = "java.util.List";
        // Can throw InstanceNotFoundException if the Relation Service
        // is not registered (to be transformed).
        // Can throw a MBeanException wrapping a RelationNotFoundException:
        // wrapped exception to be thrown
        //
        // Shall not throw a ReflectionException
        try {
            myRelServiceMBeanServer.invoke(myRelServiceName,
                                           "updateRoleMap",
                                           params,
                                           signature);
        } catch (ReflectionException exc1) {
            throw new RuntimeException(exc1.getMessage());
        } catch (InstanceNotFoundException exc2) {
            throw new
                 RelationServiceNotRegisteredException(exc2.getMessage());
        } catch (MBeanException exc3) {
            Exception wrappedExc = exc3.getTargetException();
            if (wrappedExc instanceof RelationNotFoundException) {
                throw ((RelationNotFoundException)wrappedExc);
            } else {
                throw new RuntimeException(wrappedExc.getMessage());
            }
        }
    }

    RELATION_LOGGER.log(Level.TRACE, "RETURN");
    return;
}
 
Example 45
Project: openjdk-jdk10   File: GmbalMBeanNOPImpl.java   Source Code and License 4 votes vote down vote up
public void setAttribute(Attribute attribute)
    throws AttributeNotFoundException, InvalidAttributeValueException,
        MBeanException, ReflectionException {

    // NO-OP
}
 
Example 46
Project: monarch   File: MBeanServerWrapper.java   Source Code and License 4 votes vote down vote up
@Override
public ObjectInstance createMBean(String className, ObjectName name) throws ReflectionException,
    InstanceAlreadyExistsException, MBeanException, NotCompliantMBeanException {
  checkDomain(name);
  return mbs.createMBean(className, name);
}
 
Example 47
Project: openjdk-jdk10   File: DiagnosticCommandImpl.java   Source Code and License 4 votes vote down vote up
@Override
public Object getAttribute(String attribute) throws AttributeNotFoundException,
    MBeanException, ReflectionException {
    throw new AttributeNotFoundException(attribute);
}
 
Example 48
Project: Pogamut3   File: Test01_JMXLogCategories.java   Source Code and License 4 votes vote down vote up
@Test
public void receiveLogEventThroughJMX()
		throws InstanceAlreadyExistsException, MBeanRegistrationException,
		NotCompliantMBeanException, MalformedObjectNameException,
		PogamutException, MalformedURLException, IOException,
		InterruptedException, MBeanException, InstanceNotFoundException,
		AttributeNotFoundException, ReflectionException {
	
	final String testMsg = "TEST LOG MESSAGE FROM receiveLogEventThroughJMX()";
	
	ObjectName parentName = PogamutJMX.getObjectName("testDomain", "root", "test");
	
	
	// export the log on the MBean server
	ILogCategories logCategories = new LogCategories();
	
	String testLogCategoryNameStr = "testLogCategory";
	LogCategory testLog = logCategories.getCategory(testLogCategoryNameStr);
			
	JMXLogCategories jmxLogCategories = new JMXLogCategories(
			logCategories,
			Pogamut.getPlatform().getMBeanServer(),
			parentName
	);

	// connect through RMI and get the proxy
	MBeanServerConnection mbsc = Pogamut.getPlatform().getMBeanServerConnection();
	ObjectName logCatsName = jmxLogCategories.getJMXLogCategoriesName();
	
	// get the name of all log category names
	String[] catNames = (String[]) mbsc.getAttribute(logCatsName, "CategoryNames");		
	boolean found = false;
	for (String catName : catNames) {
		if (catName.equals(testLogCategoryNameStr)) {
			found = true;
			break;
		}
	}
	Assert.assertTrue(testLogCategoryNameStr + " must be among exported log category names", found);
	
	// get the object name for the test log category
	ObjectName testCategoryName = 
		(ObjectName) 
		mbsc.invoke(
			logCatsName, 
			"getJMXLogCategoryName", 
			new Object[]{ testLogCategoryNameStr }, 
			new String[] { "java.lang.String" }
		);
	
	// add the listener
	mbsc.addNotificationListener(testCategoryName,
		new NotificationListener() {

			public void handleNotification(Notification notification,
					Object handback) {
				receivedMessage = notification.getMessage();
				messageReceivedLatch.countDown();
			}
		}, null, this
	);

	// send log event
	if (testLog.isLoggable(Level.INFO)) testLog.info(testMsg);
	// wait
	messageReceivedLatch.await(30000, TimeUnit.MILLISECONDS);
	// compare
	assertTrue("Received message must contain testMsg", receivedMessage.contains(testMsg));
	
	System.out.println("---/// TEST OK ///---");
	
	Pogamut.getPlatform().close();
}
 
Example 49
Project: jdk8u-jdk   File: RelationService.java   Source Code and License 4 votes vote down vote up
/**
 * Retrieves values of roles with given names in given relation.
 *
 * @param relationId  relation id
 * @param roleNameArray  array of names of roles to be retrieved
 *
 * @return a RoleResult object, including a RoleList (for roles
 * successfully retrieved) and a RoleUnresolvedList (for roles not
 * retrieved).
 *
 * @exception RelationServiceNotRegisteredException  if the Relation
 * Service is not registered in the MBean Server
 * @exception IllegalArgumentException  if null parameter
 * @exception RelationNotFoundException  if no relation with given id
 *
 * @see #setRoles
 */
public RoleResult getRoles(String relationId,
                           String[] roleNameArray)
    throws RelationServiceNotRegisteredException,
           IllegalArgumentException,
           RelationNotFoundException {

    if (relationId == null || roleNameArray == null) {
        String excMsg = "Invalid parameter.";
        throw new IllegalArgumentException(excMsg);
    }

    RELATION_LOGGER.entering(RelationService.class.getName(),
            "getRoles", relationId);

    // Can throw RelationServiceNotRegisteredException
    isActive();

    // Can throw a RelationNotFoundException
    Object relObj = getRelation(relationId);

    RoleResult result;

    if (relObj instanceof RelationSupport) {
        // Internal relation
        result = ((RelationSupport)relObj).getRolesInt(roleNameArray,
                                                    true,
                                                    this);
    } else {
        // Relation MBean
        Object[] params = new Object[1];
        params[0] = roleNameArray;
        String[] signature = new String[1];
        try {
            signature[0] = (roleNameArray.getClass()).getName();
        } catch (Exception exc) {
            // OK : This is an array of java.lang.String
            //      so this should never happen...
        }
        // Shall not throw InstanceNotFoundException, ReflectionException
        // or MBeanException
        try {
            result = (RoleResult)
                (myMBeanServer.invoke(((ObjectName)relObj),
                                      "getRoles",
                                      params,
                                      signature));
        } catch (InstanceNotFoundException exc1) {
            throw new RuntimeException(exc1.getMessage());
        } catch (ReflectionException exc2) {
            throw new RuntimeException(exc2.getMessage());
        } catch (MBeanException exc3) {
            throw new
                RuntimeException((exc3.getTargetException()).getMessage());
        }
    }

    RELATION_LOGGER.exiting(RelationService.class.getName(), "getRoles");
    return result;
}
 
Example 50
Project: Android_Code_Arbiter   File: OgnlReflectionProvider.java   Source Code and License 4 votes vote down vote up
public PropertyDescriptor getPropertyDescriptor(Class targetClass,
                                                String propertyName) throws IntrospectionException,
        ReflectionException {
    return null;
}
 
Example 51
Project: OpenJSharp   File: MBeanServerAccessController.java   Source Code and License 4 votes vote down vote up
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public Object instantiate(String className)
    throws ReflectionException, MBeanException {
    checkCreate(className);
    return getMBeanServer().instantiate(className);
}
 
Example 52
Project: hadoop-oss   File: MetricsSourceAdapter.java   Source Code and License 4 votes vote down vote up
@Override
public void setAttribute(Attribute attribute)
    throws AttributeNotFoundException, InvalidAttributeValueException,
           MBeanException, ReflectionException {
  throw new UnsupportedOperationException("Metrics are read-only.");
}
 
Example 53
Project: openjdk-jdk10   File: OldMBeanServerTest.java   Source Code and License 4 votes vote down vote up
public ObjectInstance createMBean(String className, ObjectName name)
throws ReflectionException, InstanceAlreadyExistsException,
        MBeanRegistrationException, MBeanException,
        NotCompliantMBeanException {
    return createMBean(className, name, null, null);
}
 
Example 54
Project: openjdk-jdk10   File: RelationService.java   Source Code and License 4 votes vote down vote up
/**
 * Retrieves the number of MBeans currently referenced in the given role.
 *
 * @param relationId  relation id
 * @param roleName  name of role
 *
 * @return the number of currently referenced MBeans in that role
 *
 * @exception IllegalArgumentException  if null parameter
 * @exception RelationNotFoundException  if no relation with given id
 * @exception RoleNotFoundException  if there is no role with given name
 */
public Integer getRoleCardinality(String relationId,
                                  String roleName)
    throws IllegalArgumentException,
           RelationNotFoundException,
           RoleNotFoundException {

    if (relationId == null || roleName == null) {
        String excMsg = "Invalid parameter.";
        throw new IllegalArgumentException(excMsg);
    }

    RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1}",
                        relationId, roleName);

    // Can throw a RelationNotFoundException
    Object relObj = getRelation(relationId);

    Integer result;

    if (relObj instanceof RelationSupport) {
        // Internal relation
        // Can throw RoleNotFoundException
        result = ((RelationSupport)relObj).getRoleCardinality(roleName);

    } else {
        // Relation MBean
        Object[] params = new Object[1];
        params[0] = roleName;
        String[] signature = new String[1];
        signature[0] = "java.lang.String";
        // Can throw MBeanException wrapping RoleNotFoundException:
        // throw wrapped exception
        //
        // Shall not throw InstanceNotFoundException or ReflectionException
        try {
            result = (Integer)
                (myMBeanServer.invoke(((ObjectName)relObj),
                                      "getRoleCardinality",
                                      params,
                                      signature));
        } catch (InstanceNotFoundException exc1) {
            throw new RuntimeException(exc1.getMessage());
        } catch (ReflectionException exc2) {
            throw new RuntimeException(exc2.getMessage());
        } catch (MBeanException exc3) {
            Exception wrappedExc = exc3.getTargetException();
            if (wrappedExc instanceof RoleNotFoundException) {
                throw ((RoleNotFoundException)wrappedExc);
            } else {
                throw new RuntimeException(wrappedExc.getMessage());
            }
        }
    }

    RELATION_LOGGER.log(Level.TRACE, "RETURN");
    return result;
}
 
Example 55
Project: Android_Code_Arbiter   File: OgnlReflectionProvider.java   Source Code and License 4 votes vote down vote up
public void setValue(String expression, Map<String, Object> context, Object root,
                     Object value) throws ReflectionException {
}
 
Example 56
Project: OpenJSharp   File: XSheet.java   Source Code and License 4 votes vote down vote up
private void displayMBeanNode(final DefaultMutableTreeNode node) {
    final XNodeInfo uo = (XNodeInfo) node.getUserObject();
    if (!uo.getType().equals(Type.MBEAN)) {
        return;
    }
    mbean = (XMBean) uo.getData();
    SwingWorker<MBeanInfo, Void> sw = new SwingWorker<MBeanInfo, Void>() {
        @Override
        public MBeanInfo doInBackground() throws InstanceNotFoundException,
                IntrospectionException, ReflectionException, IOException {
            return mbean.getMBeanInfo();
        }
        @Override
        protected void done() {
            try {
                MBeanInfo mbi = get();
                if (mbi != null) {
                    if (!isSelectedNode(node, currentNode)) {
                        return;
                    }
                    mbeanInfo.addMBeanInfo(mbean, mbi);
                    invalidate();
                    mainPanel.removeAll();
                    mainPanel.add(mbeanInfo, BorderLayout.CENTER);
                    southPanel.setVisible(false);
                    southPanel.removeAll();
                    validate();
                    repaint();
                }
            } catch (Exception e) {
                Throwable t = Utils.getActualException(e);
                if (JConsole.isDebug()) {
                    System.err.println("Couldn't get MBeanInfo for MBean [" +
                            mbean.getObjectName() + "]");
                    t.printStackTrace();
                }
                showErrorDialog(t.toString(),
                        Messages.PROBLEM_DISPLAYING_MBEAN);
            }
        }
    };
    sw.execute();
}
 
Example 57
Project: OpenJSharp   File: XSheet.java   Source Code and License 4 votes vote down vote up
private void displayMBeanOperationsNode(final DefaultMutableTreeNode node) {
    final XNodeInfo uo = (XNodeInfo) node.getUserObject();
    if (!uo.getType().equals(Type.OPERATIONS)) {
        return;
    }
    mbean = (XMBean) uo.getData();
    SwingWorker<MBeanInfo, Void> sw = new SwingWorker<MBeanInfo, Void>() {
        @Override
        public MBeanInfo doInBackground() throws InstanceNotFoundException,
                IntrospectionException, ReflectionException, IOException {
            return mbean.getMBeanInfo();
        }
        @Override
        protected void done() {
            try {
                MBeanInfo mbi = get();
                if (mbi != null) {
                    if (!isSelectedNode(node, currentNode)) {
                        return;
                    }
                    mbeanOperations.loadOperations(mbean, mbi);
                    invalidate();
                    mainPanel.removeAll();
                    JPanel borderPanel = new JPanel(new BorderLayout());
                    borderPanel.setBorder(BorderFactory.createTitledBorder(
                            Messages.OPERATION_INVOCATION));
                    borderPanel.add(new JScrollPane(mbeanOperations));
                    mainPanel.add(borderPanel, BorderLayout.CENTER);
                    southPanel.setVisible(false);
                    southPanel.removeAll();
                    validate();
                    repaint();
                }
            } catch (Exception e) {
                Throwable t = Utils.getActualException(e);
                if (JConsole.isDebug()) {
                    System.err.println("Problem displaying MBean " +
                            "operations for MBean [" +
                            mbean.getObjectName() + "]");
                    t.printStackTrace();
                }
                showErrorDialog(t.toString(),
                        Messages.PROBLEM_DISPLAYING_MBEAN);
            }
        }
    };
    sw.execute();
}
 
Example 58
Project: jdk8u-jdk   File: OldMBeanServerTest.java   Source Code and License 4 votes vote down vote up
public Object invoke(
        ObjectName name, String operationName, Object[] params,
        String[] signature)
throws InstanceNotFoundException, MBeanException, ReflectionException {
    return getMBean(name).invoke(operationName, params, signature);
}
 
Example 59
Project: OpenJSharp   File: DefaultMBeanServerInterceptor.java   Source Code and License 4 votes vote down vote up
public Object instantiate(String className, ObjectName loaderName) throws ReflectionException,
                                                                          MBeanException,
                                                                          InstanceNotFoundException {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
Example 60
Project: jdk8u-jdk   File: OldMBeanServerTest.java   Source Code and License 4 votes vote down vote up
public AttributeList getAttributes(ObjectName name, String[] attributes)
throws InstanceNotFoundException, ReflectionException {
    return getMBean(name).getAttributes(attributes);
}