Search in sources :

Example 36 with Var

use of com.google.errorprone.annotations.Var in project infrautils by opendaylight.

the class AbstractMXBean method readMBeanAttribute.

/**
 * Read an mbean attribute from the platform MBean server.
 *
 * @return Object if successfully executed, "" otherwise.
 */
public Object readMBeanAttribute(String attribute) {
    @Var Object attributeObj = "";
    try {
        ObjectName objectName = this.getMBeanObjectName();
        MBeanServer platformMbeanServer = ManagementFactory.getPlatformMBeanServer();
        attributeObj = platformMbeanServer.getAttribute(objectName, attribute);
    } catch (AttributeNotFoundException | InstanceNotFoundException | MBeanException | ReflectionException | MalformedObjectNameException e) {
        LOG.info("Failed when reading MBean attribute", e);
    }
    return attributeObj;
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) MalformedObjectNameException(javax.management.MalformedObjectNameException) Var(com.google.errorprone.annotations.Var) InstanceNotFoundException(javax.management.InstanceNotFoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Example 37 with Var

use of com.google.errorprone.annotations.Var in project infrautils by opendaylight.

the class AbstractMXBean method invokeMBeanFunction.

/**
 * invoke an mbean function with the platform MBean server.
 *
 * @return Object if successfully executed, "" otherwise.
 */
public Object invokeMBeanFunction(String functionName) {
    @Var Object result = "";
    try {
        ObjectName objectName = this.getMBeanObjectName();
        MBeanServer mplatformMbeanServer = ManagementFactory.getPlatformMBeanServer();
        result = mplatformMbeanServer.invoke(objectName, functionName, null, null);
    } catch (InstanceNotFoundException | MBeanException | ReflectionException | MalformedObjectNameException e) {
        LOG.error("Failed when executing MBean function", e);
    }
    return result;
}
Also used : ReflectionException(javax.management.ReflectionException) MalformedObjectNameException(javax.management.MalformedObjectNameException) Var(com.google.errorprone.annotations.Var) InstanceNotFoundException(javax.management.InstanceNotFoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Aggregations

Var (com.google.errorprone.annotations.Var)37 Test (org.junit.Test)9 Path (java.nio.file.Path)7 InstanceNotFoundException (javax.management.InstanceNotFoundException)6 MalformedObjectNameException (javax.management.MalformedObjectNameException)6 ObjectName (javax.management.ObjectName)6 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 ArrayList (java.util.ArrayList)4 Nullable (javax.annotation.Nullable)4 MBeanException (javax.management.MBeanException)4 MBeanServer (javax.management.MBeanServer)4 ReflectionException (javax.management.ReflectionException)4 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 IOException (java.io.IOException)3 AccessibleObject (java.lang.reflect.AccessibleObject)3 ClassPath (com.google.common.reflect.ClassPath)2 EqualsTester (com.google.common.testing.EqualsTester)2 UnicastRemoteObject (java.rmi.server.UnicastRemoteObject)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeUnit (java.util.concurrent.TimeUnit)2