⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simpledynamic.java

📁 Sun公司官方网站上下载的JDK文档
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        AttributeList resultList = new AttributeList();        // If attributeNames is empty, nothing more to do        //        if (attributes.isEmpty())            return resultList;        // For each attribute, try to set it and add to the result list if        // successfull        //        for (Iterator i = attributes.iterator(); i.hasNext();) {            Attribute attr = (Attribute) i.next();            try {                setAttribute(attr);                String name = attr.getName();                Object value = getAttribute(name);                 resultList.add(new Attribute(name,value));            } catch(Exception e) {                e.printStackTrace();            }        }        return resultList;    }    /**     * Allows an operation to be invoked on the Dynamic MBean.     */    public Object invoke(String operationName,                         Object params[],                         String signature[])        throws MBeanException, ReflectionException {        // Check operationName is not null to avoid NullPointerException        // later on        //        if (operationName == null) {            throw new RuntimeOperationsException(                 new IllegalArgumentException("Operation name cannot be null"),                  "Cannot invoke a null operation in " + dClassName);        }        // Check for a recognized operation name and call the corresponding        // operation        //        if (operationName.equals("reset")) {            reset();            return null;        } else {             // Unrecognized operation name            //            throw new ReflectionException(                                new NoSuchMethodException(operationName),                                 "Cannot find the operation " + operationName +                                " in " + dClassName);        }    }    /**     * This method provides the exposed attributes and operations of the     * Dynamic MBean. It provides this information using an MBeanInfo object.     */    public MBeanInfo getMBeanInfo() {        // Return the information we want to expose for management:        // the dMBeanInfo private field has been built at instanciation time        //        return dMBeanInfo;    }    /*     * -----------------------------------------------------     * OTHER PUBLIC METHODS     * -----------------------------------------------------     */    /**     * Getter: get the "State" attribute of the "SimpleDynamic" dynamic MBean.     */    public String getState() {        return state;    }    /**      * Setter: set the "State" attribute of the "SimpleDynamic" dynamic MBean.     */    public void setState(String s) {        state = s;        nbChanges++;    }    /**     * Getter: get the "NbChanges" attribute of the "SimpleDynamic" dynamic     * MBean.     */    public Integer getNbChanges() {        return new Integer(nbChanges);    }    /**     * Operation: reset to their initial values the "State" and "NbChanges"      * attributes of the "SimpleDynamic" dynamic MBean.      */    public void reset() {        AttributeChangeNotification acn =            new AttributeChangeNotification(this,                                            0,                                            0,                                            "NbChanges reset",                                            "NbChanges",                                            "Integer",                                            new Integer(nbChanges),                                            new Integer(0));        state = "initial state";        nbChanges = 0;        nbResets++;        sendNotification(acn);    }    /**     * Return the "NbResets" property.      * This method is not a Getter in the JMX sense because      * it is not returned by the getMBeanInfo() method.     */    public Integer getNbResets() {        return new Integer(nbResets);    }    /*     * -----------------------------------------------------     * PRIVATE METHODS     * -----------------------------------------------------     */      /**     * Build the private dMBeanInfo field,     * which represents the management interface exposed by the MBean,     * that is, the set of attributes, constructors, operations and     * notifications which are available for management.      *     * A reference to the dMBeanInfo object is returned by the getMBeanInfo()     * method of the DynamicMBean interface. Note that, once constructed, an     * MBeanInfo object is immutable.     */    private void buildDynamicMBeanInfo() {        dAttributes[0] =            new MBeanAttributeInfo("State",                                   "java.lang.String",                                   "State string.",                                   true,                                   true,                                   false);        dAttributes[1] =            new MBeanAttributeInfo("NbChanges",                                   "java.lang.Integer",                                   "Number of times the " +                                   "State string has been changed.",                                   true,                                   false,                                   false);        Constructor[] constructors = this.getClass().getConstructors();        dConstructors[0] =            new MBeanConstructorInfo("Constructs a " +                                     "SimpleDynamic object",                                     constructors[0]);        MBeanParameterInfo[] params = null;        dOperations[0] =            new MBeanOperationInfo("reset",                                   "reset State and NbChanges " +                                   "attributes to their initial values",                                   params ,                                    "void",                                    MBeanOperationInfo.ACTION);        dNotifications[0] =            new MBeanNotificationInfo(            new String[] { AttributeChangeNotification.ATTRIBUTE_CHANGE },            AttributeChangeNotification.class.getName(),            "This notification is emitted when the reset() method is called.");        dMBeanInfo = new MBeanInfo(dClassName,                                   dDescription,                                   dAttributes,                                   dConstructors,                                   dOperations,                                   dNotifications);    }    /*     * -----------------------------------------------------     * PRIVATE VARIABLES     * -----------------------------------------------------     */    private String state = "initial state";    private int nbChanges = 0;    private int nbResets = 0;    private String dClassName = this.getClass().getName();    private String dDescription = "Simple implementation of a dynamic MBean.";    private MBeanAttributeInfo[] dAttributes =        new MBeanAttributeInfo[2];    private MBeanConstructorInfo[] dConstructors =        new MBeanConstructorInfo[1];    private MBeanNotificationInfo[] dNotifications =        new MBeanNotificationInfo[1];    private MBeanOperationInfo[] dOperations =        new MBeanOperationInfo[1];    private MBeanInfo dMBeanInfo = null;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -