1 7 8 package javax.management.relation; 9 10 import javax.management.Attribute ; 11 import javax.management.AttributeNotFoundException ; 12 import javax.management.NotificationListener ; 13 import javax.management.ObjectName ; 14 import javax.management.NotCompliantMBeanException ; 15 import javax.management.Notification ; 16 import javax.management.NotificationBroadcasterSupport ; 17 import javax.management.MBeanRegistration ; 18 import javax.management.MBeanServer ; 19 import javax.management.ListenerNotFoundException ; 20 import javax.management.InstanceNotFoundException ; 21 import javax.management.InvalidAttributeValueException ; 22 import javax.management.MBeanException ; 23 import javax.management.ReflectionException ; 24 import javax.management.MBeanServerNotification ; 25 import javax.management.MBeanNotificationInfo ; 26 import javax.management.MalformedObjectNameException ; 27 28 import com.sun.jmx.defaults.ServiceName; 29 30 import com.sun.jmx.trace.Trace; 31 32 import java.util.ArrayList ; 33 import java.util.HashMap ; 34 import java.util.Iterator ; 35 import java.util.Set ; 36 import java.util.List ; 37 import java.util.Map ; 38 import java.util.Date ; 39 40 55 public class RelationService extends NotificationBroadcasterSupport 56 implements RelationServiceMBean , MBeanRegistration , NotificationListener { 57 58 62 private HashMap myRelId2ObjMap = new HashMap (); 68 69 private HashMap myRelId2RelTypeMap = new HashMap (); 72 73 private HashMap myRelMBeanObjName2RelIdMap = new HashMap (); 76 77 private HashMap myRelType2ObjMap = new HashMap (); 80 81 private HashMap myRelType2RelIdsMap = new HashMap (); 85 86 private HashMap myRefedMBeanObjName2RelIdsMap = new HashMap (); 92 93 private boolean myPurgeFlg = true; 100 101 private Long myNtfSeqNbrCounter = new Long (0); 105 106 private ObjectName myObjName = null; 108 109 private MBeanServer myMBeanServer = null; 111 112 private MBeanServerNotificationFilter myUnregNtfFilter = null; 115 116 private ArrayList myUnregNtfList = new ArrayList (); 120 121 125 135 public RelationService(boolean theImmediatePurgeFlg) { 136 137 if (isTraceOn()) 138 trace("Constructor: entering", null); 139 140 setPurgeFlag(theImmediatePurgeFlg); 141 142 if (isTraceOn()) 143 trace("Constructor: exiting", null); 144 return; 145 } 146 147 155 public void isActive() 156 throws RelationServiceNotRegisteredException { 157 if (myMBeanServer == null) { 158 String excMsg = 162 "Relation Service not registered in the MBean Server."; 163 throw new RelationServiceNotRegisteredException (excMsg); 164 } 165 return; 166 } 167 168 172 public ObjectName preRegister(MBeanServer server, 176 ObjectName name) 177 throws Exception { 178 179 myMBeanServer = server; 180 myObjName = name; 181 return name; 182 } 183 184 public void postRegister(Boolean registrationDone) { 186 return; 187 } 188 189 public void preDeregister() 191 throws Exception { 192 return; 193 } 194 195 public void postDeregister() { 197 return; 198 } 199 200 204 216 public boolean getPurgeFlag() { 217 return myPurgeFlg; 218 } 219 220 232 public void setPurgeFlag(boolean thePurgeFlg) { 233 234 myPurgeFlg = thePurgeFlg; 235 return; 236 } 237 238 private Long getNotificationSequenceNumber() { 243 Long result = null; 244 synchronized(myNtfSeqNbrCounter) { 245 result = new Long (myNtfSeqNbrCounter.longValue() + 1); 246 myNtfSeqNbrCounter = new Long (result.longValue()); 247 } 248 return result; 249 } 250 251 255 270 public void createRelationType(String theRelTypeName, 271 RoleInfo [] theRoleInfoArray) 272 throws IllegalArgumentException , 273 InvalidRelationTypeException { 274 275 if (theRelTypeName == null || theRoleInfoArray == null) { 276 String excMsg = "Invalid parameter."; 278 throw new IllegalArgumentException (excMsg); 279 } 280 281 if (isTraceOn()) 282 trace("createRelationType: entering", theRelTypeName); 283 284 RelationType relType = 286 new RelationTypeSupport (theRelTypeName, theRoleInfoArray); 287 288 addRelationTypeInt(relType); 289 290 if (isTraceOn()) 291 trace("createRelationType: exiting", null); 292 return; 293 } 294 295 309 public void addRelationType(RelationType theRelTypeObj) 310 throws IllegalArgumentException , 311 InvalidRelationTypeException { 312 313 if (theRelTypeObj == null) { 314 String excMsg = "Invalid parameter."; 316 throw new IllegalArgumentException (excMsg); 317 } 318 319 if (isTraceOn()) 320 trace("addRelationType: entering", null); 321 322 List roleInfoList = theRelTypeObj.getRoleInfos(); 324 if (roleInfoList == null) { 325 String excMsg = "No role info provided."; 327 throw new InvalidRelationTypeException (excMsg); 328 } 329 330 RoleInfo [] roleInfoArray = new RoleInfo [roleInfoList.size()]; 331 int i = 0; 332 for (Iterator roleInfoIter = roleInfoList.iterator(); 333 roleInfoIter.hasNext();) { 334 RoleInfo currRoleInfo = (RoleInfo )(roleInfoIter.next()); 335 roleInfoArray[i] = currRoleInfo; 336 i++; 337 } 338 RelationTypeSupport.checkRoleInfos(roleInfoArray); 340 341 addRelationTypeInt(theRelTypeObj); 342 343 if (isTraceOn()) 344 trace("addRelationType: exiting", null); 345 return; 346 } 347 348 353 public List getAllRelationTypeNames() { 354 ArrayList result = null; 355 synchronized(myRelType2ObjMap) { 356 result = new ArrayList (myRelType2ObjMap.keySet()); 357 } 358 return result; 359 } 360 361 373 public List getRoleInfos(String theRelTypeName) 374 throws IllegalArgumentException , 375 RelationTypeNotFoundException { 376 377 if (theRelTypeName == null) { 378 String excMsg = "Invalid parameter."; 380 throw new IllegalArgumentException (excMsg); 381 } 382 383 if (isTraceOn()) 384 trace("getRoleInfos: entering", theRelTypeName); 385 386 RelationType relType = getRelationType(theRelTypeName); 388 389 if (isTraceOn()) 390 trace("getRoleInfos: exiting", null); 391 return relType.getRoleInfos(); 392 } 393 394 408 public RoleInfo getRoleInfo(String theRelTypeName, 409 String theRoleInfoName) 410 throws IllegalArgumentException , 411 RelationTypeNotFoundException , 412 RoleInfoNotFoundException { 413 414 if (theRelTypeName == null || theRoleInfoName == null) { 415 String excMsg = "Invalid parameter."; 417 throw new IllegalArgumentException (excMsg); 418 } 419 420 if (isTraceOn()) { 421 String str = "theRelTypeName " + theRelTypeName 422 + ", theRoleInfoName " + theRoleInfoName; 423 trace("getRoleInfo: entering", str); 424 } 425 426 RelationType relType = getRelationType(theRelTypeName); 428 429 RoleInfo roleInfo = relType.getRoleInfo(theRoleInfoName); 431 432 if (isTraceOn()) 433 trace("getRoleInfo: exiting", null); 434 return roleInfo; 435 } 436 437 450 public void removeRelationType(String theRelTypeName) 451 throws RelationServiceNotRegisteredException , 452 IllegalArgumentException , 453 RelationTypeNotFoundException { 454 455 isActive(); 457 458 if (theRelTypeName == null) { 459 String excMsg = "Invalid parameter."; 461 throw new IllegalArgumentException (excMsg); 462 } 463 464 if (isTraceOn()) 465 trace("removeRelationType: entering", theRelTypeName); 466 467 RelationType relType = getRelationType(theRelTypeName); 470 471 ArrayList relIdList = null; 473 synchronized(myRelType2RelIdsMap) { 474 ArrayList relIdList1 = (ArrayList ) 477 (myRelType2RelIdsMap.get(theRelTypeName)); 478 if (relIdList1 != null) { 479 relIdList = (ArrayList )(relIdList1.clone()); 480 } 481 } 482 483 synchronized(myRelType2ObjMap) { 485 myRelType2ObjMap.remove(theRelTypeName); 486 } 487 synchronized(myRelType2RelIdsMap) { 488 myRelType2RelIdsMap.remove(theRelTypeName); 489 } 490 491 if (relIdList != null) { 493 for (Iterator relIdIter = relIdList.iterator(); 494 relIdIter.hasNext();) { 495 String currRelId = (String )(relIdIter.next()); 496 try { 502 removeRelation(currRelId); 503 } catch (RelationNotFoundException exc1) { 504 throw new RuntimeException (exc1.getMessage()); 505 } 506 } 507 } 508 509 if (isTraceOn()) 510 trace("removeRelationType: exiting", null); 511 return; 512 } 513 514 518 552 public void createRelation(String theRelId, 553 String theRelTypeName, 554 RoleList theRoleList) 555 throws RelationServiceNotRegisteredException , 556 IllegalArgumentException , 557 RoleNotFoundException , 558 InvalidRelationIdException , 559 RelationTypeNotFoundException , 560 InvalidRoleValueException { 561 562 isActive(); 564 565 if (theRelId == null || 566 theRelTypeName == null) { 567 String excMsg = "Invalid parameter."; 569 throw new IllegalArgumentException (excMsg); 570 } 571 572 if (isTraceOn()) { 573 StringBuffer strB = 574 new StringBuffer ("theRelId " + theRelId 575 + ", theRelTypeName " + theRelTypeName); 576 if (theRoleList != null) { 577 strB.append(", theRoleList " + theRoleList.toString()); 578 } 579 trace("createRelation: entering", strB.toString()); 580 } 581 582 RelationSupport relObj = new RelationSupport (theRelId, 585 myObjName, 586 theRelTypeName, 587 theRoleList); 588 589 addRelationInt(true, 595 relObj, 596 null, 597 theRelId, 598 theRelTypeName, 599 theRoleList); 600 601 if (isTraceOn()) 602 trace("createRelation: exiting", null); 603 return; 604 } 605 606 651 public void addRelation(ObjectName theRelObjectName) 652 throws IllegalArgumentException , 653 RelationServiceNotRegisteredException , 654 NoSuchMethodException , 655 InvalidRelationIdException , 656 InstanceNotFoundException , 657 InvalidRelationServiceException , 658 RelationTypeNotFoundException , 659 RoleNotFoundException , 660 InvalidRoleValueException { 661 662 if (theRelObjectName == null) { 663 String excMsg = "Invalid parameter."; 665 throw new IllegalArgumentException (excMsg); 666 } 667 668 if (isTraceOn()) 669 trace("addRelation: entering", theRelObjectName.toString()); 670 671 isActive(); 673 674 if ((!(myMBeanServer.isInstanceOf(theRelObjectName, "javax.management.relation.Relation")))) { 678 String excMsg = "This MBean does not implement the Relation interface."; 680 throw new NoSuchMethodException (excMsg); 681 } 682 String relId = null; 688 try { 689 relId = (String )(myMBeanServer.getAttribute(theRelObjectName, 690 "RelationId")); 691 692 } catch (MBeanException exc1) { 693 throw new RuntimeException ( 694 (exc1.getTargetException()).getMessage()); 695 } catch (ReflectionException exc2) { 696 throw new RuntimeException (exc2.getMessage()); 697 } catch (AttributeNotFoundException exc3) { 698 throw new RuntimeException (exc3.getMessage()); 699 } 700 701 if (relId == null) { 702 String excMsg = "This MBean does not provide a relation id."; 704 throw new InvalidRelationIdException (excMsg); 705 } 706 ObjectName relServObjName = null; 712 try { 713 relServObjName = (ObjectName ) 714 (myMBeanServer.getAttribute(theRelObjectName, 715 "RelationServiceName")); 716 717 } catch (MBeanException exc1) { 718 throw new RuntimeException ( 719 (exc1.getTargetException()).getMessage()); 720 } catch (ReflectionException exc2) { 721 throw new RuntimeException (exc2.getMessage()); 722 } catch (AttributeNotFoundException exc3) { 723 throw new RuntimeException (exc3.getMessage()); 724 } 725 726 boolean badRelServFlg = false; 727 if (relServObjName == null) { 728 badRelServFlg = true; 729 730 } else if (!(relServObjName.equals(myObjName))) { 731 badRelServFlg = true; 732 } 733 if (badRelServFlg) { 734 String excMsg = "The Relation Service referenced in the MBean is not the current one."; 736 throw new InvalidRelationServiceException (excMsg); 737 } 738 String relTypeName = null; 743 try { 744 relTypeName = (String )(myMBeanServer.getAttribute(theRelObjectName, 745 "RelationTypeName")); 746 747 } catch (MBeanException exc1) { 748 throw new RuntimeException ( 749 (exc1.getTargetException()).getMessage()); 750 }catch (ReflectionException exc2) { 751 throw new RuntimeException (exc2.getMessage()); 752 } catch (AttributeNotFoundException exc3) { 753 throw new RuntimeException (exc3.getMessage()); 754 } 755 if (relTypeName == null) { 756 String excMsg = "No relation type provided."; 758 throw new RelationTypeNotFoundException (excMsg); 759 } 760 RoleList roleList = null; 765 try { 766 roleList = (RoleList )(myMBeanServer.invoke(theRelObjectName, 767 "retrieveAllRoles", 768 null, 769 null)); 770 } catch (MBeanException exc1) { 771 throw new RuntimeException ( 772 (exc1.getTargetException()).getMessage()); 773 } catch (ReflectionException exc2) { 774 throw new RuntimeException (exc2.getMessage()); 775 } 776 777 addRelationInt(false, 780 null, 781 theRelObjectName, 782 relId, 783 relTypeName, 784 roleList); 785 synchronized(myRelMBeanObjName2RelIdMap) { 787 myRelMBeanObjName2RelIdMap.put(theRelObjectName, relId); 788 } 789 790 try { 795 myMBeanServer.setAttribute(theRelObjectName, 796 new Attribute ( 797 "RelationServiceManagementFlag", 798 new Boolean (true))); 799 } catch (Exception exc) { 800 } 802 803 ArrayList newRefList = new ArrayList (); 806 newRefList.add(theRelObjectName); 807 updateUnregistrationListener(newRefList, null); 808 809 if (isTraceOn()) 810 trace("addRelation: exiting", null); 811 return; 812 } 813 814 828 public ObjectName isRelationMBean(String theRelId) 829 throws IllegalArgumentException , 830 RelationNotFoundException { 831 832 if (theRelId == null) { 833 String excMsg = "Invalid parameter."; 835 throw new IllegalArgumentException (excMsg); 836 } 837 838 if (isTraceOn()) 839 trace("isRelationMBean", theRelId); 840 841 Object result = getRelation(theRelId); 843 if (result instanceof ObjectName ) { 844 return ((ObjectName )result); 845 } else { 846 return null; 847 } 848 } 849 850 861 public String isRelation(ObjectName theObjName) 862 throws IllegalArgumentException { 863 864 if (theObjName == null) { 865 String excMsg = "Invalid parameter."; 867 throw new IllegalArgumentException (excMsg); 868 } 869 870 if (isTraceOn()) 871 trace("isRelation", theObjName.toString()); 872 873 String result = null; 874 synchronized(myRelMBeanObjName2RelIdMap) { 875 String relId = (String ) 876 (myRelMBeanObjName2RelIdMap.get(theObjName)); 877 if (relId != null) { 878 result = relId; 879 } 880 } 881 return result; 882 } 883 884 894 public Boolean hasRelation(String theRelId) 895 throws IllegalArgumentException { 896 897 if (theRelId == null) { 898 String excMsg = "Invalid parameter."; 900 throw new IllegalArgumentException (excMsg); 901 } 902 903 if (isTraceOn()) 904 trace("hasRelation", theRelId); 905 906 try { 907 Object result = getRelation(theRelId); 909 return new Boolean (true); 910 } catch (RelationNotFoundException exc) { 911 return new Boolean (false); 912 } 913 } 914 915 921 public List getAllRelationIds() { 922 ArrayList result = null; 923 synchronized(myRelId2ObjMap) { 924 result = new ArrayList (myRelId2ObjMap.keySet()); 925 } 926 return result; 927 } 928 929 945 public Integer checkRoleReading(String theRoleName, 946 String theRelTypeName) 947 throws IllegalArgumentException , 948 RelationTypeNotFoundException { 949 950 if (theRoleName == null || theRelTypeName == null) { 951 String excMsg = "Invalid parameter."; 953 throw new IllegalArgumentException (excMsg); 954 } 955 956 if (isTraceOn()) { 957 String str = "theRoleName " + theRoleName 958 + ", theRelTypeName " + theRelTypeName; 959 trace("checkRoleReading: entering", str); 960 } 961 962 Integer result = null; 963 964 RelationType relType = getRelationType(theRelTypeName); 966 967 try { 968 RoleInfo roleInfo = relType.getRoleInfo(theRoleName); 971 972 result = checkRoleInt(1, 973 theRoleName, 974 null, 975 roleInfo, 976 false); 977 978 } catch (RoleInfoNotFoundException exc) { 979 result = new Integer (RoleStatus.NO_ROLE_WITH_NAME); 980 } 981 982 if (isTraceOn()) 983 trace("checkRoleReading: exiting", null); 984 return result; 985 } 986 987 1008 public Integer checkRoleWriting(Role theRole, 1009 String theRelTypeName, 1010 Boolean theInitFlg) 1011 throws IllegalArgumentException , 1012 RelationTypeNotFoundException { 1013 1014 if (theRole == null || 1015 theRelTypeName == null || 1016 theInitFlg == null) { 1017 String excMsg = "Invalid parameter."; 1019 throw new IllegalArgumentException (excMsg); 1020 } 1021 1022 if (isTraceOn()) { 1023 String str = new String ("theRole " + theRole.toString() 1024 + ", theRelTypeName " + theRelTypeName 1025 + ", theInitFlg " + theInitFlg); 1026 trace("checkRoleWriting: entering", str); 1027 } 1028 1029 RelationType relType = getRelationType(theRelTypeName); 1031 1032 String roleName = theRole.getRoleName(); 1033 ArrayList roleValue = (ArrayList )(theRole.getRoleValue()); 1034 boolean writeChkFlg = true; 1035 if (theInitFlg.booleanValue()) { 1036 writeChkFlg = false; 1037 } 1038 1039 RoleInfo roleInfo = null; 1040 try { 1041 roleInfo = relType.getRoleInfo(roleName); 1042 } catch (RoleInfoNotFoundException exc) { 1043 if (isTraceOn()) 1044 trace("checkRoleWriting: exiting", null); 1045 return new Integer (RoleStatus.NO_ROLE_WITH_NAME); 1046 } 1047 1048 Integer result = checkRoleInt(2, 1049 roleName, 1050 roleValue, 1051 roleInfo, 1052 writeChkFlg); 1053 1054 if (isTraceOn()) 1055 trace("checkRoleWriting: exiting", null); 1056 return result; 1057 } 1058 1059 1076 public void sendRelationCreationNotification(String theRelId) 1077 throws IllegalArgumentException , 1078 RelationNotFoundException { 1079 1080 if (theRelId == null) { 1081 String excMsg = "Invalid parameter."; 1083 throw new IllegalArgumentException (excMsg); 1084 } 1085 1086 if (isTraceOn()) 1087 trace("sendRelationCreationNotification: entering", theRelId); 1088 1089 StringBuffer ntfMsg = new StringBuffer ("Creation of relation "); 1092 ntfMsg.append(theRelId); 1093 1094 sendNotificationInt(1, 1096 ntfMsg.toString(), 1097 theRelId, 1098 null, 1099 null, 1100 null, 1101 null); 1102 1103 if (isTraceOn()) 1104 trace("sendRelationCreationNotification: exiting", null); 1105 return; 1106 } 1107 1108 1130 public void sendRoleUpdateNotification(String theRelId, 1131 Role theNewRole, 1132 List theOldRoleValue) 1133 throws IllegalArgumentException , 1134 RelationNotFoundException { 1135 1136 if (theRelId == null || 1137 theNewRole == null || 1138 theOldRoleValue == null) { 1139 String excMsg = "Invalid parameter."; 1141 throw new IllegalArgumentException (excMsg); 1142 } 1143 1144 if (!(theOldRoleValue instanceof ArrayList )) 1145 theOldRoleValue = new ArrayList (theOldRoleValue); 1146 1147 if (isTraceOn()) { 1148 String str = new String ("theRelId " + theRelId 1149 + ", theNewRole " + theNewRole.toString() 1150 + ", theOldRoleValue " 1151 + theOldRoleValue.toString()); 1152 trace("sendRoleUpdateNotification: entering", str); 1153 } 1154 1155 String roleName = theNewRole.getRoleName(); 1156 ArrayList newRoleVal = (ArrayList )(theNewRole.getRoleValue()); 1157 1158 String newRoleValString = Role.roleValueToString(newRoleVal); 1160 String oldRoleValString = Role.roleValueToString(theOldRoleValue); 1161 StringBuffer ntfMsg = new StringBuffer ("Value of role "); 1163 ntfMsg.append(roleName); 1164 ntfMsg.append(" has changed\nOld value:\n"); 1165 ntfMsg.append(oldRoleValString); 1166 ntfMsg.append("\nNew value:\n"); 1167 ntfMsg.append(newRoleValString); 1168 1169 sendNotificationInt(2, 1171 ntfMsg.toString(), 1172 theRelId, 1173 null, 1174 roleName, 1175 newRoleVal, 1176 theOldRoleValue); 1177 1178 if (isTraceOn()) 1179 trace("sendRoleUpdateNotification: exiting", null); 1180 return; 1181 } 1182 1183 1201 public void sendRelationRemovalNotification(String theRelId, 1202 List theUnregMBeanList) 1203 throws IllegalArgumentException , 1204 RelationNotFoundException { 1205 1206 if (theRelId == null) { 1207 String excMsg = "Invalid parameter"; 1208 throw new IllegalArgumentException (excMsg); 1209 } 1210 1211 if (isTraceOn()) { 1212 StringBuffer strB = new StringBuffer ("theRelId " + theRelId); 1213 if (theUnregMBeanList != null) { 1214 strB.append(", theUnregMBeanList " 1215 + theUnregMBeanList.toString()); 1216 } 1217 trace("sendRelationRemovalNotification: entering", 1218 strB.toString()); 1219 } 1220 1221 StringBuffer ntfMsg = new StringBuffer ("Removal of relation "); 1224 ntfMsg.append(theRelId); 1225 1226 sendNotificationInt(3, 1228 ntfMsg.toString(), 1229 theRelId, 1230 theUnregMBeanList, 1231 null, 1232 null, 1233 null); 1234 1235 if (isTraceOn()) 1236 trace("sendRelationRemovalNotification: exiting", null); 1237 return; 1238 } 1239 1240 1261 public void updateRoleMap(String theRelId, 1262 Role theNewRole, 1263 List theOldRoleValue) 1264 throws IllegalArgumentException , 1265 RelationServiceNotRegisteredException , 1266 RelationNotFoundException { 1267 1268 if (theRelId == null || 1269 theNewRole == null || 1270 theOldRoleValue == null) { 1271 String excMsg = "Invalid parameter."; 1272 throw new IllegalArgumentException (excMsg); 1273 } 1274 1275 if (isTraceOn()) { 1276 String str = new String ("theRelId " + theRelId 1277 + ", theNewRole " + theNewRole.toString() 1278 + ", theOldRoleValue " 1279 + theOldRoleValue.toString()); 1280 trace("updateRoleMap: entering", str); 1281 } 1282 1283 isActive(); 1285 1286 Object result = getRelation(theRelId); 1289 1290 String roleName = theNewRole.getRoleName(); 1291 ArrayList newRoleValue = (ArrayList )(theNewRole.getRoleValue()); 1292 ArrayList oldRoleValue = new ArrayList (theOldRoleValue); 1295 1296 ArrayList newRefList = new ArrayList (); 1298 1299 for (Iterator newRoleIter = newRoleValue.iterator(); 1300 newRoleIter.hasNext();) { 1301 ObjectName currObjName = (ObjectName )(newRoleIter.next()); 1302 1303 int currObjNamePos = oldRoleValue.indexOf(currObjName); 1308 1309 if (currObjNamePos == -1) { 1310 1312 boolean isNewFlg = addNewMBeanReference(currObjName, 1316 theRelId, 1317 roleName); 1318 1319 if (isNewFlg) { 1320 newRefList.add(currObjName); 1322 } 1323 1324 } else { 1325 1327 oldRoleValue.remove(currObjNamePos); 1330 } 1331 } 1332 1333 ArrayList obsRefList = new ArrayList (); 1335 1336 for (Iterator oldRoleIter = oldRoleValue.iterator(); 1339 oldRoleIter.hasNext();) { 1340 1341 ObjectName currObjName = (ObjectName )(oldRoleIter.next()); 1342 boolean noLongerRefFlg = removeMBeanReference(currObjName, 1346 theRelId, 1347 roleName, 1348 false); 1349 1350 if (noLongerRefFlg) { 1351 obsRefList.add(currObjName); 1353 } 1354 } 1355 1356 updateUnregistrationListener(newRefList, obsRefList); 1360 1361 if (isTraceOn()) 1362 trace("updateRoleMap: exiting", null); 1363 return; 1364 } 1365 1366 1383 public void removeRelation(String theRelId) 1384 throws RelationServiceNotRegisteredException , 1385 IllegalArgumentException , 1386 RelationNotFoundException { 1387 1388 isActive(); 1390 1391 if (theRelId == null) { 1392 String excMsg = "Invalid parameter."; 1394 throw new IllegalArgumentException (excMsg); 1395 } 1396 1397 if (isTraceOn()) 1398 trace("removeRelation: entering", theRelId); 1399 1400 Object result = getRelation(theRelId); 1403 1404 if (result instanceof ObjectName ) { 1406 ArrayList obsRefList = new ArrayList (); 1407 obsRefList.add((ObjectName )result); 1408 updateUnregistrationListener(null, obsRefList); 1410 } 1411 1412 1417 1422 sendRelationRemovalNotification(theRelId, null); 1424 1425 1427 ArrayList refMBeanList = new ArrayList (); 1436 ArrayList nonRefObjNameList = new ArrayList (); 1439 1440 synchronized(myRefedMBeanObjName2RelIdsMap) { 1441 1442 for (Iterator refMBeanIter = 1443 (myRefedMBeanObjName2RelIdsMap.keySet()).iterator(); 1444 refMBeanIter.hasNext();) { 1445 1446 ObjectName currRefObjName = (ObjectName )(refMBeanIter.next()); 1447 HashMap relIdMap = (HashMap ) 1449 (myRefedMBeanObjName2RelIdsMap.get(currRefObjName)); 1450 1451 if (relIdMap.containsKey(theRelId)) { 1452 relIdMap.remove(theRelId); 1453 refMBeanList.add(currRefObjName); 1454 } 1455 1456 if (relIdMap.isEmpty()) { 1457 nonRefObjNameList.add(currRefObjName); 1461 } 1462 } 1463 1464 for (Iterator nonRefObjNameIter = nonRefObjNameList.iterator(); 1467 nonRefObjNameIter.hasNext();) { 1468 ObjectName currRefObjName = (ObjectName ) 1469 (nonRefObjNameIter.next()); 1470 myRefedMBeanObjName2RelIdsMap.remove(currRefObjName); 1471 } 1472 } 1473 1474 synchronized(myRelId2ObjMap) { 1476 myRelId2ObjMap.remove(theRelId); 1477 } 1478 1479 if (result instanceof ObjectName ) { 1480 synchronized(myRelMBeanObjName2RelIdMap) { 1482 myRelMBeanObjName2RelIdMap.remove((ObjectName )result); 1483 } 1484 } 1485 1486 String relTypeName = null; 1489 synchronized(myRelId2RelTypeMap) { 1490 relTypeName = (String )(myRelId2RelTypeMap.get(theRelId)); 1491 myRelId2RelTypeMap.remove(theRelId); 1492 } 1493 synchronized(myRelType2RelIdsMap) { 1495 ArrayList relIdList = 1496 (ArrayList )(myRelType2RelIdsMap.get(relTypeName)); 1497 if (relIdList != null) { 1498 relIdList.remove(theRelId); 1500 if (relIdList.isEmpty()) { 1501 myRelType2RelIdsMap.remove(relTypeName); 1503 } 1504 } 1505 } 1506 1507 if (isTraceOn()) 1508 trace("removeRelation: exiting", null); 1509 return; 1510 } 1511 1512 1538 public void purgeRelations() 1539 throws RelationServiceNotRegisteredException { 1540 1541 if (isTraceOn()) 1542 trace("purgeRelations: entering", null); 1543 1544 isActive(); 1546 1547 1553 1554 ArrayList localUnregNtfList = null; 1557 synchronized(myUnregNtfList) { 1558 localUnregNtfList = (ArrayList )(myUnregNtfList.clone()); 1559 myUnregNtfList = new ArrayList (); 1561 } 1562 1563 1564 ArrayList obsRefList = new ArrayList (); 1571 HashMap localMBean2RelIdMap = new HashMap (); 1574 1575 synchronized(myRefedMBeanObjName2RelIdsMap) { 1576 for (Iterator unregNtfIter = localUnregNtfList.iterator(); 1577 unregNtfIter.hasNext();) { 1578 1579 MBeanServerNotification currNtf = 1580 (MBeanServerNotification )(unregNtfIter.next()); 1581 1582 ObjectName unregMBeanName = currNtf.getMBeanName(); 1583 1584 obsRefList.add(unregMBeanName); 1587 1588 HashMap relIdMap = (HashMap ) 1590 (myRefedMBeanObjName2RelIdsMap.get(unregMBeanName)); 1591 localMBean2RelIdMap.put(unregMBeanName, relIdMap); 1592 1593 myRefedMBeanObjName2RelIdsMap.remove(unregMBeanName); 1594 } 1595 } 1596 1597 updateUnregistrationListener(null, obsRefList); 1600 1601 for (Iterator unregNtfIter = localUnregNtfList.iterator(); 1602 unregNtfIter.hasNext();) { 1603 1604 MBeanServerNotification currNtf = 1605 (MBeanServerNotification )(unregNtfIter.next()); 1606 1607 ObjectName unregMBeanName = currNtf.getMBeanName(); 1608 1609 HashMap localRelIdMap = (HashMap ) 1611 (localMBean2RelIdMap.get(unregMBeanName)); 1612 1613 Set localRelIdSet = localRelIdMap.keySet(); 1616 for (Iterator relIdIter = localRelIdSet.iterator(); 1617 relIdIter.hasNext();) { 1618 1619 String currRelId = (String )(relIdIter.next()); 1620 1621 ArrayList localRoleNameList = (ArrayList ) 1624 (localRelIdMap.get(currRelId)); 1625 1626 try { 1638 handleReferenceUnregistration(currRelId, 1639 unregMBeanName, 1640 localRoleNameList); 1641 } catch (RelationNotFoundException exc1) { 1642 throw new RuntimeException (exc1.getMessage()); 1643 } catch (RoleNotFoundException exc2) { 1644 throw new RuntimeException (exc2.getMessage()); 1645 } 1646 } 1647 } 1648 1649 if (isTraceOn()) 1650 trace("purgeRelations: exiting", null); 1651 return; 1652 } 1653 1654 1674 public Map findReferencingRelations(ObjectName theMBeanName, 1675 String theRelTypeName, 1676 String theRoleName) 1677 throws IllegalArgumentException { 1678 1679 if (theMBeanName == null) { 1680 String excMsg = "Invalid parameter."; 1682 throw new IllegalArgumentException (excMsg); 1683 } 1684 1685 if (isTraceOn()) { 1686 String str = new String ("theMBeanName " + theMBeanName.toString() 1687 + ", theRelTypeName " + theRelTypeName 1688 + ", theRoleName " + theRoleName); 1689 trace("findReferencingRelations: entering", str); 1690 } 1691 1692 HashMap result = new HashMap (); 1693 1694 synchronized(myRefedMBeanObjName2RelIdsMap) { 1695 1696 HashMap relId2RoleNamesMap = 1698 (HashMap )(myRefedMBeanObjName2RelIdsMap.get(theMBeanName)); 1699 1700 if (relId2RoleNamesMap != null) { 1701 1702 Set allRelIdSet = relId2RoleNamesMap.keySet(); 1704 1705 ArrayList relIdList = null; 1708 if (theRelTypeName == null) { 1709 relIdList = new ArrayList (allRelIdSet); 1711 1712 } else { 1713 1714 relIdList = new ArrayList (); 1715 1716 for (Iterator relIdIter = allRelIdSet.iterator(); 1719 relIdIter.hasNext();) { 1720 String currRelId = (String )(relIdIter.next()); 1721 1722 String currRelTypeName = null; 1724 synchronized(myRelId2RelTypeMap) { 1725 currRelTypeName = (String ) 1726 (myRelId2RelTypeMap.get(currRelId)); 1727 } 1728 1729 if (currRelTypeName.equals(theRelTypeName)) { 1730 1731 relIdList.add(currRelId); 1732 1733 } 1734 } 1735 } 1736 1737 1740 for (Iterator relIdIter = relIdList.iterator(); 1741 relIdIter.hasNext();) { 1742 1743 String currRelId = (String )(relIdIter.next()); 1744 ArrayList currRoleNameList = 1747 (ArrayList )(relId2RoleNamesMap.get(currRelId)); 1748 1749 if (theRoleName == null) { 1750 result.put(currRelId, 1754 (ArrayList )(currRoleNameList.clone())); 1755 1756 } else if (currRoleNameList.contains(theRoleName)) { 1757 ArrayList dummyList = new ArrayList (); 1760 dummyList.add(theRoleName); 1761 result.put(currRelId, dummyList); 1762 } 1763 } 1764 } 1765 } 1766 1767 if (isTraceOn()) 1768 trace("findReferencingRelations: exiting", null); 1769 return result; 1770 } 1771 1772 1792 public Map findAssociatedMBeans(ObjectName theMBeanName, 1793 String theRelTypeName, 1794 String theRoleName) 1795 throws IllegalArgumentException { 1796 1797 if (theMBeanName == null) { 1798 String excMsg = "Invalid parameter."; 1800 throw new IllegalArgumentException (excMsg); 1801 } 1802 1803 if (isTraceOn()) { 1804 String str = new String ("theMBeanName " + theMBeanName.toString() 1805 + ", theRelTypeName " + theRelTypeName 1806 + ", theRoleName " + theRoleName); 1807 trace("findAssociatedMBeans: entering", str); 1808 } 1809 1810 HashMap relId2RoleNamesMap = (HashMap ) 1813 (findReferencingRelations(theMBeanName, 1814 theRelTypeName, 1815 theRoleName)); 1816 1817 HashMap result = new HashMap (); 1818 1819 for (Iterator relIdIter = (relId2RoleNamesMap.keySet()).iterator(); 1820 relIdIter.hasNext();) { 1821 1822 String currRelId = (String )(relIdIter.next()); 1823 1824 HashMap objName2RoleNamesMap = null; 1829 try { 1830 objName2RoleNamesMap = 1831 (HashMap )(getReferencedMBeans(currRelId)); 1832 } catch (RelationNotFoundException exc) { 1833 throw new RuntimeException (exc.getMessage()); 1834 } 1835 1836 for (Iterator objNameIter = 1839 (objName2RoleNamesMap.keySet()).iterator(); 1840 objNameIter.hasNext();) { 1841 1842 ObjectName currObjName = (ObjectName )(objNameIter.next()); 1843 1844 if (!(currObjName.equals(theMBeanName))) { 1845 1846 ArrayList currRelIdList = 1849 (ArrayList )(result.get(currObjName)); 1850 if (currRelIdList == null) { 1851 1852 currRelIdList = new ArrayList (); 1853 currRelIdList.add(currRelId); 1854 result.put(currObjName, currRelIdList); 1855 1856 } else { 1857 currRelIdList.add(currRelId); 1858 } 1859 } 1860 } 1861 } 1862 1863 if (isTraceOn()) 1864 trace("findReferencingRelations: exiting", null); 1865 return result; 1866 } 1867 1868 1879 public List findRelationsOfType(String theRelTypeName) 1880 throws IllegalArgumentException , 1881 RelationTypeNotFoundException { 1882 1883 if (theRelTypeName == null) { 1884 String excMsg = "Invalid parameter."; 1886 throw new IllegalArgumentException (excMsg); 1887 } 1888 1889 if (isTraceOn()) 1890 trace("findRelationsOfType: entering", theRelTypeName); 1891 1892 RelationType relType = getRelationType(theRelTypeName); 1894 1895 ArrayList result = new ArrayList (); 1896 synchronized(myRelType2RelIdsMap) { 1897 ArrayList result1 = (ArrayList ) 1898 (myRelType2RelIdsMap.get(theRelTypeName)); 1899 if (result1 != null) { 1900 result = (ArrayList )(result1.clone()); 1901 } 1902 } 1903 1904 if (isTraceOn()) 1905 trace("findRelationsOfType: exiting", null); 1906 return result; 1907 } 1908 1909 1928 public List getRole(String theRelId, 1929 String theRoleName) 1930 throws RelationServiceNotRegisteredException , 1931 IllegalArgumentException , 1932 RelationNotFoundException , 1933 RoleNotFoundException { 1934 1935 if (theRelId == null || theRoleName == null) { 1936 String excMsg = "Invalid parameter."; 1938 throw new IllegalArgumentException (excMsg); 1939 } 1940 1941 if (isTraceOn()) { 1942 String str = "theRelId " + theRelId 1943 + ", theRoleName " + theRoleName; 1944 trace("getRole: entering", str); 1945 } 1946 1947 isActive(); 1949 1950 Object relObj = getRelation(theRelId); 1952 1953 ArrayList result = null; 1954 1955 if (relObj instanceof RelationSupport ) { 1956 result = (ArrayList ) 1959 (((RelationSupport )relObj).getRoleInt(theRoleName, 1960 true, 1961 this, 1962 false)); 1963 1964 } else { 1965 Object [] params = new Object [1]; 1967 params[0] = theRoleName; 1968 String [] signature = new String [1]; 1969 signature[0] = "java.lang.String"; 1970 try { 1975 List invokeResult = (List ) 1976 (myMBeanServer.invoke(((ObjectName )relObj), 1977 "getRole", 1978 params, 1979 signature)); 1980 if (invokeResult == null || invokeResult instanceof ArrayList ) 1981 result = (ArrayList ) invokeResult; 1982 else 1983 result = new ArrayList (result); 1984 } catch (InstanceNotFoundException exc1) { 1985 throw new RuntimeException (exc1.getMessage()); 1986 } catch (ReflectionException exc2) { 1987 throw new RuntimeException (exc2.getMessage()); 1988 } catch (MBeanException exc3) { 1989 Exception wrappedExc = exc3.getTargetException(); 1990 if (wrappedExc instanceof RoleNotFoundException ) { 1991 throw ((RoleNotFoundException )wrappedExc); 1992 } else { 1993 throw new RuntimeException (wrappedExc.getMessage()); 1994 } 1995 } 1996 } 1997 1998 if (isTraceOn()) 1999 trace("getRole: exiting", null); 2000 return result; 2001 } 2002 2003 2020 public RoleResult getRoles(String theRelId, 2021 String [] theRoleNameArray) 2022 throws RelationServiceNotRegisteredException , 2023 IllegalArgumentException , 2024 RelationNotFoundException { 2025 2026 if (theRelId == null || theRoleNameArray == null) { 2027 String excMsg = "Invalid parameter."; 2029 throw new IllegalArgumentException (excMsg); 2030 } 2031 2032 if (isTraceOn()) 2033 trace("getRoles: entering", theRelId); 2034 2035 isActive(); 2037 2038 Object relObj = getRelation(theRelId); 2040 2041 RoleResult result = null; 2042 2043 if (relObj instanceof RelationSupport ) { 2044 result = ((RelationSupport )relObj).getRolesInt(theRoleNameArray, 2046 true, 2047 this); 2048 } else { 2049 Object [] params = new Object [1]; 2051 params[0] = theRoleNameArray; 2052 String [] signature = new String [1]; 2053 try { 2054 signature[0] = (theRoleNameArray.getClass()).getName(); 2055 } catch (Exception exc) { 2056 } 2059 try { 2062 result = (RoleResult ) 2063 (myMBeanServer.invoke(((ObjectName )relObj), 2064 "getRoles", 2065 params, 2066 signature)); 2067 } catch (InstanceNotFoundException exc1) { 2068 throw new RuntimeException (exc1.getMessage()); 2069 } catch (ReflectionException exc2) { 2070 throw new RuntimeException (exc2.getMessage()); 2071 } catch (MBeanException exc3) { 2072 throw new 2073 RuntimeException ((exc3.getTargetException()).getMessage()); 2074 } 2075 } 2076 2077 if (isTraceOn()) 2078 trace("getRoles: exiting", null); 2079 return result; 2080 } 2081 2082 2096 public RoleResult getAllRoles(String theRelId) 2097 throws IllegalArgumentException , 2098 RelationNotFoundException , 2099 RelationServiceNotRegisteredException { 2100 2101 if (theRelId == null) { 2102 String excMsg = "Invalid parameter."; 2104 throw new IllegalArgumentException (excMsg); 2105 } 2106 2107 if (isTraceOn()) 2108 trace("getAllRoles: entering", theRelId); 2109 2110 Object relObj = getRelation(theRelId); 2112 2113 RoleResult result = null; 2114 2115 if (relObj instanceof RelationSupport ) { 2116 result = ((RelationSupport )relObj).getAllRolesInt(true, this); 2118 2119 } else { 2120 try { 2123 result = (RoleResult ) 2124 (myMBeanServer.getAttribute(((ObjectName )relObj), 2125 "AllRoles")); 2126 } catch (Exception exc) { 2127 throw new RuntimeException (exc.getMessage()); 2128 } 2129 } 2130 2131 if (isTraceOn()) 2132 trace("getAllRoles: exiting", null); 2133 return result; 2134 } 2135 2136 2148 public Integer getRoleCardinality(String theRelId, 2149 String theRoleName) 2150 throws IllegalArgumentException , 2151 RelationNotFoundException , 2152 RoleNotFoundException { 2153 2154 if (theRelId == null || theRoleName == null) { 2155 String excMsg = "Invalid parameter."; 2157 throw new IllegalArgumentException (excMsg); 2158 } 2159 2160 if (isTraceOn()) { 2161 String str = "theRelId " + theRelId 2162 + ", theRoleName " + theRoleName; 2163 trace("getRoleCardinality: entering", str); 2164 } 2165 2166 Object relObj = getRelation(theRelId); 2168 2169 Integer result = null; 2170 2171 if (relObj instanceof RelationSupport ) { 2172 result = (Integer ) 2175 (((RelationSupport )relObj).getRoleCardinality(theRoleName)); 2176 2177 } else { 2178 Object [] params = new Object [1]; 2180 params[0] = theRoleName; 2181 String [] signature = new String [1]; 2182 signature[0] = "java.lang.String"; 2183 try { 2188 result = (Integer ) 2189 (myMBeanServer.invoke(((ObjectName )relObj), 2190 "getRoleCardinality", 2191 params, 2192 signature)); 2193 } catch (InstanceNotFoundException exc1) { 2194 throw new RuntimeException (exc1.getMessage()); 2195 } catch (ReflectionException exc2) { 2196 throw new RuntimeException (exc2.getMessage()); 2197 } catch (MBeanException exc3) { 2198 Exception wrappedExc = exc3.getTargetException(); 2199 if (wrappedExc instanceof RoleNotFoundException ) { 2200 throw ((RoleNotFoundException )wrappedExc); 2201 } else { 2202 throw new RuntimeException (wrappedExc.getMessage()); 2203 } 2204 } 2205 } 2206 2207 if (isTraceOn()) 2208 trace("getRoleCardinality: exiting", null); 2209 return result; 2210 } 2211 2212 2243 public void setRole(String theRelId, 2244 Role theRole) 2245 throws RelationServiceNotRegisteredException , 2246 IllegalArgumentException , 2247 RelationNotFoundException , 2248 RoleNotFoundException , 2249 InvalidRoleValueException { 2250 2251 if (theRelId == null || theRole == null) { 2252 String excMsg = "Invalid parameter."; 2254 throw new IllegalArgumentException (excMsg); 2255 } 2256 2257 if (isTraceOn()) { 2258 String str = new String ("theRelId " + theRelId 2259 + ", theRole " + theRole.toString()); 2260 trace("setRole: entering", str); 2261 } 2262 2263 isActive(); 2265 2266 Object relObj = getRelation(theRelId); 2268 2269 if (relObj instanceof RelationSupport ) { 2270 try { 2278 ((RelationSupport )relObj).setRoleInt(theRole, 2279 true, 2280 this, 2281 false); 2282 2283 } catch (RelationTypeNotFoundException exc) { 2284 throw new RuntimeException (exc.getMessage()); 2285 } 2286 2287 } else { 2288 Object [] params = new Object [1]; 2290 params[0] = theRole; 2291 String [] signature = new String [1]; 2292 signature[0] = "javax.management.relation.Role"; 2293 try { 2300 myMBeanServer.setAttribute(((ObjectName )relObj), 2301 new Attribute ("Role", theRole)); 2302 2303 } catch (InstanceNotFoundException exc1) { 2304 throw new RuntimeException (exc1.getMessage()); 2305 } catch (ReflectionException exc3) { 2306 throw new RuntimeException (exc3.getMessage()); 2307 } catch (MBeanException exc2) { 2308 Exception wrappedExc = exc2.getTargetException(); 2309 if (wrappedExc instanceof RoleNotFoundException ) { 2310 throw ((RoleNotFoundException )wrappedExc); 2311 } else if (wrappedExc instanceof InvalidRoleValueException ) { 2312 throw ((InvalidRoleValueException )wrappedExc); 2313 } else { 2314 throw new RuntimeException (wrappedExc.getMessage()); 2315 2316 } 2317 } catch (AttributeNotFoundException exc4) { 2318 throw new RuntimeException (exc4.getMessage()); 2319 } catch (InvalidAttributeValueException exc5) { 2320 throw new RuntimeException (exc5.getMessage()); 2321 } 2322 } 2323 2324 if (isTraceOn()) 2325 trace("setRole: exiting", null); 2326 return; 2327 } 2328 2329 2350 public RoleResult setRoles(String theRelId, 2351 RoleList theRoleList) 2352 throws RelationServiceNotRegisteredException , 2353 IllegalArgumentException , 2354 RelationNotFoundException { 2355 2356 if (theRelId == null || theRoleList == null) { 2357 String excMsg = "Invalid parameter."; 2359 throw new IllegalArgumentException (excMsg); 2360 } 2361 2362 if (isTraceOn()) { 2363 String str = new String ("theRelId " + theRelId 2364 + ", theRoleList " 2365 + theRoleList.toString()); 2366 trace("setRoles: entering", str); 2367 } 2368 2369 isActive(); 2371 2372 Object relObj = getRelation(theRelId); 2374 2375 RoleResult result = null; 2376 2377 if (relObj instanceof RelationSupport ) { 2378 try { 2384 result = ((RelationSupport )relObj).setRolesInt(theRoleList, 2385 true, 2386 this); 2387 } catch (RelationTypeNotFoundException exc) { 2388 throw new RuntimeException (exc.getMessage()); 2389 } 2390 2391 } else { 2392 Object [] params = new Object [1]; 2394 params[0] = theRoleList; 2395 String [] signature = new String [1]; 2396 signature[0] = "javax.management.relation.RoleList"; 2397 try { 2400 result = (RoleResult ) 2401 (myMBeanServer.invoke(((ObjectName )relObj), 2402 "setRoles", 2403 params, 2404 signature)); 2405 } catch (InstanceNotFoundException exc1) { 2406 throw new RuntimeException (exc1.getMessage()); 2407 } catch (ReflectionException exc3) { 2408 throw new RuntimeException (exc3.getMessage()); 2409 } catch (MBeanException exc2) { 2410 throw new 2411 RuntimeException ((exc2.getTargetException()).getMessage()); 2412 } 2413 } 2414 2415 if (isTraceOn()) 2416 trace("setRoles: exiting", null); 2417 return result; 2418 } 2419 2420 2433 public Map getReferencedMBeans(String theRelId) 2434 throws IllegalArgumentException , 2435 RelationNotFoundException { 2436 2437 if (theRelId == null) { 2438 String excMsg = "Invalid parameter."; 2440 throw new IllegalArgumentException (excMsg); 2441 } 2442 2443 if (isTraceOn()) 2444 trace("getReferencedMBeans: entering", theRelId); 2445 2446 Object relObj = getRelation(theRelId); 2448 2449 HashMap result = null; 2450 2451 if (relObj instanceof RelationSupport ) { 2452 result = (HashMap )(((RelationSupport )relObj).getReferencedMBeans()); 2454 2455 } else { 2456 try { 2459 result = (HashMap ) 2460 (myMBeanServer.getAttribute(((ObjectName )relObj), 2461 "ReferencedMBeans")); 2462 } catch (Exception exc) { 2463 throw new RuntimeException (exc.getMessage()); 2464 } 2465 } 2466 2467 if (isTraceOn()) 2468 trace("getReferencedMBeans: exiting", null); 2469 return result; 2470 } 2471 2472 2483 public String getRelationTypeName(String theRelId) 2484 throws IllegalArgumentException , 2485 RelationNotFoundException { 2486 2487 if (theRelId == null) { 2488 String excMsg = "Invalid parameter."; 2490 throw new IllegalArgumentException (excMsg); 2491 } 2492 2493 if (isTraceOn()) 2494 trace("getRelationTypeName: entering", theRelId); 2495 2496 Object relObj = getRelation(theRelId); 2498 2499 String result = null; 2500 2501 if (relObj instanceof RelationSupport ) { 2502 result = ((RelationSupport )relObj).getRelationTypeName(); 2504 2505 } else { 2506 try { 2509 result = (String ) 2510 (myMBeanServer.getAttribute(((ObjectName )relObj), 2511 "RelationTypeName")); 2512 } catch (Exception exc) { 2513 throw new RuntimeException (exc.getMessage()); 2514 } 2515 } 2516 2517 if (isTraceOn()) 2518 trace("getRelationTypeName: exiting", null); 2519 return result; 2520 } 2521 2522 2526 2535 public void handleNotification(Notification theNtf, 2536 Object theHandback) { 2537 2538 if (theNtf == null) { 2539 String excMsg = "Invalid parameter."; 2541 throw new IllegalArgumentException (excMsg); 2542 } 2543 2544 if (isTraceOn()) 2545 trace("handleNotification: entering", theNtf.toString()); 2546 2547 if (theNtf instanceof MBeanServerNotification ) { 2548 2549 String ntfType = theNtf.getType(); 2550 2551 if (ntfType.equals( 2552 MBeanServerNotification.UNREGISTRATION_NOTIFICATION )) { 2553 ObjectName mbeanName = 2554 ((MBeanServerNotification )theNtf).getMBeanName(); 2555 2556 boolean isRefedMBeanFlg = false; 2559 synchronized(myRefedMBeanObjName2RelIdsMap) { 2560 2561 if (myRefedMBeanObjName2RelIdsMap.containsKey(mbeanName)) { 2562 synchronized(myUnregNtfList) { 2564 myUnregNtfList.add(theNtf); 2565 } 2566 isRefedMBeanFlg = true; 2567 } 2568 if (isRefedMBeanFlg && myPurgeFlg) { 2569 try { 2573 purgeRelations(); 2574 } catch (Exception exc) { 2575 throw new RuntimeException (exc.getMessage()); 2576 } 2577 } 2578 } 2579 2580 String relId = null; 2583 synchronized(myRelMBeanObjName2RelIdMap){ 2584 relId = (String ) 2585 (myRelMBeanObjName2RelIdMap.get(mbeanName)); 2586 } 2587 if (relId != null) { 2588 try { 2595 removeRelation(relId); 2596 } catch (Exception exc) { 2597 throw new RuntimeException (exc.getMessage()); 2598 } 2599 } 2600 } 2601 } 2602 2603 if (isTraceOn()) 2604 trace("handleNotification: exiting", null); 2605 return; 2606 } 2607 2608 2612 2616 public MBeanNotificationInfo [] getNotificationInfo() { 2617 2618 if (isTraceOn()) 2619 trace("getNotificationInfo: entering", null); 2620 2621 MBeanNotificationInfo [] ntfInfoArray = 2622 new MBeanNotificationInfo [1]; 2623 2624 String ntfClass = "javax.management.relation.RelationNotification"; 2625 2626 String [] ntfTypes = new String [] { 2627 RelationNotification.RELATION_BASIC_CREATION, 2628 RelationNotification.RELATION_MBEAN_CREATION, 2629 RelationNotification.RELATION_BASIC_UPDATE, 2630 RelationNotification.RELATION_MBEAN_UPDATE, 2631 RelationNotification.RELATION_BASIC_REMOVAL, 2632 RelationNotification.RELATION_MBEAN_REMOVAL, 2633 }; 2634 2635 String ntfDesc = "Sent when a relation is created, updated or deleted."; 2636 2637 MBeanNotificationInfo ntfInfo = 2638 new MBeanNotificationInfo (ntfTypes, ntfClass, ntfDesc); 2639 2640 if (isTraceOn()) 2641 trace("getNotificationInfo: exiting", null); 2642 return new MBeanNotificationInfo [] {ntfInfo}; 2643 } 2644 2645 2649 private void addRelationTypeInt(RelationType theRelTypeObj) 2657 throws IllegalArgumentException , 2658 InvalidRelationTypeException { 2659 2660 if (theRelTypeObj == null) { 2661 String excMsg = "Invalid parameter."; 2663 throw new IllegalArgumentException (excMsg); 2664 } 2665 2666 if (isDebugOn()) 2667 debug("addRelationTypeInt: entering", null); 2668 2669 String relTypeName = theRelTypeObj.getRelationTypeName(); 2670 2671 try { 2674 RelationType relType = getRelationType(relTypeName); 2676 2677 if (relType != null) { 2678 String excMsg = "There is already a relation type in the Relation Service with name "; 2680 StringBuffer excMsgStrB = new StringBuffer (excMsg); 2681 excMsgStrB.append(relTypeName); 2682 throw new InvalidRelationTypeException (excMsgStrB.toString()); 2683 } 2684 2685 } catch (RelationTypeNotFoundException exc) { 2686 } 2688 2689 synchronized(myRelType2ObjMap) { 2691 myRelType2ObjMap.put(relTypeName, theRelTypeObj); 2692 } 2693 2694 if (theRelTypeObj instanceof RelationTypeSupport ) { 2695 ((RelationTypeSupport )theRelTypeObj).setRelationServiceFlag(true); 2696 } 2697 2698 if (isDebugOn()) 2699 debug("addRelationTypeInt: exiting", null); 2700 return; 2701 } 2702 2703 RelationType getRelationType(String theRelTypeName) 2715 throws IllegalArgumentException , 2716 RelationTypeNotFoundException { 2717 2718 if (theRelTypeName == null) { 2719 String excMsg = "Invalid parameter."; 2721 throw new IllegalArgumentException (excMsg); 2722 } 2723 2724 if (isDebugOn()) 2725 debug("getRelationType: entering", theRelTypeName); 2726 2727 RelationType relType = null; 2729 synchronized(myRelType2ObjMap) { 2730 relType = (RelationType )(myRelType2ObjMap.get(theRelTypeName)); 2731 } 2732 2733 if (relType == null) { 2734 String excMsg = "No relation type created in the Relation Service with the name "; 2736 StringBuffer excMsgStrB = new StringBuffer (excMsg); 2737 excMsgStrB.append(theRelTypeName); 2738 throw new RelationTypeNotFoundException (excMsgStrB.toString()); 2739 } 2740 2741 if (isDebugOn()) 2742 debug("getRelationType: exiting", null); 2743 return relType; 2744 } 2745 2746 Object getRelation(String theRelId) 2761 throws IllegalArgumentException , 2762 RelationNotFoundException { 2763 2764 if (theRelId == null) { 2765 String excMsg = "Invalid parameter."; 2767 throw new IllegalArgumentException (excMsg); 2768 } 2769 2770 if (isDebugOn()) 2771 debug("getRelation: entering", theRelId); 2772 2773 Object rel = null; 2775 synchronized(myRelId2ObjMap) { 2776 rel = myRelId2ObjMap.get(theRelId); 2777 } 2778 2779 if (rel == null) { 2780 StringBuffer excMsgStrB = new StringBuffer (); 2781 String excMsg = "No relation associated to relation id "; 2783 excMsgStrB.append(excMsg); 2784 excMsgStrB.append(theRelId); 2785 throw new RelationNotFoundException (excMsgStrB.toString()); 2786 } 2787 2788 if (isDebugOn()) 2789 debug("getRelation: exiting", null); 2790 return rel; 2791 } 2792 2793 private boolean addNewMBeanReference(ObjectName theObjName, 2808 String theRelId, 2809 String theRoleName) 2810 throws IllegalArgumentException { 2811 2812 if (theObjName == null || 2813 theRelId == null || 2814 theRoleName == null) { 2815 String excMsg = "Invalid parameter."; 2817 throw new IllegalArgumentException (excMsg); 2818 } 2819 2820 if (isDebugOn()) { 2821 String str = new String ("theObjName " + theObjName.toString() 2822 + ", theRelId " + theRelId 2823 + ", theRoleName " + theRoleName); 2824 debug("addNewMBeanReference: entering", str); 2825 } 2826 2827 boolean isNewFlg = false; 2828 2829 synchronized(myRefedMBeanObjName2RelIdsMap) { 2830 2831 HashMap mbeanRefMap = (HashMap ) 2834 (myRefedMBeanObjName2RelIdsMap.get(theObjName)); 2835 2836 if (mbeanRefMap == null) { 2837 2839 isNewFlg = true; 2840 2841 ArrayList roleNames = new ArrayList (); 2844 roleNames.add(theRoleName); 2845 2846 mbeanRefMap = new HashMap (); 2848 mbeanRefMap.put(theRelId, roleNames); 2849 2850 myRefedMBeanObjName2RelIdsMap.put(theObjName, mbeanRefMap); 2851 2852 } else { 2853 ArrayList roleNames = (ArrayList )(mbeanRefMap.get(theRelId)); 2857 2858 if (roleNames == null) { 2859 2861 roleNames = new ArrayList (); 2864 roleNames.add(theRoleName); 2865 2866 mbeanRefMap.put(theRelId, roleNames); 2868 2869 } else { 2870 roleNames.add(theRoleName); 2874 } 2875 } 2876 } 2877 2878 if (isDebugOn()) 2879 debug("addNewMBeanReference: exiting", null); 2880 return isNewFlg; 2881 } 2882 2883 private boolean removeMBeanReference(ObjectName theObjName, 2899 String theRelId, 2900 String theRoleName, 2901 boolean theAllRolesFlg) 2902 throws IllegalArgumentException { 2903 2904 if (theObjName == null || 2905 theRelId == null || 2906 theRoleName == null) { 2907 String excMsg = "Invalid parameter."; 2909 throw new IllegalArgumentException (excMsg); 2910 } 2911 2912 if (isDebugOn()) { 2913 String str = new String ("theObjName " + theObjName.toString() 2914 + ", theRelId " + theRelId 2915 + ", theRoleName " + theRoleName 2916 + ", theAllRolesFlg " + theAllRolesFlg); 2917 debug("removeMBeanReference: entering", str); 2918 } 2919 2920 boolean noLongerRefFlg = false; 2921 2922 synchronized(myRefedMBeanObjName2RelIdsMap) { 2923 2924 HashMap mbeanRefMap = (HashMap ) 2930 (myRefedMBeanObjName2RelIdsMap.get(theObjName)); 2931 2932 if (mbeanRefMap == null) { 2933 if (isDebugOn()) 2935 debug("removeMBeanReference: exiting", null); 2936 return true; 2937 } 2938 2939 ArrayList roleNames = new ArrayList (); 2940 if (!theAllRolesFlg) { 2941 roleNames = (ArrayList )(mbeanRefMap.get(theRelId)); 2944 2945 int obsRefIdx = roleNames.indexOf(theRoleName); 2947 if (obsRefIdx != -1) { 2948 roleNames.remove(obsRefIdx); 2949 } 2950 } 2951 2952 if (roleNames.isEmpty() || theAllRolesFlg) { 2955 mbeanRefMap.remove(theRelId); 2958 } 2959 2960 if (mbeanRefMap.isEmpty()) { 2962 myRefedMBeanObjName2RelIdsMap.remove(theObjName); 2964 noLongerRefFlg = true; 2965 } 2966 } 2967 2968 if (isDebugOn()) 2969 debug("removeMBeanReference: exiting", null); 2970 return noLongerRefFlg; 2971 } 2972 2973 private void updateUnregistrationListener(List theNewRefList, 2984 List theObsRefList) 2985 throws RelationServiceNotRegisteredException { 2986 2987 if (theNewRefList != null && theObsRefList != null) { 2988 if (theNewRefList.isEmpty() && theObsRefList.isEmpty()) { 2989 return; 2991 } 2992 } 2993 2994 if (isDebugOn()) { 2995 StringBuffer strB = new StringBuffer (); 2996 if (theNewRefList != null) { 2997 strB.append("theNewRefList " + theNewRefList.toString()); 2998 } 2999 if (theObsRefList != null) { 3000 strB.append(", theObsRefList" + theObsRefList.toString()); 3001 } 3002 debug("updateUnregistrationListener: entering", strB.toString()); 3003 } 3004 3005 isActive(); 3007 3008 if (theNewRefList != null || theObsRefList != null) { 3009 3010 boolean newListenerFlg = false; 3011 if (myUnregNtfFilter == null) { 3012 myUnregNtfFilter = new MBeanServerNotificationFilter (); 3014 newListenerFlg = true; 3015 } 3016 3017 synchronized(myUnregNtfFilter) { 3018 3019 if (theNewRefList != null) { 3021 for (Iterator newRefIter = theNewRefList.iterator(); 3022 newRefIter.hasNext();) { 3023 3024 ObjectName newObjName = (ObjectName ) 3025 (newRefIter.next()); 3026 myUnregNtfFilter.enableObjectName(newObjName); 3027 } 3028 } 3029 3030 if (theObsRefList != null) { 3031 for (Iterator obsRefIter = theObsRefList.iterator(); 3033 obsRefIter.hasNext();) { 3034 3035 ObjectName obsObjName = (ObjectName ) 3036 (obsRefIter.next()); 3037 myUnregNtfFilter.disableObjectName(obsObjName); 3038 } 3039 } 3040 3041 ObjectName mbeanServerDelegateName = null; 3044 try { 3045 mbeanServerDelegateName = 3046 new ObjectName (ServiceName.DELEGATE); 3047 } catch (MalformedObjectNameException exc) { 3048 } 3050 3051 if (newListenerFlg) { 3053 try { 3054 myMBeanServer.addNotificationListener( 3055 mbeanServerDelegateName, 3056 this, 3057 myUnregNtfFilter, 3058 null); 3059 } catch (InstanceNotFoundException exc) { 3060 throw new 3061 RelationServiceNotRegisteredException (exc.getMessage()); 3062 } 3063 } 3064 3066 3067 3087 } 3105 } 3106 3107 if (isDebugOn()) 3108 debug("updateUnregistrationListener: exiting", null); 3109 return; 3110 } 3111 3112 private void addRelationInt(boolean theRelBaseFlg, 3150 RelationSupport theRelObj, 3151 ObjectName theRelObjName, 3152 String theRelId, 3153 String theRelTypeName, 3154 RoleList theRoleList) 3155 throws IllegalArgumentException , 3156 RelationServiceNotRegisteredException , 3157 RoleNotFoundException , 3158 InvalidRelationIdException , 3159 RelationTypeNotFoundException , 3160 InvalidRoleValueException { 3161 3162 if (theRelId == null || 3163 theRelTypeName == null || 3164 (theRelBaseFlg && 3165 (theRelObj == null || 3166 theRelObjName != null)) || 3167 (!theRelBaseFlg && 3168 (theRelObjName == null || 3169 theRelObj != null))) { 3170 String excMsg = "Invalid parameter."; 3172 throw new IllegalArgumentException (excMsg); 3173 } 3174 3175 if (isDebugOn()) { 3176 StringBuffer strB = new StringBuffer ("theRelBaseFlg " 3177 + theRelBaseFlg 3178 + ", theRelId " + theRelId 3179 + ", theRelTypeName " 3180 + theRelTypeName); 3181 if (theRelObjName != null) { 3182 strB.append(", theRelObjName " + theRelObjName.toString()); 3183 } 3184 if (theRoleList != null) { 3185 strB.append(", theRoleList " + theRoleList.toString()); 3186 } 3187 debug("addRelationInt: entering", strB.toString()); 3188 } 3189 3190 isActive(); 3192 3193 try { 3195 Object rel = getRelation(theRelId); 3197 3198 if (rel != null) { 3199 String excMsg = "There is already a relation with id "; 3202 StringBuffer excMsgStrB = new StringBuffer (excMsg); 3203 excMsgStrB.append(theRelId); 3204 throw new InvalidRelationIdException (excMsgStrB.toString()); 3205 } 3206 } catch (RelationNotFoundException exc) { 3207 } 3209 3210 RelationType relType = getRelationType(theRelTypeName); 3213 3214 ArrayList roleInfoList = (ArrayList ) 3221 (((ArrayList )(relType.getRoleInfos())).clone()); 3222 3223 if (theRoleList != null) { 3224 3225 for (Iterator roleIter = theRoleList.iterator(); 3226 roleIter.hasNext();) { 3227 3228 Role currRole = (Role )(roleIter.next()); 3229 String currRoleName = currRole.getRoleName(); 3230 ArrayList currRoleValue = (ArrayList ) 3231 (currRole.getRoleValue()); 3232 RoleInfo roleInfo = null; 3236 try { 3237 roleInfo = relType.getRoleInfo(currRoleName); 3238 } catch (RoleInfoNotFoundException exc) { 3239 throw new RoleNotFoundException (exc.getMessage()); 3240 } 3241 3242 Integer status = checkRoleInt(2, 3244 currRoleName, 3245 currRoleValue, 3246 roleInfo, 3247 false); 3248 int pbType = status.intValue(); 3249 if (pbType != 0) { 3250 throwRoleProblemException(pbType, currRoleName); 3253 } 3254 3255 int roleInfoIdx = roleInfoList.indexOf(roleInfo); 3258 roleInfoList.remove(roleInfoIdx); 3260 } 3261 } 3262 3263 initialiseMissingRoles(theRelBaseFlg, 3266 theRelObj, 3267 theRelObjName, 3268 theRelId, 3269 theRelTypeName, 3270 roleInfoList); 3271 3272 3274 synchronized(myRelId2ObjMap) { 3277 if (theRelBaseFlg) { 3278 myRelId2ObjMap.put(theRelId, theRelObj); 3280 } else { 3281 myRelId2ObjMap.put(theRelId, theRelObjName); 3282 } 3283 } 3284 3285 synchronized(myRelId2RelTypeMap) { 3287 myRelId2RelTypeMap.put(theRelId, 3288 theRelTypeName); 3289 } 3290 3291 synchronized(myRelType2RelIdsMap) { 3293 ArrayList relIdList = (ArrayList ) 3294 (myRelType2RelIdsMap.get(theRelTypeName)); 3295 boolean firstRelFlg = false; 3296 if (relIdList == null) { 3297 firstRelFlg = true; 3298 relIdList = new ArrayList (); 3299 } 3300 relIdList.add(theRelId); 3301 if (firstRelFlg) { 3302 myRelType2RelIdsMap.put(theRelTypeName, relIdList); 3303 } 3304 } 3305 3306 for (Iterator roleIter = theRoleList.iterator(); 3311 roleIter.hasNext();) { 3312 Role currRole = (Role )(roleIter.next()); 3313 ArrayList dummyList = new ArrayList (); 3316 try { 3319 updateRoleMap(theRelId, currRole, dummyList); 3320 3321 } catch (RelationNotFoundException exc) { 3322 } 3324 } 3325 3326 try { 3329 sendRelationCreationNotification(theRelId); 3330 3331 } catch (RelationNotFoundException exc) { 3332 } 3334 3335 if (isDebugOn()) 3336 debug("addRelationInt: exiting", null); 3337 return; 3338 } 3339 3340 private Integer checkRoleInt(int theChkType, 3363 String theRoleName, 3364 List theRoleValue, 3365 RoleInfo theRoleInfo, 3366 boolean theWriteChkFlg) 3367 throws IllegalArgumentException { 3368 3369 if (theRoleName == null || 3370 theRoleInfo == null || 3371 (theChkType == 2 && theRoleValue == null)) { 3372 String excMsg = "Invalid parameter."; 3374 throw new IllegalArgumentException (excMsg); 3375 } 3376 3377 if (isDebugOn()) { 3378 StringBuffer strB = new StringBuffer ("theChkType " 3379 + theChkType 3380 + ", theRoleName " 3381 + theRoleName 3382 + ", theRoleInfo " 3383 + theRoleInfo.toString() 3384 + ", theWriteChkFlg " 3385 + theWriteChkFlg); 3386 if (theRoleValue != null) { 3387 strB.append(", theRoleValue " + theRoleValue.toString()); 3388 } 3389 debug("checkRoleInt: entering", strB.toString()); 3390 } 3391 3392 String expName = theRoleInfo.getName(); 3394 if (!(theRoleName.equals(expName))) { 3395 if (isDebugOn()) 3396 debug("checkRoleInt: exiting", null); 3397 return new Integer (RoleStatus.NO_ROLE_WITH_NAME); 3398 } 3399 3400 if (theChkType == 1) { 3402 boolean isReadable = theRoleInfo.isReadable(); 3403 if (!isReadable) { 3404 if (isDebugOn()) 3405 debug("checkRoleInt: exiting", null); 3406 return new Integer (RoleStatus.ROLE_NOT_READABLE); 3407 } else { 3408 if (isDebugOn()) 3410 debug("checkRoleInt: exiting", null); 3411 return new Integer (0); 3412 } 3413 } 3414 3415 if (theWriteChkFlg) { 3417 boolean isWritable = theRoleInfo.isWritable(); 3418 if (!isWritable) { 3419 if (isDebugOn()) 3420 debug("checkRoleInt: exiting", null); 3421 return new Integer (RoleStatus.ROLE_NOT_WRITABLE); 3422 } 3423 } 3424 3425 int refNbr = theRoleValue.size(); 3426 3427 boolean chkMinFlg = theRoleInfo.checkMinDegree(refNbr); 3429 if (!chkMinFlg) { 3430 if (isDebugOn()) 3431 debug("checkRoleInt: exiting", null); 3432 return new Integer (RoleStatus.LESS_THAN_MIN_ROLE_DEGREE); 3433 } 3434 3435 boolean chkMaxFlg = theRoleInfo.checkMaxDegree(refNbr); 3437 if (!chkMaxFlg) { 3438 if (isDebugOn()) 3439 debug("checkRoleInt: exiting", null); 3440 return new Integer (RoleStatus.MORE_THAN_MAX_ROLE_DEGREE); 3441 } 3442 3443 String expClassName = theRoleInfo.getRefMBeanClassName(); 3450 3451 for (Iterator refMBeanIter = theRoleValue.iterator(); 3452 refMBeanIter.hasNext();) { 3453 ObjectName currObjName = (ObjectName )(refMBeanIter.next()); 3454 3455 if (currObjName == null) { 3457 if (isDebugOn()) 3458 debug("checkRoleInt: exiting", null); 3459 return new Integer (RoleStatus.REF_MBEAN_NOT_REGISTERED); 3460 } 3461 3462 try { 3465 boolean classSts = myMBeanServer.isInstanceOf(currObjName, 3466 expClassName); 3467 if (!classSts) { 3468 if (isDebugOn()) 3469 debug("checkRoleInt: exiting", null); 3470 return new Integer (RoleStatus.REF_MBEAN_OF_INCORRECT_CLASS); 3471 } 3472 3473 } catch (InstanceNotFoundException exc) { 3474 if (isDebugOn()) 3475 debug("checkRoleInt: exiting", null); 3476 return new Integer (RoleStatus.REF_MBEAN_NOT_REGISTERED); 3477 } 3478 } 3479 3480 if (isDebugOn()) 3481 debug("checkRoleInt: exiting", null); 3482 return new Integer (0); 3483 } 3484 3485 3486 3508 private void initialiseMissingRoles(boolean theRelBaseFlg, 3511 RelationSupport theRelObj, 3512 ObjectName theRelObjName, 3513 String theRelId, 3514 String theRelTypeName, 3515 List theRoleInfoList) 3516 throws IllegalArgumentException , 3517 RelationServiceNotRegisteredException , 3518 InvalidRoleValueException { 3519 3520 if ((theRelBaseFlg && 3521 (theRelObj == null || 3522 theRelObjName != null)) || 3523 (!theRelBaseFlg && 3524 (theRelObjName == null || 3525 theRelObj != null)) || 3526 theRelId == null || 3527 theRelTypeName == null || 3528 theRoleInfoList == null) { 3529 String excMsg = "Invalid parameter."; 3531 throw new IllegalArgumentException (excMsg); 3532 } 3533 3534 if (isDebugOn()) { 3535 StringBuffer strB = 3536 new StringBuffer ("theRelBaseFlg " + theRelBaseFlg 3537 + ", theRelId " + theRelId 3538 + ", theRelTypeName " + theRelTypeName 3539 + ", theRoleInfoList " + theRoleInfoList); 3540 if (theRelObjName != null) { 3541 strB.append(theRelObjName.toString()); 3542 } 3543 debug("initialiseMissingRoles: entering", strB.toString()); 3544 } 3545 3546 isActive(); 3548 3549 for (Iterator roleInfoIter = theRoleInfoList.iterator(); 3555 roleInfoIter.hasNext();) { 3556 3557 RoleInfo currRoleInfo = (RoleInfo )(roleInfoIter.next()); 3558 String roleName = currRoleInfo.getName(); 3559 3560 ArrayList emptyValue = new ArrayList (); 3562 Role role = new Role (roleName, emptyValue); 3564 3565 if (theRelBaseFlg) { 3566 3567 try { 3574 theRelObj.setRoleInt(role, true, this, false); 3575 3576 } catch (RoleNotFoundException exc1) { 3577 throw new RuntimeException (exc1.getMessage()); 3578 } catch (RelationNotFoundException exc2) { 3579 throw new RuntimeException (exc2.getMessage()); 3580 } catch (RelationTypeNotFoundException exc3) { 3581 throw new RuntimeException (exc3.getMessage()); 3582 } 3583 3584 } else { 3585 3586 Object [] params = new Object [1]; 3589 params[0] = role; 3590 String [] signature = new String [1]; 3591 signature[0] = "javax.management.relation.Role"; 3592 try { 3603 myMBeanServer.setAttribute(theRelObjName, 3604 new Attribute ("Role", role)); 3605 3606 } catch (InstanceNotFoundException exc1) { 3607 throw new RuntimeException (exc1.getMessage()); 3608 } catch (ReflectionException exc3) { 3609 throw new RuntimeException (exc3.getMessage()); 3610 } catch (MBeanException exc2) { 3611 Exception wrappedExc = exc2.getTargetException(); 3612 if (wrappedExc instanceof InvalidRoleValueException ) { 3613 throw ((InvalidRoleValueException )wrappedExc); 3614 } else { 3615 throw new RuntimeException (wrappedExc.getMessage()); 3616 } 3617 } catch (AttributeNotFoundException exc4) { 3618 throw new RuntimeException (exc4.getMessage()); 3619 } catch (InvalidAttributeValueException exc5) { 3620 throw new RuntimeException (exc5.getMessage()); 3621 } 3622 } 3623 } 3624 3625 if (isDebugOn()) 3626 debug("initializeMissingRoles: exiting", null); 3627 return; 3628 } 3629 3630 static void throwRoleProblemException(int thePbType, 3646 String theRoleName) 3647 throws IllegalArgumentException , 3648 RoleNotFoundException , 3649 InvalidRoleValueException { 3650 3651 if (theRoleName == null) { 3652 String excMsg = "Invalid parameter."; 3654 throw new IllegalArgumentException (excMsg); 3655 } 3656 3657 int excType = 0; 3660 3661 String excMsgPart = null; 3662 3663 switch (thePbType) { 3665 case RoleStatus.NO_ROLE_WITH_NAME: 3666 excMsgPart = " does not exist in relation."; 3667 excType = 1; 3668 break; 3669 case RoleStatus.ROLE_NOT_READABLE: 3670 excMsgPart = " is not readable."; 3671 excType = 1; 3672 break; 3673 case RoleStatus.ROLE_NOT_WRITABLE: 3674 excMsgPart = " is not writable."; 3675 excType = 1; 3676 break; 3677 case RoleStatus.LESS_THAN_MIN_ROLE_DEGREE: 3678 excMsgPart = " has a number of MBean references less than the expected minimum degree."; 3679 excType = 2; 3680 break; 3681 case RoleStatus.MORE_THAN_MAX_ROLE_DEGREE: 3682 excMsgPart = " has a number of MBean references greater than the expected maximum degree."; 3683 excType = 2; 3684 break; 3685 case RoleStatus.REF_MBEAN_OF_INCORRECT_CLASS: 3686 excMsgPart = " has an MBean reference to an MBean not of the expected class of references for that role."; 3687 excType = 2; 3688 break; 3689 case RoleStatus.REF_MBEAN_NOT_REGISTERED: 3690 excMsgPart = " has a reference to null or to an MBean not registered."; 3691 excType = 2; 3692 break; 3693 } 3694 3696 StringBuffer excMsgStrB = new StringBuffer (theRoleName); 3697 excMsgStrB.append(excMsgPart); 3698 String excMsg = excMsgStrB.toString(); 3699 if (excType == 1) { 3700 throw new RoleNotFoundException (excMsg); 3701 3702 } else if (excType == 2) { 3703 throw new InvalidRoleValueException (excMsg); 3704 } 3705 } 3706 3707 private void sendNotificationInt(int theIntNtfType, 3725 String theMsg, 3726 String theRelId, 3727 List theUnregMBeanList, 3728 String theRoleName, 3729 List theRoleNewValue, 3730 List theOldRoleValue) 3731 throws IllegalArgumentException , 3732 RelationNotFoundException { 3733 3734 if (theMsg == null || 3735 theRelId == null || 3736 (theIntNtfType != 3 && theUnregMBeanList != null) || 3737 (theIntNtfType == 2 && 3738 (theRoleName == null || 3739 theRoleNewValue == null || 3740 theOldRoleValue == null))) { 3741 String excMsg = "Invalid parameter."; 3743 throw new IllegalArgumentException (excMsg); 3744 } 3745 3746 if (isDebugOn()) { 3747 StringBuffer strB = 3748 new StringBuffer ("theIntNtfType " + theIntNtfType 3749 + ", theMsg " + theMsg 3750 + ", theRelId " + theRelId); 3751 if (theUnregMBeanList != null) { 3752 strB.append(", theUnregMBeanList " + 3753 theUnregMBeanList.toString()); 3754 } 3755 if (theRoleName != null) { 3756 strB.append(", theRoleName " + theRoleName); 3757 } 3758 if (theRoleNewValue != null) { 3759 strB.append(", theRoleNewValue " + theRoleNewValue.toString()); 3760 } 3761 if (theOldRoleValue != null) { 3762 strB.append(", theOldRoleValue " + theOldRoleValue.toString()); 3763 } 3764 debug("sendNotificationInt: entering", strB.toString()); 3765 } 3766 3767 String relTypeName = null; 3771 synchronized(myRelId2RelTypeMap) { 3772 relTypeName = (String )(myRelId2RelTypeMap.get(theRelId)); 3773 } 3774 3775 ObjectName relObjName = isRelationMBean(theRelId); 3778 3779 String ntfType = null; 3780 if (relObjName != null) { 3781 switch (theIntNtfType) { 3782 case 1: 3783 ntfType = RelationNotification.RELATION_MBEAN_CREATION; 3784 break; 3785 case 2: 3786 ntfType = RelationNotification.RELATION_MBEAN_UPDATE; 3787 break; 3788 case 3: 3789 ntfType = RelationNotification.RELATION_MBEAN_REMOVAL; 3790 break; 3791 } 3792 } else { 3793 switch (theIntNtfType) { 3794 case 1: 3795 ntfType = RelationNotification.RELATION_BASIC_CREATION; 3796 break; 3797 case 2: 3798 ntfType = RelationNotification.RELATION_BASIC_UPDATE; 3799 break; 3800 case 3: 3801 ntfType = RelationNotification.RELATION_BASIC_REMOVAL; 3802 break; 3803 } 3804 } 3805 3806 Long seqNbr = getNotificationSequenceNumber(); 3808 3809 Date currDate = new Date (); 3811 long timeStamp = currDate.getTime(); 3812 3813 RelationNotification ntf = null; 3814 3815 if (ntfType.equals(RelationNotification.RELATION_BASIC_CREATION) || 3816 ntfType.equals(RelationNotification.RELATION_MBEAN_CREATION) || 3817 ntfType.equals(RelationNotification.RELATION_BASIC_REMOVAL) || 3818 ntfType.equals(RelationNotification.RELATION_MBEAN_REMOVAL)) 3819 3820 ntf = new RelationNotification (ntfType, 3822 this, 3823 seqNbr.longValue(), 3824 timeStamp, 3825 theMsg, 3826 theRelId, 3827 relTypeName, 3828 relObjName, 3829 theUnregMBeanList); 3830 3831 else if (ntfType.equals(RelationNotification.RELATION_BASIC_UPDATE) 3832 || 3833 ntfType.equals(RelationNotification.RELATION_MBEAN_UPDATE)) 3834 { 3835 ntf = new RelationNotification (ntfType, 3837 this, 3838 seqNbr.longValue(), 3839 timeStamp, 3840 theMsg, 3841 theRelId, 3842 relTypeName, 3843 relObjName, 3844 theRoleName, 3845 theRoleNewValue, 3846 theOldRoleValue); 3847 } 3848 3849 sendNotification(ntf); 3850 3851 if (isDebugOn()) 3852 debug("sendNotificationInt: exiting", null); 3853 return; 3854 } 3855 3856 private void handleReferenceUnregistration(String theRelId, 3875 ObjectName theObjName, 3876 List theRoleNameList) 3877 throws IllegalArgumentException , 3878 RelationServiceNotRegisteredException , 3879 RelationNotFoundException , 3880 RoleNotFoundException { 3881 3882 if (theRelId == null || 3883 theRoleNameList == null || 3884 theObjName == null) { 3885 String excMsg = "Invalid parameter."; 3887 throw new IllegalArgumentException (excMsg); 3888 } 3889 3890 if (isDebugOn()) { 3891 String str = 3892 new String ("theRelId " + theRelId 3893 + ", theRoleNameList " + theRoleNameList.toString() 3894 + "theObjName " + theObjName.toString()); 3895 debug("handleReferenceUnregistration: entering", str); 3896 } 3897 3898 isActive(); 3900 3901 String currRelTypeName = getRelationTypeName(theRelId); 3904 3905 Object relObj = getRelation(theRelId); 3908 3909 boolean deleteRelFlg = false; 3911 3912 for (Iterator roleNameIter = theRoleNameList.iterator(); 3913 roleNameIter.hasNext();) { 3914 3915 if (deleteRelFlg) { 3916 break; 3917 } 3918 3919 String currRoleName = (String )(roleNameIter.next()); 3920 int currRoleRefNbr = 3926 (getRoleCardinality(theRelId, currRoleName)).intValue(); 3927 3928 int currRoleNewRefNbr = currRoleRefNbr - 1; 3930 3931 RoleInfo currRoleInfo = null; 3936 try { 3937 currRoleInfo = getRoleInfo(currRelTypeName, 3938 currRoleName); 3939 } catch (RelationTypeNotFoundException exc1) { 3940 throw new RuntimeException (exc1.getMessage()); 3941 } catch (RoleInfoNotFoundException exc2) { 3942 throw new RuntimeException (exc2.getMessage()); 3943 } 3944 3945 boolean chkMinFlg = currRoleInfo.checkMinDegree(currRoleNewRefNbr); 3947 3948 if (!chkMinFlg) { 3949 deleteRelFlg = true; 3951 } 3952 } 3953 3954 if (deleteRelFlg) { 3955 removeRelation(theRelId); 3957 3958 } else { 3959 3960 for (Iterator roleNameIter = theRoleNameList.iterator(); 3972 roleNameIter.hasNext();) { 3973 3974 String currRoleName = (String )(roleNameIter.next()); 3975 3976 if (relObj instanceof RelationSupport ) { 3977 try { 3986 ((RelationSupport )relObj).handleMBeanUnregistrationInt( 3987 theObjName, 3988 currRoleName, 3989 true, 3990 this); 3991 } catch (RelationTypeNotFoundException exc3) { 3992 throw new RuntimeException (exc3.getMessage()); 3993 } catch (InvalidRoleValueException exc4) { 3994 throw new RuntimeException (exc4.getMessage()); 3995 } 3996 3997 } else { 3998 Object [] params = new Object [2]; 4000 params[0] = theObjName; 4001 params[1] = currRoleName; 4002 String [] signature = new String [2]; 4003 signature[0] = "javax.management.ObjectName"; 4004 signature[1] = "java.lang.String"; 4005 try { 4010 myMBeanServer.invoke(((ObjectName )relObj), 4011 "handleMBeanUnregistration", 4012 params, 4013 signature); 4014 } catch (InstanceNotFoundException exc1) { 4015 throw new RuntimeException (exc1.getMessage()); 4016 } catch (ReflectionException exc3) { 4017 throw new RuntimeException (exc3.getMessage()); 4018 } catch (MBeanException exc2) { 4019 Exception wrappedExc = exc2.getTargetException(); 4020 throw new RuntimeException (wrappedExc.getMessage()); 4021 } 4022 4023 } 4024 } 4025 } 4026 4027 if (isDebugOn()) 4028 debug("handleReferenceUnregistration: exiting", null); 4029 return; 4030 } 4031 4032 4034 private static String localClassName = "RelationService"; 4035 4036 private boolean isTraceOn() { 4038 return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_RELATION); 4039 } 4040 4041 4045 private void trace(String methodName, String info) { 4046 Trace.send(Trace.LEVEL_TRACE, Trace.INFO_RELATION, localClassName, methodName, info); 4047 Trace.send(Trace.LEVEL_TRACE, Trace.INFO_RELATION, "", "", "\n"); 4048 } 4049 4050 4054 4058 private boolean isDebugOn() { 4060 return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_RELATION); 4061 } 4062 4063 4067 private void debug(String methodName, String info) { 4068 Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_RELATION, localClassName, methodName, info); 4069 Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_RELATION, "", "", "\n"); 4070 } 4071 4072 4076} 4080 | Popular Tags |