jdk/test/javax/management/MBeanServer/PostExceptionTest.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 1002 1e6a1b77f22a
child 30376 2ccf2cf7ea48
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1002
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1002
diff changeset
     2
 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
1002
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
     4
 *
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
     8
 *
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    13
 * accompanied this code).
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    14
 *
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1002
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1002
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1002
diff changeset
    21
 * questions.
1002
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    22
 */
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    23
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    24
/*
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    25
 * @test
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    26
 * @bug 6730926
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    27
 * @summary Check behaviour of MBeanServer when postRegister and postDeregister
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    28
 *          throw exceptions.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    29
 * @author Daniel Fuchs
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    30
 * @compile PostExceptionTest.java
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    31
 * @run main PostExceptionTest
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    32
 */
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    33
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    34
import javax.management.*;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    35
import java.io.Serializable;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    36
import java.net.URL;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    37
import java.util.EnumSet;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    38
import javax.management.loading.MLet;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    39
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    40
public class PostExceptionTest {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    41
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    42
    /**
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    43
     * A test case where we instantiate an ExceptionalWombatMBean (or a
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    44
     * subclass of it) which will throw the exception {@code t} from within
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    45
     * the methods indicated by {@code where}
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    46
     */
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    47
    public static class Case {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    48
        public final Throwable t;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    49
        public final EnumSet<WHERE> where;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    50
        public Case(Throwable t,EnumSet<WHERE> where) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    51
            this.t=t; this.where=where;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    52
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    53
    }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    54
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    55
    // Various methods to create an instance of Case in a single line
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    56
    // --------------------------------------------------------------
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    57
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    58
    public static Case caze(Throwable t, WHERE w) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    59
        return new Case(t,EnumSet.of(w));
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    60
    }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    61
    public static Case caze(Throwable t, EnumSet<WHERE> where) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    62
        return new Case(t,where);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    63
    }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    64
    public static Case caze(Throwable t, WHERE w, WHERE... rest) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    65
        return new Case(t,EnumSet.of(w,rest));
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    66
    }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    67
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    68
    /**
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    69
     * Here is the list of our test cases:
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    70
     */
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    71
    public static Case[] cases ={
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    72
        caze(new RuntimeException(),WHERE.PREREGISTER),
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    73
        caze(new RuntimeException(),WHERE.POSTREGISTER),
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    74
        caze(new RuntimeException(),WHERE.POSTREGISTER, WHERE.PREDEREGISTER),
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    75
        caze(new RuntimeException(),WHERE.POSTREGISTER, WHERE.POSTDEREGISTER),
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    76
        caze(new Exception(),WHERE.PREREGISTER),
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    77
        caze(new Exception(),WHERE.POSTREGISTER),
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    78
        caze(new Exception(),WHERE.POSTREGISTER, WHERE.PREDEREGISTER),
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    79
        caze(new Exception(),WHERE.POSTREGISTER, WHERE.POSTDEREGISTER),
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    80
        caze(new Error(),WHERE.PREREGISTER),
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    81
        caze(new Error(),WHERE.POSTREGISTER),
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    82
        caze(new Error(),WHERE.POSTREGISTER, WHERE.PREDEREGISTER),
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    83
        caze(new Error(),WHERE.POSTREGISTER, WHERE.POSTDEREGISTER),
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    84
        caze(new RuntimeException(),EnumSet.allOf(WHERE.class)),
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    85
        caze(new Exception(),EnumSet.allOf(WHERE.class)),
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    86
        caze(new Error(),EnumSet.allOf(WHERE.class)),
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    87
    };
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    88
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    89
    public static void main(String[] args) throws Exception {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    90
        System.out.println("Test behaviour of MBeanServer when postRegister " +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    91
                "or postDeregister throw exceptions");
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    92
        MBeanServer mbs = MBeanServerFactory.newMBeanServer();
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    93
        int failures = 0;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    94
        final ObjectName n = new ObjectName("test:type=Wombat");
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    95
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    96
        // We're going to test each cases, using each of the 4 createMBean
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    97
        // forms + registerMBean in turn to create the MBean.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    98
        // Wich method is used to create the MBean is indicated by "how"
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
    99
        //
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   100
        for (Case caze:cases) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   101
            for (CREATE how : CREATE.values()) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   102
                failures+=test(mbs,n,how,caze.t,caze.where);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   103
            }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   104
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   105
        if (failures == 0)
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   106
            System.out.println("Test passed");
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   107
        else {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   108
            System.out.println("TEST FAILED: " + failures + " failure(s)");
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   109
            System.exit(1);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   110
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   111
    }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   112
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   113
    // Execute a test case composed of:
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   114
    // mbs:   The MBeanServer where the MBean will be registered,
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   115
    // name:  The name of that MBean
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   116
    // how:   How will the MBean be created/registered (which MBeanServer
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   117
    //        method)
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   118
    // t:     The exception/error that the MBean will throw
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   119
    // where: In which pre/post register/deregister method the exception/error
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   120
    //        will be thrown
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   121
    //
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   122
    private static int test(MBeanServer mbs, ObjectName name, CREATE how,
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   123
            Throwable t, EnumSet<WHERE> where)
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   124
            throws Exception {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   125
        System.out.println("-------<"+how+"> / <"+t+"> / "+ where + "-------");
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   126
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   127
        int failures = 0;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   128
        ObjectInstance oi = null;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   129
        Exception reg = null;    // exception thrown by create/register
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   130
        Exception unreg = null;  // exception thrown by unregister
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   131
        try {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   132
            // Create the MBean
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   133
            oi = how.create(t, where, mbs, name);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   134
        } catch (Exception xx) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   135
            reg=xx;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   136
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   137
        final ObjectName n = (oi==null)?name:oi.getObjectName();
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   138
        final boolean isRegistered = mbs.isRegistered(n);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   139
        try {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   140
            // If the MBean is registered, unregister it
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   141
            if (isRegistered) mbs.unregisterMBean(n);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   142
        } catch (Exception xxx) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   143
            unreg=xxx;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   144
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   145
        final boolean isUnregistered = !mbs.isRegistered(n);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   146
        if (!isUnregistered) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   147
            // if the MBean is still registered (preDeregister threw an
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   148
            // exception) signify to the MBean that it now should stop
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   149
            // throwing anaything and unregister it.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   150
            JMX.newMBeanProxy(mbs, n, ExceptionalWombatMBean.class).end();
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   151
            mbs.unregisterMBean(n);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   152
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   153
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   154
        // Now analyze the result. If we didn't ask the MBean to throw any
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   155
        // exception then reg should be null.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   156
        if (where.isEmpty() && reg!=null) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   157
            System.out.println("Unexpected registration exception: "+
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   158
                    reg);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   159
            throw new RuntimeException("Unexpected registration exception: "+
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   160
                    reg,reg);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   161
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   162
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   163
        // If we didn't ask the MBean to throw any exception then unreg should
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   164
        // also be null.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   165
        if (where.isEmpty() && unreg!=null) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   166
            System.out.println("Unexpected unregistration exception: "+
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   167
                    unreg);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   168
            throw new RuntimeException("Unexpected unregistration exception: "+
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   169
                    unreg,unreg);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   170
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   171
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   172
        // If we asked the MBean to throw an exception in either of preRegister
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   173
        // or postRegister, then reg should not be null.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   174
        if ((where.contains(WHERE.PREREGISTER)
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   175
            || where.contains(WHERE.POSTREGISTER))&& reg==null) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   176
            System.out.println("Expected registration exception not " +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   177
                    "thrown by "+where);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   178
            throw new RuntimeException("Expected registration exception not " +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   179
                    "thrown by "+where);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   180
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   181
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   182
        // If we asked the MBean not to throw any exception in preRegister
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   183
        // then the MBean should have been registered, unregisterMBean should
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   184
        // have been called.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   185
        // If we asked the MBean to throw an exception in either of preDeregister
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   186
        // or postDeregister, then unreg should not be null.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   187
        if ((where.contains(WHERE.PREDEREGISTER)
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   188
            || where.contains(WHERE.POSTDEREGISTER))&& unreg==null
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   189
            && !where.contains(WHERE.PREREGISTER)) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   190
            System.out.println("Expected unregistration exception not " +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   191
                    "thrown by "+where);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   192
            throw new RuntimeException("Expected unregistration exception not " +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   193
                    "thrown by "+where);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   194
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   195
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   196
        // If we asked the MBean to throw an exception in preRegister
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   197
        // then the MBean should not have been registered.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   198
        if (where.contains(WHERE.PREREGISTER)) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   199
            if (isRegistered) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   200
                System.out.println("MBean is still registered [" +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   201
                        where+
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   202
                        "]: "+name+" / "+reg);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   203
                throw new RuntimeException("MBean is still registered [" +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   204
                        where+
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   205
                        "]: "+name+" / "+reg,reg);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   206
            }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   207
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   208
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   209
        // If we asked the MBean not to throw an exception in preRegister,
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   210
        // but to throw an exception in postRegister, then the MBean should
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   211
        // have been registered.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   212
        if (where.contains(WHERE.POSTREGISTER) &&
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   213
                !where.contains(WHERE.PREREGISTER)) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   214
            if (!isRegistered) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   215
                System.out.println("MBean is already unregistered [" +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   216
                        where+
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   217
                        "]: "+name+" / "+reg);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   218
                throw new RuntimeException("MBean is already unregistered [" +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   219
                        where+
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   220
                        "]: "+name+" / "+reg,reg);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   221
            }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   222
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   223
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   224
        // If we asked the MBean to throw an exception in preRegister,
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   225
        // check that the exception we caught was as expected.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   226
        //
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   227
        if (where.contains(WHERE.PREREGISTER)) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   228
            WHERE.PREREGISTER.check(reg, t);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   229
        } else if (where.contains(WHERE.POSTREGISTER)) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   230
            // If we asked the MBean to throw an exception in postRegister,
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   231
            // check that the exception we caught was as expected.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   232
            // We don't do this check if we asked the MBean to also throw an
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   233
            // exception in pre register, because postRegister will not have
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   234
            // been called.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   235
            WHERE.POSTREGISTER.check(reg, t);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   236
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   237
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   238
        if (!isRegistered) return failures;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   239
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   240
        // The MBean was registered, so unregisterMBean was called. Check
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   241
        // unregisterMBean exceptions...
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   242
        //
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   243
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   244
        // If we asked the MBean to throw an exception in preDeregister
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   245
        // then the MBean should not have been deregistered.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   246
        if (where.contains(WHERE.PREDEREGISTER)) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   247
            if (isUnregistered) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   248
                System.out.println("MBean is already unregistered [" +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   249
                        where+
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   250
                        "]: "+name+" / "+unreg);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   251
                throw new RuntimeException("MBean is already unregistered [" +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   252
                        where+
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   253
                        "]: "+name+" / "+unreg,unreg);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   254
            }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   255
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   256
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   257
        // If we asked the MBean not to throw an exception in preDeregister,
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   258
        // but to throw an exception in postDeregister, then the MBean should
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   259
        // have been deregistered.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   260
        if (where.contains(WHERE.POSTDEREGISTER) &&
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   261
                !where.contains(WHERE.PREDEREGISTER)) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   262
            if (!isUnregistered) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   263
                System.out.println("MBean is not unregistered [" +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   264
                        where+
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   265
                        "]: "+name+" / "+unreg);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   266
                throw new RuntimeException("MBean is not unregistered [" +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   267
                        where+
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   268
                        "]: "+name+" / "+unreg,unreg);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   269
            }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   270
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   271
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   272
        // If we asked the MBean to throw an exception in preDeregister,
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   273
        // check that the exception we caught was as expected.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   274
        //
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   275
        if (where.contains(WHERE.PREDEREGISTER)) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   276
            WHERE.PREDEREGISTER.check(unreg, t);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   277
        } else if (where.contains(WHERE.POSTDEREGISTER)) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   278
            // If we asked the MBean to throw an exception in postDeregister,
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   279
            // check that the exception we caught was as expected.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   280
            // We don't do this check if we asked the MBean to also throw an
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   281
            // exception in pre register, because postRegister will not have
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   282
            // been called.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   283
            WHERE.POSTDEREGISTER.check(unreg, t);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   284
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   285
        return failures;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   286
    }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   287
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   288
    /**
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   289
     * This enum lists the 4 methods in MBeanRegistration.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   290
     */
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   291
    public static enum WHERE {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   292
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   293
        PREREGISTER, POSTREGISTER, PREDEREGISTER, POSTDEREGISTER;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   294
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   295
        // Checks that an exception thrown by the MBeanServer correspond to
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   296
        // what is expected when an MBean throws an exception in this
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   297
        // MBeanRegistration method ("this" is one of the 4 enum values above)
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   298
        //
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   299
        public void check(Exception thrown, Throwable t)
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   300
                throws Exception {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   301
           if (t instanceof RuntimeException) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   302
               if (!(thrown instanceof RuntimeMBeanException)) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   303
                   System.out.println("Expected RuntimeMBeanException, got "+
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   304
                           thrown);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   305
                   throw new Exception("Expected RuntimeMBeanException, got "+
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   306
                           thrown);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   307
               }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   308
           } else if (t instanceof Error) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   309
               if (!(thrown instanceof RuntimeErrorException)) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   310
                   System.out.println("Expected RuntimeErrorException, got "+
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   311
                           thrown);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   312
                   throw new Exception("Expected RuntimeErrorException, got "+
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   313
                           thrown);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   314
               }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   315
           } else if (t instanceof Exception) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   316
               if (EnumSet.of(POSTDEREGISTER,POSTREGISTER).contains(this)) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   317
                   if (!(thrown instanceof RuntimeMBeanException)) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   318
                       System.out.println("Expected RuntimeMBeanException, got "+
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   319
                           thrown);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   320
                       throw new Exception("Expected RuntimeMBeanException, got "+
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   321
                           thrown);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   322
                   }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   323
                   if (! (thrown.getCause() instanceof RuntimeException)) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   324
                       System.out.println("Bad cause: " +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   325
                               "expected RuntimeException, " +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   326
                           "got <"+thrown.getCause()+">");
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   327
                       throw new Exception("Bad cause: " +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   328
                               "expected RuntimeException, " +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   329
                           "got <"+thrown.getCause()+">");
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   330
                   }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   331
               }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   332
               if (EnumSet.of(PREDEREGISTER,PREREGISTER).contains(this)) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   333
                   if (!(thrown instanceof MBeanRegistrationException)) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   334
                       System.out.println("Expected " +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   335
                               "MBeanRegistrationException, got "+
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   336
                           thrown);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   337
                       throw new Exception("Expected " +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   338
                               "MBeanRegistrationException, got "+
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   339
                           thrown);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   340
                   }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   341
                   if (! (thrown.getCause() instanceof Exception)) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   342
                       System.out.println("Bad cause: " +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   343
                               "expected Exception, " +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   344
                           "got <"+thrown.getCause()+">");
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   345
                       throw new Exception("Bad cause: " +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   346
                               "expected Exception, " +
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   347
                           "got <"+thrown.getCause()+">");
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   348
                   }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   349
               }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   350
           }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   351
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   352
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   353
    }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   354
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   355
    /**
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   356
     * This enum lists the 5 methods to create and register an
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   357
     * ExceptionalWombat MBean
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   358
     */
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   359
    public static enum CREATE {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   360
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   361
        CREATE1() {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   362
            // Creates an ExceptionalWombat MBean using createMBean form #1
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   363
            public ObjectInstance create(Throwable t, EnumSet<WHERE> where,
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   364
                    MBeanServer server, ObjectName name) throws Exception {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   365
                ExceptionallyHackyWombat.t = t;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   366
                ExceptionallyHackyWombat.w = where;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   367
                return server.createMBean(
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   368
                        ExceptionallyHackyWombat.class.getName(),
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   369
                        name);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   370
            }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   371
        },
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   372
        CREATE2() {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   373
            // Creates an ExceptionalWombat MBean using createMBean form #2
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   374
            public ObjectInstance create(Throwable t, EnumSet<WHERE> where,
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   375
                    MBeanServer server, ObjectName name) throws Exception {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   376
                ExceptionallyHackyWombat.t = t;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   377
                ExceptionallyHackyWombat.w = where;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   378
                final ObjectName loaderName = registerMLet(server);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   379
                return server.createMBean(
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   380
                        ExceptionallyHackyWombat.class.getName(),
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   381
                        name, loaderName);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   382
            }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   383
        },
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   384
        CREATE3() {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   385
            // Creates an ExceptionalWombat MBean using createMBean form #3
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   386
            public ObjectInstance create(Throwable t, EnumSet<WHERE> where,
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   387
                    MBeanServer server, ObjectName name) throws Exception {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   388
                final Object[] params = {t, where};
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   389
                final String[] signature = {Throwable.class.getName(),
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   390
                    EnumSet.class.getName()
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   391
                };
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   392
                return server.createMBean(
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   393
                        ExceptionalWombat.class.getName(), name,
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   394
                        params, signature);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   395
            }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   396
        },
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   397
        CREATE4() {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   398
            // Creates an ExceptionalWombat MBean using createMBean form #4
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   399
            public ObjectInstance create(Throwable t, EnumSet<WHERE> where,
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   400
                    MBeanServer server, ObjectName name) throws Exception {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   401
                final Object[] params = {t, where};
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   402
                final String[] signature = {Throwable.class.getName(),
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   403
                    EnumSet.class.getName()
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   404
                };
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   405
                return server.createMBean(
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   406
                        ExceptionalWombat.class.getName(), name,
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   407
                        registerMLet(server), params, signature);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   408
            }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   409
        },
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   410
        REGISTER() {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   411
            // Creates an ExceptionalWombat MBean using registerMBean
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   412
            public ObjectInstance create(Throwable t, EnumSet<WHERE> where,
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   413
                    MBeanServer server, ObjectName name) throws Exception {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   414
                final ExceptionalWombat wombat =
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   415
                        new ExceptionalWombat(t, where);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   416
                return server.registerMBean(wombat, name);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   417
            }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   418
        };
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   419
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   420
        // Creates an ExceptionalWombat MBean using the method denoted by this
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   421
        // Enum value - one of CREATE1, CREATE2, CREATE3, CREATE4, or REGISTER.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   422
        public abstract ObjectInstance create(Throwable t, EnumSet<WHERE> where,
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   423
                MBeanServer server, ObjectName name) throws Exception;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   424
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   425
        // This is a bit of a hack - we use an MLet that delegates to the
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   426
        // System ClassLoader so that we can use createMBean form #2 and #3
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   427
        // while still using the same class loader (system).
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   428
        // This is necessary to make the ExceptionallyHackyWombatMBean work ;-)
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   429
        //
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   430
        public ObjectName registerMLet(MBeanServer server) throws Exception {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   431
            final ObjectName name = new ObjectName("test:type=MLet");
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   432
            if (server.isRegistered(name)) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   433
                return name;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   434
            }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   435
            final MLet mlet = new MLet(new URL[0],
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   436
                    ClassLoader.getSystemClassLoader());
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   437
            return server.registerMBean(mlet, name).getObjectName();
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   438
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   439
    }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   440
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   441
    /**
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   442
     *A Wombat MBean that can throw exceptions or errors in any of the
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   443
     * MBeanRegistration methods.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   444
     */
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   445
    public static interface ExceptionalWombatMBean {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   446
        // Tells the MBean to stop throwing exceptions - we sometime
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   447
        // need to call this at the end of the test so that we can
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   448
        // actually unregister the MBean.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   449
        public void end();
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   450
    }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   451
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   452
    /**
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   453
     *A Wombat MBean that can throw exceptions or errors in any of the
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   454
     * MBeanRegistration methods.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   455
     */
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   456
    public static class ExceptionalWombat
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   457
            implements ExceptionalWombatMBean, MBeanRegistration {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   458
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   459
        private final Throwable throwable;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   460
        private final EnumSet<WHERE> where;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   461
        private volatile boolean end=false;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   462
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   463
        public ExceptionalWombat(Throwable t, EnumSet<WHERE> where) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   464
            this.throwable=t; this.where=where;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   465
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   466
        private Exception doThrow() {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   467
            if (throwable instanceof Error)
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   468
                throw (Error)throwable;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   469
            if (throwable instanceof RuntimeException)
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   470
                throw (RuntimeException)throwable;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   471
            return (Exception)throwable;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   472
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   473
        public ObjectName preRegister(MBeanServer server, ObjectName name)
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   474
                throws Exception {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   475
            if (!end && where.contains(WHERE.PREREGISTER))
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   476
                throw doThrow();
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   477
            return name;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   478
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   479
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   480
        public void postRegister(Boolean registrationDone) {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   481
            if (!end && where.contains(WHERE.POSTREGISTER))
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   482
                throw new RuntimeException(doThrow());
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   483
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   484
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   485
        public void preDeregister() throws Exception {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   486
            if (!end && where.contains(WHERE.PREDEREGISTER))
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   487
                throw doThrow();
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   488
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   489
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   490
        public void postDeregister() {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   491
            if (!end && where.contains(WHERE.POSTREGISTER))
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   492
                throw new RuntimeException(doThrow());
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   493
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   494
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   495
        public void end() {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   496
            this.end=true;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   497
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   498
    }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   499
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   500
    /**
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   501
     * This is a big ugly hack to call createMBean form #1 and #2 - where
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   502
     * the empty constructor is used. Since we still want to supply parameters
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   503
     * to the ExceptionalWombat super class, we temporarily store these
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   504
     * parameter value in a static volatile before calling create MBean.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   505
     * Of course this only works because our test is sequential and single
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   506
     * threaded, and nobody but our test uses this ExceptionallyHackyWombat.
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   507
     */
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   508
    public static class ExceptionallyHackyWombat extends ExceptionalWombat {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   509
        public static volatile Throwable  t;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   510
        public static volatile EnumSet<WHERE> w;
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   511
        public ExceptionallyHackyWombat() {
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   512
            super(t,w);
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   513
        }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   514
    }
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   515
1e6a1b77f22a 6730926: Document that create/registerMBean can throw RuntimeMBeanException from postRegister
dfuchs
parents:
diff changeset
   516
}