jdk/test/javax/management/remote/mandatory/passwordAccessFile/SimpleStandard.java
author ykantser
Thu, 07 May 2015 09:11:49 +0200
changeset 30376 2ccf2cf7ea48
parent 5506 202f599c92aa
permissions -rw-r--r--
8078896: Add @modules as needed to the jdk_svc tests Reviewed-by: alanb, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * build     @BUILD_TAG_PLACEHOLDER@
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @COPYRIGHT_MINI_LEGAL_NOTICE_PLACEHOLDER@
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * Simple definition of a standard MBean, named "SimpleStandard".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * The "SimpleStandard" standard MBean shows how to expose attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * and operations for management by implementing its corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * "SimpleStandardMBean" management interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * This MBean has two attributes and one operation exposed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * for management by a JMX agent:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *      - the read/write "State" attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *      - the read only "NbChanges" attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *      - the "reset()" operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * This object also has one property and one method not exposed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * for management by a JMX agent:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *      - the "NbResets" property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *      - the "getNbResets()" method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.management.AttributeChangeNotification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import javax.management.NotificationBroadcasterSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public class SimpleStandard
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    extends NotificationBroadcasterSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    implements SimpleStandardMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * -----------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * CONSTRUCTORS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * -----------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /* "SimpleStandard" does not provide any specific constructors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * However, "SimpleStandard" is JMX compliant with regards to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * contructors because the default contructor SimpleStandard()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * provided by the Java compiler is public.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * -----------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * IMPLEMENTATION OF THE SimpleStandardMBean INTERFACE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * -----------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * Getter: get the "State" attribute of the "SimpleStandard" standard MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @return the current value of the "State" attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public String getState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        return state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Setter: set the "State" attribute of the "SimpleStandard" standard MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @param <VAR>s</VAR> the new value of the "State" attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public void setState(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        state = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        nbChanges++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * Getter: get the "NbChanges" attribute of the "SimpleStandard" standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @return the current value of the "NbChanges" attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public int getNbChanges() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        return nbChanges;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Operation: reset to their initial values the "State" and "NbChanges"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * attributes of the "SimpleStandard" standard MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public void reset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        AttributeChangeNotification acn =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            new AttributeChangeNotification(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                                            0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                                            0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                            "NbChanges reset",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                                            "NbChanges",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                                            "Integer",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                                            new Integer(nbChanges),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                            new Integer(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        state = "initial state";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        nbChanges = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        nbResets++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        sendNotification(acn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * -----------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * METHOD NOT EXPOSED FOR MANAGEMENT BY A JMX AGENT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * -----------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Return the "NbResets" property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * This method is not a Getter in the JMX sense because it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * is not exposed in the "SimpleStandardMBean" interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @return the current value of the "NbResets" property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public int getNbResets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return nbResets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * -----------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * ATTRIBUTES ACCESSIBLE FOR MANAGEMENT BY A JMX AGENT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * -----------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    private String state = "initial state";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    private int nbChanges = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * -----------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * PROPERTY NOT ACCESSIBLE FOR MANAGEMENT BY A JMX AGENT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * -----------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    private int nbResets = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
}