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