jdk/src/java.management/share/classes/javax/management/relation/RelationService.java
author dfuchs
Fri, 20 Jan 2017 18:41:12 +0000
changeset 43235 da1786d695b6
parent 25859 3317bb8137f4
permissions -rw-r--r--
8172971: java.management could use System.Logger Summary: java.management is updated to use System.Logger instead of java.util.logging.Logger. Reviewed-by: mchung, rriggs
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
import static com.sun.jmx.defaults.JmxProperties.RELATION_LOGGER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import static com.sun.jmx.mbeanserver.Util.cast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Set;
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
    38
import java.util.concurrent.atomic.AtomicLong;
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
    39
import java.lang.System.Logger.Level;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.management.Attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.management.AttributeNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.management.InstanceNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.management.InvalidAttributeValueException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.management.MBeanException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.management.MBeanNotificationInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.management.MBeanRegistration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.management.MBeanServerDelegate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import javax.management.MBeanServerNotification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import javax.management.Notification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import javax.management.NotificationBroadcasterSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import javax.management.NotificationListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import javax.management.ReflectionException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * The Relation Service is in charge of creating and deleting relation types
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * and relations, of handling the consistency and of providing query
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * mechanisms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <P>It implements the NotificationBroadcaster by extending
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * NotificationBroadcasterSupport to send notifications when a relation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * removed from it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <P>It implements the NotificationListener interface to be able to receive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * notifications concerning unregistration of MBeans referenced in relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * roles and of relation MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <P>It implements the MBeanRegistration interface to be able to retrieve
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * its ObjectName and MBean Server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
public class RelationService extends NotificationBroadcasterSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    implements RelationServiceMBean, MBeanRegistration, NotificationListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    // Private members
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    // Map associating:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    //      <relation id> -> <RelationSupport object/ObjectName>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    // depending if the relation has been created using createRelation()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    // method (so internally handled) or is an MBean added as a relation by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    // user
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private Map<String,Object> myRelId2ObjMap = new HashMap<String,Object>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    // Map associating:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    //      <relation id> -> <relation type name>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private Map<String,String> myRelId2RelTypeMap = new HashMap<String,String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    // Map associating:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    //      <relation MBean Object Name> -> <relation id>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private Map<ObjectName,String> myRelMBeanObjName2RelIdMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        new HashMap<ObjectName,String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    // Map associating:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    //       <relation type name> -> <RelationType object>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private Map<String,RelationType> myRelType2ObjMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        new HashMap<String,RelationType>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    // Map associating:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    //       <relation type name> -> ArrayList of <relation id>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    // to list all the relations of a given type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private Map<String,List<String>> myRelType2RelIdsMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        new HashMap<String,List<String>>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    // Map associating:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    //       <ObjectName> -> HashMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    // the value HashMap mapping:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    //       <relation id> -> ArrayList of <role name>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    // to track where a given MBean is referenced.
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
   111
    private final Map<ObjectName,Map<String,List<String>>>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        myRefedMBeanObjName2RelIdsMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            new HashMap<ObjectName,Map<String,List<String>>>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    // Flag to indicate if, when a notification is received for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    // unregistration of an MBean referenced in a relation, if an immediate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    // "purge" of the relations (look for the relations no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    // longer valid) has to be performed , or if that will be performed only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    // when the purgeRelations method will be explicitly called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    // true is immediate purge.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private boolean myPurgeFlag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    // Internal counter to provide sequence numbers for notifications sent by:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    // - the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    // - a relation handled by the Relation Service
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   126
    private final AtomicLong atomicSeqNo = new AtomicLong();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    // ObjectName used to register the Relation Service in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private ObjectName myObjName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    // MBean Server where the Relation Service is registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    private MBeanServer myMBeanServer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    // Filter registered in the MBean Server with the Relation Service to be
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
   135
    // informed of referenced MBean deregistrations
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private MBeanServerNotificationFilter myUnregNtfFilter = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    // List of unregistration notifications received (storage used if purge
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    // of relations when unregistering a referenced MBean is not immediate but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    // on user request)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private List<MBeanServerNotification> myUnregNtfList =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        new ArrayList<MBeanServerNotification>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    // Constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @param immediatePurgeFlag  flag to indicate when a notification is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * received for the unregistration of an MBean referenced in a relation, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * an immediate "purge" of the relations (look for the relations no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * longer valid) has to be performed , or if that will be performed only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * when the purgeRelations method will be explicitly called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * <P>true is immediate purge.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public RelationService(boolean immediatePurgeFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   160
        RELATION_LOGGER.log(Level.TRACE, "ENTRY");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        setPurgeFlag(immediatePurgeFlag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   164
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Checks if the Relation Service is active.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Current condition is that the Relation Service must be registered in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @exception RelationServiceNotRegisteredException  if it is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public void isActive()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        throws RelationServiceNotRegisteredException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        if (myMBeanServer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            // MBean Server not set by preRegister(): relation service not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            // registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            String excMsg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                "Relation Service not registered in the MBean Server.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            throw new RelationServiceNotRegisteredException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    // MBeanRegistration interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    // Pre-registration: retrieves its ObjectName and MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    // No exception thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public ObjectName preRegister(MBeanServer server,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                                  ObjectName name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        myMBeanServer = server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        myObjName = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    // Post-registration: does nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public void postRegister(Boolean registrationDone) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    // Pre-unregistration: does nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public void preDeregister()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    // Post-unregistration: does nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public void postDeregister() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    // Accessors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Returns the flag to indicate if when a notification is received for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * unregistration of an MBean referenced in a relation, if an immediate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * "purge" of the relations (look for the relations no longer valid)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * has to be performed , or if that will be performed only when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * purgeRelations method will be explicitly called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * <P>true is immediate purge.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @return true if purges are automatic.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @see #setPurgeFlag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public boolean getPurgeFlag() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        return myPurgeFlag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Sets the flag to indicate if when a notification is received for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * unregistration of an MBean referenced in a relation, if an immediate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * "purge" of the relations (look for the relations no longer valid)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * has to be performed , or if that will be performed only when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * purgeRelations method will be explicitly called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * <P>true is immediate purge.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @param purgeFlag  flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @see #getPurgeFlag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public void setPurgeFlag(boolean purgeFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        myPurgeFlag = purgeFlag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    // Relation type handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Creates a relation type (a RelationTypeSupport object) with given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * role infos (provided by the RoleInfo objects), and adds it in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @param relationTypeName  name of the relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @param roleInfoArray  array of role infos
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @exception InvalidRelationTypeException  If:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * <P>- there is already a relation type with that name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * <P>- the same name has been used for two different role infos
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * <P>- no role info provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * <P>- one null role info provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public void createRelationType(String relationTypeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                                   RoleInfo[] roleInfoArray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
               InvalidRelationTypeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        if (relationTypeName == null || roleInfoArray == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   287
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0}", relationTypeName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        // Can throw an InvalidRelationTypeException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        RelationType relType =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            new RelationTypeSupport(relationTypeName, roleInfoArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        addRelationTypeInt(relType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   295
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Adds given object as a relation type. The object is expected to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * implement the RelationType interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @param relationTypeObj  relation type object (implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * RelationType interface)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @exception IllegalArgumentException  if null parameter or if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * {@link RelationType#getRelationTypeName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * relationTypeObj.getRelationTypeName()} returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @exception InvalidRelationTypeException  if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * <P>- the same name has been used for two different roles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * <P>- no role info provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * <P>- one null role info provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * <P>- there is already a relation type with that name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public void addRelationType(RelationType relationTypeObj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
               InvalidRelationTypeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        if (relationTypeObj == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   324
        RELATION_LOGGER.log(Level.TRACE, "ENTRY");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        // Checks the role infos
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        List<RoleInfo> roleInfoList = relationTypeObj.getRoleInfos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        if (roleInfoList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            String excMsg = "No role info provided.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            throw new InvalidRelationTypeException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        RoleInfo[] roleInfoArray = new RoleInfo[roleInfoList.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        for (RoleInfo currRoleInfo : roleInfoList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            roleInfoArray[i] = currRoleInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        // Can throw InvalidRelationTypeException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        RelationTypeSupport.checkRoleInfos(roleInfoArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        addRelationTypeInt(relationTypeObj);
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, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * Retrieves names of all known relation types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @return ArrayList of relation type names (Strings)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    public List<String> getAllRelationTypeNames() {
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   354
        ArrayList<String> result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        synchronized(myRelType2ObjMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            result = new ArrayList<String>(myRelType2ObjMap.keySet());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * Retrieves list of role infos (RoleInfo objects) of a given relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @param relationTypeName  name of relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @return ArrayList of RoleInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @exception RelationTypeNotFoundException  if there is no relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * with that name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    public List<RoleInfo> getRoleInfos(String relationTypeName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
               RelationTypeNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        if (relationTypeName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   382
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0}", relationTypeName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        // Can throw a RelationTypeNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        RelationType relType = getRelationType(relationTypeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   387
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        return relType.getRoleInfos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * Retrieves role info for given role name of a given relation type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @param relationTypeName  name of relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @param roleInfoName  name of role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @return RoleInfo object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @exception RelationTypeNotFoundException  if the relation type is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * known in the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @exception RoleInfoNotFoundException  if the role is not part of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * relation type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    public RoleInfo getRoleInfo(String relationTypeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                                String roleInfoName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
               RelationTypeNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
               RoleInfoNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        if (relationTypeName == null || roleInfoName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   416
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1}",
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   417
                            relationTypeName, roleInfoName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        // Can throw a RelationTypeNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        RelationType relType = getRelationType(relationTypeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        // Can throw a RoleInfoNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        RoleInfo roleInfo = relType.getRoleInfo(roleInfoName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   425
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        return roleInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * Removes given relation type from Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * <P>The relation objects of that type will be removed from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @param relationTypeName  name of the relation type to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @exception RelationTypeNotFoundException  If there is no relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * with that name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    public void removeRelationType(String relationTypeName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        throws RelationServiceNotRegisteredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
               IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
               RelationTypeNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        // Can throw RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        isActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        if (relationTypeName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   455
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0}", relationTypeName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        // Checks if the relation type to be removed exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        // Can throw a RelationTypeNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        RelationType relType = getRelationType(relationTypeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        // Retrieves the relation ids for relations of that type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        List<String> relIdList = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        synchronized(myRelType2RelIdsMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            // Note: take a copy of the list as it is a part of a map that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            //       will be updated by removeRelation() below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            List<String> relIdList1 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                myRelType2RelIdsMap.get(relationTypeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            if (relIdList1 != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                relIdList = new ArrayList<String>(relIdList1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        // Removes the relation type from all maps
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        synchronized(myRelType2ObjMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            myRelType2ObjMap.remove(relationTypeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        synchronized(myRelType2RelIdsMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            myRelType2RelIdsMap.remove(relationTypeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        // Removes all relations of that type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        if (relIdList != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            for (String currRelId : relIdList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                // Note: will remove it from myRelId2RelTypeMap :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                // Can throw RelationServiceNotRegisteredException (detected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                // above)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                // Shall not throw a RelationNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                    removeRelation(currRelId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                } catch (RelationNotFoundException exc1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                    throw new RuntimeException(exc1.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   497
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    // Relation handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * Creates a simple relation (represented by a RelationSupport object) of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * given relation type, and adds it in the Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * <P>Roles are initialized according to the role list provided in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * parameter. The ones not initialized in this way are set to an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * ArrayList of ObjectNames.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * <P>A RelationNotification, with type RELATION_BASIC_CREATION, is sent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * @param relationId  relation identifier, to identify uniquely the relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * inside the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * @param relationTypeName  name of the relation type (has to be created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * in the Relation Service)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @param roleList  role list to initialize roles of the relation (can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * be null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * @exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * @exception IllegalArgumentException  if null parameter, except the role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * list which can be null if no role initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * @exception RoleNotFoundException  if a value is provided for a role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * that does not exist in the relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @exception InvalidRelationIdException  if relation id already used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * @exception RelationTypeNotFoundException  if relation type not known in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @exception InvalidRoleValueException if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * <P>- the same role name is used for two different roles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * <P>- the number of referenced MBeans in given value is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * expected minimum degree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * <P>- the number of referenced MBeans in provided value exceeds expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * maximum degree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * <P>- one referenced MBean in the value is not an Object of the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * class expected for that role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * <P>- an MBean provided for that role does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    public void createRelation(String relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                               String relationTypeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                               RoleList roleList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        throws RelationServiceNotRegisteredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
               IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
               RoleNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
               InvalidRelationIdException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
               RelationTypeNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
               InvalidRoleValueException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        // Can throw RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        isActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        if (relationId == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            relationTypeName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   558
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1} {2}",
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   559
                            relationId, relationTypeName, roleList);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        // Creates RelationSupport object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        // Can throw InvalidRoleValueException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        RelationSupport relObj = new RelationSupport(relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                                               myObjName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                                               relationTypeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                                               roleList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        // Adds relation object as a relation into the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        // Can throw RoleNotFoundException, InvalidRelationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        // RelationTypeNotFoundException, InvalidRoleValueException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        // Cannot throw MBeanException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        addRelationInt(true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                       relObj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                       null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                       relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                       relationTypeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                       roleList);
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   579
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * Adds an MBean created by the user (and registered by him in the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * Server) as a relation in the Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * <P>To be added as a relation, the MBean must conform to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * <P>- implement the Relation interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * <P>- have for RelationService ObjectName the ObjectName of current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * <P>- have a relation id unique and unused in current Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * <P>- have for relation type a relation type created in the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * <P>- have roles conforming to the role info provided in the relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * @param relationObjectName  ObjectName of the relation MBean to be added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * @exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * @exception NoSuchMethodException  If the MBean does not implement the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * Relation interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * @exception InvalidRelationIdException  if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * <P>- no relation identifier in MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * <P>- the relation identifier is already used in the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * @exception InstanceNotFoundException  if the MBean for given ObjectName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * has not been registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * @exception InvalidRelationServiceException  if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * <P>- no Relation Service name in MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * <P>- the Relation Service name in the MBean is not the one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * current Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * @exception RelationTypeNotFoundException  if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * <P>- no relation type name in MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * <P>- the relation type name in MBean does not correspond to a relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * type created in the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * @exception InvalidRoleValueException  if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * <P>- the number of referenced MBeans in a role is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * expected minimum degree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * <P>- the number of referenced MBeans in a role exceeds expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * maximum degree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * <P>- one referenced MBean in the value is not an Object of the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * class expected for that role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * <P>- an MBean provided for a role does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * @exception RoleNotFoundException  if a value is provided for a role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * that does not exist in the relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    public void addRelation(ObjectName relationObjectName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
               RelationServiceNotRegisteredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
               NoSuchMethodException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
               InvalidRelationIdException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
               InstanceNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
               InvalidRelationServiceException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
               RelationTypeNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
               RoleNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
               InvalidRoleValueException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        if (relationObjectName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   644
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0}", relationObjectName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        // Can throw RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        isActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        // Checks that the relation MBean implements the Relation interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        // It will also check that the provided ObjectName corresponds to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        // registered MBean (else will throw an InstanceNotFoundException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        if ((!(myMBeanServer.isInstanceOf(relationObjectName, "javax.management.relation.Relation")))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            String excMsg = "This MBean does not implement the Relation interface.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            throw new NoSuchMethodException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        // Checks there is a relation id in the relation MBean (its uniqueness
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        // is checked in addRelationInt())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        // Can throw InstanceNotFoundException (but detected above)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        // No MBeanException as no exception raised by this method, and no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        // ReflectionException
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   661
        String relId;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            relId = (String)(myMBeanServer.getAttribute(relationObjectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                                                        "RelationId"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        } catch (MBeanException exc1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            throw new RuntimeException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                                     (exc1.getTargetException()).getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        } catch (ReflectionException exc2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            throw new RuntimeException(exc2.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        } catch (AttributeNotFoundException exc3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            throw new RuntimeException(exc3.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        if (relId == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            String excMsg = "This MBean does not provide a relation id.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            throw new InvalidRelationIdException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        // Checks that the Relation Service where the relation MBean is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        // expected to be added is the current one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        // Can throw InstanceNotFoundException (but detected above)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        // No MBeanException as no exception raised by this method, no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        // ReflectionException
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   684
        ObjectName relServObjName;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            relServObjName = (ObjectName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                (myMBeanServer.getAttribute(relationObjectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                                            "RelationServiceName"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        } catch (MBeanException exc1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            throw new RuntimeException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                                     (exc1.getTargetException()).getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        } catch (ReflectionException exc2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            throw new RuntimeException(exc2.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        } catch (AttributeNotFoundException exc3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            throw new RuntimeException(exc3.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        boolean badRelServFlag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        if (relServObjName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            badRelServFlag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        } else if (!(relServObjName.equals(myObjName))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            badRelServFlag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        if (badRelServFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            String excMsg = "The Relation Service referenced in the MBean is not the current one.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            throw new InvalidRelationServiceException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        // Checks that a relation type has been specified for the relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        // Can throw InstanceNotFoundException (but detected above)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        // No MBeanException as no exception raised by this method, no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        // ReflectionException
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   714
        String relTypeName;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            relTypeName = (String)(myMBeanServer.getAttribute(relationObjectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                                                              "RelationTypeName"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        } catch (MBeanException exc1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            throw new RuntimeException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                                     (exc1.getTargetException()).getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        }catch (ReflectionException exc2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            throw new RuntimeException(exc2.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        } catch (AttributeNotFoundException exc3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            throw new RuntimeException(exc3.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        if (relTypeName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            String excMsg = "No relation type provided.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            throw new RelationTypeNotFoundException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        // Retrieves all roles without considering read mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        // Can throw InstanceNotFoundException (but detected above)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        // No MBeanException as no exception raised by this method, no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        // ReflectionException
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   735
        RoleList roleList;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            roleList = (RoleList)(myMBeanServer.invoke(relationObjectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                                                       "retrieveAllRoles",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                                                       null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                                                       null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        } catch (MBeanException exc1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            throw new RuntimeException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                                     (exc1.getTargetException()).getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        } catch (ReflectionException exc2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            throw new RuntimeException(exc2.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        // Can throw RoleNotFoundException, InvalidRelationIdException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        // RelationTypeNotFoundException, InvalidRoleValueException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        addRelationInt(false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                       null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                       relationObjectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                       relId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                       relTypeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                       roleList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        // Adds relation MBean ObjectName in map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        synchronized(myRelMBeanObjName2RelIdMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            myRelMBeanObjName2RelIdMap.put(relationObjectName, relId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        // Updates flag to specify that the relation is managed by the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        // Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        // This flag and setter are inherited from RelationSupport and not parts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        // of the Relation interface, so may be not supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            myMBeanServer.setAttribute(relationObjectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                                       new Attribute(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                                         "RelationServiceManagementFlag",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                                         Boolean.TRUE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        } catch (Exception exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            // OK : The flag is not supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        // Updates listener information to received notification for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        // unregistration of this MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        List<ObjectName> newRefList = new ArrayList<ObjectName>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        newRefList.add(relationObjectName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        updateUnregistrationListener(newRefList, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   780
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * If the relation is represented by an MBean (created by the user and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * added as a relation in the Relation Service), returns the ObjectName of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * the MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * @param relationId  relation id identifying the relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * @return ObjectName of the corresponding relation MBean, or null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * the relation is not an MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * @exception RelationNotFoundException there is no relation associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * to that id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    public ObjectName isRelationMBean(String relationId)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
               RelationNotFoundException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        if (relationId == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   807
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0}", relationId);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        // Can throw RelationNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        Object result = getRelation(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        if (result instanceof ObjectName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            return ((ObjectName)result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * Returns the relation id associated to the given ObjectName if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * MBean has been added as a relation in the Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * @param objectName  ObjectName of supposed relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * @return relation id (String) or null (if the ObjectName is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * relation handled by the Relation Service)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    public String isRelation(ObjectName objectName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        if (objectName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   837
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0}", objectName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        String result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        synchronized(myRelMBeanObjName2RelIdMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            String relId = myRelMBeanObjName2RelIdMap.get(objectName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            if (relId != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                result = relId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * Checks if there is a relation identified in Relation Service with given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * relation id.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * @param relationId  relation id identifying the relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * @return boolean: true if there is a relation, false else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    public Boolean hasRelation(String relationId)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        if (relationId == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   867
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0}", relationId);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            // Can throw RelationNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            Object result = getRelation(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        } catch (RelationNotFoundException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * Returns all the relation ids for all the relations handled by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * @return ArrayList of String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    public List<String> getAllRelationIds() {
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   885
        List<String> result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        synchronized(myRelId2ObjMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            result = new ArrayList<String>(myRelId2ObjMap.keySet());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * Checks if given Role can be read in a relation of the given type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * @param roleName  name of role to be checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * @param relationTypeName  name of the relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * @return an Integer wrapping an integer corresponding to possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * problems represented as constants in RoleUnresolved:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * <P>- 0 if role can be read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * <P>- integer corresponding to RoleStatus.NO_ROLE_WITH_NAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * <P>- integer corresponding to RoleStatus.ROLE_NOT_READABLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * @exception RelationTypeNotFoundException  if the relation type is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * known in the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    public Integer checkRoleReading(String roleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                                    String relationTypeName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
               RelationTypeNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        if (roleName == null || relationTypeName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   918
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1}",
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   919
                            roleName, relationTypeName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   921
        Integer result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        // Can throw a RelationTypeNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        RelationType relType = getRelationType(relationTypeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            // Can throw a RoleInfoNotFoundException to be transformed into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            // returned value RoleStatus.NO_ROLE_WITH_NAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            RoleInfo roleInfo = relType.getRoleInfo(roleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            result =  checkRoleInt(1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                                   roleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                                   null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                                   roleInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                                   false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        } catch (RoleInfoNotFoundException exc) {
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   938
            result = Integer.valueOf(RoleStatus.NO_ROLE_WITH_NAME);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   941
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * Checks if given Role can be set in a relation of given type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * @param role  role to be checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * @param relationTypeName  name of relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * @param initFlag  flag to specify that the checking is done for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * initialization of a role, write access shall not be verified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     * @return an Integer wrapping an integer corresponding to possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * problems represented as constants in RoleUnresolved:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     * <P>- 0 if role can be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     * <P>- integer corresponding to RoleStatus.NO_ROLE_WITH_NAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * <P>- integer for RoleStatus.ROLE_NOT_WRITABLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     * <P>- integer for RoleStatus.LESS_THAN_MIN_ROLE_DEGREE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * <P>- integer for RoleStatus.MORE_THAN_MAX_ROLE_DEGREE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * <P>- integer for RoleStatus.REF_MBEAN_OF_INCORRECT_CLASS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * <P>- integer for RoleStatus.REF_MBEAN_NOT_REGISTERED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     * @exception RelationTypeNotFoundException  if unknown relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    public Integer checkRoleWriting(Role role,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                                    String relationTypeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                                    Boolean initFlag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
               RelationTypeNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        if (role == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            relationTypeName == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
            initFlag == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   979
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1} {2}",
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   980
                            role, relationTypeName, initFlag);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        // Can throw a RelationTypeNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        RelationType relType = getRelationType(relationTypeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        String roleName = role.getRoleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        List<ObjectName> roleValue = role.getRoleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        boolean writeChkFlag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        if (initFlag.booleanValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            writeChkFlag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   992
        RoleInfo roleInfo;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            roleInfo = relType.getRoleInfo(roleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        } catch (RoleInfoNotFoundException exc) {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   996
            RELATION_LOGGER.log(Level.TRACE, "RETURN");
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   997
            return Integer.valueOf(RoleStatus.NO_ROLE_WITH_NAME);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        Integer result = checkRoleInt(2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                                      roleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                                      roleValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                                      roleInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                                      writeChkFlag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1006
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * Sends a notification (RelationNotification) for a relation creation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * The notification type is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * <P>- RelationNotification.RELATION_BASIC_CREATION if the relation is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * object internal to the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * <P>- RelationNotification.RELATION_MBEAN_CREATION if the relation is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * MBean added as a relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * <P>The source object is the Relation Service itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * <P>It is called in Relation Service createRelation() and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * addRelation() methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * @param relationId  relation identifier of the updated relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * @exception RelationNotFoundException  if there is no relation for given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * relation id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
    public void sendRelationCreationNotification(String relationId)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
               RelationNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        if (relationId == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1036
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0}", relationId);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        // Message
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        StringBuilder ntfMsg = new StringBuilder("Creation of relation ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        ntfMsg.append(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        // Can throw RelationNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        sendNotificationInt(1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                            ntfMsg.toString(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                            relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                            null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                            null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                            null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                            null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1051
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     * Sends a notification (RelationNotification) for a role update in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * given relation. The notification type is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     * <P>- RelationNotification.RELATION_BASIC_UPDATE if the relation is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     * object internal to the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     * <P>- RelationNotification.RELATION_MBEAN_UPDATE if the relation is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     * MBean added as a relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * <P>The source object is the Relation Service itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * <P>It is called in relation MBean setRole() (for given role) and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * setRoles() (for each role) methods (implementation provided in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * RelationSupport class).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * <P>It is also called in Relation Service setRole() (for given role) and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * setRoles() (for each role) methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     * @param relationId  relation identifier of the updated relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     * @param newRole  new role (name and new value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     * @param oldValue  old role value (List of ObjectName objects)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * @exception RelationNotFoundException  if there is no relation for given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * relation id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    public void sendRoleUpdateNotification(String relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                                           Role newRole,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                                           List<ObjectName> oldValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
               RelationNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        if (relationId == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            newRole == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            oldValue == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  1090
        if (!(oldValue instanceof ArrayList<?>))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            oldValue = new ArrayList<ObjectName>(oldValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1093
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1} {2}",
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1094
                            relationId, newRole, oldValue);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        String roleName = newRole.getRoleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        List<ObjectName> newRoleVal = newRole.getRoleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        // Message
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        String newRoleValString = Role.roleValueToString(newRoleVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        String oldRoleValString = Role.roleValueToString(oldValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        StringBuilder ntfMsg = new StringBuilder("Value of role ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        ntfMsg.append(roleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        ntfMsg.append(" has changed\nOld value:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        ntfMsg.append(oldRoleValString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        ntfMsg.append("\nNew value:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        ntfMsg.append(newRoleValString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        // Can throw a RelationNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        sendNotificationInt(2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                            ntfMsg.toString(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                            relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                            null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                            roleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                            newRoleVal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                            oldValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1118
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
     * Sends a notification (RelationNotification) for a relation removal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
     * The notification type is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
     * <P>- RelationNotification.RELATION_BASIC_REMOVAL if the relation is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     * object internal to the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     * <P>- RelationNotification.RELATION_MBEAN_REMOVAL if the relation is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     * MBean added as a relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     * <P>The source object is the Relation Service itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     * <P>It is called in Relation Service removeRelation() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     * @param relationId  relation identifier of the updated relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * @param unregMBeanList  List of ObjectNames of MBeans expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * to be unregistered due to relation removal (can be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * @exception RelationNotFoundException  if there is no relation for given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * relation id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    public void sendRelationRemovalNotification(String relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                                                List<ObjectName> unregMBeanList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
               RelationNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        if (relationId == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
            String excMsg = "Invalid parameter";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1149
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1}",
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1150
                            relationId, unregMBeanList);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        // Can throw RelationNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        sendNotificationInt(3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                            "Removal of relation " + relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                            relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                            unregMBeanList,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
                            null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                            null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                            null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1162
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * Handles update of the Relation Service role map for the update of given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     * role in given relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     * <P>It is called in relation MBean setRole() (for given role) and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     * setRoles() (for each role) methods (implementation provided in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * RelationSupport class).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * <P>It is also called in Relation Service setRole() (for given role) and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     * setRoles() (for each role) methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * <P>To allow the Relation Service to maintain the consistency (in case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * of MBean unregistration) and to be able to perform queries, this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     * must be called when a role is updated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     * @param relationId  relation identifier of the updated relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     * @param newRole  new role (name and new value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     * @param oldValue  old role value (List of ObjectName objects)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     * @exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     * Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     * @exception RelationNotFoundException  if no relation for given id.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
    public void updateRoleMap(String relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                              Role newRole,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                              List<ObjectName> oldValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
               RelationServiceNotRegisteredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
               RelationNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        if (relationId == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            newRole == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
            oldValue == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1201
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1} {2}",
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1202
                            relationId, newRole, oldValue);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        // Can throw RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
        isActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        // Verifies the relation has been added in the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        // Can throw a RelationNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        Object result = getRelation(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
        String roleName = newRole.getRoleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        List<ObjectName> newRoleValue = newRole.getRoleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        // Note: no need to test if oldValue not null before cloning,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        //       tested above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        List<ObjectName> oldRoleValue =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
            new ArrayList<ObjectName>(oldValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        // List of ObjectNames of new referenced MBeans
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        List<ObjectName> newRefList = new ArrayList<ObjectName>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        for (ObjectName currObjName : newRoleValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            // Checks if this ObjectName was already present in old value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            // Note: use copy (oldRoleValue) instead of original
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
            //       oldValue to speed up, as oldRoleValue is decreased
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
            //       by removing unchanged references :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            int currObjNamePos = oldRoleValue.indexOf(currObjName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
            if (currObjNamePos == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
                // New reference to an ObjectName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                // Stores this reference into map
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                // Returns true if new reference, false if MBean already
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                // referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
                boolean isNewFlag = addNewMBeanReference(currObjName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
                                                        relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
                                                        roleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
                if (isNewFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
                    // Adds it into list of new reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                    newRefList.add(currObjName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                // MBean was already referenced in old value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
                // Removes it from old value (local list) to ignore it when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
                // looking for remove MBean references
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                oldRoleValue.remove(currObjNamePos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        // List of ObjectNames of MBeans no longer referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        List<ObjectName> obsRefList = new ArrayList<ObjectName>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        // Each ObjectName remaining in oldRoleValue is an ObjectName no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
        // referenced in new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        for (ObjectName currObjName : oldRoleValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
            // Removes MBean reference from map
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
            // Returns true if the MBean is no longer referenced in any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            // relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            boolean noLongerRefFlag = removeMBeanReference(currObjName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                                                          relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                                                          roleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                                                          false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
            if (noLongerRefFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                // Adds it into list of references to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                obsRefList.add(currObjName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        // To avoid having one listener per ObjectName of referenced MBean,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        // and to increase performances, there is only one listener recording
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        // all ObjectNames of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        updateUnregistrationListener(newRefList, obsRefList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1278
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
     * Removes given relation from the Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
     * <P>A RelationNotification notification is sent, its type being:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
     * <P>- RelationNotification.RELATION_BASIC_REMOVAL if the relation was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
     * only internal to the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
     * <P>- RelationNotification.RELATION_MBEAN_REMOVAL if the relation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
     * registered as an MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
     * <P>For MBeans referenced in such relation, nothing will be done,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
     * @param relationId  relation id of the relation to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
     * @exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
     * Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     * @exception RelationNotFoundException  if no relation corresponding to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
     * given relation id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
    public void removeRelation(String relationId)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        throws RelationServiceNotRegisteredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
               IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
               RelationNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
        // Can throw RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
        isActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        if (relationId == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1312
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0}", relationId);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        // Checks there is a relation with this id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        // Can throw RelationNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
        Object result = getRelation(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        // Removes it from listener filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        if (result instanceof ObjectName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
            List<ObjectName> obsRefList = new ArrayList<ObjectName>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            obsRefList.add((ObjectName)result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
            // Can throw a RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
            updateUnregistrationListener(null, obsRefList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        // Sends a notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        // Note: has to be done FIRST as needs the relation to be still in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        //       Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        // No RelationNotFoundException as checked above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        // Revisit [cebro] Handle CIM "Delete" and "IfDeleted" qualifiers:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        //   deleting the relation can mean to delete referenced MBeans. In
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        //   that case, MBeans to be unregistered are put in a list sent along
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        //   with the notification below
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        // Can throw a RelationNotFoundException (but detected above)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
        sendRelationRemovalNotification(relationId, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        // Removes the relation from various internal maps
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        //  - MBean reference map
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        // Retrieves the MBeans referenced in this relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        // Note: here we cannot use removeMBeanReference() because it would
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
        //       require to know the MBeans referenced in the relation. For
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        //       that it would be necessary to call 'getReferencedMBeans()'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        //       on the relation itself. Ok if it is an internal one, but if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        //       it is an MBean, it is possible it is already unregistered, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        //       not available through the MBean Server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        List<ObjectName> refMBeanList = new ArrayList<ObjectName>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
        // List of MBeans no longer referenced in any relation, to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        // removed fom the map
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
        List<ObjectName> nonRefObjNameList = new ArrayList<ObjectName>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        synchronized(myRefedMBeanObjName2RelIdsMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
            for (ObjectName currRefObjName :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
                     myRefedMBeanObjName2RelIdsMap.keySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
                // Retrieves relations where the MBean is referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
                Map<String,List<String>> relIdMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
                    myRefedMBeanObjName2RelIdsMap.get(currRefObjName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
                if (relIdMap.containsKey(relationId)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                    relIdMap.remove(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
                    refMBeanList.add(currRefObjName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                if (relIdMap.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                    // MBean no longer referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
                    // Note: do not remove it here because pointed by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
                    //       iterator!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
                    nonRefObjNameList.add(currRefObjName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
            // Cleans MBean reference map by removing MBeans no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
            // referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
            for (ObjectName currRefObjName : nonRefObjNameList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
                myRefedMBeanObjName2RelIdsMap.remove(currRefObjName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        // - Relation id to object map
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        synchronized(myRelId2ObjMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
            myRelId2ObjMap.remove(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        if (result instanceof ObjectName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
            // - ObjectName to relation id map
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
            synchronized(myRelMBeanObjName2RelIdMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
                myRelMBeanObjName2RelIdMap.remove((ObjectName)result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
        // Relation id to relation type name map
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
        // First retrieves the relation type name
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1397
        String relTypeName;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
        synchronized(myRelId2RelTypeMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
            relTypeName = myRelId2RelTypeMap.get(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
            myRelId2RelTypeMap.remove(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
        // - Relation type name to relation id map
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
        synchronized(myRelType2RelIdsMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
            List<String> relIdList = myRelType2RelIdsMap.get(relTypeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
            if (relIdList != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
                // Can be null if called from removeRelationType()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                relIdList.remove(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
                if (relIdList.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                    // No other relation of that type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                    myRelType2RelIdsMap.remove(relTypeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1415
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
     * Purges the relations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     * <P>Depending on the purgeFlag value, this method is either called
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     * automatically when a notification is received for the unregistration of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     * an MBean referenced in a relation (if the flag is set to true), or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     * (if the flag is set to false).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     * <P>In that case it is up to the user to call it to maintain the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
     * consistency of the relations. To be kept in mind that if an MBean is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
     * unregistered and the purge not done immediately, if the ObjectName is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
     * reused and assigned to another MBean referenced in a relation, calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
     * manually this purgeRelations() method will cause trouble, as will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
     * consider the ObjectName as corresponding to the unregistered MBean, not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
     * seeing the new one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
     * <P>The behavior depends on the cardinality of the role where the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
     * unregistered MBean is referenced:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
     * <P>- if removing one MBean reference in the role makes its number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
     * references less than the minimum degree, the relation has to be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
     * <P>- if the remaining number of references after removing the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
     * reference is still in the cardinality range, keep the relation and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
     * update it calling its handleMBeanUnregistration() callback.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     * @exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
     * Service is not registered in the MBean Server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
    public void purgeRelations()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
        throws RelationServiceNotRegisteredException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1448
        RELATION_LOGGER.log(Level.TRACE, "ENTRY");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
        // Can throw RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        isActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
        // Revisit [cebro] Handle the CIM "Delete" and "IfDeleted" qualifier:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
        //    if the unregistered MBean has the "IfDeleted" qualifier,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
        //    possible that the relation itself or other referenced MBeans
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
        //    have to be removed (then a notification would have to be sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
        //    to inform that they should be unregistered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        // Clones the list of notifications to be able to still receive new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
        // notifications while proceeding those ones
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        List<MBeanServerNotification> localUnregNtfList;
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
  1463
        synchronized(myRefedMBeanObjName2RelIdsMap) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
            localUnregNtfList =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
                new ArrayList<MBeanServerNotification>(myUnregNtfList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
            // Resets list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
            myUnregNtfList = new ArrayList<MBeanServerNotification>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        // Updates the listener filter to avoid receiving notifications for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
        // those MBeans again
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
        // Makes also a local "myRefedMBeanObjName2RelIdsMap" map, mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
        // ObjectName -> relId -> roles, to remove the MBean from the global
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
        // map
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
        // List of references to be removed from the listener filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
        List<ObjectName> obsRefList = new ArrayList<ObjectName>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
        // Map including ObjectNames for unregistered MBeans, with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
        // referencing relation ids and roles
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
        Map<ObjectName,Map<String,List<String>>> localMBean2RelIdMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
            new HashMap<ObjectName,Map<String,List<String>>>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
        synchronized(myRefedMBeanObjName2RelIdsMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
            for (MBeanServerNotification currNtf : localUnregNtfList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
                ObjectName unregMBeanName = currNtf.getMBeanName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                // Adds the unregsitered MBean in the list of references to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
                // remove from the listener filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
                obsRefList.add(unregMBeanName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
                // Retrieves the associated map of relation ids and roles
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
                Map<String,List<String>> relIdMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                    myRefedMBeanObjName2RelIdsMap.get(unregMBeanName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
                localMBean2RelIdMap.put(unregMBeanName, relIdMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
                myRefedMBeanObjName2RelIdsMap.remove(unregMBeanName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
        // Updates the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
        // Can throw RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        updateUnregistrationListener(null, obsRefList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
        for (MBeanServerNotification currNtf : localUnregNtfList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
            ObjectName unregMBeanName = currNtf.getMBeanName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
            // Retrieves the relations where the MBean is referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
            Map<String,List<String>> localRelIdMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
                    localMBean2RelIdMap.get(unregMBeanName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
            // List of relation ids where the unregistered MBean is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
            // referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
            for (Map.Entry<String,List<String>> currRel :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
                        localRelIdMap.entrySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
                final String currRelId = currRel.getKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
                // List of roles of the relation where the MBean is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
                // referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
                List<String> localRoleNameList = currRel.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
                // Checks if the relation has to be removed or not,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
                // regarding expected minimum role cardinality and current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
                // number of references after removal of the current one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
                // If the relation is kept, calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
                // handleMBeanUnregistration() callback of the relation to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                // update it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
                // Can throw RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
                // Shall not throw RelationNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
                // RoleNotFoundException, MBeanException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
                    handleReferenceUnregistration(currRelId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
                                                  unregMBeanName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                                                  localRoleNameList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
                } catch (RelationNotFoundException exc1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
                    throw new RuntimeException(exc1.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
                } catch (RoleNotFoundException exc2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
                    throw new RuntimeException(exc2.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1545
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
     * Retrieves the relations where a given MBean is referenced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
     * <P>This corresponds to the CIM "References" and "ReferenceNames"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
     * operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
     * @param mbeanName  ObjectName of MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
     * @param relationTypeName  can be null; if specified, only the relations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
     * of that type will be considered in the search. Else all relation types
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
     * are considered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
     * @param roleName  can be null; if specified, only the relations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
     * where the MBean is referenced in that role will be returned. Else all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
     * roles are considered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
     * @return an HashMap, where the keys are the relation ids of the relations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
     * where the MBean is referenced, and the value is, for each key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
     * an ArrayList of role names (as an MBean can be referenced in several
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
     * roles in the same relation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
    public Map<String,List<String>>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
        findReferencingRelations(ObjectName mbeanName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                                 String relationTypeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
                                 String roleName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
            throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
        if (mbeanName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1580
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1} {2}",
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1581
                            mbeanName, relationTypeName, roleName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
        Map<String,List<String>> result = new HashMap<String,List<String>>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
        synchronized(myRefedMBeanObjName2RelIdsMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
            // Retrieves the relations referencing the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
            Map<String,List<String>> relId2RoleNamesMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
                myRefedMBeanObjName2RelIdsMap.get(mbeanName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
            if (relId2RoleNamesMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
                // Relation Ids where the MBean is referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
                Set<String> allRelIdSet = relId2RoleNamesMap.keySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
                // List of relation ids of interest regarding the selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
                // relation type
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1598
                List<String> relIdList;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
                if (relationTypeName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                    // Considers all relations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                    relIdList = new ArrayList<String>(allRelIdSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
                    relIdList = new ArrayList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
                    // Considers only the relation ids for relations of given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
                    // type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
                    for (String currRelId : allRelIdSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
                        // Retrieves its relation type
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1612
                        String currRelTypeName;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
                        synchronized(myRelId2RelTypeMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
                            currRelTypeName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
                                myRelId2RelTypeMap.get(currRelId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
                        if (currRelTypeName.equals(relationTypeName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
                            relIdList.add(currRelId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
                // Now looks at the roles where the MBean is expected to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
                // referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
                for (String currRelId : relIdList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
                    // Retrieves list of role names where the MBean is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
                    // referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
                    List<String> currRoleNameList =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
                        relId2RoleNamesMap.get(currRelId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
                    if (roleName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
                        // All roles to be considered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
                        // Note: no need to test if list not null before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
                        //       cloning, MUST be not null else bug :(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
                        result.put(currRelId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
                                   new ArrayList<String>(currRoleNameList));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
                    }  else if (currRoleNameList.contains(roleName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
                        // Filters only the relations where the MBean is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
                        // referenced in // given role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
                        List<String> dummyList = new ArrayList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
                        dummyList.add(roleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
                        result.put(currRelId, dummyList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1653
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
     * Retrieves the MBeans associated to given one in a relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
     * <P>This corresponds to CIM Associators and AssociatorNames operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
     * @param mbeanName  ObjectName of MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
     * @param relationTypeName  can be null; if specified, only the relations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
     * of that type will be considered in the search. Else all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
     * relation types are considered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
     * @param roleName  can be null; if specified, only the relations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
     * where the MBean is referenced in that role will be considered. Else all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
     * roles are considered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
     * @return an HashMap, where the keys are the ObjectNames of the MBeans
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
     * associated to given MBean, and the value is, for each key, an ArrayList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
     * of the relation ids of the relations where the key MBean is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
     * associated to given one (as they can be associated in several different
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
     * relations).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
    public Map<ObjectName,List<String>>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
        findAssociatedMBeans(ObjectName mbeanName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
                             String relationTypeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
                             String roleName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
            throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
        if (mbeanName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1688
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1} {2}",
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1689
                            mbeanName, relationTypeName, roleName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
        // Retrieves the map <relation id> -> <role names> for those
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
        // criterias
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
        Map<String,List<String>> relId2RoleNamesMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
            findReferencingRelations(mbeanName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
                                     relationTypeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
                                     roleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
        Map<ObjectName,List<String>> result =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
            new HashMap<ObjectName,List<String>>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
        for (String currRelId : relId2RoleNamesMap.keySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
            // Retrieves ObjectNames of MBeans referenced in this relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
            // Shall not throw a RelationNotFoundException if incorrect status
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
            // of maps :(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
            Map<ObjectName,List<String>> objName2RoleNamesMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
                objName2RoleNamesMap = getReferencedMBeans(currRelId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
            } catch (RelationNotFoundException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
                throw new RuntimeException(exc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
            // For each MBean associated to given one in a relation, adds the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
            // association <ObjectName> -> <relation id> into result map
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
            for (ObjectName currObjName : objName2RoleNamesMap.keySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
                if (!(currObjName.equals(mbeanName))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
                    // Sees if this MBean is already associated to the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
                    // one in another relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
                    List<String> currRelIdList = result.get(currObjName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
                    if (currRelIdList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
                        currRelIdList = new ArrayList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
                        currRelIdList.add(currRelId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
                        result.put(currObjName, currRelIdList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
                        currRelIdList.add(currRelId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1736
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
     * Returns the relation ids for relations of the given type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
     * @param relationTypeName  relation type name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
     * @return an ArrayList of relation ids.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
     * @exception RelationTypeNotFoundException  if there is no relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
     * with that name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
    public List<String> findRelationsOfType(String relationTypeName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
               RelationTypeNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
        if (relationTypeName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1760
        RELATION_LOGGER.log(Level.TRACE, "ENTRY");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
        // Can throw RelationTypeNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
        RelationType relType = getRelationType(relationTypeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
        List<String> result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
        synchronized(myRelType2RelIdsMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
            List<String> result1 = myRelType2RelIdsMap.get(relationTypeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
            if (result1 == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
                result = new ArrayList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
                result = new ArrayList<String>(result1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1774
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
     * Retrieves role value for given role name in given relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
     * @param relationId  relation id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
     * @param roleName  name of role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
     * @return the ArrayList of ObjectName objects being the role value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
     * @exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
     * Service is not registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
     * @exception RelationNotFoundException  if no relation with given id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
     * @exception RoleNotFoundException  if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
     * <P>- there is no role with given name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
     * <P>or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
     * <P>- the role is not readable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
     * @see #setRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
    public List<ObjectName> getRole(String relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
                                    String roleName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
        throws RelationServiceNotRegisteredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
               IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
               RelationNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
               RoleNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
        if (relationId == null || roleName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1809
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1}",
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1810
                            relationId, roleName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
        // Can throw RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
        isActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
        // Can throw a RelationNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
        Object relObj = getRelation(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
        List<ObjectName> result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
        if (relObj instanceof RelationSupport) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
            // Internal relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
            // Can throw RoleNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
            result = cast(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
                ((RelationSupport)relObj).getRoleInt(roleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
                                                     true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
                                                     this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
                                                     false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
            // Relation MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
            Object[] params = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
            params[0] = roleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
            String[] signature = new String[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
            signature[0] = "java.lang.String";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
            // Can throw MBeanException wrapping a RoleNotFoundException:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
            // throw wrapped exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
            // Shall not throw InstanceNotFoundException or ReflectionException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
                List<ObjectName> invokeResult = cast(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
                    myMBeanServer.invoke(((ObjectName)relObj),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
                                         "getRole",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
                                         params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
                                         signature));
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  1845
                if (invokeResult == null || invokeResult instanceof ArrayList<?>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
                    result = invokeResult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
                    result = new ArrayList<ObjectName>(invokeResult);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
            } catch (InstanceNotFoundException exc1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
                throw new RuntimeException(exc1.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
            } catch (ReflectionException exc2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
                throw new RuntimeException(exc2.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
            } catch (MBeanException exc3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
                Exception wrappedExc = exc3.getTargetException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
                if (wrappedExc instanceof RoleNotFoundException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
                    throw ((RoleNotFoundException)wrappedExc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
                    throw new RuntimeException(wrappedExc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1863
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
     * Retrieves values of roles with given names in given relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
     * @param relationId  relation id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
     * @param roleNameArray  array of names of roles to be retrieved
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
     * @return a RoleResult object, including a RoleList (for roles
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
     * successfully retrieved) and a RoleUnresolvedList (for roles not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
     * retrieved).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
     * @exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
     * Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
     * @exception RelationNotFoundException  if no relation with given id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
     * @see #setRoles
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
    public RoleResult getRoles(String relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                               String[] roleNameArray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
        throws RelationServiceNotRegisteredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
               IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
               RelationNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
        if (relationId == null || roleNameArray == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1895
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0}", relationId);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
        // Can throw RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
        isActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
        // Can throw a RelationNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
        Object relObj = getRelation(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1903
        RoleResult result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
        if (relObj instanceof RelationSupport) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
            // Internal relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
            result = ((RelationSupport)relObj).getRolesInt(roleNameArray,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
                                                        true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
                                                        this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
            // Relation MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
            Object[] params = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
            params[0] = roleNameArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
            String[] signature = new String[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
                signature[0] = (roleNameArray.getClass()).getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
            } catch (Exception exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
                // OK : This is an array of java.lang.String
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
                //      so this should never happen...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
            // Shall not throw InstanceNotFoundException, ReflectionException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
            // or MBeanException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
                result = (RoleResult)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
                    (myMBeanServer.invoke(((ObjectName)relObj),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
                                          "getRoles",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
                                          params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
                                          signature));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
            } catch (InstanceNotFoundException exc1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
                throw new RuntimeException(exc1.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
            } catch (ReflectionException exc2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
                throw new RuntimeException(exc2.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
            } catch (MBeanException exc3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
                throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
                    RuntimeException((exc3.getTargetException()).getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1939
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
     * Returns all roles present in the relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
     * @param relationId  relation id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
     * @return a RoleResult object, including a RoleList (for roles
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
     * successfully retrieved) and a RoleUnresolvedList (for roles not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
     * readable).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
     * @exception RelationNotFoundException  if no relation for given id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
     * @exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
     * Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
    public RoleResult getAllRoles(String relationId)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
               RelationNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
               RelationServiceNotRegisteredException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
        if (relationId == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1967
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0}", relationId);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
        // Can throw a RelationNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
        Object relObj = getRelation(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1972
        RoleResult result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
        if (relObj instanceof RelationSupport) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
            // Internal relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
            result = ((RelationSupport)relObj).getAllRolesInt(true, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
            // Relation MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
            // Shall not throw any Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
                result = (RoleResult)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
                    (myMBeanServer.getAttribute(((ObjectName)relObj),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
                                                "AllRoles"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
            } catch (Exception exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
                throw new RuntimeException(exc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  1990
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
     * Retrieves the number of MBeans currently referenced in the given role.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
     * @param relationId  relation id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
     * @param roleName  name of role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
     * @return the number of currently referenced MBeans in that role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
     * @exception RelationNotFoundException  if no relation with given id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
     * @exception RoleNotFoundException  if there is no role with given name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
    public Integer getRoleCardinality(String relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
                                      String roleName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
               RelationNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
               RoleNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
        if (relationId == null || roleName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2017
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1}",
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2018
                            relationId, roleName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
        // Can throw a RelationNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
        Object relObj = getRelation(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  2023
        Integer result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
        if (relObj instanceof RelationSupport) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
            // Internal relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
            // Can throw RoleNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
            result = ((RelationSupport)relObj).getRoleCardinality(roleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
            // Relation MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
            Object[] params = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
            params[0] = roleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
            String[] signature = new String[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
            signature[0] = "java.lang.String";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
            // Can throw MBeanException wrapping RoleNotFoundException:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
            // throw wrapped exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
            // Shall not throw InstanceNotFoundException or ReflectionException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
                result = (Integer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
                    (myMBeanServer.invoke(((ObjectName)relObj),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
                                          "getRoleCardinality",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
                                          params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
                                          signature));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
            } catch (InstanceNotFoundException exc1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
                throw new RuntimeException(exc1.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
            } catch (ReflectionException exc2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
                throw new RuntimeException(exc2.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
            } catch (MBeanException exc3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
                Exception wrappedExc = exc3.getTargetException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
                if (wrappedExc instanceof RoleNotFoundException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
                    throw ((RoleNotFoundException)wrappedExc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
                    throw new RuntimeException(wrappedExc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2060
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
     * Sets the given role in given relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
     * <P>Will check the role according to its corresponding role definition
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
     * provided in relation's relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
     * <P>The Relation Service will keep track of the change to keep the
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
  2069
     * consistency of relations by handling referenced MBean deregistrations.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
     * @param relationId  relation id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
     * @param role  role to be set (name and new value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
     * @exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
     * Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
     * @exception RelationNotFoundException  if no relation with given id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
     * @exception RoleNotFoundException  if the role does not exist or is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
     * writable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
     * @exception InvalidRoleValueException  if value provided for role is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
     * valid:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
     * <P>- the number of referenced MBeans in given value is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
     * expected minimum degree
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
     * <P>or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
     * <P>- the number of referenced MBeans in provided value exceeds expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
     * maximum degree
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
     * <P>or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
     * <P>- one referenced MBean in the value is not an Object of the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
     * class expected for that role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
     * <P>or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
     * <P>- an MBean provided for that role does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
     * @see #getRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
    public void setRole(String relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
                        Role role)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
        throws RelationServiceNotRegisteredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
               IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
               RelationNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
               RoleNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
               InvalidRoleValueException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
        if (relationId == null || role == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2108
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1}",
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2109
                            relationId, role);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
        // Can throw RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
        isActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
        // Can throw a RelationNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
        Object relObj = getRelation(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
        if (relObj instanceof RelationSupport) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
            // Internal relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
            // Can throw RoleNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
            // InvalidRoleValueException and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
            // RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
            // Shall not throw RelationTypeNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
            // (as relation exists in the RS, its relation type is known)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
                ((RelationSupport)relObj).setRoleInt(role,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
                                                  true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
                                                  this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
                                                  false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
            } catch (RelationTypeNotFoundException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
                throw new RuntimeException(exc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
            // Relation MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
            Object[] params = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
            params[0] = role;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
            String[] signature = new String[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
            signature[0] = "javax.management.relation.Role";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
            // Can throw MBeanException wrapping RoleNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
            // InvalidRoleValueException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
            // Shall not MBeanException wrapping an MBeanException wrapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
            // RelationTypeNotFoundException, or ReflectionException, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
            // InstanceNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
                myMBeanServer.setAttribute(((ObjectName)relObj),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
                                           new Attribute("Role", role));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
            } catch (InstanceNotFoundException exc1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
                throw new RuntimeException(exc1.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
            } catch (ReflectionException exc3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
                throw new RuntimeException(exc3.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
            } catch (MBeanException exc2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
                Exception wrappedExc = exc2.getTargetException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
                if (wrappedExc instanceof RoleNotFoundException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
                    throw ((RoleNotFoundException)wrappedExc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
                } else if (wrappedExc instanceof InvalidRoleValueException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
                    throw ((InvalidRoleValueException)wrappedExc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
                    throw new RuntimeException(wrappedExc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
            } catch (AttributeNotFoundException exc4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
              throw new RuntimeException(exc4.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
            } catch (InvalidAttributeValueException exc5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
              throw new RuntimeException(exc5.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2172
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
     * Sets the given roles in given relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
     * <P>Will check the role according to its corresponding role definition
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
     * provided in relation's relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
     * <P>The Relation Service keeps track of the changes to keep the
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
  2181
     * consistency of relations by handling referenced MBean deregistrations.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
     * @param relationId  relation id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
     * @param roleList  list of roles to be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
     * @return a RoleResult object, including a RoleList (for roles
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
     * successfully set) and a RoleUnresolvedList (for roles not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
     * set).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
     * @exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
     * Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
     * @exception RelationNotFoundException  if no relation with given id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
     * @see #getRoles
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
    public RoleResult setRoles(String relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
                               RoleList roleList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
        throws RelationServiceNotRegisteredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
               IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
               RelationNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
        if (relationId == null || roleList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2208
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1}",
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2209
                            relationId, roleList);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
        // Can throw RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
        isActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
        // Can throw a RelationNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
        Object relObj = getRelation(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  2217
        RoleResult result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
        if (relObj instanceof RelationSupport) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
            // Internal relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
            // Can throw RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
            // Shall not throw RelationTypeNotFoundException (as relation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
            // known, its relation type exists)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
                result = ((RelationSupport)relObj).setRolesInt(roleList,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
                                                            true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
                                                            this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
            } catch (RelationTypeNotFoundException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
                throw new RuntimeException(exc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
            // Relation MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
            Object[] params = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
            params[0] = roleList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
            String[] signature = new String[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
            signature[0] = "javax.management.relation.RoleList";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
            // Shall not throw InstanceNotFoundException or an MBeanException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
            // or ReflectionException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
                result = (RoleResult)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
                    (myMBeanServer.invoke(((ObjectName)relObj),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
                                          "setRoles",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
                                          params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
                                          signature));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
            } catch (InstanceNotFoundException exc1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
                throw new RuntimeException(exc1.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
            } catch (ReflectionException exc3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
                throw new RuntimeException(exc3.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
            } catch (MBeanException exc2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
                throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
                    RuntimeException((exc2.getTargetException()).getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2257
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
     * Retrieves MBeans referenced in the various roles of the relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
     * @param relationId  relation id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
     * @return a HashMap mapping:
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 21278
diff changeset
  2267
     * <P> ObjectName {@literal ->} ArrayList of String (role names)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
     * @exception RelationNotFoundException  if no relation for given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
     * relation id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
    public Map<ObjectName,List<String>>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
        getReferencedMBeans(String relationId)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
            throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
        RelationNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
        if (relationId == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2283
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0}",
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2284
                            relationId);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
        // Can throw a RelationNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
        Object relObj = getRelation(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
        Map<ObjectName,List<String>> result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
        if (relObj instanceof RelationSupport) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
            // Internal relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
            result = ((RelationSupport)relObj).getReferencedMBeans();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
            // Relation MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
            // No Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
                result = cast(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
                    myMBeanServer.getAttribute(((ObjectName)relObj),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
                                               "ReferencedMBeans"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
            } catch (Exception exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
                throw new RuntimeException(exc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2307
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
     * Returns name of associated relation type for given relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
     * @param relationId  relation id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
     * @return the name of the associated relation type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
     * @exception RelationNotFoundException  if no relation for given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
     * relation id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
    public String getRelationTypeName(String relationId)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
               RelationNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
        if (relationId == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2331
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0}", relationId);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
        // Can throw a RelationNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
        Object relObj = getRelation(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  2336
        String result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
        if (relObj instanceof RelationSupport) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
            // Internal relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
            result = ((RelationSupport)relObj).getRelationTypeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
            // Relation MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
            // No Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
                result = (String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
                    (myMBeanServer.getAttribute(((ObjectName)relObj),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
                                                "RelationTypeName"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
            } catch (Exception exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
                throw new RuntimeException(exc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2354
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
    // NotificationListener Interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
     * Invoked when a JMX notification occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
     * Currently handles notifications for unregistration of MBeans, either
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
     * referenced in a relation role or being a relation itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
     * @param notif  The notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
     * @param handback  An opaque object which helps the listener to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
     * associate information regarding the MBean emitter (can be null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
    public void handleNotification(Notification notif,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
                                   Object handback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
        if (notif == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2379
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0}", notif);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
        if (notif instanceof MBeanServerNotification) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
            MBeanServerNotification mbsNtf = (MBeanServerNotification) notif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
            String ntfType = notif.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
            if (ntfType.equals(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
                       MBeanServerNotification.UNREGISTRATION_NOTIFICATION )) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
                ObjectName mbeanName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
                    ((MBeanServerNotification)notif).getMBeanName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
                // Note: use a flag to block access to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
                // myRefedMBeanObjName2RelIdsMap only for a quick access
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
                boolean isRefedMBeanFlag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
                synchronized(myRefedMBeanObjName2RelIdsMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
                    if (myRefedMBeanObjName2RelIdsMap.containsKey(mbeanName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
                        // Unregistration of a referenced MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
                        synchronized(myUnregNtfList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
                            myUnregNtfList.add(mbsNtf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
                        isRefedMBeanFlag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
                    if (isRefedMBeanFlag && myPurgeFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
                        // Immediate purge
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
                        // Can throw RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
                        // but assume that will be fine :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
                            purgeRelations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
                        } catch (Exception exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
                            throw new RuntimeException(exc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
                // Note: do both tests as a relation can be an MBean and be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
                //       itself referenced in another relation :)
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  2417
                String relId;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
                synchronized(myRelMBeanObjName2RelIdMap){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
                    relId = myRelMBeanObjName2RelIdMap.get(mbeanName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
                if (relId != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
                    // Unregistration of a relation MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
                    // Can throw RelationTypeNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
                    // RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
                    // Shall not throw RelationTypeNotFoundException or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
                    // InstanceNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
                        removeRelation(relId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
                    } catch (Exception exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
                        throw new RuntimeException(exc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2437
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
    // NotificationBroadcaster interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
     * Returns a NotificationInfo object containing the name of the Java class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
     * of the notification and the notification types sent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
    public MBeanNotificationInfo[] getNotificationInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2451
        RELATION_LOGGER.log(Level.TRACE, "ENTRY");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
        String ntfClass = "javax.management.relation.RelationNotification";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
        String[] ntfTypes = new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
            RelationNotification.RELATION_BASIC_CREATION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
            RelationNotification.RELATION_MBEAN_CREATION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
            RelationNotification.RELATION_BASIC_UPDATE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
            RelationNotification.RELATION_MBEAN_UPDATE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
            RelationNotification.RELATION_BASIC_REMOVAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
            RelationNotification.RELATION_MBEAN_REMOVAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
        String ntfDesc = "Sent when a relation is created, updated or deleted.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
        MBeanNotificationInfo ntfInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
            new MBeanNotificationInfo(ntfTypes, ntfClass, ntfDesc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2469
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
        return new MBeanNotificationInfo[] {ntfInfo};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
    // Misc
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
    // Adds given object as a relation type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
    // -param relationTypeObj  relation type object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
    // -exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
    // -exception InvalidRelationTypeException  if there is already a relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
    //  type with that name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
    private void addRelationTypeInt(RelationType relationTypeObj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
               InvalidRelationTypeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
        if (relationTypeObj == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2493
        RELATION_LOGGER.log(Level.TRACE, "ENTRY");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
        String relTypeName = relationTypeObj.getRelationTypeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
        // Checks that there is not already a relation type with that name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
        // existing in the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
            // Can throw a RelationTypeNotFoundException (in fact should ;)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
            RelationType relType = getRelationType(relTypeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
            if (relType != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
                String excMsg = "There is already a relation type in the Relation Service with name ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
                StringBuilder excMsgStrB = new StringBuilder(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
                excMsgStrB.append(relTypeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
                throw new InvalidRelationTypeException(excMsgStrB.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
        } catch (RelationTypeNotFoundException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
            // OK : The RelationType could not be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
        // Adds the relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
        synchronized(myRelType2ObjMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
            myRelType2ObjMap.put(relTypeName, relationTypeObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
        if (relationTypeObj instanceof RelationTypeSupport) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
            ((RelationTypeSupport)relationTypeObj).setRelationServiceFlag(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2523
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
    // Retrieves relation type with given name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
    // -param relationTypeName  expected name of a relation type created in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
    //  Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
    // -return RelationType object corresponding to given name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
    // -exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
    // -exception RelationTypeNotFoundException  if no relation type for that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
    //  name created in Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
    RelationType getRelationType(String relationTypeName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
               RelationTypeNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
        if (relationTypeName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2547
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0}", relationTypeName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
        // No null relation type accepted, so can use get()
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  2550
        RelationType relType;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
        synchronized(myRelType2ObjMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
            relType = (myRelType2ObjMap.get(relationTypeName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
        if (relType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
            String excMsg = "No relation type created in the Relation Service with the name ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
            StringBuilder excMsgStrB = new StringBuilder(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
            excMsgStrB.append(relationTypeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
            throw new RelationTypeNotFoundException(excMsgStrB.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2562
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
        return relType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
    // Retrieves relation corresponding to given relation id.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
    // Returns either:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
    // - a RelationSupport object if the relation is internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
    // or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
    // - the ObjectName of the corresponding MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
    // -param relationId  expected relation id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
    // -return RelationSupport object or ObjectName of relation with given id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
    // -exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
    // -exception RelationNotFoundException  if no relation for that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
    //  relation id created in Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
    Object getRelation(String relationId)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
               RelationNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
        if (relationId == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2589
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0}", relationId);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
        // No null relation  accepted, so can use get()
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  2592
        Object rel;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
        synchronized(myRelId2ObjMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
            rel = myRelId2ObjMap.get(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
        if (rel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
            String excMsg = "No relation associated to relation id " + relationId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
            throw new RelationNotFoundException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2602
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
        return rel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
    // Adds a new MBean reference (reference to an ObjectName) in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
    // referenced MBean map (myRefedMBeanObjName2RelIdsMap).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
    // -param objectName  ObjectName of new referenced MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
    // -param relationId  relation id of the relation where the MBean is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
    //  referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
    // -param roleName  name of the role where the MBean is referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
    // -return boolean:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
    //  - true  if the MBean was not referenced before, so really a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
    //    reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
    //  - false else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
    // -exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
    private boolean addNewMBeanReference(ObjectName objectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
                                         String relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
                                         String roleName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
        if (objectName == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
            relationId == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
            roleName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2632
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1} {2}",
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2633
                            objectName, relationId, roleName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
        boolean isNewFlag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
        synchronized(myRefedMBeanObjName2RelIdsMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
            // Checks if the MBean was already referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
            // No null value allowed, use get() directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
            Map<String,List<String>> mbeanRefMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
                myRefedMBeanObjName2RelIdsMap.get(objectName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
            if (mbeanRefMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
                // MBean not referenced in any relation yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
                isNewFlag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
                // List of roles where the MBean is referenced in given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
                // relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
                List<String> roleNames = new ArrayList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
                roleNames.add(roleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
                // Map of relations where the MBean is referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
                mbeanRefMap = new HashMap<String,List<String>>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
                mbeanRefMap.put(relationId, roleNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
                myRefedMBeanObjName2RelIdsMap.put(objectName, mbeanRefMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
                // MBean already referenced in at least another relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
                // Checks if already referenced in another role in current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
                // relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
                List<String> roleNames = mbeanRefMap.get(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
                if (roleNames == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
                    // MBean not referenced in current relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
                    // List of roles where the MBean is referenced in given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
                    // relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
                    roleNames = new ArrayList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
                    roleNames.add(roleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
                    // Adds new reference done in current relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
                    mbeanRefMap.put(relationId, roleNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
                    // MBean already referenced in current relation in another
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
                    // role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
                    // Adds new reference done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
                    roleNames.add(roleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2686
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
        return isNewFlag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
    // Removes an obsolete MBean reference (reference to an ObjectName) in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
    // the referenced MBean map (myRefedMBeanObjName2RelIdsMap).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
    // -param objectName  ObjectName of MBean no longer referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
    // -param relationId  relation id of the relation where the MBean was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
    //  referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
    // -param roleName  name of the role where the MBean was referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
    // -param allRolesFlag  flag, if true removes reference to MBean for all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
    //  roles in the relation, not only for the one above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
    // -return boolean:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
    //  - true  if the MBean is no longer reference in any relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
    //  - false else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
    // -exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
    private boolean removeMBeanReference(ObjectName objectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
                                         String relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
                                         String roleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
                                         boolean allRolesFlag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
        if (objectName == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
            relationId == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
            roleName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2718
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1} {2} {3}",
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2719
                            objectName, relationId, roleName, allRolesFlag);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
        boolean noLongerRefFlag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
        synchronized(myRefedMBeanObjName2RelIdsMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
            // Retrieves the set of relations (designed via their relation ids)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
            // where the MBean is referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
            // Note that it is possible that the MBean has already been removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
            // from the internal map: this is the case when the MBean is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
            // unregistered, the role is updated, then we arrive here.
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  2730
            Map<String,List<String>> mbeanRefMap =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
                (myRefedMBeanObjName2RelIdsMap.get(objectName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
            if (mbeanRefMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
                // The MBean is no longer referenced
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2735
                RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  2739
            List<String> roleNames = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
            if (!allRolesFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
                // Now retrieves the roles of current relation where the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
                // was referenced
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  2743
                roleNames = mbeanRefMap.get(relationId);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
                // Removes obsolete reference to role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
                int obsRefIdx = roleNames.indexOf(roleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
                if (obsRefIdx != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
                    roleNames.remove(obsRefIdx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
            // Checks if there is still at least one role in current relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
            // where the MBean is referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
            if (roleNames.isEmpty() || allRolesFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
                // MBean no longer referenced in current relation: removes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
                // entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
                mbeanRefMap.remove(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
            // Checks if the MBean is still referenced in at least on relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
            if (mbeanRefMap.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
                // MBean no longer referenced in any relation: removes entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
                myRefedMBeanObjName2RelIdsMap.remove(objectName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
                noLongerRefFlag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2768
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
        return noLongerRefFlag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
    // Updates the listener registered to the MBean Server to be informed of
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
  2773
    // referenced MBean deregistrations
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
    // -param newRefList  ArrayList of ObjectNames for new references done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
    //  to MBeans (can be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
    // -param obsoleteRefList  ArrayList of ObjectNames for obsolete references
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
    //  to MBeans (can be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
    // -exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
    //  Service is not registered in the MBean Server.
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  2782
    private void updateUnregistrationListener(List<ObjectName> newRefList,
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  2783
                                              List<ObjectName> obsoleteRefList)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
        throws RelationServiceNotRegisteredException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
        if (newRefList != null && obsoleteRefList != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
            if (newRefList.isEmpty() && obsoleteRefList.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
                // Nothing to do :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2793
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1}",
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2794
                            newRefList, obsoleteRefList);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
        // Can throw RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
        isActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
        if (newRefList != null || obsoleteRefList != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
            boolean newListenerFlag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
            if (myUnregNtfFilter == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
                // Initialize it to be able to synchronise it :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
                myUnregNtfFilter = new MBeanServerNotificationFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
                newListenerFlag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
            synchronized(myUnregNtfFilter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
                // Enables ObjectNames in newRefList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
                if (newRefList != null) {
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  2812
                    for (ObjectName newObjName : newRefList)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
                        myUnregNtfFilter.enableObjectName(newObjName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
                if (obsoleteRefList != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
                    // Disables ObjectNames in obsoleteRefList
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  2818
                    for (ObjectName obsObjName : obsoleteRefList)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
                        myUnregNtfFilter.disableObjectName(obsObjName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
// Under test
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
                if (newListenerFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
                        myMBeanServer.addNotificationListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
                                MBeanServerDelegate.DELEGATE_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
                                this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
                                myUnregNtfFilter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
                                null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
                    } catch (InstanceNotFoundException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
                        throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
                       RelationServiceNotRegisteredException(exc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
// End test
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
//              if (!newListenerFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
                    // The Relation Service was already registered as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
                    // listener:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
                    // removes it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
                    // Shall not throw InstanceNotFoundException (as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
                    // MBean Server Delegate is expected to exist) or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
                    // ListenerNotFoundException (as it has been checked above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
                    // that the Relation Service is registered)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
//                  try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
//                      myMBeanServer.removeNotificationListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
//                              MBeanServerDelegate.DELEGATE_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
//                              this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
//                  } catch (InstanceNotFoundException exc1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
//                      throw new RuntimeException(exc1.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
//                  } catch (ListenerNotFoundException exc2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
//                      throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
//                          RelationServiceNotRegisteredException(exc2.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
//                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
//              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
                // Adds Relation Service with current filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
                // Can throw InstanceNotFoundException if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
                // Service is not registered, to be transformed into
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
                // RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
                // Assume that there will not be any InstanceNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
                // for the MBean Server Delegate :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
//              try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
//                  myMBeanServer.addNotificationListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
//                              MBeanServerDelegate.DELEGATE_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
//                              this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
//                              myUnregNtfFilter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
//                              null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
//              } catch (InstanceNotFoundException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
//                  throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
//                     RelationServiceNotRegisteredException(exc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
//              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2878
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
    // Adds a relation (being either a RelationSupport object or an MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
    // referenced using its ObjectName) in the Relation Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
    // Will send a notification RelationNotification with type:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
    // - RelationNotification.RELATION_BASIC_CREATION for internal relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
    //   creation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
    // - RelationNotification.RELATION_MBEAN_CREATION for an MBean being added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
    //   as a relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
    // -param relationBaseFlag  flag true if the relation is a RelationSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
    //  object, false if it is an MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
    // -param relationObj  RelationSupport object (if relation is internal)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
    // -param relationObjName  ObjectName of the MBean to be added as a relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
    //  (only for the relation MBean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
    // -param relationId  relation identifier, to uniquely identify the relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
    //  inside the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
    // -param relationTypeName  name of the relation type (has to be created
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
    //  in the Relation Service)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
    // -param roleList  role list to initialize roles of the relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
    //  (can be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
    // -exception IllegalArgumentException  if null paramater
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
    // -exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
    //  Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
    // -exception RoleNotFoundException  if a value is provided for a role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
    //  that does not exist in the relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
    // -exception InvalidRelationIdException  if relation id already used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
    // -exception RelationTypeNotFoundException  if relation type not known in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
    //  Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
    // -exception InvalidRoleValueException if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
    //  - the same role name is used for two different roles
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
    //  - the number of referenced MBeans in given value is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
    //    expected minimum degree
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
    //  - the number of referenced MBeans in provided value exceeds expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
    //    maximum degree
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
    //  - one referenced MBean in the value is not an Object of the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
    //    class expected for that role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
    //  - an MBean provided for that role does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
    private void addRelationInt(boolean relationBaseFlag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
                                RelationSupport relationObj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
                                ObjectName relationObjName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
                                String relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
                                String relationTypeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
                                RoleList roleList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
               RelationServiceNotRegisteredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
               RoleNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
               InvalidRelationIdException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
               RelationTypeNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
               InvalidRoleValueException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
        if (relationId == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
            relationTypeName == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
            (relationBaseFlag &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
             (relationObj == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
              relationObjName != null)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
            (!relationBaseFlag &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
             (relationObjName == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
              relationObj != null))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2944
        RELATION_LOGGER.log(Level.TRACE,
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2945
                            "ENTRY {0} {1} {2} {3} {4} {5}",
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2946
                            relationBaseFlag, relationObj, relationObjName,
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  2947
                            relationId, relationTypeName, roleList);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
        // Can throw RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
        isActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
        // Checks if there is already a relation with given id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
            // Can throw a RelationNotFoundException (in fact should :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
            Object rel = getRelation(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
            if (rel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
                // There is already a relation with that id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
                String excMsg = "There is already a relation with id ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
                StringBuilder excMsgStrB = new StringBuilder(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
                excMsgStrB.append(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
                throw new InvalidRelationIdException(excMsgStrB.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
        } catch (RelationNotFoundException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
            // OK : The Relation could not be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
        // Retrieves the relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
        // Can throw RelationTypeNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
        RelationType relType = getRelationType(relationTypeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
        // Checks that each provided role conforms to its role info provided in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
        // the relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
        // First retrieves a local list of the role infos of the relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
        // to see which roles have not been initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
        // Note: no need to test if list not null before cloning, not allowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
        //       to have an empty relation type.
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  2978
        List<RoleInfo> roleInfoList = new ArrayList<RoleInfo>(relType.getRoleInfos());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
        if (roleList != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  2982
            for (Role currRole : roleList.asList()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
                String currRoleName = currRole.getRoleName();
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  2984
                List<ObjectName> currRoleValue = currRole.getRoleValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
                // Retrieves corresponding role info
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
                // Can throw a RoleInfoNotFoundException to be converted into a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
                // RoleNotFoundException
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  2988
                RoleInfo roleInfo;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2990
                    roleInfo = relType.getRoleInfo(currRoleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2991
                } catch (RoleInfoNotFoundException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2992
                    throw new RoleNotFoundException(exc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2993
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2994
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
                // Checks that role conforms to role info,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
                Integer status = checkRoleInt(2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
                                              currRoleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
                                              currRoleValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
                                              roleInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
                                              false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
                int pbType = status.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
                if (pbType != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
                    // A problem has occurred: throws appropriate exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3004
                    // here InvalidRoleValueException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
                    throwRoleProblemException(pbType, currRoleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3008
                // Removes role info for that list from list of role infos for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
                // roles to be defaulted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
                int roleInfoIdx = roleInfoList.indexOf(roleInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
                // Note: no need to check if != -1, MUST be there :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
                roleInfoList.remove(roleInfoIdx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
        // Initializes roles not initialized by roleList
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
        // Can throw InvalidRoleValueException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
        initializeMissingRoles(relationBaseFlag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
                               relationObj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
                               relationObjName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
                               relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
                               relationTypeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
                               roleInfoList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
        // Creation of relation successfull!!!!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
        // Updates internal maps
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
        // Relation id to object map
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
        synchronized(myRelId2ObjMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
            if (relationBaseFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
                // Note: do not clone relation object, created by us :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
                myRelId2ObjMap.put(relationId, relationObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
                myRelId2ObjMap.put(relationId, relationObjName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
        // Relation id to relation type name map
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
        synchronized(myRelId2RelTypeMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
            myRelId2RelTypeMap.put(relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
                                   relationTypeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
        // Relation type to relation id map
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
        synchronized(myRelType2RelIdsMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
            List<String> relIdList =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
                myRelType2RelIdsMap.get(relationTypeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
            boolean firstRelFlag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
            if (relIdList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
                firstRelFlag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
                relIdList = new ArrayList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
            relIdList.add(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
            if (firstRelFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
                myRelType2RelIdsMap.put(relationTypeName, relIdList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3059
        // Referenced MBean to relation id map
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
        // Only role list parameter used, as default initialization of roles
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
        // done automatically in initializeMissingRoles() sets each
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
        // uninitialized role to an empty value.
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  3063
        for (Role currRole : roleList.asList()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
            // Creates a dummy empty ArrayList of ObjectNames to be the old
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
            // role value :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3066
            List<ObjectName> dummyList = new ArrayList<ObjectName>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3067
            // Will not throw a RelationNotFoundException (as the RelId2Obj map
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3068
            // has been updated above) so catch it :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3069
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
                updateRoleMap(relationId, currRole, dummyList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3072
            } catch (RelationNotFoundException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
                // OK : The Relation could not be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3077
        // Sends a notification for relation creation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
        // Will not throw RelationNotFoundException so catch it :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3079
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
            sendRelationCreationNotification(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
        } catch (RelationNotFoundException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
            // OK : The Relation could not be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3085
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3086
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
    // Checks that given role conforms to given role info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3091
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3092
    // -param chkType  type of check:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3093
    //  - 1: read, just check read access
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
    //  - 2: write, check value and write access if writeChkFlag
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
    // -param roleName  role name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
    // -param roleValue  role value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
    // -param roleInfo  corresponding role info
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3098
    // -param writeChkFlag  boolean to specify a current write access and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3099
    //  to check it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
    // -return Integer with value:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3102
    //  - 0: ok
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3103
    //  - RoleStatus.NO_ROLE_WITH_NAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3104
    //  - RoleStatus.ROLE_NOT_READABLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3105
    //  - RoleStatus.ROLE_NOT_WRITABLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3106
    //  - RoleStatus.LESS_THAN_MIN_ROLE_DEGREE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3107
    //  - RoleStatus.MORE_THAN_MAX_ROLE_DEGREE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3108
    //  - RoleStatus.REF_MBEAN_OF_INCORRECT_CLASS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3109
    //  - RoleStatus.REF_MBEAN_NOT_REGISTERED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3110
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3111
    // -exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3112
    private Integer checkRoleInt(int chkType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3113
                                 String roleName,
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  3114
                                 List<ObjectName> roleValue,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3115
                                 RoleInfo roleInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3116
                                 boolean writeChkFlag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3117
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3119
        if (roleName == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3120
            roleInfo == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3121
            (chkType == 2 && roleValue == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3122
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3123
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3125
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3126
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1} {2} {3} {4}",
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3127
                            chkType, roleName, roleValue, roleInfo, writeChkFlag);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3129
        // Compares names
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3130
        String expName = roleInfo.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
        if (!(roleName.equals(expName))) {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3132
            RELATION_LOGGER.log(Level.TRACE, "RETURN");
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  3133
            return Integer.valueOf(RoleStatus.NO_ROLE_WITH_NAME);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3136
        // Checks read access if required
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3137
        if (chkType == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3138
            boolean isReadable = roleInfo.isReadable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3139
            if (!isReadable) {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3140
                RELATION_LOGGER.log(Level.TRACE, "RETURN");
527
a33264d48a84 6703552: Missing files from changeset for 6701459
emcmanus
parents: 526
diff changeset
  3141
                return Integer.valueOf(RoleStatus.ROLE_NOT_READABLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3142
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
                // End of check :)
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3144
                RELATION_LOGGER.log(Level.TRACE, "RETURN");
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 23010
diff changeset
  3145
                return 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3146
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3149
        // Checks write access if required
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3150
        if (writeChkFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3151
            boolean isWritable = roleInfo.isWritable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3152
            if (!isWritable) {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3153
                RELATION_LOGGER.log(Level.TRACE, "RETURN");
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 23010
diff changeset
  3154
                return RoleStatus.ROLE_NOT_WRITABLE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3155
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
        int refNbr = roleValue.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
        // Checks minimum cardinality
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
        boolean chkMinFlag = roleInfo.checkMinDegree(refNbr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3162
        if (!chkMinFlag) {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3163
            RELATION_LOGGER.log(Level.TRACE, "RETURN");
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 23010
diff changeset
  3164
            return RoleStatus.LESS_THAN_MIN_ROLE_DEGREE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3166
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3167
        // Checks maximum cardinality
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3168
        boolean chkMaxFlag = roleInfo.checkMaxDegree(refNbr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3169
        if (!chkMaxFlag) {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3170
            RELATION_LOGGER.log(Level.TRACE, "RETURN");
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 23010
diff changeset
  3171
            return RoleStatus.MORE_THAN_MAX_ROLE_DEGREE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3173
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3174
        // Verifies that each referenced MBean is registered in the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3175
        // Server and that it is an instance of the class specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3176
        // role info, or of a subclass of it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3177
        // Note that here again this is under the assumption that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3178
        // referenced MBeans, relation MBeans and the Relation Service are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3179
        // registered in the same MBean Server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3180
        String expClassName = roleInfo.getRefMBeanClassName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3181
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  3182
        for (ObjectName currObjName : roleValue) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3184
            // Checks it is registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3185
            if (currObjName == null) {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3186
                RELATION_LOGGER.log(Level.TRACE, "RETURN");
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 23010
diff changeset
  3187
                return RoleStatus.REF_MBEAN_NOT_REGISTERED;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3188
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3190
            // Checks if it is of the correct class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3191
            // Can throw an InstanceNotFoundException, if MBean not registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
                boolean classSts = myMBeanServer.isInstanceOf(currObjName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3194
                                                              expClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3195
                if (!classSts) {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3196
                    RELATION_LOGGER.log(Level.TRACE, "RETURN");
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 23010
diff changeset
  3197
                    return RoleStatus.REF_MBEAN_OF_INCORRECT_CLASS;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3198
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3200
            } catch (InstanceNotFoundException exc) {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3201
                RELATION_LOGGER.log(Level.TRACE, "RETURN");
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 23010
diff changeset
  3202
                return RoleStatus.REF_MBEAN_NOT_REGISTERED;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3206
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 23010
diff changeset
  3207
        return 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
    // Initializes roles associated to given role infos to default value (empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
    // ArrayList of ObjectNames) in given relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
    // It will succeed for every role except if the role info has a minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
    // cardinality greater than 0. In that case, an InvalidRoleValueException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
    // will be raised.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
    // -param relationBaseFlag  flag true if the relation is a RelationSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
    //  object, false if it is an MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
    // -param relationObj  RelationSupport object (if relation is internal)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
    // -param relationObjName  ObjectName of the MBean to be added as a relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3221
    //  (only for the relation MBean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
    // -param relationId  relation id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
    // -param relationTypeName  name of the relation type (has to be created
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3224
    //  in the Relation Service)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3225
    // -param roleInfoList  list of role infos for roles to be defaulted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
    // -exception IllegalArgumentException  if null paramater
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
    // -exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
    //  Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3230
    // -exception InvalidRoleValueException  if role must have a non-empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
    //  value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
    // Revisit [cebro] Handle CIM qualifiers as REQUIRED to detect roles which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
    //    should have been initialized by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
    private void initializeMissingRoles(boolean relationBaseFlag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
                                        RelationSupport relationObj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
                                        ObjectName relationObjName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
                                        String relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
                                        String relationTypeName,
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  3240
                                        List<RoleInfo> roleInfoList)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
               RelationServiceNotRegisteredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
               InvalidRoleValueException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
        if ((relationBaseFlag &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
             (relationObj == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
              relationObjName != null)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
            (!relationBaseFlag &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
             (relationObjName == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3250
              relationObj != null)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3251
            relationId == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3252
            relationTypeName == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3253
            roleInfoList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3254
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3255
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3257
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3258
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1} {2} {3} {4} {5}",
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3259
                            relationBaseFlag, relationObj, relationObjName,
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3260
                            relationId, relationTypeName, roleInfoList);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
        // Can throw RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3263
        isActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
        // For each role info (corresponding to a role not initialized by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3266
        // role list provided by the user), try to set in the relation a role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
        // with an empty list of ObjectNames.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3268
        // A check is performed to verify that the role can be set to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3269
        // empty value, according to its minimum cardinality
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  3270
        for (RoleInfo currRoleInfo : roleInfoList) {
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  3271
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
            String roleName = currRoleInfo.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
            // Creates an empty value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
            List<ObjectName> emptyValue = new ArrayList<ObjectName>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
            // Creates a role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3277
            Role role = new Role(roleName, emptyValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3279
            if (relationBaseFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3280
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3281
                // Internal relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3282
                // Can throw InvalidRoleValueException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3283
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3284
                // Will not throw RoleNotFoundException (role to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
                // initialized), or RelationNotFoundException, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
                // RelationTypeNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3287
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
                    relationObj.setRoleInt(role, true, this, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
                } catch (RoleNotFoundException exc1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3291
                    throw new RuntimeException(exc1.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
                } catch (RelationNotFoundException exc2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3293
                    throw new RuntimeException(exc2.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
                } catch (RelationTypeNotFoundException exc3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
                    throw new RuntimeException(exc3.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
                // Relation is an MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
                // Use standard setRole()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
                Object[] params = new Object[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
                params[0] = role;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
                String[] signature = new String[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
                signature[0] = "javax.management.relation.Role";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
                // Can throw MBeanException wrapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
                // InvalidRoleValueException. Returns the target exception to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
                // be homogeneous.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3309
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
                // Will not throw MBeanException (wrapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
                // RoleNotFoundException or MBeanException) or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
                // InstanceNotFoundException, or ReflectionException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3313
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3314
                // Again here the assumption is that the Relation Service and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3315
                // the relation MBeans are registered in the same MBean Server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3316
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
                    myMBeanServer.setAttribute(relationObjName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3318
                                               new Attribute("Role", role));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3320
                } catch (InstanceNotFoundException exc1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
                    throw new RuntimeException(exc1.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
                } catch (ReflectionException exc3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
                    throw new RuntimeException(exc3.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3324
                } catch (MBeanException exc2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
                    Exception wrappedExc = exc2.getTargetException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
                    if (wrappedExc instanceof InvalidRoleValueException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
                        throw ((InvalidRoleValueException)wrappedExc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
                        throw new RuntimeException(wrappedExc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
                } catch (AttributeNotFoundException exc4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3332
                  throw new RuntimeException(exc4.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
                } catch (InvalidAttributeValueException exc5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
                  throw new RuntimeException(exc5.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3338
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3339
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
    // Throws an exception corresponding to a given problem type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
    // -param pbType  possible problem, defined in RoleUnresolved
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
    // -param roleName  role name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
    // -exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3349
    // -exception RoleNotFoundException  for problems:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
    //  - NO_ROLE_WITH_NAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
    //  - ROLE_NOT_READABLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3352
    //  - ROLE_NOT_WRITABLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
    // -exception InvalidRoleValueException  for problems:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
    //  - LESS_THAN_MIN_ROLE_DEGREE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3355
    //  - MORE_THAN_MAX_ROLE_DEGREE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3356
    //  - REF_MBEAN_OF_INCORRECT_CLASS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3357
    //  - REF_MBEAN_NOT_REGISTERED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
    static void throwRoleProblemException(int pbType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3359
                                          String roleName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
               RoleNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
               InvalidRoleValueException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3364
        if (roleName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3368
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3369
        // Exception type: 1 = RoleNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3370
        //                 2 = InvalidRoleValueException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3371
        int excType = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3373
        String excMsgPart = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
        switch (pbType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
        case RoleStatus.NO_ROLE_WITH_NAME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3377
            excMsgPart = " does not exist in relation.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3378
            excType = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3379
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3380
        case RoleStatus.ROLE_NOT_READABLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3381
            excMsgPart = " is not readable.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3382
            excType = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3383
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3384
        case RoleStatus.ROLE_NOT_WRITABLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3385
            excMsgPart = " is not writable.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3386
            excType = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3388
        case RoleStatus.LESS_THAN_MIN_ROLE_DEGREE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
            excMsgPart = " has a number of MBean references less than the expected minimum degree.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
            excType = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
        case RoleStatus.MORE_THAN_MAX_ROLE_DEGREE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
            excMsgPart = " has a number of MBean references greater than the expected maximum degree.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
            excType = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
        case RoleStatus.REF_MBEAN_OF_INCORRECT_CLASS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
            excMsgPart = " has an MBean reference to an MBean not of the expected class of references for that role.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3398
            excType = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3400
        case RoleStatus.REF_MBEAN_NOT_REGISTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3401
            excMsgPart = " has a reference to null or to an MBean not registered.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3402
            excType = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
        // No default as we must have been in one of those cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3406
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
        StringBuilder excMsgStrB = new StringBuilder(roleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3408
        excMsgStrB.append(excMsgPart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3409
        String excMsg = excMsgStrB.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3410
        if (excType == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3411
            throw new RoleNotFoundException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3412
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
        } else if (excType == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
            throw new InvalidRoleValueException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
    // Sends a notification of given type, with given parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3419
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
    // -param intNtfType  integer to represent notification type:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3421
    //  - 1 : create
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
    //  - 2 : update
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3423
    //  - 3 : delete
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
    // -param message  human-readable message
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3425
    // -param relationId  relation id of the created/updated/deleted relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
    // -param unregMBeanList  list of ObjectNames of referenced MBeans
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
    //  expected to be unregistered due to relation removal (only for removal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
    //  due to CIM qualifiers, can be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3429
    // -param roleName  role name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
    // -param roleNewValue  role new value (ArrayList of ObjectNames)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3431
    // -param oldValue  old role value (ArrayList of ObjectNames)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3432
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3433
    // -exception IllegalArgument  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3434
    // -exception RelationNotFoundException  if no relation for given id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3435
    private void sendNotificationInt(int intNtfType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3436
                                     String message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3437
                                     String relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
                                     List<ObjectName> unregMBeanList,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3439
                                     String roleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3440
                                     List<ObjectName> roleNewValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3441
                                     List<ObjectName> oldValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3442
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3443
               RelationNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3444
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3445
        if (message == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3446
            relationId == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3447
            (intNtfType != 3 && unregMBeanList != null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3448
            (intNtfType == 2 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
             (roleName == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3450
              roleNewValue == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3451
              oldValue == null))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3453
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3455
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3456
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1} {2} {3} {4} {5} {6}",
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3457
                            intNtfType, message, relationId, unregMBeanList,
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3458
                            roleName, roleNewValue, oldValue);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3460
        // Relation type name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3461
        // Note: do not use getRelationTypeName() as if it is a relation MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3462
        //       it is already unregistered.
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  3463
        String relTypeName;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
        synchronized(myRelId2RelTypeMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
            relTypeName = (myRelId2RelTypeMap.get(relationId));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3468
        // ObjectName (for a relation MBean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3469
        // Can also throw a RelationNotFoundException, but detected above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3470
        ObjectName relObjName = isRelationMBean(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3471
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3472
        String ntfType = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3473
        if (relObjName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3474
            switch (intNtfType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
            case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
                ntfType = RelationNotification.RELATION_MBEAN_CREATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3477
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3478
            case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
                ntfType = RelationNotification.RELATION_MBEAN_UPDATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3481
            case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3482
                ntfType = RelationNotification.RELATION_MBEAN_REMOVAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3483
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3486
            switch (intNtfType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
            case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
                ntfType = RelationNotification.RELATION_BASIC_CREATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
            case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
                ntfType = RelationNotification.RELATION_BASIC_UPDATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3493
            case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3494
                ntfType = RelationNotification.RELATION_BASIC_REMOVAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3495
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3496
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3499
        // Sequence number
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  3500
        Long seqNo = atomicSeqNo.incrementAndGet();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3501
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3502
        // Timestamp
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3503
        Date currDate = new Date();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3504
        long timeStamp = currDate.getTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
        RelationNotification ntf = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3507
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3508
        if (ntfType.equals(RelationNotification.RELATION_BASIC_CREATION) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3509
            ntfType.equals(RelationNotification.RELATION_MBEAN_CREATION) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
            ntfType.equals(RelationNotification.RELATION_BASIC_REMOVAL) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
            ntfType.equals(RelationNotification.RELATION_MBEAN_REMOVAL))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3513
            // Creation or removal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
            ntf = new RelationNotification(ntfType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
                                           this,
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  3516
                                           seqNo.longValue(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3517
                                           timeStamp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3518
                                           message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3519
                                           relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3520
                                           relTypeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3521
                                           relObjName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3522
                                           unregMBeanList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3524
        else if (ntfType.equals(RelationNotification.RELATION_BASIC_UPDATE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3525
                 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3526
                 ntfType.equals(RelationNotification.RELATION_MBEAN_UPDATE))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
                // Update
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
                ntf = new RelationNotification(ntfType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
                                               this,
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  3531
                                               seqNo.longValue(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
                                               timeStamp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3533
                                               message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
                                               relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3535
                                               relTypeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3536
                                               relObjName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3537
                                               roleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3538
                                               roleNewValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3539
                                               oldValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3540
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3541
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3542
        sendNotification(ntf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3543
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3544
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3545
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3546
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3547
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3548
    // Checks, for the unregistration of an MBean referenced in the roles given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3549
    // in parameter, if the relation has to be removed or not, regarding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3550
    // expected minimum role cardinality and current number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3551
    // references in each role after removal of the current one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3552
    // If the relation is kept, calls handleMBeanUnregistration() callback of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3553
    // the relation to update it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3554
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3555
    // -param relationId  relation id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3556
    // -param objectName  ObjectName of the unregistered MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3557
    // -param roleNameList  list of names of roles where the unregistered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3558
    //  MBean is referenced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3559
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3560
    // -exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3561
    // -exception RelationServiceNotRegisteredException  if the Relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3562
    //  Service is not registered in the MBean Server
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3563
    // -exception RelationNotFoundException  if unknown relation id
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3564
    // -exception RoleNotFoundException  if one role given as parameter does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3565
    //  not exist in the relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3566
    private void handleReferenceUnregistration(String relationId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3567
                                               ObjectName objectName,
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  3568
                                               List<String> roleNameList)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3569
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3570
               RelationServiceNotRegisteredException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3571
               RelationNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3572
               RoleNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3574
        if (relationId == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3575
            roleNameList == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3576
            objectName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3577
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3578
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3580
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3581
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0} {1} {2}",
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3582
                            relationId, objectName, roleNameList);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3583
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3584
        // Can throw RelationServiceNotRegisteredException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3585
        isActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3586
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3587
        // Retrieves the relation type name of the relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3588
        // Can throw RelationNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3589
        String currRelTypeName = getRelationTypeName(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3590
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3591
        // Retrieves the relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3592
        // Can throw RelationNotFoundException, but already detected above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3593
        Object relObj = getRelation(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3594
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3595
        // Flag to specify if the relation has to be deleted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3596
        boolean deleteRelFlag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3597
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  3598
        for (String currRoleName : roleNameList) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3599
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3600
            if (deleteRelFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3601
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3602
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3604
            // Retrieves number of MBeans currently referenced in role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3605
            // BEWARE! Do not use getRole() as role may be not readable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3606
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3607
            // Can throw RelationNotFoundException (but already checked),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3608
            // RoleNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3609
            int currRoleRefNbr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3610
                (getRoleCardinality(relationId, currRoleName)).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3611
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3612
            // Retrieves new number of element in role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3613
            int currRoleNewRefNbr = currRoleRefNbr - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3614
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3615
            // Retrieves role info for that role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3616
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3617
            // Shall not throw RelationTypeNotFoundException or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3618
            // RoleInfoNotFoundException
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  3619
            RoleInfo currRoleInfo;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3620
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3621
                currRoleInfo = getRoleInfo(currRelTypeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3622
                                           currRoleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3623
            } catch (RelationTypeNotFoundException exc1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3624
                throw new RuntimeException(exc1.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3625
            } catch (RoleInfoNotFoundException exc2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3626
                throw new RuntimeException(exc2.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3627
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3628
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3629
            // Checks with expected minimum number of elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3630
            boolean chkMinFlag = currRoleInfo.checkMinDegree(currRoleNewRefNbr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3631
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3632
            if (!chkMinFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3633
                // The relation has to be deleted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3634
                deleteRelFlag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3635
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3636
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3637
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3638
        if (deleteRelFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3639
            // Removes the relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3640
            removeRelation(relationId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3641
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3642
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3643
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3644
            // Updates each role in the relation using
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3645
            // handleMBeanUnregistration() callback
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3646
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3647
            // BEWARE: this roleNameList list MUST BE A COPY of a role name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3648
            //         list for a referenced MBean in a relation, NOT a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3649
            //         reference to an original one part of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3650
            //         myRefedMBeanObjName2RelIdsMap!!!! Because each role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3651
            //         which name is in that list will be updated (potentially
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3652
            //         using setRole(). So the Relation Service will update the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3653
            //         myRefedMBeanObjName2RelIdsMap to refelect the new role
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3654
            //         value!
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  3655
            for (String currRoleName : roleNameList) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3656
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3657
                if (relObj instanceof RelationSupport) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3658
                    // Internal relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3659
                    // Can throw RoleNotFoundException (but already checked)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3660
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3661
                    // Shall not throw
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3662
                    // RelationTypeNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3663
                    // InvalidRoleValueException (value was correct, removing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3664
                    // one reference shall not invalidate it, else detected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3665
                    // above)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3666
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3667
                        ((RelationSupport)relObj).handleMBeanUnregistrationInt(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3668
                                                  objectName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3669
                                                  currRoleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3670
                                                  true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3671
                                                  this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3672
                    } catch (RelationTypeNotFoundException exc3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3673
                        throw new RuntimeException(exc3.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3674
                    } catch (InvalidRoleValueException exc4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3675
                        throw new RuntimeException(exc4.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3676
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3677
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3678
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3679
                    // Relation MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3680
                    Object[] params = new Object[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3681
                    params[0] = objectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3682
                    params[1] = currRoleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3683
                    String[] signature = new String[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3684
                    signature[0] = "javax.management.ObjectName";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3685
                    signature[1] = "java.lang.String";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3686
                    // Shall not throw InstanceNotFoundException, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3687
                    // MBeanException (wrapping RoleNotFoundException or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3688
                    // MBeanException or InvalidRoleValueException) or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3689
                    // ReflectionException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3690
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3691
                        myMBeanServer.invoke(((ObjectName)relObj),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3692
                                             "handleMBeanUnregistration",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3693
                                             params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3694
                                             signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3695
                    } catch (InstanceNotFoundException exc1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3696
                        throw new RuntimeException(exc1.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3697
                    } catch (ReflectionException exc3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3698
                        throw new RuntimeException(exc3.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3699
                    } catch (MBeanException exc2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3700
                        Exception wrappedExc = exc2.getTargetException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3701
                        throw new RuntimeException(wrappedExc.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3702
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3703
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3704
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3705
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3706
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3707
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
  3708
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3709
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3710
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3711
}