jdk/src/share/classes/javax/management/relation/RelationSupport.java
author rriggs
Tue, 12 Nov 2013 14:03:28 -0500
changeset 21656 d4c777ccb1db
parent 5506 202f599c92aa
child 23010 6dadb192ad81
permissions -rw-r--r--
8028014: Doclint warning/error cleanup in javax.management Summary: Improve generated html by fixing doclint warnings Reviewed-by: sla, jbachorik
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1510
diff changeset
     2
 * Copyright (c) 2000, 2008, 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: 1510
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: 1510
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: 1510
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1510
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1510
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
    37
import java.util.concurrent.atomic.AtomicBoolean;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import static com.sun.jmx.defaults.JmxProperties.RELATION_LOGGER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import static com.sun.jmx.mbeanserver.Util.cast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.management.InstanceNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.management.MBeanException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.management.MBeanRegistration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.management.ReflectionException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * A RelationSupport object is used internally by the Relation Service to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * represent simple relations (only roles, no properties or methods), with an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * unlimited number of roles, of any relation type. As internal representation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * it is not exposed to the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <P>RelationSupport class conforms to the design patterns of standard MBean. So
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * the user can decide to instantiate a RelationSupport object himself as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * a MBean (as it follows the MBean design patterns), to register it in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * MBean Server, and then to add it in the Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <P>The user can also, when creating his own MBean relation class, have it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * extending RelationSupport, to retrieve the implementations of required
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * interfaces (see below).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <P>It is also possible to have in a user relation MBean class a member
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * being a RelationSupport object, and to implement the required interfaces by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * delegating all to this member.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <P> RelationSupport implements the Relation interface (to be handled by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * Relation Service).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <P>It implements also the MBeanRegistration interface to be able to retrieve
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * the MBean Server where it is registered (if registered as a MBean) to access
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * to its Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
public class RelationSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    implements RelationSupportMBean, MBeanRegistration {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    // Private members
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    // Relation identifier (expected to be unique in the Relation Service where
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    // the RelationSupport object will be added)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private String myRelId = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    // ObjectName of the Relation Service where the relation will be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    // REQUIRED if the RelationSupport is created by the user to be registered as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    // a MBean, as it will have to access the Relation Service via the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    // Server to perform the check regarding the relation type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    // Is null if current object is directly created by the Relation Service,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    // as the object will directly access it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private ObjectName myRelServiceName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    // Reference to the MBean Server where the Relation Service is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    // registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    // REQUIRED if the RelationSupport is created by the user to be registered as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    // a MBean, as it will have to access the Relation Service via the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    // Server to perform the check regarding the relation type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    // If the Relationbase object is created by the Relation Service (use of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    // createRelation() method), this is null as not needed, direct access to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    // the Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    // If the Relationbase object is created by the user and registered as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    // MBean, this is set by the preRegister() method below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private MBeanServer myRelServiceMBeanServer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    // Relation type name (must be known in the Relation Service where the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    // relation will be added)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private String myRelTypeName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    // Role map, mapping <role-name> -> <Role>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    // Initialized by role list in the constructor, then updated:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    // - if the relation is a MBean, via setRole() and setRoles() methods, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    //   via Relation Service setRole() and setRoles() methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    // - if the relation is internal to the Relation Service, via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    //   setRoleInt() and setRolesInt() methods.
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   111
    private final Map<String,Role> myRoleName2ValueMap = new HashMap<String,Role>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    // Flag to indicate if the object has been added in the Relation Service
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   114
    private final AtomicBoolean myInRelServFlg = new AtomicBoolean();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    // Constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Creates a {@code RelationSupport} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * <P>This constructor has to be used when the RelationSupport object will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * be registered as a MBean by the user, or when creating a user relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * MBean whose class extends RelationSupport.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * <P>Nothing is done at the Relation Service level, i.e.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * the {@code RelationSupport} object is not added to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * {@code RelationService} and no checks are performed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * see if the provided values are correct.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * The object is always created, EXCEPT if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * <P>- any of the required parameters is {@code null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * <P>- the same name is used for two roles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * <P>To be handled as a relation, the {@code RelationSupport} object has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * to be added to the Relation Service using the Relation Service method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * addRelation().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @param relationId  relation identifier, to identify the relation in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * <P>Expected to be unique in the given Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @param relationServiceName  ObjectName of the Relation Service where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * the relation will be registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * <P>This parameter is required as it is the Relation Service that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * aware of the definition of the relation type of the given relation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * so that will be able to check update operations (set).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @param relationTypeName  Name of relation type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * <P>Expected to have been created in the given Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @param list  list of roles (Role objects) to initialize the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * relation. Can be {@code null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * <P>Expected to conform to relation info in associated relation type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @exception InvalidRoleValueException  if the same name is used for two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * roles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @exception IllegalArgumentException  if any of the required parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * (relation id, relation service ObjectName, or relation type name) is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * {@code null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public RelationSupport(String relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                        ObjectName relationServiceName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                        String relationTypeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                        RoleList list)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        throws InvalidRoleValueException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
               IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        RELATION_LOGGER.entering(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                "RelationSupport");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        // Can throw InvalidRoleValueException and IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        initMembers(relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    relationServiceName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    relationTypeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        RELATION_LOGGER.exiting(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                "RelationSupport");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Creates a {@code RelationSupport} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * <P>This constructor has to be used when the user relation MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * implements the interfaces expected to be supported by a relation by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * delegating to a RelationSupport object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * <P>This object needs to know the Relation Service expected to handle the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * relation. So it has to know the MBean Server where the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * is registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * <P>According to a limitation, a relation MBean must be registered in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * same MBean Server as the Relation Service expected to handle it. So the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * user relation MBean has to be created and registered, and then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * wrapped RelationSupport object can be created within the identified MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * Server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * <P>Nothing is done at the Relation Service level, i.e.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * the {@code RelationSupport} object is not added to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * {@code RelationService} and no checks are performed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * see if the provided values are correct.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * The object is always created, EXCEPT if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * <P>- any of the required parameters is {@code null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * <P>- the same name is used for two roles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * <P>To be handled as a relation, the {@code RelationSupport} object has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * to be added to the Relation Service using the Relation Service method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * addRelation().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @param relationId  relation identifier, to identify the relation in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * <P>Expected to be unique in the given Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @param relationServiceName  ObjectName of the Relation Service where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * the relation will be registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * <P>This parameter is required as it is the Relation Service that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * aware of the definition of the relation type of the given relation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * so that will be able to check update operations (set).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @param relationServiceMBeanServer  MBean Server where the wrapping MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * is or will be registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * <P>Expected to be the MBean Server where the Relation Service is or will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * be registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @param relationTypeName  Name of relation type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * <P>Expected to have been created in the given Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @param list  list of roles (Role objects) to initialize the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * relation. Can be {@code null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * <P>Expected to conform to relation info in associated relation type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @exception InvalidRoleValueException  if the same name is used for two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * roles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @exception IllegalArgumentException  if any of the required parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * (relation id, relation service ObjectName, relation service MBeanServer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * or relation type name) is {@code null}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public RelationSupport(String relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                        ObjectName relationServiceName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                        MBeanServer relationServiceMBeanServer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                        String relationTypeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                        RoleList list)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        throws InvalidRoleValueException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
               IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if (relationServiceMBeanServer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        RELATION_LOGGER.entering(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                "RelationSupport");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        // Can throw InvalidRoleValueException and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        // IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        initMembers(relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    relationServiceName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    relationServiceMBeanServer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    relationTypeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        RELATION_LOGGER.exiting(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                "RelationSupport");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    // Relation Interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Retrieves role value for given role name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * <P>Checks if the role exists and is readable according to the relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @param roleName  name of role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @return the ArrayList of ObjectName objects being the role value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @exception IllegalArgumentException  if null role name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @exception RoleNotFoundException  if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * <P>- there is no role with given name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * <P>- the role is not readable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @see #setRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public List<ObjectName> getRole(String roleName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
               RoleNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
               RelationServiceNotRegisteredException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (roleName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        RELATION_LOGGER.entering(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                "getRole", roleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        // Can throw RoleNotFoundException and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        // RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        List<ObjectName> result = cast(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            getRoleInt(roleName, false, null, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        RELATION_LOGGER.exiting(RelationSupport.class.getName(), "getRole");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Retrieves values of roles with given names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * <P>Checks for each role if it exists and is readable according to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * relation type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @param roleNameArray  array of names of roles to be retrieved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @return a RoleResult object, including a RoleList (for roles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * successfully retrieved) and a RoleUnresolvedList (for roles not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * retrieved).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @exception IllegalArgumentException  if null role name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @see #setRoles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    public RoleResult getRoles(String[] roleNameArray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
               RelationServiceNotRegisteredException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        if (roleNameArray == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        RELATION_LOGGER.entering(RelationSupport.class.getName(), "getRoles");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        // Can throw RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        RoleResult result = getRolesInt(roleNameArray, false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        RELATION_LOGGER.exiting(RelationSupport.class.getName(), "getRoles");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * Returns all roles present in the relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * @return a RoleResult object, including a RoleList (for roles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * successfully retrieved) and a RoleUnresolvedList (for roles not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * readable).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    public RoleResult getAllRoles()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        throws RelationServiceNotRegisteredException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        RELATION_LOGGER.entering(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                "getAllRoles");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        RoleResult result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            result = getAllRolesInt(false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        } catch (IllegalArgumentException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            // OK : Invalid parameters, ignore...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        RELATION_LOGGER.exiting(RelationSupport.class.getName(), "getAllRoles");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * Returns all roles in the relation without checking read mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @return a RoleList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    public RoleList retrieveAllRoles() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        RELATION_LOGGER.entering(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                "retrieveAllRoles");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        RoleList result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        synchronized(myRoleName2ValueMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            result =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                new RoleList(new ArrayList<Role>(myRoleName2ValueMap.values()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        RELATION_LOGGER.exiting(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                "retrieveAllRoles");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * Returns the number of MBeans currently referenced in the given role.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * @param roleName  name of role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * @return the number of currently referenced MBeans in that role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @exception IllegalArgumentException  if null role name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @exception RoleNotFoundException  if there is no role with given name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    public Integer getRoleCardinality(String roleName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
               RoleNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        if (roleName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        RELATION_LOGGER.entering(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                "getRoleCardinality", roleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        // Try to retrieve the role
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   407
        Role role;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        synchronized(myRoleName2ValueMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            // No null Role is allowed, so direct use of get()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            role = (myRoleName2ValueMap.get(roleName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        if (role == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            int pbType = RoleStatus.NO_ROLE_WITH_NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            // Will throw a RoleNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            // Will not throw InvalidRoleValueException, so catch it for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            // compiler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                RelationService.throwRoleProblemException(pbType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                                                          roleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            } catch (InvalidRoleValueException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                // OK : Do not throw InvalidRoleValueException as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                //      a RoleNotFoundException will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   427
        List<ObjectName> roleValue = role.getRoleValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        RELATION_LOGGER.exiting(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                "getRoleCardinality");
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   431
        return roleValue.size();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * Sets the given role.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * <P>Will check the role according to its corresponding role definition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * provided in relation's relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * <P>Will send a notification (RelationNotification with type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * RELATION_BASIC_UPDATE or RELATION_MBEAN_UPDATE, depending if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * relation is a MBean or not).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * @param role  role to be set (name and new value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @exception IllegalArgumentException  if null role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @exception RoleNotFoundException  if there is no role with the supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * role's name or if the role is not writable (no test on the write access
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * mode performed when initializing the role)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @exception InvalidRoleValueException  if value provided for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * role is not valid, i.e.:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * <P>- the number of referenced MBeans in given value is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * expected minimum degree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * <P>- the number of referenced MBeans in provided value exceeds expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * maximum degree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * <P>- one referenced MBean in the value is not an Object of the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * class expected for that role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * <P>- a MBean provided for that role does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * @exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @exception RelationTypeNotFoundException  if the relation type has not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * been declared in the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @exception RelationNotFoundException  if the relation has not been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * added in the Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @see #getRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    public void setRole(Role role)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
               RoleNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
               RelationTypeNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
               InvalidRoleValueException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
               RelationServiceNotRegisteredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
               RelationNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        if (role == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        RELATION_LOGGER.entering(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                "setRole", role);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        // Will return null :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        Object result = setRoleInt(role, false, null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        RELATION_LOGGER.exiting(RelationSupport.class.getName(), "setRole");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * Sets the given roles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * <P>Will check the role according to its corresponding role definition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * provided in relation's relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * <P>Will send one notification (RelationNotification with type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * RELATION_BASIC_UPDATE or RELATION_MBEAN_UPDATE, depending if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * relation is a MBean or not) per updated role.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @param list  list of roles to be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * @return a RoleResult object, including a RoleList (for roles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * successfully set) and a RoleUnresolvedList (for roles not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * set).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @exception IllegalArgumentException  if null role list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @exception RelationTypeNotFoundException  if the relation type has not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * been declared in the Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * @exception RelationNotFoundException  if the relation MBean has not been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * added in the Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * @see #getRoles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    public RoleResult setRoles(RoleList list)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
               RelationServiceNotRegisteredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
               RelationTypeNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
               RelationNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        if (list == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        RELATION_LOGGER.entering(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                "setRoles", list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        RoleResult result = setRolesInt(list, false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        RELATION_LOGGER.exiting(RelationSupport.class.getName(), "setRoles");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * Callback used by the Relation Service when a MBean referenced in a role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * is unregistered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * <P>The Relation Service will call this method to let the relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * take action to reflect the impact of such unregistration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * <P>BEWARE. the user is not expected to call this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * <P>Current implementation is to set the role with its current value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * (list of ObjectNames of referenced MBeans) without the unregistered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * @param objectName  ObjectName of unregistered MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * @param roleName  name of role where the MBean is referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * @exception RoleNotFoundException  if role does not exist in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * relation or is not writable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * @exception InvalidRoleValueException  if role value does not conform to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * the associated role info (this will never happen when called from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * Relation Service)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * @exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * @exception RelationTypeNotFoundException  if the relation type has not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * been declared in the Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * @exception RelationNotFoundException  if this method is called for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * relation MBean not added in the Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    public void handleMBeanUnregistration(ObjectName objectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                                          String roleName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
               RoleNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
               InvalidRoleValueException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
               RelationServiceNotRegisteredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
               RelationTypeNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
               RelationNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        if (objectName == null || roleName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        RELATION_LOGGER.entering(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                "handleMBeanUnregistration",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                new Object[]{objectName, roleName});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        // Can throw RoleNotFoundException, InvalidRoleValueException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        // or RelationTypeNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        handleMBeanUnregistrationInt(objectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                                     roleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                                     false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                                     null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        RELATION_LOGGER.exiting(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                "handleMBeanUnregistration");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        return;
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
     * Retrieves MBeans referenced in the various roles of the relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * @return a HashMap mapping:
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   593
     * <P> ObjectName {@literal ->} ArrayList of String (role names)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    public Map<ObjectName,List<String>> getReferencedMBeans() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        RELATION_LOGGER.entering(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                "getReferencedMBeans");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        Map<ObjectName,List<String>> refMBeanMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            new HashMap<ObjectName,List<String>>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        synchronized(myRoleName2ValueMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            for (Role currRole : myRoleName2ValueMap.values()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                String currRoleName = currRole.getRoleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                // Retrieves ObjectNames of MBeans referenced in current role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                List<ObjectName> currRefMBeanList = currRole.getRoleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                for (ObjectName currRoleObjName : currRefMBeanList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                    // Sees if current MBean has been already referenced in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                    // roles already seen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                    List<String> mbeanRoleNameList =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                        refMBeanMap.get(currRoleObjName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                    boolean newRefFlg = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                    if (mbeanRoleNameList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                        newRefFlg = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                        mbeanRoleNameList = new ArrayList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                    mbeanRoleNameList.add(currRoleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                    if (newRefFlg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                        refMBeanMap.put(currRoleObjName, mbeanRoleNameList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        RELATION_LOGGER.exiting(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                "getReferencedMBeans");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        return refMBeanMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * Returns name of associated relation type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    public String getRelationTypeName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        return myRelTypeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * Returns ObjectName of the Relation Service handling the relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * @return the ObjectName of the Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    public ObjectName getRelationServiceName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        return myRelServiceName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * Returns relation identifier (used to uniquely identify the relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * inside the Relation Service).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * @return the relation id.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    public String getRelationId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        return myRelId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    // MBeanRegistration interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    // Pre-registration: retrieves the MBean Server (useful to access to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    // Relation Service)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    // This is the way to retrieve the MBean Server when the relation object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    // a MBean created by the user outside of the Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    // No exception thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    public ObjectName preRegister(MBeanServer server,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                                  ObjectName name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        myRelServiceMBeanServer = server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    // Post-registration: does nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    public void postRegister(Boolean registrationDone) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    // Pre-unregistration: does nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    public void preDeregister()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    // Post-unregistration: does nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    public void postDeregister() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    // Others
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * Returns an internal flag specifying if the object is still handled by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * the Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    public Boolean isInRelationService() {
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   705
        return myInRelServFlg.get();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    public void setRelationServiceManagementFlag(Boolean flag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        if (flag == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        }
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   715
        myInRelServFlg.set(flag);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    // Misc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    // Gets the role with given name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    // Checks if the role exists and is readable according to the relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    // type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    // This method is called in getRole() above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    // It is also called in the Relation Service getRole() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    // It is also called in getRolesInt() below (used for getRoles() above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    // and for Relation Service getRoles() method).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    // Depending on parameters reflecting its use (either in the scope of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    // getting a single role or of getting several roles), will return:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    // - in case of success:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    //   - for single role retrieval, the ArrayList of ObjectNames being the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    //     role value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    //   - for multi-role retrieval, the Role object itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    // - in case of failure (except critical exceptions):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    //   - for single role retrieval, if role does not exist or is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    //     readable, an RoleNotFoundException exception is raised
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    //   - for multi-role retrieval, a RoleUnresolved object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    // -param roleName  name of role to be retrieved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    // -param relationServCallFlg  true if call from the Relation Service; this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    //  will happen if the current RelationSupport object has been created by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    //  the Relation Service (via createRelation()) method, so direct access is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    //  possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    // -param relationServ  reference to Relation Service object, if object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    //  created by Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    // -param multiRoleFlg  true if getting the role in the scope of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    //  multiple retrieval.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    // -return:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    //  - for single role retrieval (multiRoleFlg false):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    //    - ArrayList of ObjectName objects, value of role with given name, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    //      the role can be retrieved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    //    - raise a RoleNotFoundException exception else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    //  - for multi-role retrieval (multiRoleFlg true):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    //    - the Role object for given role name if role can be retrieved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    //    - a RoleUnresolved object with problem.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    // -exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    // -exception RoleNotFoundException  if multiRoleFlg is false and:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    //  - there is no role with given name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    //  or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    //  - the role is not readable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    // -exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    //  Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    Object getRoleInt(String roleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                      boolean relationServCallFlg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                      RelationService relationServ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                      boolean multiRoleFlg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
               RoleNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
               RelationServiceNotRegisteredException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        if (roleName == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            (relationServCallFlg && relationServ == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        RELATION_LOGGER.entering(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                "getRoleInt", roleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        int pbType = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   787
        Role role;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        synchronized(myRoleName2ValueMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            // No null Role is allowed, so direct use of get()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            role = (myRoleName2ValueMap.get(roleName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        if (role == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                pbType = RoleStatus.NO_ROLE_WITH_NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            // Checks if the role is readable
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   798
            Integer status;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            if (relationServCallFlg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                // Call from the Relation Service, so direct access to it,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                // avoiding MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                // Shall not throw a RelationTypeNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                    status = relationServ.checkRoleReading(roleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                                                         myRelTypeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                } catch (RelationTypeNotFoundException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                    throw new RuntimeException(exc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                // Call from getRole() method above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                // So we have a MBean. We must access the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                // via the MBean Server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                Object[] params = new Object[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                params[0] = roleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                params[1] = myRelTypeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                String[] signature = new String[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                signature[0] = "java.lang.String";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                signature[1] = "java.lang.String";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                // Can throw InstanceNotFoundException if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                // Service is not registered (to be catched in any case and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                // transformed into RelationServiceNotRegisteredException).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                // Shall not throw a MBeanException, or a ReflectionException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                // or an InstanceNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                    status = (Integer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                        (myRelServiceMBeanServer.invoke(myRelServiceName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                                                        "checkRoleReading",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                                                        params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                                                        signature));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                } catch (MBeanException exc1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                    throw new RuntimeException("incorrect relation type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                } catch (ReflectionException exc2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                    throw new RuntimeException(exc2.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                } catch (InstanceNotFoundException exc3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                    throw new RelationServiceNotRegisteredException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                                                            exc3.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            pbType = status.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   848
        Object result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        if (pbType == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            // Role can be retrieved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            if (!(multiRoleFlg)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                // Single role retrieved: returns its value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                // Note: no need to test if role value (list) not null before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                //       cloning, null value not allowed, empty list if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                //       nothing.
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   858
                result = new ArrayList<ObjectName>(role.getRoleValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                // Role retrieved during multi-role retrieval: returns the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                // role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                result = (Role)(role.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            // Role not retrieved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            if (!(multiRoleFlg)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                // Problem when retrieving a simple role: either role not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                // found or not readable, so raises a RoleNotFoundException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                    RelationService.throwRoleProblemException(pbType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                                                              roleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                    // To keep compiler happy :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                } catch (InvalidRoleValueException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                    throw new RuntimeException(exc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                // Problem when retrieving a role in a multi-role retrieval:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                // returns a RoleUnresolved object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                result = new RoleUnresolved(roleName, null, pbType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        RELATION_LOGGER.exiting(RelationSupport.class.getName(), "getRoleInt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    // Gets the given roles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    // For each role, verifies if the role exists and is readable according to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    // the relation type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    // This method is called in getRoles() above and in Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    // getRoles() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    // -param roleNameArray  array of names of roles to be retrieved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    // -param relationServCallFlg  true if call from the Relation Service; this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    //  will happen if the current RelationSupport object has been created by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    //  the Relation Service (via createRelation()) method, so direct access is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    //  possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    // -param relationServ  reference to Relation Service object, if object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    //  created by Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    // -return a RoleResult object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    // -exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    // -exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    //  Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    RoleResult getRolesInt(String[] roleNameArray,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                           boolean relationServCallFlg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                           RelationService relationServ)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
               RelationServiceNotRegisteredException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        if (roleNameArray == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            (relationServCallFlg && relationServ == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        RELATION_LOGGER.entering(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                "getRolesInt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        RoleList roleList = new RoleList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        RoleUnresolvedList roleUnresList = new RoleUnresolvedList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        for (int i = 0; i < roleNameArray.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            String currRoleName = roleNameArray[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   933
            Object currResult;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            // Can throw RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            // RoleNotFoundException: not possible but catch it for compiler :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                currResult = getRoleInt(currRoleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                                        relationServCallFlg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                                        relationServ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                                        true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            } catch (RoleNotFoundException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                return null; // :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            if (currResult instanceof Role) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                // Can throw IllegalArgumentException if role is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                // (normally should not happen :(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                    roleList.add((Role)currResult);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                } catch (IllegalArgumentException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                    throw new RuntimeException(exc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            } else if (currResult instanceof RoleUnresolved) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                // Can throw IllegalArgumentException if role is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                // (normally should not happen :(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                    roleUnresList.add((RoleUnresolved)currResult);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                } catch (IllegalArgumentException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                    throw new RuntimeException(exc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        RoleResult result = new RoleResult(roleList, roleUnresList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        RELATION_LOGGER.exiting(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                "getRolesInt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    // Returns all roles present in the relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    // -return a RoleResult object, including a RoleList (for roles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    //  successfully retrieved) and a RoleUnresolvedList (for roles not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    //  readable).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    // -exception IllegalArgumentException if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    // -exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    //  Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    RoleResult getAllRolesInt(boolean relationServCallFlg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                              RelationService relationServ)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
               RelationServiceNotRegisteredException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        if (relationServCallFlg && relationServ == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        RELATION_LOGGER.entering(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                "getAllRolesInt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        List<String> roleNameList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        synchronized(myRoleName2ValueMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            roleNameList =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                new ArrayList<String>(myRoleName2ValueMap.keySet());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        String[] roleNames = new String[roleNameList.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        roleNameList.toArray(roleNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        RoleResult result = getRolesInt(roleNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                                        relationServCallFlg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                                        relationServ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        RELATION_LOGGER.exiting(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                "getAllRolesInt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    // Sets the role with given value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    // This method is called in setRole() above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    // It is also called by the Relation Service setRole() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    // It is also called in setRolesInt() method below (used in setRoles()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    // above and in RelationService setRoles() method).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    // Will check the role according to its corresponding role definition
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
    // provided in relation's relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    // Will send a notification (RelationNotification with type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
    // RELATION_BASIC_UPDATE or RELATION_MBEAN_UPDATE, depending if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    // relation is a MBean or not) if not initialization of role.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
    // -param aRole  role to be set (name and new value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    // -param relationServCallFlg  true if call from the Relation Service; this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
    //  will happen if the current RelationSupport object has been created by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    //  the Relation Service (via createRelation()) method, so direct access is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
    //  possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
    // -param relationServ  reference to Relation Service object, if internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
    //  relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
    // -param multiRoleFlg  true if getting the role in the scope of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
    //  multiple retrieval.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    // -return (except other "critical" exceptions):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    //  - for single role retrieval (multiRoleFlg false):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    //    - null if the role has been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
    //    - raise an InvalidRoleValueException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    // else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
    //  - for multi-role retrieval (multiRoleFlg true):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    //    - the Role object for given role name if role has been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
    //    - a RoleUnresolved object with problem else.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    // -exception IllegalArgumentException if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    // -exception RoleNotFoundException  if multiRoleFlg is false and:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
    //  - internal relation and the role does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    //  or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
    //  - existing role (i.e. not initializing it) and the role is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    //    writable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
    // -exception InvalidRoleValueException  ifmultiRoleFlg is false and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    //  value provided for:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
    //   - the number of referenced MBeans in given value is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    //     expected minimum degree
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    //   or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
    //   - the number of referenced MBeans in provided value exceeds expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    //     maximum degree
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    //   or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    //   - one referenced MBean in the value is not an Object of the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    //     class expected for that role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    //   or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    //   - a MBean provided for that role does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
    // -exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    //  Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
    // -exception RelationTypeNotFoundException  if relation type unknown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
    // -exception RelationNotFoundException  if a relation MBean has not been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
    //  added in the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    Object setRoleInt(Role aRole,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                      boolean relationServCallFlg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                      RelationService relationServ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                      boolean multiRoleFlg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
               RoleNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
               InvalidRoleValueException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
               RelationServiceNotRegisteredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
               RelationTypeNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
               RelationNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        if (aRole == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            (relationServCallFlg && relationServ == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        RELATION_LOGGER.entering(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                "setRoleInt", new Object[] {aRole, relationServCallFlg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                relationServ, multiRoleFlg});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        String roleName = aRole.getRoleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        int pbType = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        // Checks if role exists in the relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        // No error if the role does not exist in the relation, to be able to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        // handle initialization of role when creating the relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        // (roles provided in the RoleList parameter are directly set but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        // roles automatically initialized are set using setRole())
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1098
        Role role;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        synchronized(myRoleName2ValueMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            role = (myRoleName2ValueMap.get(roleName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        List<ObjectName> oldRoleValue;
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1104
        Boolean initFlg;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        if (role == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            initFlg = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            oldRoleValue = new ArrayList<ObjectName>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            initFlg = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            oldRoleValue = role.getRoleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        // Checks if the role can be set: is writable (except if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        // initialization) and correct value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        try {
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1118
            Integer status;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
            if (relationServCallFlg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
                // Call from the Relation Service, so direct access to it,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                // avoiding MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                // Shall not raise a RelationTypeNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                status = relationServ.checkRoleWriting(aRole,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                                                     myRelTypeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                                                     initFlg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                // Call from setRole() method above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                // So we have a MBean. We must access the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                // via the MBean Server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                Object[] params = new Object[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
                params[0] = aRole;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                params[1] = myRelTypeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                params[2] = initFlg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                String[] signature = new String[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                signature[0] = "javax.management.relation.Role";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                signature[1] = "java.lang.String";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                signature[2] = "java.lang.Boolean";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                // Can throw InstanceNotFoundException if the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                // is not registered (to be transformed into
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                // RelationServiceNotRegisteredException in any case).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
                // Can throw a MBeanException wrapping a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                // RelationTypeNotFoundException:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                // throw wrapped exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                // Shall not throw a ReflectionException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                status = (Integer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                    (myRelServiceMBeanServer.invoke(myRelServiceName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                                                    "checkRoleWriting",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                                                    params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                                                    signature));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
            pbType = status.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        } catch (MBeanException exc2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
            // Retrieves underlying exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            Exception wrappedExc = exc2.getTargetException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            if (wrappedExc instanceof RelationTypeNotFoundException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                throw ((RelationTypeNotFoundException)wrappedExc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                throw new RuntimeException(wrappedExc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        } catch (ReflectionException exc3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            throw new RuntimeException(exc3.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        } catch (RelationTypeNotFoundException exc4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            throw new RuntimeException(exc4.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        } catch (InstanceNotFoundException exc5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            throw new RelationServiceNotRegisteredException(exc5.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        Object result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        if (pbType == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
            // Role can be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            if (!(initFlg.booleanValue())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                // Not initializing the role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                // If role being initialized:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                // - do not send an update notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
                // - do not try to update internal map of Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
                //   listing referenced MBeans, as role is initialized to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
                //   empty list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
                // Sends a notification (RelationNotification)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                // Can throw a RelationNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                sendRoleUpdateNotification(aRole,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                                           oldRoleValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                                           relationServCallFlg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                                           relationServ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                // Updates the role map of the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                // Can throw RelationNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                updateRelationServiceMap(aRole,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                                         oldRoleValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
                                         relationServCallFlg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                                         relationServ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            // Sets the role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
            synchronized(myRoleName2ValueMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                myRoleName2ValueMap.put(roleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                                        (Role)(aRole.clone()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
            // Single role set: returns null: nothing to set in result
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            if (multiRoleFlg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                // Multi-roles retrieval: returns the role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
                result = aRole;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
            // Role not set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            if (!(multiRoleFlg)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
                // Problem when setting a simple role: either role not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
                // found, not writable, or incorrect value:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                // raises appropriate exception, RoleNotFoundException or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                // InvalidRoleValueException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                RelationService.throwRoleProblemException(pbType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                                                          roleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
                // To keep compiler happy :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
                // Problem when retrieving a role in a multi-role retrieval:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
                // returns a RoleUnresolved object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                result = new RoleUnresolved(roleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
                                            aRole.getRoleValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                                            pbType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        RELATION_LOGGER.exiting(RelationSupport.class.getName(), "setRoleInt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    // Requires the Relation Service to send a notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
    // RelationNotification, with type being either:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    // - RelationNotification.RELATION_BASIC_UPDATE if the updated relation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
    //   a relation internal to the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    // - RelationNotification.RELATION_MBEAN_UPDATE if the updated relation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
    //   a relation MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
    // -param newRole  new role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
    // -param oldRoleValue  old role value (ArrayList of ObjectNames)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
    // -param relationServCallFlg  true if call from the Relation Service; this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    //  will happen if the current RelationSupport object has been created by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
    //  the Relation Service (via createRelation()) method, so direct access is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
    //  possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
    // -param relationServ  reference to Relation Service object, if object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
    //  created by Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
    // -exception IllegalArgumentException  if null parameter provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    // -exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
    //  Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    // -exception RelationNotFoundException if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    //  - relation MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
    //  and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
    //  - it has not been added into the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    private void sendRoleUpdateNotification(Role newRole,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
                                            List<ObjectName> oldRoleValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                                            boolean relationServCallFlg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
                                            RelationService relationServ)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
               RelationServiceNotRegisteredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
               RelationNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        if (newRole == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            oldRoleValue == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
            (relationServCallFlg && relationServ == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        RELATION_LOGGER.entering(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                "sendRoleUpdateNotification", new Object[] {newRole,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                oldRoleValue, relationServCallFlg, relationServ});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
        if (relationServCallFlg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
            // Direct call to the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
            // Shall not throw a RelationNotFoundException for an internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
            // relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                relationServ.sendRoleUpdateNotification(myRelId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                                                      newRole,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                                                      oldRoleValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
            } catch (RelationNotFoundException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                throw new RuntimeException(exc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
            Object[] params = new Object[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            params[0] = myRelId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            params[1] = newRole;
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1310
            params[2] = oldRoleValue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            String[] signature = new String[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
            signature[0] = "java.lang.String";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
            signature[1] = "javax.management.relation.Role";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
            signature[2] = "java.util.List";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            // Can throw InstanceNotFoundException if the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
            // is not registered (to be transformed).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
            // Can throw a MBeanException wrapping a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
            // RelationNotFoundException (to be raised in any case): wrapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            // exception to be thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
            // Shall not throw a ReflectionException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
                myRelServiceMBeanServer.invoke(myRelServiceName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
                                               "sendRoleUpdateNotification",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
                                               params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
                                               signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            } catch (ReflectionException exc1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                throw new RuntimeException(exc1.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            } catch (InstanceNotFoundException exc2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
                throw new RelationServiceNotRegisteredException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
                                                            exc2.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
            } catch (MBeanException exc3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
                Exception wrappedExc = exc3.getTargetException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
                if (wrappedExc instanceof RelationNotFoundException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                    throw ((RelationNotFoundException)wrappedExc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
                    throw new RuntimeException(wrappedExc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
        RELATION_LOGGER.exiting(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                "sendRoleUpdateNotification");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
    // Requires the Relation Service to update its internal map handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    // MBeans referenced in relations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
    // The Relation Service will also update its recording as a listener to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
    // be informed about unregistration of new referenced MBeans, and no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
    // informed of MBeans no longer referenced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
    // -param newRole  new role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
    // -param oldRoleValue  old role value (ArrayList of ObjectNames)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    // -param relationServCallFlg  true if call from the Relation Service; this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
    //  will happen if the current RelationSupport object has been created by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
    //  the Relation Service (via createRelation()) method, so direct access is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
    //  possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
    // -param relationServ  reference to Relation Service object, if object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
    //  created by Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
    // -exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
    // -exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
    //  Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
    // -exception RelationNotFoundException if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
    //  - relation MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
    //  and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
    //  - the relation is not added in the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
    private void updateRelationServiceMap(Role newRole,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
                                          List<ObjectName> oldRoleValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
                                          boolean relationServCallFlg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
                                          RelationService relationServ)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
               RelationServiceNotRegisteredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
               RelationNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        if (newRole == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
            oldRoleValue == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
            (relationServCallFlg && relationServ == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        RELATION_LOGGER.entering(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
                "updateRelationServiceMap", new Object[] {newRole,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                oldRoleValue, relationServCallFlg, relationServ});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
        if (relationServCallFlg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
            // Direct call to the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
            // Shall not throw a RelationNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                relationServ.updateRoleMap(myRelId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                                         newRole,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                                         oldRoleValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
            } catch (RelationNotFoundException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                throw new RuntimeException(exc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
            Object[] params = new Object[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
            params[0] = myRelId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
            params[1] = newRole;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
            params[2] = oldRoleValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
            String[] signature = new String[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
            signature[0] = "java.lang.String";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
            signature[1] = "javax.management.relation.Role";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
            signature[2] = "java.util.List";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
            // Can throw InstanceNotFoundException if the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
            // is not registered (to be transformed).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
            // Can throw a MBeanException wrapping a RelationNotFoundException:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
            // wrapped exception to be thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
            // Shall not throw a ReflectionException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
                myRelServiceMBeanServer.invoke(myRelServiceName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
                                               "updateRoleMap",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
                                               params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
                                               signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
            } catch (ReflectionException exc1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
                throw new RuntimeException(exc1.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
            } catch (InstanceNotFoundException exc2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
                throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
                     RelationServiceNotRegisteredException(exc2.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
            } catch (MBeanException exc3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
                Exception wrappedExc = exc3.getTargetException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
                if (wrappedExc instanceof RelationNotFoundException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
                    throw ((RelationNotFoundException)wrappedExc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
                    throw new RuntimeException(wrappedExc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
        RELATION_LOGGER.exiting(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
                "updateRelationServiceMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
    // Sets the given roles
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
    // For each role:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
    // - will check the role according to its corresponding role definition
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
    //   provided in relation's relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
    // - will send a notification (RelationNotification with type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
    //   RELATION_BASIC_UPDATE or RELATION_MBEAN_UPDATE, depending if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
    //   relation is a MBean or not) for each updated role.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
    // This method is called in setRoles() above and in Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
    // setRoles() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
    // -param list  list of roles to be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
    // -param relationServCallFlg  true if call from the Relation Service; this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
    //  will happen if the current RelationSupport object has been created by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
    //  the Relation Service (via createRelation()) method, so direct access is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
    //  possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
    // -param relationServ  reference to Relation Service object, if object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
    //  created by Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
    // -return a RoleResult object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
    // -exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
    // -exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
    //  Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
    // -exception RelationTypeNotFoundException if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
    //  - relation MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
    //  and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
    //  - unknown relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
    // -exception RelationNotFoundException if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
    //  - relation MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
    // and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
    // - not added in the RS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
    RoleResult setRolesInt(RoleList list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
                           boolean relationServCallFlg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
                           RelationService relationServ)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
               RelationServiceNotRegisteredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
               RelationTypeNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
               RelationNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
        if (list == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
            (relationServCallFlg && relationServ == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
        RELATION_LOGGER.entering(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                "setRolesInt",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
                new Object[] {list, relationServCallFlg, relationServ});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
        RoleList roleList = new RoleList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
        RoleUnresolvedList roleUnresList = new RoleUnresolvedList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
  1494
        for (Role currRole : list.asList()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
            Object currResult = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
            // Can throw:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
            // RelationServiceNotRegisteredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            // RelationTypeNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
            // Will not throw, due to parameters, RoleNotFoundException or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
            // InvalidRoleValueException, but catch them to keep compiler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
            // happy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
                currResult = setRoleInt(currRole,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
                                        relationServCallFlg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
                                        relationServ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
                                        true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
            } catch (RoleNotFoundException exc1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
                // OK : Do not throw a RoleNotFoundException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
            } catch (InvalidRoleValueException exc2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
                // OK : Do not throw an InvalidRoleValueException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
            if (currResult instanceof Role) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
                // Can throw IllegalArgumentException if role is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
                // (normally should not happen :(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
                    roleList.add((Role)currResult);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
                } catch (IllegalArgumentException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
                    throw new RuntimeException(exc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
            } else if (currResult instanceof RoleUnresolved) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
                // Can throw IllegalArgumentException if role is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
                // (normally should not happen :(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
                    roleUnresList.add((RoleUnresolved)currResult);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
                } catch (IllegalArgumentException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
                    throw new RuntimeException(exc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
        RoleResult result = new RoleResult(roleList, roleUnresList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
        RELATION_LOGGER.exiting(RelationSupport.class.getName(), "setRolesInt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
    // Initializes all members
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
    // -param relationId  relation identifier, to identify the relation in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
    // Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
    // Expected to be unique in the given Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
    // -param relationServiceName  ObjectName of the Relation Service where
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
    // the relation will be registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
    // It is required as this is the Relation Service that is aware of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
    // definition of the relation type of given relation, so that will be able
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
    // to check update operations (set). Direct access via the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
    // Service (RelationService.setRole()) do not need this information but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
    // as any user relation is a MBean, setRole() is part of its management
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
    // interface and can be called directly on the user relation MBean. So the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
    // user relation MBean must be aware of the Relation Service where it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
    // be added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
    // -param relationTypeName  Name of relation type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
    // Expected to have been created in given Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
    // -param list  list of roles (Role objects) to initialized the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
    // relation. Can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
    // Expected to conform to relation info in associated relation type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
    // -exception InvalidRoleValueException  if the same name is used for two
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
    //  roles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
    // -exception IllegalArgumentException  if a required value (Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
    //  Service Object Name, etc.) is not provided as parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
    private void initMembers(String relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                             ObjectName relationServiceName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
                             MBeanServer relationServiceMBeanServer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
                             String relationTypeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
                             RoleList list)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
        throws InvalidRoleValueException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
               IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
        if (relationId == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
            relationServiceName == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
            relationTypeName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
        RELATION_LOGGER.entering(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
                "initMembers", new Object[] {relationId, relationServiceName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
                relationServiceMBeanServer, relationTypeName, list});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
        myRelId = relationId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
        myRelServiceName = relationServiceName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
        myRelServiceMBeanServer = relationServiceMBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
        myRelTypeName = relationTypeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
        // Can throw InvalidRoleValueException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
        initRoleMap(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
        RELATION_LOGGER.exiting(RelationSupport.class.getName(), "initMembers");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
    // Initialize the internal role map from given RoleList parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
    // -param list  role list. Can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
    //  As it is a RoleList object, it cannot include null (rejected).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
    // -exception InvalidRoleValueException  if the same role name is used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
    //  several roles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
    private void initRoleMap(RoleList list)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
        throws InvalidRoleValueException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
        if (list == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
        RELATION_LOGGER.entering(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
                "initRoleMap", list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
        synchronized(myRoleName2ValueMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
  1616
            for (Role currRole : list.asList()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
                // No need to check if role is null, it is not allowed to store
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
                // a null role in a RoleList :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
                String currRoleName = currRole.getRoleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
                if (myRoleName2ValueMap.containsKey(currRoleName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
                    // Role already provided in current list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
                    StringBuilder excMsgStrB = new StringBuilder("Role name ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
                    excMsgStrB.append(currRoleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
                    excMsgStrB.append(" used for two roles.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
                    throw new InvalidRoleValueException(excMsgStrB.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
                myRoleName2ValueMap.put(currRoleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
                                        (Role)(currRole.clone()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
        RELATION_LOGGER.exiting(RelationSupport.class.getName(), "initRoleMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
    // Callback used by the Relation Service when a MBean referenced in a role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
    // is unregistered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
    // The Relation Service will call this method to let the relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
    // take action to reflect the impact of such unregistration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
    // Current implementation is to set the role with its current value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
    // (list of ObjectNames of referenced MBeans) without the unregistered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
    // one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
    // -param objectName  ObjectName of unregistered MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
    // -param roleName  name of role where the MBean is referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
    // -param relationServCallFlg  true if call from the Relation Service; this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
    //  will happen if the current RelationSupport object has been created by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
    //  the Relation Service (via createRelation()) method, so direct access is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
    //  possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
    // -param relationServ  reference to Relation Service object, if internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
    //  relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
    // -exception IllegalArgumentException if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
    // -exception RoleNotFoundException  if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
    //  - the role does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
    //  or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
    //  - role not writable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
    // -exception InvalidRoleValueException  if value provided for:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
    //   - the number of referenced MBeans in given value is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
    //     expected minimum degree
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
    //   or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
    //   - the number of referenced MBeans in provided value exceeds expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
    //     maximum degree
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
    //   or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
    //   - one referenced MBean in the value is not an Object of the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
    //     class expected for that role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
    //   or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
    //   - a MBean provided for that role does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
    // -exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
    //  Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
    // -exception RelationTypeNotFoundException if unknown relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
    // -exception RelationNotFoundException if current relation has not been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
    //  added in the RS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
    void handleMBeanUnregistrationInt(ObjectName objectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
                                      String roleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
                                      boolean relationServCallFlg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
                                      RelationService relationServ)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
               RoleNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
               InvalidRoleValueException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
               RelationServiceNotRegisteredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
               RelationTypeNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
               RelationNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
        if (objectName == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
            roleName == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
            (relationServCallFlg && relationServ == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
        RELATION_LOGGER.entering(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
                "handleMBeanUnregistrationInt", new Object[] {objectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
                roleName, relationServCallFlg, relationServ});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
        // Retrieves current role value
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1700
        Role role;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
        synchronized(myRoleName2ValueMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
            role = (myRoleName2ValueMap.get(roleName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
        if (role == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
            StringBuilder excMsgStrB = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
            String excMsg = "No role with name ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
            excMsgStrB.append(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
            excMsgStrB.append(roleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
            throw new RoleNotFoundException(excMsgStrB.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
        List<ObjectName> currRoleValue = role.getRoleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
        // Note: no need to test if list not null before cloning, null value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
        //       not allowed for role value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
        List<ObjectName> newRoleValue = new ArrayList<ObjectName>(currRoleValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
        newRoleValue.remove(objectName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
        Role newRole = new Role(roleName, newRoleValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
        // Can throw InvalidRoleValueException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
        // RelationTypeNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
        // (RoleNotFoundException already detected)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
        Object result =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
            setRoleInt(newRole, relationServCallFlg, relationServ, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
        RELATION_LOGGER.exiting(RelationSupport.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
                "handleMBeanUnregistrationInt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
}