jdk/test/javax/management/mxbean/Basic.java
author olagneau
Fri, 18 Dec 2015 17:42:06 +0100
changeset 34827 de746e7eb1e3
permissions -rw-r--r--
8058865: JMX Test Refactoring Reviewed-by: jbachorik
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34827
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
     1
/*
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
     2
 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
     4
 *
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
     7
 * published by the Free Software Foundation.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
     8
 *
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    13
 * accompanied this code).
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    14
 *
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    18
 *
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    21
 * questions.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    22
 */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    23
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    24
import java.util.Collection;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    25
import java.util.Date;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    26
import java.util.HashMap;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    27
import java.util.HashSet;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    28
import java.util.List;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    29
import java.util.Map;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    30
import java.util.concurrent.Callable;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    31
import java.util.concurrent.ExecutorService;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    32
import java.util.concurrent.Executors;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    33
import java.util.concurrent.Future;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    34
import javax.management.Descriptor;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    35
import javax.management.ImmutableDescriptor;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    36
import javax.management.ListenerNotFoundException;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    37
import javax.management.MBeanNotificationInfo;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    38
import javax.management.MBeanRegistration;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    39
import javax.management.MBeanServer;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    40
import javax.management.Notification;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    41
import javax.management.NotificationBroadcasterSupport;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    42
import javax.management.NotificationEmitter;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    43
import javax.management.NotificationFilter;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    44
import javax.management.NotificationListener;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    45
import javax.management.ObjectName;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    46
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    47
/**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    48
 * Class Basic
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    49
 * Basic Description
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    50
 */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    51
public class Basic implements BasicMXBean, NotificationEmitter,
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    52
                              MBeanRegistration {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    53
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    54
    public static final String EXCEPTION_MESSAGE = "from Basic";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    55
    public static final String NOTIFICATION_MESSAGE = "from Basic";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    56
    /** Attribute : IntAtt */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    57
    private int intAtt = 0;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    58
    /** Attribute : IntegerAtt */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    59
    private Integer integerAtt = 0;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    60
    /** Attribute : BoolAtt */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    61
    private boolean boolAtt = false;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    62
    /** Attribute : BooleanAtt */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    63
    private Boolean booleanAtt = false;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    64
    /** Attribute : StringAtt */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    65
    private String stringAtt = null;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    66
    /** Attribute : DateAtt */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    67
    private Date dateAtt = null;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    68
    /** Attribute : ObjectNameAtt */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    69
    private ObjectName objectNameAtt = null;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    70
    /** Attribute : NotifDescriptorAsMapAtt */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    71
    private Map<String, String> notifDescriptorAsMapAtt = null;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    72
    /** Attribute : NotifDescriptorAtt */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    73
    private Descriptor notifDescriptorAtt = null;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    74
    /** Attribute : SqeParameter */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    75
    private SqeParameter sqeParameterAtt = null;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    76
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    77
    /* Creates a new instance of Basic */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    78
    @SqeDescriptorKey("CONSTRUCTOR Basic")
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    79
    public Basic() {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    80
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    81
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    82
    /* Creates a new instance of Basic */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    83
    @SqeDescriptorKey("CONSTRUCTOR Basic")
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    84
    public Basic(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    85
            @SqeDescriptorKey("CONSTRUCTOR PARAMETER SqeParameter") SqeParameter param) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    86
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    87
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    88
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    89
     * Get int attribute
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    90
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    91
    public int getIntAtt() {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    92
        return intAtt;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    93
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    94
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    95
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    96
     * Set int attribute
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    97
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    98
    public void setIntAtt(int value) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
    99
        intAtt = value;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   100
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   101
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   102
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   103
     * Get Integer attribute
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   104
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   105
    public Integer getIntegerAtt() {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   106
        return integerAtt;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   107
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   108
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   109
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   110
     * Set Integer attribute
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   111
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   112
    public void setIntegerAtt(Integer value) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   113
        integerAtt = value;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   114
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   115
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   116
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   117
     * Get boolean attribute
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   118
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   119
    public boolean getBoolAtt() {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   120
        return boolAtt;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   121
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   122
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   123
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   124
     * Set boolean attribute
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   125
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   126
    public void setBoolAtt(boolean value) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   127
        boolAtt = value;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   128
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   129
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   130
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   131
     * Get Boolean attribute
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   132
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   133
    public Boolean getBooleanAtt() {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   134
        return booleanAtt;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   135
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   136
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   137
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   138
     * Set Boolean attribute
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   139
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   140
    public void setBooleanAtt(Boolean value) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   141
        booleanAtt = value;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   142
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   143
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   144
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   145
     * Get String attribute
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   146
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   147
    public String getStringAtt() {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   148
        return stringAtt;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   149
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   150
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   151
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   152
     * Set String attribute
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   153
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   154
    public void setStringAtt(String value) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   155
        stringAtt = value;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   156
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   157
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   158
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   159
     * Get Date attribute
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   160
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   161
    public Date getDateAtt() {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   162
        return dateAtt;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   163
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   164
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   165
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   166
     * Set Date attribute
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   167
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   168
    public void setDateAtt(Date value) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   169
        dateAtt = value;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   170
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   171
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   172
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   173
     * Get ObjectName attribute
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   174
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   175
    public ObjectName getObjectNameAtt() {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   176
        return objectNameAtt;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   177
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   178
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   179
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   180
     * Set ObjectName attribute
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   181
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   182
    public void setObjectNameAtt(ObjectName value) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   183
        objectNameAtt = value;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   184
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   185
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   186
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   187
     * Get SqeParameter attribute
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   188
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   189
    public SqeParameter getSqeParameterAtt() throws Exception {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   190
        if (sqeParameterAtt == null) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   191
            sqeParameterAtt = new SqeParameter();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   192
            sqeParameterAtt.setGlop("INITIALIZED");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   193
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   194
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   195
        return sqeParameterAtt;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   196
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   197
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   198
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   199
     * Set SqeParameter attribute
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   200
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   201
    public void setSqeParameterAtt(SqeParameter value) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   202
        sqeParameterAtt = value;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   203
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   204
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   205
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   206
     * Get the Descriptor used to build the NotificationInfo
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   207
     * of emitted notifications.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   208
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   209
    public Map<String, String> getNotifDescriptorAsMapAtt() {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   210
        if (notifDescriptorAsMapAtt == null) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   211
            initNotifDescriptorAtt();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   212
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   213
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   214
        return notifDescriptorAsMapAtt;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   215
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   216
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   217
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   218
     * Set the Descriptor used to build the NotificationInfo
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   219
     * of emitted notifications.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   220
     * <br>A Map<String, Object> would better fit Descriptor needs but then
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   221
     * it is not convertible according the MXBean specification so the MBean
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   222
     * registration fails.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   223
     * As we plan to test our custom Descriptor finds its way into
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   224
     * the metadata of emitted notifications, String is good enough.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   225
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   226
    public void setNotifDescriptorAsMapAtt(Map<String, String> value) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   227
        notifDescriptorAsMapAtt = new HashMap<String, String>(value);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   228
        notifDescriptorAtt = new ImmutableDescriptor(value);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   229
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   230
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   231
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   232
     * Do nothing
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   233
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   234
    public void doNothing() {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   235
        // I said NOTHING !
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   236
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   237
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   238
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   239
     * Do take SqeParameter as a parameter
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   240
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   241
    public void doWeird(SqeParameter param) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   242
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   243
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   244
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   245
     * Throw an Exception
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   246
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   247
    public void throwException() throws Exception {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   248
        throw new Exception(EXCEPTION_MESSAGE);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   249
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   250
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   251
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   252
     * Throw an Error
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   253
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   254
    public void throwError() {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   255
        throw new InternalError(EXCEPTION_MESSAGE);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   256
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   257
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   258
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   259
     * Reset all attributes
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   260
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   261
    public void reset() {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   262
        intAtt = 0;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   263
        integerAtt = 0;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   264
        boolAtt = false;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   265
        booleanAtt = Boolean.FALSE;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   266
        stringAtt = null;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   267
        dateAtt = null;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   268
        objectNameAtt = null;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   269
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   270
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   271
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   272
     * Returns the weather for the coming days
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   273
     * @param verbose <code>boolean</code> verbosity
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   274
     * @throws java.lang.Exception <code>storm</code>
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   275
     * @return <code>ObjectName</code>
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   276
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   277
    public Weather getWeather(boolean verbose)
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   278
            throws java.lang.Exception {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   279
        return Weather.SUNNY;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   280
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   281
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   282
    // Starting here are the 4 methods of MBeanRegistration interface.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   283
    // We use that to grab the ObjectName the MBean is registered with.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   284
    //
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   285
    public ObjectName preRegister(MBeanServer server, ObjectName name)
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   286
            throws Exception {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   287
        // Grab a reference on the MBeanServer we're registered in.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   288
        mbs = server;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   289
        // Compute the name we're registered with.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   290
        if (name != null) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   291
            mbeanName = name;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   292
            return name;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   293
        } else {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   294
            mbeanName =
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   295
                new ObjectName("sqe:type=" + Basic.class.getName());
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   296
            return mbeanName;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   297
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   298
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   299
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   300
    public void postRegister(Boolean registrationDone) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   301
        // Do nothing
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   302
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   303
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   304
    public void preDeregister() throws Exception {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   305
        // Do nothing
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   306
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   307
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   308
    public void postDeregister() {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   309
        // Do nothing
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   310
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   311
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   312
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   313
     * Send one Notification of the provided notifType type.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   314
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   315
    public void sendNotification(String notifType) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   316
        Notification notification = null;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   317
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   318
        if (notifType.equals(NOTIF_TYPE_0)) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   319
            notification = new Notification(NOTIF_TYPE_0,
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   320
                    mbeanName,
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   321
                    seqNumber,
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   322
                    NOTIFICATION_MESSAGE);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   323
        } else if (notifType.equals(NOTIF_TYPE_1)) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   324
            notification = new SqeNotification(NOTIF_TYPE_1,
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   325
                    mbeanName,
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   326
                    seqNumber,
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   327
                    NOTIFICATION_MESSAGE);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   328
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   329
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   330
        seqNumber++;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   331
        broadcaster.sendNotification(notification);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   332
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   333
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   334
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   335
     * That method starts a set of threads, each thread sends a given number of
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   336
     * notifications.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   337
     * The number of threads can be set via the attribute numOfNotificationSenders.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   338
     * The number of notification sent by each thread can be set via
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   339
     * the attribute numOfNotificationSenderLoops.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   340
     * Depending on the parameter customNotification we send either custom
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   341
     * notification(s) or MBeanServer registration and unregistration notification(s).
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   342
     * When customNotification=true the total number of notification(s) sent is
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   343
     * (numOfNotificationSenders * numOfNotificationSenderLoops). They are
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   344
     * sequentially of type NOTIF_TYPE_0 then NOTIF_TYPE_1 and so on.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   345
     *
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   346
     * When customNotification=false the total number of notification(s) sent is
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   347
     * (numOfNotificationSenders * numOfNotificationSenderLoops) registration
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   348
     * notification(s)
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   349
     * +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   350
     * (numOfNotificationSenders * numOfNotificationSenderLoops) unregistration
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   351
     * notification(s)
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   352
     *
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   353
     * @throws java.lang.Exception
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   354
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   355
    public void sendNotificationWave(boolean customNotification) throws
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   356
            Exception {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   357
        // Build the set of notification sender.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   358
        Collection<Callable<Integer>> tasks =
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   359
                new HashSet<Callable<Integer>>(numOfNotificationSenders);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   360
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   361
        for (int i = 1; i <= numOfNotificationSenders; i++) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   362
            tasks.add(new NotifSender(numOfNotificationSenderLoops,
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   363
                    customNotification, i));
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   364
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   365
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   366
        // Start all notification sender in parallel.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   367
        ExecutorService execServ = null;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   368
        try {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   369
            execServ = Executors.newFixedThreadPool(numOfNotificationSenders);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   370
            List<Future<Integer>> taskHandlers = execServ.invokeAll(tasks);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   371
            checkNotifSenderThreadStatus(taskHandlers);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   372
        } finally {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   373
            if (!execServ.isShutdown()) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   374
                execServ.shutdown();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   375
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   376
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   377
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   378
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   379
    public void setNumOfNotificationSenders(int value) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   380
        numOfNotificationSenders = value;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   381
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   382
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   383
    public void setNumOfNotificationSenderLoops(int value) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   384
        numOfNotificationSenderLoops = value;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   385
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   386
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   387
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   388
     * MBean Notification support
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   389
     * You shouldn't update these methods
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   390
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   391
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   392
    public void addNotificationListener(NotificationListener listener,
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   393
                                        NotificationFilter filter,
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   394
                                        Object handback)
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   395
            throws IllegalArgumentException {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   396
        broadcaster.addNotificationListener(listener, filter, handback);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   397
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   398
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   399
    public MBeanNotificationInfo[] getNotificationInfo() {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   400
        if (notifDescriptorAtt == null) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   401
            initNotifDescriptorAtt();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   402
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   403
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   404
        return new MBeanNotificationInfo[]{
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   405
                    new MBeanNotificationInfo(new String[]{
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   406
                        NOTIF_TYPE_0
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   407
                    },
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   408
                    javax.management.Notification.class.getName(),
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   409
                    "Standard JMX Notification",
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   410
                    notifDescriptorAtt),
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   411
                    new MBeanNotificationInfo(new String[]{
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   412
                        NOTIF_TYPE_1
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   413
                    },
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   414
                    SqeNotification.class.getName(),
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   415
                    "SQE Notification",
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   416
                    notifDescriptorAtt)
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   417
                };
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   418
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   419
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   420
    public void removeNotificationListener(NotificationListener listener)
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   421
            throws ListenerNotFoundException {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   422
        broadcaster.removeNotificationListener(listener);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   423
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   424
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   425
    public void removeNotificationListener(NotificationListener listener,
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   426
                                           NotificationFilter filter,
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   427
                                           Object handback)
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   428
            throws ListenerNotFoundException {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   429
        broadcaster.removeNotificationListener(listener, filter, handback);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   430
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   431
    // </editor-fold>
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   432
    private synchronized long getNextSeqNumber() {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   433
        return seqNumber++;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   434
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   435
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   436
    private void initNotifDescriptorAtt() {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   437
        String key = "CRABE";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   438
        String value = "TAMBOUR";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   439
        notifDescriptorAtt =
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   440
                new ImmutableDescriptor(new String[]{key + "=" + value});
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   441
        notifDescriptorAsMapAtt =
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   442
                new HashMap<String, String>();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   443
        notifDescriptorAsMapAtt.put(key, value);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   444
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   445
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   446
    private void checkNotifSenderThreadStatus(
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   447
            List<Future<Integer>> taskHandlers)
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   448
            throws Exception {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   449
        String msgTag = "Basic::checkNotifSenderThreadStatus: ";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   450
        // Grab back status of each notification sender.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   451
        for (Future<Integer> f : taskHandlers) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   452
            if (f.isCancelled()) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   453
                String message = msgTag +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   454
                        "---- ERROR : One thread has been cancelled";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   455
                System.out.println(message);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   456
                throw new RuntimeException(message);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   457
            } else {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   458
                Integer effectiveNumOfLoops = f.get();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   459
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   460
                if (effectiveNumOfLoops != numOfNotificationSenderLoops) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   461
                    String message = msgTag + "---- ERROR : One thread did " +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   462
                            effectiveNumOfLoops + " loops in place of " +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   463
                            numOfNotificationSenderLoops;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   464
                    System.out.println(message);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   465
                    throw new RuntimeException(message);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   466
                }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   467
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   468
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   469
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   470
    //
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   471
    private int numOfNotificationSenderLoops = 2;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   472
    private int numOfNotificationSenders = 13;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   473
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   474
    private class NotifSender implements Callable<Integer> {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   475
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   476
        private int cycles;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   477
        private boolean customNotification;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   478
        private int senderID;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   479
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   480
        public NotifSender(int cycles, boolean customNotification, int id) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   481
            this.cycles = cycles;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   482
            this.customNotification = customNotification;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   483
            this.senderID = id;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   484
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   485
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   486
        public Integer call() throws Exception {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   487
            int callsDone = 0;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   488
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   489
            try {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   490
                for (int i = 1; i <= cycles; i++) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   491
                    if (customNotification) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   492
                        if (i % 2 == 0) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   493
                            sendNotification(NOTIF_TYPE_0);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   494
                        } else {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   495
                            sendNotification(NOTIF_TYPE_1);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   496
                        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   497
                    } else {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   498
                        ObjectName mbeanName = new ObjectName("SQE:type=" +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   499
                                mbeanClassName + ",senderID=" + senderID);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   500
                        mbs.createMBean(mbeanClassName, mbeanName);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   501
                        mbs.unregisterMBean(mbeanName);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   502
                    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   503
                    callsDone++;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   504
                }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   505
            } catch (Exception e) {
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   506
                System.out.println("NotifSender::call: (ERROR) Thread [" + senderID +
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   507
                        "] failed after " + callsDone + " cycles");
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   508
                throw e;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   509
            }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   510
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   511
            return Integer.valueOf(callsDone);
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   512
        }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   513
    }
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   514
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   515
    //
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   516
    private long seqNumber;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   517
    private final NotificationBroadcasterSupport broadcaster =
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   518
            new NotificationBroadcasterSupport();
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   519
    private ObjectName mbeanName;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   520
    private MBeanServer mbs;
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   521
    private String mbeanClassName = "Simple";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   522
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   523
    /**
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   524
     * Notification types definitions. To use when creating JMX Notifications.
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   525
     */
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   526
    public static final String NOTIF_TYPE_0 =
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   527
            "sqe.notification.a.type";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   528
    public static final String NOTIF_TYPE_1 =
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   529
            "sqe.notification.b.type";
de746e7eb1e3 8058865: JMX Test Refactoring
olagneau
parents:
diff changeset
   530
}