Java MBean invoke(Logger logger, MBeanServer mbeanServer, ObjectName mbeanName, String methodName, Object... arguments)

Here you can find the source of invoke(Logger logger, MBeanServer mbeanServer, ObjectName mbeanName, String methodName, Object... arguments)

Description

Utility method to invoke methods on MBeans.

License

Apache License

Parameter

Parameter Description
logger the logger to use to log exceptions.
mbeanServer the mbean server.
mbeanName the name of the meban to invoke a method on.
methodName the name of the method to invoke.
arguments method arguments. Signature is generated based on runtime type of arguments.

Return

the object returned by the method invocation or null.

Declaration

public static Object invoke(Logger logger, MBeanServer mbeanServer,
        ObjectName mbeanName, String methodName, Object... arguments) 

Method Source Code

//package com.java2s;
/*/*from www  . j  a  v a 2s  . c  om*/
 * Copyright 2012 The Clustermeister Team.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import org.slf4j.Logger;

public class Main {
    /**
     * Utility method to invoke methods on MBeans.
     *
     * Exceptions are logged to the supplies logger.
     *
     * @param logger        the logger to use to log exceptions.
     * @param mbeanServer   the mbean server.
     * @param mbeanName     the name of the meban to invoke a method on.
     * @param methodName    the name of the method to invoke.
     * @param arguments     method arguments. Signature is generated based on runtime type of arguments.
     * 
     * @return the object returned by the method invocation or null.
     */
    public static Object invoke(Logger logger, MBeanServer mbeanServer,
            ObjectName mbeanName, String methodName, Object... arguments) {
        try {
            String[] signature;
            if (arguments != null) {
                signature = new String[arguments.length];
                for (int i = 0; i < arguments.length; ++i) {
                    signature[i] = arguments[i].getClass()
                            .getCanonicalName();
                }
            } else {
                signature = null;
            }
            return mbeanServer.invoke(mbeanName, methodName, arguments,
                    signature);
        } catch (InstanceNotFoundException ex) {
            logger.warn("No such MBean instance found.", ex);
        } catch (MBeanException ex) {
            logger.warn("MBean raised exception during method invokation.",
                    ex);
        } catch (ReflectionException ex) {
            logger.warn("Method not found.", ex);
        }

        return null;
    }
}

Related

  1. getOperation(MBeanInfo info, String opName)
  2. getProxy(MBeanServerConnection connection, ObjectName objectName, final Class objectClass)
  3. getServerId(MBeanServer server)
  4. infoArrayEquals(MBeanParameterInfo[] a, MBeanParameterInfo[] a2)
  5. infoEquals(MBeanInfo one, MBeanInfo two)
  6. invoke(MBeanServer mbs, ObjectName name, String operationName, Object params[], String signature[])
  7. invokeStopOperation(ObjectName name, MBeanServer server)
  8. isRegistered(MBeanServer mbs, ObjectName objectName)
  9. isServerStarted(MBeanServerConnection server)