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