src/java.management/share/classes/javax/management/relation/RelationNotification.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 25859 jdk/src/java.management/share/classes/javax/management/relation/RelationNotification.java@3317bb8137f4
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
     2
 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.management.relation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.management.Notification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
    31
import java.io.InvalidObjectException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.ObjectStreamField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.ArrayList;
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
    41
import java.util.Arrays;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.Collections;
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
    43
import java.util.HashSet;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.util.List;
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
    45
import java.util.Set;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import com.sun.jmx.mbeanserver.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import static com.sun.jmx.mbeanserver.Util.cast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * A notification of a change in the Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * A RelationNotification notification is sent when a relation is created via
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * the Relation Service, or an MBean is added as a relation in the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * Service, or a role is updated in a relation, or a relation is removed from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * the Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>The <b>serialVersionUID</b> of this class is <code>-6871117877523310399L</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
@SuppressWarnings("serial")  // serialVersionUID not constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
public class RelationNotification extends Notification {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // Serialization compatibility stuff:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    // Two serial forms are supported in this class. The selected form depends
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    // on system property "jmx.serial.form":
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    //  - "1.0" for JMX 1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    //  - any other value for JMX 1.1 and higher
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    // Serial version for old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static final long oldSerialVersionUID = -2126464566505527147L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    // Serial version for new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static final long newSerialVersionUID = -6871117877523310399L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    // Serializable fields in old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private static final ObjectStreamField[] oldSerialPersistentFields =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        new ObjectStreamField("myNewRoleValue", ArrayList.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        new ObjectStreamField("myOldRoleValue", ArrayList.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        new ObjectStreamField("myRelId", String.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        new ObjectStreamField("myRelObjName", ObjectName.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        new ObjectStreamField("myRelTypeName", String.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        new ObjectStreamField("myRoleName", String.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        new ObjectStreamField("myUnregMBeanList", ArrayList.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    // Serializable fields in new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static final ObjectStreamField[] newSerialPersistentFields =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        new ObjectStreamField("newRoleValue", List.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        new ObjectStreamField("oldRoleValue", List.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        new ObjectStreamField("relationId", String.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        new ObjectStreamField("relationObjName", ObjectName.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        new ObjectStreamField("relationTypeName", String.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        new ObjectStreamField("roleName", String.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        new ObjectStreamField("unregisterMBeanList", List.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    // Actual serial version and serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private static final long serialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @serialField relationId String Relation identifier of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * created/removed/updated relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @serialField relationTypeName String Relation type name of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * created/removed/updated relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @serialField relationObjName ObjectName {@link ObjectName} of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * the relation MBean of created/removed/updated relation (only if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * the relation is represented by an MBean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @serialField unregisterMBeanList List List of {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * ObjectName}s of referenced MBeans to be unregistered due to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * relation removal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @serialField roleName String Name of updated role (only for role update)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @serialField oldRoleValue List Old role value ({@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * ArrayList} of {@link ObjectName}s) (only for role update)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @serialField newRoleValue List New role value ({@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * ArrayList} of {@link ObjectName}s) (only for role update)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private static final ObjectStreamField[] serialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private static boolean compat = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            String form = AccessController.doPrivileged(act);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            compat = (form != null && form.equals("1.0"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            // OK : Too bad, no compat with 1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        if (compat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            serialPersistentFields = oldSerialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            serialVersionUID = oldSerialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            serialPersistentFields = newSerialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            serialVersionUID = newSerialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    // END Serialization compatibility stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    // Notification types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Type for the creation of an internal relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public static final String RELATION_BASIC_CREATION = "jmx.relation.creation.basic";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Type for the relation MBean added into the Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public static final String RELATION_MBEAN_CREATION = "jmx.relation.creation.mbean";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Type for an update of an internal relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public static final String RELATION_BASIC_UPDATE = "jmx.relation.update.basic";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Type for the update of a relation MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public static final String RELATION_MBEAN_UPDATE = "jmx.relation.update.mbean";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Type for the removal from the Relation Service of an internal relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public static final String RELATION_BASIC_REMOVAL = "jmx.relation.removal.basic";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Type for the removal from the Relation Service of a relation MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public static final String RELATION_MBEAN_REMOVAL = "jmx.relation.removal.mbean";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    // Private members
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @serial Relation identifier of created/removed/updated relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    private String relationId = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @serial Relation type name of created/removed/updated relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    private String relationTypeName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @serial {@link ObjectName} of the relation MBean of created/removed/updated relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *         (only if the relation is represented by an MBean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    private ObjectName relationObjName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @serial List of {@link ObjectName}s of referenced MBeans to be unregistered due to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *         relation removal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    private List<ObjectName> unregisterMBeanList = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @serial Name of updated role (only for role update)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    private String roleName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @serial Old role value ({@link ArrayList} of {@link ObjectName}s) (only for role update)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    private List<ObjectName> oldRoleValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @serial New role value ({@link ArrayList} of {@link ObjectName}s) (only for role update)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    private List<ObjectName> newRoleValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    // Constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Creates a notification for either a relation creation (RelationSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * object created internally in the Relation Service, or an MBean added as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * relation) or for a relation removal from the Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @param notifType  type of the notification; either:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * <P>- RELATION_BASIC_CREATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * <P>- RELATION_MBEAN_CREATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * <P>- RELATION_BASIC_REMOVAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * <P>- RELATION_MBEAN_REMOVAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @param sourceObj  source object, sending the notification.  This is either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * an ObjectName or a RelationService object.  In the latter case it must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * the MBean emitting the notification; the MBean Server will rewrite the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * source to be the ObjectName under which that MBean is registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @param sequence  sequence number to identify the notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @param timeStamp  time stamp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @param message  human-readable message describing the notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @param id  relation id identifying the relation in the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @param typeName  name of the relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @param objectName  ObjectName of the relation object if it is an MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * (null for relations internally handled by the Relation Service)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @param unregMBeanList  list of ObjectNames of referenced MBeans
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * expected to be unregistered due to relation removal (only for removal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * due to CIM qualifiers, can be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @exception IllegalArgumentException  if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * <P>- no value for the notification type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * <P>- the notification type is not RELATION_BASIC_CREATION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * RELATION_MBEAN_CREATION, RELATION_BASIC_REMOVAL or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * RELATION_MBEAN_REMOVAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * <P>- no source object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * <P>- the source object is not a Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * <P>- no relation id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * <P>- no relation type name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public RelationNotification(String notifType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                                Object sourceObj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                                long sequence,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                                long timeStamp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                                String message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                                String id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                                String typeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                                ObjectName objectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                                List<ObjectName> unregMBeanList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        super(notifType, sourceObj, sequence, timeStamp, message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
19202
b16d052a39ef 8011038: sourceObj validation during desereliazation of RelationNotification should be relaxed
dsamersoff
parents: 18217
diff changeset
   263
        if (!isValidBasicStrict(notifType,sourceObj,id,typeName) || !isValidCreate(notifType)) {
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   264
            throw new IllegalArgumentException("Invalid parameter.");
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   265
        }
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   266
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   267
        relationId = id;
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   268
        relationTypeName = typeName;
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   269
        relationObjName = safeGetObjectName(objectName);
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   270
        unregisterMBeanList = safeGetObjectNameList(unregMBeanList);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * Creates a notification for a role update in a relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @param notifType  type of the notification; either:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * <P>- RELATION_BASIC_UPDATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * <P>- RELATION_MBEAN_UPDATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param sourceObj  source object, sending the notification. This is either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * an ObjectName or a RelationService object.  In the latter case it must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * the MBean emitting the notification; the MBean Server will rewrite the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * source to be the ObjectName under which that MBean is registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @param sequence  sequence number to identify the notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @param timeStamp  time stamp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @param message  human-readable message describing the notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @param id  relation id identifying the relation in the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @param typeName  name of the relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @param objectName  ObjectName of the relation object if it is an MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * (null for relations internally handled by the Relation Service)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @param name  name of the updated role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @param newValue  new role value (List of ObjectName objects)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @param oldValue  old role value (List of ObjectName objects)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public RelationNotification(String notifType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                                Object sourceObj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                                long sequence,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                                long timeStamp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                                String message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                String id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                                String typeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                                ObjectName objectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                                String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                                List<ObjectName> newValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                                List<ObjectName> oldValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                                )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        super(notifType, sourceObj, sequence, timeStamp, message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
19202
b16d052a39ef 8011038: sourceObj validation during desereliazation of RelationNotification should be relaxed
dsamersoff
parents: 18217
diff changeset
   313
        if (!isValidBasicStrict(notifType,sourceObj,id,typeName) || !isValidUpdate(notifType,name,newValue,oldValue)) {
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   314
            throw new IllegalArgumentException("Invalid parameter.");
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   315
        }
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   316
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   317
        relationId = id;
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   318
        relationTypeName = typeName;
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   319
        relationObjName = safeGetObjectName(objectName);
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   320
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   321
        roleName = name;
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   322
        oldRoleValue = safeGetObjectNameList(oldValue);
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   323
        newRoleValue = safeGetObjectNameList(newValue);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    // Accessors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Returns the relation identifier of created/removed/updated relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @return the relation id.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    public String getRelationId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        return relationId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * Returns the relation type name of created/removed/updated relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @return the relation type name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    public String getRelationTypeName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        return relationTypeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * Returns the ObjectName of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * created/removed/updated relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @return the ObjectName if the relation is an MBean, otherwise null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    public ObjectName getObjectName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        return relationObjName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * Returns the list of ObjectNames of MBeans expected to be unregistered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * due to a relation removal (only for relation removal).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @return a {@link List} of {@link ObjectName}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public List<ObjectName> getMBeansToUnregister() {
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   365
        List<ObjectName> result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        if (unregisterMBeanList != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            result = new ArrayList<ObjectName>(unregisterMBeanList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            result = Collections.emptyList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * Returns name of updated role of updated relation (only for role update).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * @return the name of the updated role.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    public String getRoleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        String result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        if (roleName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            result = roleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * Returns old value of updated role (only for role update).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @return the old value of the updated role.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    public List<ObjectName> getOldRoleValue() {
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   393
        List<ObjectName> result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        if (oldRoleValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            result = new ArrayList<ObjectName>(oldRoleValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            result = Collections.emptyList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * Returns new value of updated role (only for role update).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @return the new value of the updated role.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    public List<ObjectName> getNewRoleValue() {
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   408
        List<ObjectName> result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        if (newRoleValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            result = new ArrayList<ObjectName>(newRoleValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            result = Collections.emptyList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    // Misc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    // Initializes members
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    // -param notifKind  1 for creation/removal, 2 for update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    // -param notifType  type of the notification; either:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    //  - RELATION_BASIC_UPDATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    //  - RELATION_MBEAN_UPDATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    //  for an update, or:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    //  - RELATION_BASIC_CREATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    //  - RELATION_MBEAN_CREATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    //  - RELATION_BASIC_REMOVAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    //  - RELATION_MBEAN_REMOVAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    //  for a creation or removal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    // -param sourceObj  source object, sending the notification. Will always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    //  be a RelationService object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    // -param sequence  sequence number to identify the notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    // -param timeStamp  time stamp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    // -param message  human-readable message describing the notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    // -param id  relation id identifying the relation in the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    //  Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    // -param typeName  name of the relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    // -param objectName  ObjectName of the relation object if it is an MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    //  (null for relations internally handled by the Relation Service)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    // -param unregMBeanList  list of ObjectNames of MBeans expected to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    //  removed due to relation removal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    // -param name  name of the updated role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    // -param newValue  new value (List of ObjectName objects)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    // -param oldValue  old value (List of ObjectName objects)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    // -exception IllegalArgumentException  if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    //  - no value for the notification type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    //  - incorrect notification type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    //  - no source object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    //  - the source object is not a Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    //  - no relation id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    //  - no relation type name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    //  - no role name (for role update)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    //  - no role old value (for role update)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    //  - no role new value (for role update)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
19202
b16d052a39ef 8011038: sourceObj validation during desereliazation of RelationNotification should be relaxed
dsamersoff
parents: 18217
diff changeset
   460
    // Despite the fact, that validation in constructor of RelationNotification prohibit
b16d052a39ef 8011038: sourceObj validation during desereliazation of RelationNotification should be relaxed
dsamersoff
parents: 18217
diff changeset
   461
    // creation of the class instance with null sourceObj its possible to set it to null later
b16d052a39ef 8011038: sourceObj validation during desereliazation of RelationNotification should be relaxed
dsamersoff
parents: 18217
diff changeset
   462
    // by public setSource() method.
b16d052a39ef 8011038: sourceObj validation during desereliazation of RelationNotification should be relaxed
dsamersoff
parents: 18217
diff changeset
   463
    // So we should relax validation rules to preserve serialization behavior compatibility.
b16d052a39ef 8011038: sourceObj validation during desereliazation of RelationNotification should be relaxed
dsamersoff
parents: 18217
diff changeset
   464
b16d052a39ef 8011038: sourceObj validation during desereliazation of RelationNotification should be relaxed
dsamersoff
parents: 18217
diff changeset
   465
    private boolean isValidBasicStrict(String notifType, Object sourceObj, String id, String typeName){
b16d052a39ef 8011038: sourceObj validation during desereliazation of RelationNotification should be relaxed
dsamersoff
parents: 18217
diff changeset
   466
        if (sourceObj == null) {
b16d052a39ef 8011038: sourceObj validation during desereliazation of RelationNotification should be relaxed
dsamersoff
parents: 18217
diff changeset
   467
            return false;
b16d052a39ef 8011038: sourceObj validation during desereliazation of RelationNotification should be relaxed
dsamersoff
parents: 18217
diff changeset
   468
        }
b16d052a39ef 8011038: sourceObj validation during desereliazation of RelationNotification should be relaxed
dsamersoff
parents: 18217
diff changeset
   469
        return isValidBasic(notifType,sourceObj,id,typeName);
b16d052a39ef 8011038: sourceObj validation during desereliazation of RelationNotification should be relaxed
dsamersoff
parents: 18217
diff changeset
   470
    }
b16d052a39ef 8011038: sourceObj validation during desereliazation of RelationNotification should be relaxed
dsamersoff
parents: 18217
diff changeset
   471
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   472
    private boolean isValidBasic(String notifType, Object sourceObj, String id, String typeName){
19202
b16d052a39ef 8011038: sourceObj validation during desereliazation of RelationNotification should be relaxed
dsamersoff
parents: 18217
diff changeset
   473
        if (notifType == null || id == null || typeName == null) {
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   474
            return false;
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   475
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
19202
b16d052a39ef 8011038: sourceObj validation during desereliazation of RelationNotification should be relaxed
dsamersoff
parents: 18217
diff changeset
   477
        if (sourceObj != null && (
b16d052a39ef 8011038: sourceObj validation during desereliazation of RelationNotification should be relaxed
dsamersoff
parents: 18217
diff changeset
   478
            !(sourceObj instanceof RelationService) &&
b16d052a39ef 8011038: sourceObj validation during desereliazation of RelationNotification should be relaxed
dsamersoff
parents: 18217
diff changeset
   479
            !(sourceObj instanceof ObjectName))) {
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   480
            return false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   483
        return true;
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   484
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   486
    private boolean isValidCreate(String notifType) {
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   487
        String[] validTypes= {RelationNotification.RELATION_BASIC_CREATION,
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   488
                              RelationNotification.RELATION_MBEAN_CREATION,
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   489
                              RelationNotification.RELATION_BASIC_REMOVAL,
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   490
                              RelationNotification.RELATION_MBEAN_REMOVAL};
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   491
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   492
        Set<String> ctSet = new HashSet<String>(Arrays.asList(validTypes));
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   493
        return ctSet.contains(notifType);
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   494
    }
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   495
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   496
    private boolean isValidUpdate(String notifType, String name,
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   497
                                  List<ObjectName> newValue, List<ObjectName> oldValue) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   499
        if (!(notifType.equals(RelationNotification.RELATION_BASIC_UPDATE)) &&
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   500
            !(notifType.equals(RelationNotification.RELATION_MBEAN_UPDATE))) {
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   501
            return false;
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   502
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   504
        if (name == null || oldValue == null || newValue == null) {
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   505
            return false;
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   506
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   508
        return true;
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   509
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   511
    private ArrayList<ObjectName> safeGetObjectNameList(List<ObjectName> src){
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   512
        ArrayList<ObjectName> dest = null;
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   513
        if (src != null) {
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   514
            dest = new ArrayList<ObjectName>();
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   515
            for (ObjectName item : src) {
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   516
                // NPE thrown if we attempt to add null object
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   517
                dest.add(ObjectName.getInstance(item));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   520
        return dest;
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   521
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   523
    private ObjectName safeGetObjectName(ObjectName src){
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   524
        ObjectName dest = null;
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   525
        if (src != null) {
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   526
            dest = ObjectName.getInstance(src);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        }
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   528
        return dest;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * Deserializes a {@link RelationNotification} from an {@link ObjectInputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    private void readObject(ObjectInputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            throws IOException, ClassNotFoundException {
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   536
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   537
        String tmpRelationId, tmpRelationTypeName, tmpRoleName;
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   538
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   539
        ObjectName tmpRelationObjName;
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   540
        List<ObjectName> tmpNewRoleValue, tmpOldRoleValue, tmpUnregMBeanList;
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   541
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        ObjectInputStream.GetField fields = in.readFields();
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   543
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   544
        if (compat) {
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   545
            tmpRelationId = (String)fields.get("myRelId", null);
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   546
            tmpRelationTypeName = (String)fields.get("myRelTypeName", null);
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   547
            tmpRoleName = (String)fields.get("myRoleName", null);
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   548
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   549
            tmpRelationObjName = (ObjectName)fields.get("myRelObjName", null);
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   550
            tmpNewRoleValue = cast(fields.get("myNewRoleValue", null));
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   551
            tmpOldRoleValue = cast(fields.get("myOldRoleValue", null));
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   552
            tmpUnregMBeanList = cast(fields.get("myUnregMBeanList", null));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        }
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   554
        else {
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   555
            tmpRelationId = (String)fields.get("relationId", null);
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   556
            tmpRelationTypeName = (String)fields.get("relationTypeName", null);
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   557
            tmpRoleName = (String)fields.get("roleName", null);
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   558
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   559
            tmpRelationObjName = (ObjectName)fields.get("relationObjName", null);
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   560
            tmpNewRoleValue = cast(fields.get("newRoleValue", null));
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   561
            tmpOldRoleValue = cast(fields.get("oldRoleValue", null));
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   562
            tmpUnregMBeanList = cast(fields.get("unregisterMBeanList", null));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        }
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   564
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   565
        // Validate fields we just read, throw InvalidObjectException
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   566
        // if something goes wrong
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   567
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   568
        String notifType = super.getType();
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   569
        if (!isValidBasic(notifType,super.getSource(),tmpRelationId,tmpRelationTypeName)  ||
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   570
            (!isValidCreate(notifType) &&
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   571
             !isValidUpdate(notifType,tmpRoleName,tmpNewRoleValue,tmpOldRoleValue))) {
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   572
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   573
            super.setSource(null);
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   574
            throw new InvalidObjectException("Invalid object read");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        }
18217
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   576
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   577
        // assign deserialized vaules to object fields
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   578
        relationObjName = safeGetObjectName(tmpRelationObjName);
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   579
        newRoleValue = safeGetObjectNameList(tmpNewRoleValue);
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   580
        oldRoleValue = safeGetObjectNameList(tmpOldRoleValue);
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   581
        unregisterMBeanList = safeGetObjectNameList(tmpUnregMBeanList);
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   582
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   583
        relationId = tmpRelationId;
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   584
        relationTypeName = tmpRelationTypeName;
94269d97fc96 8008120: Improve JMX class checking
dsamersoff
parents: 5506
diff changeset
   585
        roleName = tmpRoleName;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * Serializes a {@link RelationNotification} to an {@link ObjectOutputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    private void writeObject(ObjectOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
      if (compat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        // Serializes this instance in the old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        ObjectOutputStream.PutField fields = out.putFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        fields.put("myNewRoleValue", newRoleValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        fields.put("myOldRoleValue", oldRoleValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        fields.put("myRelId", relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        fields.put("myRelObjName", relationObjName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        fields.put("myRelTypeName", relationTypeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        fields.put("myRoleName",roleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        fields.put("myUnregMBeanList", unregisterMBeanList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        out.writeFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        // Serializes this instance in the new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        out.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
}