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