The Relation Service is in charge of creating and deleting relation types
and relations, of handling the consistency and of providing query
mechanisms.
It implements the NotificationBroadcaster by extending
NotificationBroadcasterSupport to send notifications when a relation is
removed from it.
It implements the NotificationListener interface to be able to receive
notifications concerning unregistration of MBeans referenced in relation
roles and of relation MBeans.
It implements the MBeanRegistration interface to be able to retrieve
its ObjectName and MBean Server.
Method from javax.management.relation.RelationService Detail: |
public void addRelation(ObjectName relationObjectName) throws IllegalArgumentException, RelationServiceNotRegisteredException, NoSuchMethodException, InvalidRelationIdException, InstanceNotFoundException, InvalidRelationServiceException, RelationTypeNotFoundException, RoleNotFoundException, InvalidRoleValueException {
if (relationObjectName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"addRelation", relationObjectName);
// Can throw RelationServiceNotRegisteredException
isActive();
// Checks that the relation MBean implements the Relation interface.
// It will also check that the provided ObjectName corresponds to a
// registered MBean (else will throw an InstanceNotFoundException)
if ((!(myMBeanServer.isInstanceOf(relationObjectName, "javax.management.relation.Relation")))) {
String excMsg = "This MBean does not implement the Relation interface.";
throw new NoSuchMethodException(excMsg);
}
// Checks there is a relation id in the relation MBean (its uniqueness
// is checked in addRelationInt())
// Can throw InstanceNotFoundException (but detected above)
// No MBeanException as no exception raised by this method, and no
// ReflectionException
String relId;
try {
relId = (String)(myMBeanServer.getAttribute(relationObjectName,
"RelationId"));
} catch (MBeanException exc1) {
throw new RuntimeException(
(exc1.getTargetException()).getMessage());
} catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (AttributeNotFoundException exc3) {
throw new RuntimeException(exc3.getMessage());
}
if (relId == null) {
String excMsg = "This MBean does not provide a relation id.";
throw new InvalidRelationIdException(excMsg);
}
// Checks that the Relation Service where the relation MBean is
// expected to be added is the current one
// Can throw InstanceNotFoundException (but detected above)
// No MBeanException as no exception raised by this method, no
// ReflectionException
ObjectName relServObjName;
try {
relServObjName = (ObjectName)
(myMBeanServer.getAttribute(relationObjectName,
"RelationServiceName"));
} catch (MBeanException exc1) {
throw new RuntimeException(
(exc1.getTargetException()).getMessage());
} catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (AttributeNotFoundException exc3) {
throw new RuntimeException(exc3.getMessage());
}
boolean badRelServFlag = false;
if (relServObjName == null) {
badRelServFlag = true;
} else if (!(relServObjName.equals(myObjName))) {
badRelServFlag = true;
}
if (badRelServFlag) {
String excMsg = "The Relation Service referenced in the MBean is not the current one.";
throw new InvalidRelationServiceException(excMsg);
}
// Checks that a relation type has been specified for the relation
// Can throw InstanceNotFoundException (but detected above)
// No MBeanException as no exception raised by this method, no
// ReflectionException
String relTypeName;
try {
relTypeName = (String)(myMBeanServer.getAttribute(relationObjectName,
"RelationTypeName"));
} catch (MBeanException exc1) {
throw new RuntimeException(
(exc1.getTargetException()).getMessage());
}catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (AttributeNotFoundException exc3) {
throw new RuntimeException(exc3.getMessage());
}
if (relTypeName == null) {
String excMsg = "No relation type provided.";
throw new RelationTypeNotFoundException(excMsg);
}
// Retrieves all roles without considering read mode
// Can throw InstanceNotFoundException (but detected above)
// No MBeanException as no exception raised by this method, no
// ReflectionException
RoleList roleList;
try {
roleList = (RoleList)(myMBeanServer.invoke(relationObjectName,
"retrieveAllRoles",
null,
null));
} catch (MBeanException exc1) {
throw new RuntimeException(
(exc1.getTargetException()).getMessage());
} catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
}
// Can throw RoleNotFoundException, InvalidRelationIdException,
// RelationTypeNotFoundException, InvalidRoleValueException
addRelationInt(false,
null,
relationObjectName,
relId,
relTypeName,
roleList);
// Adds relation MBean ObjectName in map
synchronized(myRelMBeanObjName2RelIdMap) {
myRelMBeanObjName2RelIdMap.put(relationObjectName, relId);
}
// Updates flag to specify that the relation is managed by the Relation
// Service
// This flag and setter are inherited from RelationSupport and not parts
// of the Relation interface, so may be not supported.
try {
myMBeanServer.setAttribute(relationObjectName,
new Attribute(
"RelationServiceManagementFlag",
Boolean.TRUE));
} catch (Exception exc) {
// OK : The flag is not supported.
}
// Updates listener information to received notification for
// unregistration of this MBean
List< ObjectName > newRefList = new ArrayList< ObjectName >();
newRefList.add(relationObjectName);
updateUnregistrationListener(newRefList, null);
RELATION_LOGGER.exiting(RelationService.class.getName(),
"addRelation");
return;
}
Adds an MBean created by the user (and registered by him in the MBean
Server) as a relation in the Relation Service.
To be added as a relation, the MBean must conform to the
following:
- implement the Relation interface
- have for RelationService ObjectName the ObjectName of current
Relation Service
- have a relation id unique and unused in current Relation Service
- have for relation type a relation type created in the Relation
Service
- have roles conforming to the role info provided in the relation
type. |
public void addRelationType(RelationType relationTypeObj) throws IllegalArgumentException, InvalidRelationTypeException {
if (relationTypeObj == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"addRelationType");
// Checks the role infos
List< RoleInfo > roleInfoList = relationTypeObj.getRoleInfos();
if (roleInfoList == null) {
String excMsg = "No role info provided.";
throw new InvalidRelationTypeException(excMsg);
}
RoleInfo[] roleInfoArray = new RoleInfo[roleInfoList.size()];
int i = 0;
for (RoleInfo currRoleInfo : roleInfoList) {
roleInfoArray[i] = currRoleInfo;
i++;
}
// Can throw InvalidRelationTypeException
RelationTypeSupport.checkRoleInfos(roleInfoArray);
addRelationTypeInt(relationTypeObj);
RELATION_LOGGER.exiting(RelationService.class.getName(),
"addRelationType");
return;
}
Adds given object as a relation type. The object is expected to
implement the RelationType interface. |
public Integer checkRoleReading(String roleName,
String relationTypeName) throws IllegalArgumentException, RelationTypeNotFoundException {
if (roleName == null || relationTypeName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"checkRoleReading", new Object[] {roleName, relationTypeName});
Integer result;
// Can throw a RelationTypeNotFoundException
RelationType relType = getRelationType(relationTypeName);
try {
// Can throw a RoleInfoNotFoundException to be transformed into
// returned value RoleStatus.NO_ROLE_WITH_NAME
RoleInfo roleInfo = relType.getRoleInfo(roleName);
result = checkRoleInt(1,
roleName,
null,
roleInfo,
false);
} catch (RoleInfoNotFoundException exc) {
result = Integer.valueOf(RoleStatus.NO_ROLE_WITH_NAME);
}
RELATION_LOGGER.exiting(RelationService.class.getName(),
"checkRoleReading");
return result;
}
Checks if given Role can be read in a relation of the given type. |
public Integer checkRoleWriting(Role role,
String relationTypeName,
Boolean initFlag) throws IllegalArgumentException, RelationTypeNotFoundException {
if (role == null ||
relationTypeName == null ||
initFlag == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"checkRoleWriting",
new Object[] {role, relationTypeName, initFlag});
// Can throw a RelationTypeNotFoundException
RelationType relType = getRelationType(relationTypeName);
String roleName = role.getRoleName();
List< ObjectName > roleValue = role.getRoleValue();
boolean writeChkFlag = true;
if (initFlag.booleanValue()) {
writeChkFlag = false;
}
RoleInfo roleInfo;
try {
roleInfo = relType.getRoleInfo(roleName);
} catch (RoleInfoNotFoundException exc) {
RELATION_LOGGER.exiting(RelationService.class.getName(),
"checkRoleWriting");
return Integer.valueOf(RoleStatus.NO_ROLE_WITH_NAME);
}
Integer result = checkRoleInt(2,
roleName,
roleValue,
roleInfo,
writeChkFlag);
RELATION_LOGGER.exiting(RelationService.class.getName(),
"checkRoleWriting");
return result;
}
Checks if given Role can be set in a relation of given type. |
public void createRelation(String relationId,
String relationTypeName,
RoleList roleList) throws RelationServiceNotRegisteredException, IllegalArgumentException, RoleNotFoundException, InvalidRelationIdException, RelationTypeNotFoundException, InvalidRoleValueException {
// Can throw RelationServiceNotRegisteredException
isActive();
if (relationId == null ||
relationTypeName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"createRelation",
new Object[] {relationId, relationTypeName, roleList});
// Creates RelationSupport object
// Can throw InvalidRoleValueException
RelationSupport relObj = new RelationSupport(relationId,
myObjName,
relationTypeName,
roleList);
// Adds relation object as a relation into the Relation Service
// Can throw RoleNotFoundException, InvalidRelationId,
// RelationTypeNotFoundException, InvalidRoleValueException
//
// Cannot throw MBeanException
addRelationInt(true,
relObj,
null,
relationId,
relationTypeName,
roleList);
RELATION_LOGGER.exiting(RelationService.class.getName(),
"createRelation");
return;
}
Creates a simple relation (represented by a RelationSupport object) of
given relation type, and adds it in the Relation Service.
Roles are initialized according to the role list provided in
parameter. The ones not initialized in this way are set to an empty
ArrayList of ObjectNames.
A RelationNotification, with type RELATION_BASIC_CREATION, is sent. |
public void createRelationType(String relationTypeName,
RoleInfo[] roleInfoArray) throws IllegalArgumentException, InvalidRelationTypeException {
if (relationTypeName == null || roleInfoArray == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"createRelationType", relationTypeName);
// Can throw an InvalidRelationTypeException
RelationType relType =
new RelationTypeSupport(relationTypeName, roleInfoArray);
addRelationTypeInt(relType);
RELATION_LOGGER.exiting(RelationService.class.getName(),
"createRelationType");
return;
}
Creates a relation type (a RelationTypeSupport object) with given
role infos (provided by the RoleInfo objects), and adds it in the
Relation Service. |
public Map<String> findAssociatedMBeans(ObjectName mbeanName,
String relationTypeName,
String roleName) throws IllegalArgumentException {
if (mbeanName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"findAssociatedMBeans",
new Object[] {mbeanName, relationTypeName, roleName});
// Retrieves the map < relation id > - > < role names > for those
// criterias
Map< String,List< String > > relId2RoleNamesMap =
findReferencingRelations(mbeanName,
relationTypeName,
roleName);
Map< ObjectName,List< String > > result =
new HashMap< ObjectName,List< String > >();
for (String currRelId : relId2RoleNamesMap.keySet()) {
// Retrieves ObjectNames of MBeans referenced in this relation
//
// Shall not throw a RelationNotFoundException if incorrect status
// of maps :(
Map< ObjectName,List< String > > objName2RoleNamesMap;
try {
objName2RoleNamesMap = getReferencedMBeans(currRelId);
} catch (RelationNotFoundException exc) {
throw new RuntimeException(exc.getMessage());
}
// For each MBean associated to given one in a relation, adds the
// association < ObjectName > - > < relation id > into result map
for (ObjectName currObjName : objName2RoleNamesMap.keySet()) {
if (!(currObjName.equals(mbeanName))) {
// Sees if this MBean is already associated to the given
// one in another relation
List< String > currRelIdList = result.get(currObjName);
if (currRelIdList == null) {
currRelIdList = new ArrayList< String >();
currRelIdList.add(currRelId);
result.put(currObjName, currRelIdList);
} else {
currRelIdList.add(currRelId);
}
}
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(),
"findAssociatedMBeans");
return result;
}
|
public Map<String> findReferencingRelations(ObjectName mbeanName,
String relationTypeName,
String roleName) throws IllegalArgumentException {
if (mbeanName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"findReferencingRelations",
new Object[] {mbeanName, relationTypeName, roleName});
Map< String,List< String > > result = new HashMap< String,List< String > >();
synchronized(myRefedMBeanObjName2RelIdsMap) {
// Retrieves the relations referencing the MBean
Map< String,List< String > > relId2RoleNamesMap =
myRefedMBeanObjName2RelIdsMap.get(mbeanName);
if (relId2RoleNamesMap != null) {
// Relation Ids where the MBean is referenced
Set< String > allRelIdSet = relId2RoleNamesMap.keySet();
// List of relation ids of interest regarding the selected
// relation type
List< String > relIdList;
if (relationTypeName == null) {
// Considers all relations
relIdList = new ArrayList< String >(allRelIdSet);
} else {
relIdList = new ArrayList< String >();
// Considers only the relation ids for relations of given
// type
for (String currRelId : allRelIdSet) {
// Retrieves its relation type
String currRelTypeName;
synchronized(myRelId2RelTypeMap) {
currRelTypeName =
myRelId2RelTypeMap.get(currRelId);
}
if (currRelTypeName.equals(relationTypeName)) {
relIdList.add(currRelId);
}
}
}
// Now looks at the roles where the MBean is expected to be
// referenced
for (String currRelId : relIdList) {
// Retrieves list of role names where the MBean is
// referenced
List< String > currRoleNameList =
relId2RoleNamesMap.get(currRelId);
if (roleName == null) {
// All roles to be considered
// Note: no need to test if list not null before
// cloning, MUST be not null else bug :(
result.put(currRelId,
new ArrayList< String >(currRoleNameList));
} else if (currRoleNameList.contains(roleName)) {
// Filters only the relations where the MBean is
// referenced in // given role
List< String > dummyList = new ArrayList< String >();
dummyList.add(roleName);
result.put(currRelId, dummyList);
}
}
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(),
"findReferencingRelations");
return result;
}
|
public List<String> findRelationsOfType(String relationTypeName) throws IllegalArgumentException, RelationTypeNotFoundException {
if (relationTypeName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"findRelationsOfType");
// Can throw RelationTypeNotFoundException
RelationType relType = getRelationType(relationTypeName);
List< String > result;
synchronized(myRelType2RelIdsMap) {
List< String > result1 = myRelType2RelIdsMap.get(relationTypeName);
if (result1 == null)
result = new ArrayList< String >();
else
result = new ArrayList< String >(result1);
}
RELATION_LOGGER.exiting(RelationService.class.getName(),
"findRelationsOfType");
return result;
}
Returns the relation ids for relations of the given type. |
public List<String> getAllRelationIds() {
List< String > result;
synchronized(myRelId2ObjMap) {
result = new ArrayList< String >(myRelId2ObjMap.keySet());
}
return result;
}
Returns all the relation ids for all the relations handled by the
Relation Service. |
public List<String> getAllRelationTypeNames() {
ArrayList< String > result;
synchronized(myRelType2ObjMap) {
result = new ArrayList< String >(myRelType2ObjMap.keySet());
}
return result;
}
Retrieves names of all known relation types. |
public RoleResult getAllRoles(String relationId) throws IllegalArgumentException, RelationNotFoundException, RelationServiceNotRegisteredException {
if (relationId == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"getRoles", relationId);
// Can throw a RelationNotFoundException
Object relObj = getRelation(relationId);
RoleResult result;
if (relObj instanceof RelationSupport) {
// Internal relation
result = ((RelationSupport)relObj).getAllRolesInt(true, this);
} else {
// Relation MBean
// Shall not throw any Exception
try {
result = (RoleResult)
(myMBeanServer.getAttribute(((ObjectName)relObj),
"AllRoles"));
} catch (Exception exc) {
throw new RuntimeException(exc.getMessage());
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(), "getRoles");
return result;
}
Returns all roles present in the relation. |
public MBeanNotificationInfo[] getNotificationInfo() {
RELATION_LOGGER.entering(RelationService.class.getName(),
"getNotificationInfo");
String ntfClass = "javax.management.relation.RelationNotification";
String[] ntfTypes = new String[] {
RelationNotification.RELATION_BASIC_CREATION,
RelationNotification.RELATION_MBEAN_CREATION,
RelationNotification.RELATION_BASIC_UPDATE,
RelationNotification.RELATION_MBEAN_UPDATE,
RelationNotification.RELATION_BASIC_REMOVAL,
RelationNotification.RELATION_MBEAN_REMOVAL,
};
String ntfDesc = "Sent when a relation is created, updated or deleted.";
MBeanNotificationInfo ntfInfo =
new MBeanNotificationInfo(ntfTypes, ntfClass, ntfDesc);
RELATION_LOGGER.exiting(RelationService.class.getName(),
"getNotificationInfo");
return new MBeanNotificationInfo[] {ntfInfo};
}
Returns a NotificationInfo object containing the name of the Java class
of the notification and the notification types sent. |
public boolean getPurgeFlag() {
return myPurgeFlag;
}
Returns the flag to indicate if when a notification is received for the
unregistration of an MBean referenced in a relation, if an immediate
"purge" of the relations (look for the relations no longer valid)
has to be performed , or if that will be performed only when the
purgeRelations method will be explicitly called.
true is immediate purge. |
public Map<String> getReferencedMBeans(String relationId) throws IllegalArgumentException, RelationNotFoundException {
if (relationId == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"getReferencedMBeans", relationId);
// Can throw a RelationNotFoundException
Object relObj = getRelation(relationId);
Map< ObjectName,List< String > > result;
if (relObj instanceof RelationSupport) {
// Internal relation
result = ((RelationSupport)relObj).getReferencedMBeans();
} else {
// Relation MBean
// No Exception
try {
result = cast(
myMBeanServer.getAttribute(((ObjectName)relObj),
"ReferencedMBeans"));
} catch (Exception exc) {
throw new RuntimeException(exc.getMessage());
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(),
"getReferencedMBeans");
return result;
}
Retrieves MBeans referenced in the various roles of the relation. |
Object getRelation(String relationId) throws IllegalArgumentException, RelationNotFoundException {
if (relationId == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"getRelation", relationId);
// No null relation accepted, so can use get()
Object rel;
synchronized(myRelId2ObjMap) {
rel = myRelId2ObjMap.get(relationId);
}
if (rel == null) {
String excMsg = "No relation associated to relation id " + relationId;
throw new RelationNotFoundException(excMsg);
}
RELATION_LOGGER.exiting(RelationService.class.getName(),
"getRelation");
return rel;
}
|
RelationType getRelationType(String relationTypeName) throws IllegalArgumentException, RelationTypeNotFoundException {
if (relationTypeName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"getRelationType", relationTypeName);
// No null relation type accepted, so can use get()
RelationType relType;
synchronized(myRelType2ObjMap) {
relType = (myRelType2ObjMap.get(relationTypeName));
}
if (relType == null) {
String excMsg = "No relation type created in the Relation Service with the name ";
StringBuilder excMsgStrB = new StringBuilder(excMsg);
excMsgStrB.append(relationTypeName);
throw new RelationTypeNotFoundException(excMsgStrB.toString());
}
RELATION_LOGGER.exiting(RelationService.class.getName(),
"getRelationType");
return relType;
}
|
public String getRelationTypeName(String relationId) throws IllegalArgumentException, RelationNotFoundException {
if (relationId == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"getRelationTypeName", relationId);
// Can throw a RelationNotFoundException
Object relObj = getRelation(relationId);
String result;
if (relObj instanceof RelationSupport) {
// Internal relation
result = ((RelationSupport)relObj).getRelationTypeName();
} else {
// Relation MBean
// No Exception
try {
result = (String)
(myMBeanServer.getAttribute(((ObjectName)relObj),
"RelationTypeName"));
} catch (Exception exc) {
throw new RuntimeException(exc.getMessage());
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(),
"getRelationTypeName");
return result;
}
Returns name of associated relation type for given relation. |
public List<ObjectName> getRole(String relationId,
String roleName) throws RelationServiceNotRegisteredException, IllegalArgumentException, RelationNotFoundException, RoleNotFoundException {
if (relationId == null || roleName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"getRole", new Object[] {relationId, roleName});
// Can throw RelationServiceNotRegisteredException
isActive();
// Can throw a RelationNotFoundException
Object relObj = getRelation(relationId);
List< ObjectName > result;
if (relObj instanceof RelationSupport) {
// Internal relation
// Can throw RoleNotFoundException
result = cast(
((RelationSupport)relObj).getRoleInt(roleName,
true,
this,
false));
} else {
// Relation MBean
Object[] params = new Object[1];
params[0] = roleName;
String[] signature = new String[1];
signature[0] = "java.lang.String";
// Can throw MBeanException wrapping a RoleNotFoundException:
// throw wrapped exception
//
// Shall not throw InstanceNotFoundException or ReflectionException
try {
List< ObjectName > invokeResult = cast(
myMBeanServer.invoke(((ObjectName)relObj),
"getRole",
params,
signature));
if (invokeResult == null || invokeResult instanceof ArrayList< ? >)
result = invokeResult;
else
result = new ArrayList< ObjectName >(invokeResult);
} catch (InstanceNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (MBeanException exc3) {
Exception wrappedExc = exc3.getTargetException();
if (wrappedExc instanceof RoleNotFoundException) {
throw ((RoleNotFoundException)wrappedExc);
} else {
throw new RuntimeException(wrappedExc.getMessage());
}
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(), "getRole");
return result;
}
Retrieves role value for given role name in given relation. |
public Integer getRoleCardinality(String relationId,
String roleName) throws IllegalArgumentException, RelationNotFoundException, RoleNotFoundException {
if (relationId == null || roleName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"getRoleCardinality", new Object[] {relationId, roleName});
// Can throw a RelationNotFoundException
Object relObj = getRelation(relationId);
Integer result;
if (relObj instanceof RelationSupport) {
// Internal relation
// Can throw RoleNotFoundException
result = ((RelationSupport)relObj).getRoleCardinality(roleName);
} else {
// Relation MBean
Object[] params = new Object[1];
params[0] = roleName;
String[] signature = new String[1];
signature[0] = "java.lang.String";
// Can throw MBeanException wrapping RoleNotFoundException:
// throw wrapped exception
//
// Shall not throw InstanceNotFoundException or ReflectionException
try {
result = (Integer)
(myMBeanServer.invoke(((ObjectName)relObj),
"getRoleCardinality",
params,
signature));
} catch (InstanceNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (MBeanException exc3) {
Exception wrappedExc = exc3.getTargetException();
if (wrappedExc instanceof RoleNotFoundException) {
throw ((RoleNotFoundException)wrappedExc);
} else {
throw new RuntimeException(wrappedExc.getMessage());
}
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(),
"getRoleCardinality");
return result;
}
Retrieves the number of MBeans currently referenced in the given role. |
public RoleInfo getRoleInfo(String relationTypeName,
String roleInfoName) throws IllegalArgumentException, RelationTypeNotFoundException, RoleInfoNotFoundException {
if (relationTypeName == null || roleInfoName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"getRoleInfo", new Object[] {relationTypeName, roleInfoName});
// Can throw a RelationTypeNotFoundException
RelationType relType = getRelationType(relationTypeName);
// Can throw a RoleInfoNotFoundException
RoleInfo roleInfo = relType.getRoleInfo(roleInfoName);
RELATION_LOGGER.exiting(RelationService.class.getName(),
"getRoleInfo");
return roleInfo;
}
Retrieves role info for given role name of a given relation type. |
public List<RoleInfo> getRoleInfos(String relationTypeName) throws IllegalArgumentException, RelationTypeNotFoundException {
if (relationTypeName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"getRoleInfos", relationTypeName);
// Can throw a RelationTypeNotFoundException
RelationType relType = getRelationType(relationTypeName);
RELATION_LOGGER.exiting(RelationService.class.getName(),
"getRoleInfos");
return relType.getRoleInfos();
}
Retrieves list of role infos (RoleInfo objects) of a given relation
type. |
public RoleResult getRoles(String relationId,
String[] roleNameArray) throws RelationServiceNotRegisteredException, IllegalArgumentException, RelationNotFoundException {
if (relationId == null || roleNameArray == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"getRoles", relationId);
// Can throw RelationServiceNotRegisteredException
isActive();
// Can throw a RelationNotFoundException
Object relObj = getRelation(relationId);
RoleResult result;
if (relObj instanceof RelationSupport) {
// Internal relation
result = ((RelationSupport)relObj).getRolesInt(roleNameArray,
true,
this);
} else {
// Relation MBean
Object[] params = new Object[1];
params[0] = roleNameArray;
String[] signature = new String[1];
try {
signature[0] = (roleNameArray.getClass()).getName();
} catch (Exception exc) {
// OK : This is an array of java.lang.String
// so this should never happen...
}
// Shall not throw InstanceNotFoundException, ReflectionException
// or MBeanException
try {
result = (RoleResult)
(myMBeanServer.invoke(((ObjectName)relObj),
"getRoles",
params,
signature));
} catch (InstanceNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (MBeanException exc3) {
throw new
RuntimeException((exc3.getTargetException()).getMessage());
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(), "getRoles");
return result;
}
Retrieves values of roles with given names in given relation. |
public void handleNotification(Notification notif,
Object handback) {
if (notif == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"handleNotification", notif);
if (notif instanceof MBeanServerNotification) {
MBeanServerNotification mbsNtf = (MBeanServerNotification) notif;
String ntfType = notif.getType();
if (ntfType.equals(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION )) {
ObjectName mbeanName =
((MBeanServerNotification)notif).getMBeanName();
// Note: use a flag to block access to
// myRefedMBeanObjName2RelIdsMap only for a quick access
boolean isRefedMBeanFlag = false;
synchronized(myRefedMBeanObjName2RelIdsMap) {
if (myRefedMBeanObjName2RelIdsMap.containsKey(mbeanName)) {
// Unregistration of a referenced MBean
synchronized(myUnregNtfList) {
myUnregNtfList.add(mbsNtf);
}
isRefedMBeanFlag = true;
}
if (isRefedMBeanFlag && myPurgeFlag) {
// Immediate purge
// Can throw RelationServiceNotRegisteredException
// but assume that will be fine :)
try {
purgeRelations();
} catch (Exception exc) {
throw new RuntimeException(exc.getMessage());
}
}
}
// Note: do both tests as a relation can be an MBean and be
// itself referenced in another relation :)
String relId;
synchronized(myRelMBeanObjName2RelIdMap){
relId = myRelMBeanObjName2RelIdMap.get(mbeanName);
}
if (relId != null) {
// Unregistration of a relation MBean
// Can throw RelationTypeNotFoundException,
// RelationServiceNotRegisteredException
//
// Shall not throw RelationTypeNotFoundException or
// InstanceNotFoundException
try {
removeRelation(relId);
} catch (Exception exc) {
throw new RuntimeException(exc.getMessage());
}
}
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(),
"handleNotification");
return;
}
Invoked when a JMX notification occurs.
Currently handles notifications for unregistration of MBeans, either
referenced in a relation role or being a relation itself. |
public Boolean hasRelation(String relationId) throws IllegalArgumentException {
if (relationId == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"hasRelation", relationId);
try {
// Can throw RelationNotFoundException
Object result = getRelation(relationId);
return true;
} catch (RelationNotFoundException exc) {
return false;
}
}
Checks if there is a relation identified in Relation Service with given
relation id. |
public void isActive() throws RelationServiceNotRegisteredException {
if (myMBeanServer == null) {
// MBean Server not set by preRegister(): relation service not
// registered
String excMsg =
"Relation Service not registered in the MBean Server.";
throw new RelationServiceNotRegisteredException(excMsg);
}
return;
}
Checks if the Relation Service is active.
Current condition is that the Relation Service must be registered in the
MBean Server |
public String isRelation(ObjectName objectName) throws IllegalArgumentException {
if (objectName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"isRelation", objectName);
String result = null;
synchronized(myRelMBeanObjName2RelIdMap) {
String relId = myRelMBeanObjName2RelIdMap.get(objectName);
if (relId != null) {
result = relId;
}
}
return result;
}
Returns the relation id associated to the given ObjectName if the
MBean has been added as a relation in the Relation Service. |
public ObjectName isRelationMBean(String relationId) throws IllegalArgumentException, RelationNotFoundException {
if (relationId == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"isRelationMBean", relationId);
// Can throw RelationNotFoundException
Object result = getRelation(relationId);
if (result instanceof ObjectName) {
return ((ObjectName)result);
} else {
return null;
}
}
If the relation is represented by an MBean (created by the user and
added as a relation in the Relation Service), returns the ObjectName of
the MBean. |
public void postDeregister() {
return;
}
|
public void postRegister(Boolean registrationDone) {
return;
}
|
public void preDeregister() throws Exception {
return;
}
|
public ObjectName preRegister(MBeanServer server,
ObjectName name) throws Exception {
myMBeanServer = server;
myObjName = name;
return name;
}
|
public void purgeRelations() throws RelationServiceNotRegisteredException {
RELATION_LOGGER.entering(RelationService.class.getName(),
"purgeRelations");
// Can throw RelationServiceNotRegisteredException
isActive();
// Revisit [cebro] Handle the CIM "Delete" and "IfDeleted" qualifier:
// if the unregistered MBean has the "IfDeleted" qualifier,
// possible that the relation itself or other referenced MBeans
// have to be removed (then a notification would have to be sent
// to inform that they should be unregistered.
// Clones the list of notifications to be able to still receive new
// notifications while proceeding those ones
List< MBeanServerNotification > localUnregNtfList;
synchronized(myRefedMBeanObjName2RelIdsMap) {
localUnregNtfList =
new ArrayList< MBeanServerNotification >(myUnregNtfList);
// Resets list
myUnregNtfList = new ArrayList< MBeanServerNotification >();
}
// Updates the listener filter to avoid receiving notifications for
// those MBeans again
// Makes also a local "myRefedMBeanObjName2RelIdsMap" map, mapping
// ObjectName - > relId - > roles, to remove the MBean from the global
// map
// List of references to be removed from the listener filter
List< ObjectName > obsRefList = new ArrayList< ObjectName >();
// Map including ObjectNames for unregistered MBeans, with
// referencing relation ids and roles
Map< ObjectName,Map< String,List< String > > > localMBean2RelIdMap =
new HashMap< ObjectName,Map< String,List< String > > >();
synchronized(myRefedMBeanObjName2RelIdsMap) {
for (MBeanServerNotification currNtf : localUnregNtfList) {
ObjectName unregMBeanName = currNtf.getMBeanName();
// Adds the unregsitered MBean in the list of references to
// remove from the listener filter
obsRefList.add(unregMBeanName);
// Retrieves the associated map of relation ids and roles
Map< String,List< String > > relIdMap =
myRefedMBeanObjName2RelIdsMap.get(unregMBeanName);
localMBean2RelIdMap.put(unregMBeanName, relIdMap);
myRefedMBeanObjName2RelIdsMap.remove(unregMBeanName);
}
}
// Updates the listener
// Can throw RelationServiceNotRegisteredException
updateUnregistrationListener(null, obsRefList);
for (MBeanServerNotification currNtf : localUnregNtfList) {
ObjectName unregMBeanName = currNtf.getMBeanName();
// Retrieves the relations where the MBean is referenced
Map< String,List< String > > localRelIdMap =
localMBean2RelIdMap.get(unregMBeanName);
// List of relation ids where the unregistered MBean is
// referenced
for (Map.Entry< String,List< String > > currRel :
localRelIdMap.entrySet()) {
final String currRelId = currRel.getKey();
// List of roles of the relation where the MBean is
// referenced
List< String > localRoleNameList = currRel.getValue();
// Checks if the relation has to be removed or not,
// regarding expected minimum role cardinality and current
// number of references after removal of the current one
// If the relation is kept, calls
// handleMBeanUnregistration() callback of the relation to
// update it
//
// Can throw RelationServiceNotRegisteredException
//
// Shall not throw RelationNotFoundException,
// RoleNotFoundException, MBeanException
try {
handleReferenceUnregistration(currRelId,
unregMBeanName,
localRoleNameList);
} catch (RelationNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (RoleNotFoundException exc2) {
throw new RuntimeException(exc2.getMessage());
}
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(),
"purgeRelations");
return;
}
Purges the relations.
Depending on the purgeFlag value, this method is either called
automatically when a notification is received for the unregistration of
an MBean referenced in a relation (if the flag is set to true), or not
(if the flag is set to false).
In that case it is up to the user to call it to maintain the
consistency of the relations. To be kept in mind that if an MBean is
unregistered and the purge not done immediately, if the ObjectName is
reused and assigned to another MBean referenced in a relation, calling
manually this purgeRelations() method will cause trouble, as will
consider the ObjectName as corresponding to the unregistered MBean, not
seeing the new one.
The behavior depends on the cardinality of the role where the
unregistered MBean is referenced:
- if removing one MBean reference in the role makes its number of
references less than the minimum degree, the relation has to be removed.
- if the remaining number of references after removing the MBean
reference is still in the cardinality range, keep the relation and
update it calling its handleMBeanUnregistration() callback. |
public void removeRelation(String relationId) throws RelationServiceNotRegisteredException, IllegalArgumentException, RelationNotFoundException {
// Can throw RelationServiceNotRegisteredException
isActive();
if (relationId == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"removeRelation", relationId);
// Checks there is a relation with this id
// Can throw RelationNotFoundException
Object result = getRelation(relationId);
// Removes it from listener filter
if (result instanceof ObjectName) {
List< ObjectName > obsRefList = new ArrayList< ObjectName >();
obsRefList.add((ObjectName)result);
// Can throw a RelationServiceNotRegisteredException
updateUnregistrationListener(null, obsRefList);
}
// Sends a notification
// Note: has to be done FIRST as needs the relation to be still in the
// Relation Service
// No RelationNotFoundException as checked above
// Revisit [cebro] Handle CIM "Delete" and "IfDeleted" qualifiers:
// deleting the relation can mean to delete referenced MBeans. In
// that case, MBeans to be unregistered are put in a list sent along
// with the notification below
// Can throw a RelationNotFoundException (but detected above)
sendRelationRemovalNotification(relationId, null);
// Removes the relation from various internal maps
// - MBean reference map
// Retrieves the MBeans referenced in this relation
// Note: here we cannot use removeMBeanReference() because it would
// require to know the MBeans referenced in the relation. For
// that it would be necessary to call 'getReferencedMBeans()'
// on the relation itself. Ok if it is an internal one, but if
// it is an MBean, it is possible it is already unregistered, so
// not available through the MBean Server.
List< ObjectName > refMBeanList = new ArrayList< ObjectName >();
// List of MBeans no longer referenced in any relation, to be
// removed fom the map
List< ObjectName > nonRefObjNameList = new ArrayList< ObjectName >();
synchronized(myRefedMBeanObjName2RelIdsMap) {
for (ObjectName currRefObjName :
myRefedMBeanObjName2RelIdsMap.keySet()) {
// Retrieves relations where the MBean is referenced
Map< String,List< String > > relIdMap =
myRefedMBeanObjName2RelIdsMap.get(currRefObjName);
if (relIdMap.containsKey(relationId)) {
relIdMap.remove(relationId);
refMBeanList.add(currRefObjName);
}
if (relIdMap.isEmpty()) {
// MBean no longer referenced
// Note: do not remove it here because pointed by the
// iterator!
nonRefObjNameList.add(currRefObjName);
}
}
// Cleans MBean reference map by removing MBeans no longer
// referenced
for (ObjectName currRefObjName : nonRefObjNameList) {
myRefedMBeanObjName2RelIdsMap.remove(currRefObjName);
}
}
// - Relation id to object map
synchronized(myRelId2ObjMap) {
myRelId2ObjMap.remove(relationId);
}
if (result instanceof ObjectName) {
// - ObjectName to relation id map
synchronized(myRelMBeanObjName2RelIdMap) {
myRelMBeanObjName2RelIdMap.remove((ObjectName)result);
}
}
// Relation id to relation type name map
// First retrieves the relation type name
String relTypeName;
synchronized(myRelId2RelTypeMap) {
relTypeName = myRelId2RelTypeMap.get(relationId);
myRelId2RelTypeMap.remove(relationId);
}
// - Relation type name to relation id map
synchronized(myRelType2RelIdsMap) {
List< String > relIdList = myRelType2RelIdsMap.get(relTypeName);
if (relIdList != null) {
// Can be null if called from removeRelationType()
relIdList.remove(relationId);
if (relIdList.isEmpty()) {
// No other relation of that type
myRelType2RelIdsMap.remove(relTypeName);
}
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(),
"removeRelation");
return;
}
Removes given relation from the Relation Service.
A RelationNotification notification is sent, its type being:
- RelationNotification.RELATION_BASIC_REMOVAL if the relation was
only internal to the Relation Service
- RelationNotification.RELATION_MBEAN_REMOVAL if the relation is
registered as an MBean.
For MBeans referenced in such relation, nothing will be done, |
public void removeRelationType(String relationTypeName) throws RelationServiceNotRegisteredException, IllegalArgumentException, RelationTypeNotFoundException {
// Can throw RelationServiceNotRegisteredException
isActive();
if (relationTypeName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"removeRelationType", relationTypeName);
// Checks if the relation type to be removed exists
// Can throw a RelationTypeNotFoundException
RelationType relType = getRelationType(relationTypeName);
// Retrieves the relation ids for relations of that type
List< String > relIdList = null;
synchronized(myRelType2RelIdsMap) {
// Note: take a copy of the list as it is a part of a map that
// will be updated by removeRelation() below.
List< String > relIdList1 =
myRelType2RelIdsMap.get(relationTypeName);
if (relIdList1 != null) {
relIdList = new ArrayList< String >(relIdList1);
}
}
// Removes the relation type from all maps
synchronized(myRelType2ObjMap) {
myRelType2ObjMap.remove(relationTypeName);
}
synchronized(myRelType2RelIdsMap) {
myRelType2RelIdsMap.remove(relationTypeName);
}
// Removes all relations of that type
if (relIdList != null) {
for (String currRelId : relIdList) {
// Note: will remove it from myRelId2RelTypeMap :)
//
// Can throw RelationServiceNotRegisteredException (detected
// above)
// Shall not throw a RelationNotFoundException
try {
removeRelation(currRelId);
} catch (RelationNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
}
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(),
"removeRelationType");
return;
}
|
public void sendRelationCreationNotification(String relationId) throws IllegalArgumentException, RelationNotFoundException {
if (relationId == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"sendRelationCreationNotification", relationId);
// Message
StringBuilder ntfMsg = new StringBuilder("Creation of relation ");
ntfMsg.append(relationId);
// Can throw RelationNotFoundException
sendNotificationInt(1,
ntfMsg.toString(),
relationId,
null,
null,
null,
null);
RELATION_LOGGER.exiting(RelationService.class.getName(),
"sendRelationCreationNotification");
return;
}
Sends a notification (RelationNotification) for a relation creation.
The notification type is:
- RelationNotification.RELATION_BASIC_CREATION if the relation is an
object internal to the Relation Service
- RelationNotification.RELATION_MBEAN_CREATION if the relation is a
MBean added as a relation.
The source object is the Relation Service itself.
It is called in Relation Service createRelation() and
addRelation() methods. |
public void sendRelationRemovalNotification(String relationId,
List<ObjectName> unregMBeanList) throws IllegalArgumentException, RelationNotFoundException {
if (relationId == null) {
String excMsg = "Invalid parameter";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"sendRelationRemovalNotification",
new Object[] {relationId, unregMBeanList});
// Can throw RelationNotFoundException
sendNotificationInt(3,
"Removal of relation " + relationId,
relationId,
unregMBeanList,
null,
null,
null);
RELATION_LOGGER.exiting(RelationService.class.getName(),
"sendRelationRemovalNotification");
return;
}
Sends a notification (RelationNotification) for a relation removal.
The notification type is:
- RelationNotification.RELATION_BASIC_REMOVAL if the relation is an
object internal to the Relation Service
- RelationNotification.RELATION_MBEAN_REMOVAL if the relation is a
MBean added as a relation.
The source object is the Relation Service itself.
It is called in Relation Service removeRelation() method. |
public void sendRoleUpdateNotification(String relationId,
Role newRole,
List<ObjectName> oldValue) throws IllegalArgumentException, RelationNotFoundException {
if (relationId == null ||
newRole == null ||
oldValue == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
if (!(oldValue instanceof ArrayList< ? >))
oldValue = new ArrayList< ObjectName >(oldValue);
RELATION_LOGGER.entering(RelationService.class.getName(),
"sendRoleUpdateNotification",
new Object[] {relationId, newRole, oldValue});
String roleName = newRole.getRoleName();
List< ObjectName > newRoleVal = newRole.getRoleValue();
// Message
String newRoleValString = Role.roleValueToString(newRoleVal);
String oldRoleValString = Role.roleValueToString(oldValue);
StringBuilder ntfMsg = new StringBuilder("Value of role ");
ntfMsg.append(roleName);
ntfMsg.append(" has changed\nOld value:\n");
ntfMsg.append(oldRoleValString);
ntfMsg.append("\nNew value:\n");
ntfMsg.append(newRoleValString);
// Can throw a RelationNotFoundException
sendNotificationInt(2,
ntfMsg.toString(),
relationId,
null,
roleName,
newRoleVal,
oldValue);
RELATION_LOGGER.exiting(RelationService.class.getName(),
"sendRoleUpdateNotification");
}
Sends a notification (RelationNotification) for a role update in the
given relation. The notification type is:
- RelationNotification.RELATION_BASIC_UPDATE if the relation is an
object internal to the Relation Service
- RelationNotification.RELATION_MBEAN_UPDATE if the relation is a
MBean added as a relation.
The source object is the Relation Service itself.
It is called in relation MBean setRole() (for given role) and
setRoles() (for each role) methods (implementation provided in
RelationSupport class).
It is also called in Relation Service setRole() (for given role) and
setRoles() (for each role) methods. |
public void setPurgeFlag(boolean purgeFlag) {
myPurgeFlag = purgeFlag;
return;
}
Sets the flag to indicate if when a notification is received for the
unregistration of an MBean referenced in a relation, if an immediate
"purge" of the relations (look for the relations no longer valid)
has to be performed , or if that will be performed only when the
purgeRelations method will be explicitly called.
true is immediate purge. |
public void setRole(String relationId,
Role role) throws RelationServiceNotRegisteredException, IllegalArgumentException, RelationNotFoundException, RoleNotFoundException, InvalidRoleValueException {
if (relationId == null || role == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"setRole", new Object[] {relationId, role});
// Can throw RelationServiceNotRegisteredException
isActive();
// Can throw a RelationNotFoundException
Object relObj = getRelation(relationId);
if (relObj instanceof RelationSupport) {
// Internal relation
// Can throw RoleNotFoundException,
// InvalidRoleValueException and
// RelationServiceNotRegisteredException
//
// Shall not throw RelationTypeNotFoundException
// (as relation exists in the RS, its relation type is known)
try {
((RelationSupport)relObj).setRoleInt(role,
true,
this,
false);
} catch (RelationTypeNotFoundException exc) {
throw new RuntimeException(exc.getMessage());
}
} else {
// Relation MBean
Object[] params = new Object[1];
params[0] = role;
String[] signature = new String[1];
signature[0] = "javax.management.relation.Role";
// Can throw MBeanException wrapping RoleNotFoundException,
// InvalidRoleValueException
//
// Shall not MBeanException wrapping an MBeanException wrapping
// RelationTypeNotFoundException, or ReflectionException, or
// InstanceNotFoundException
try {
myMBeanServer.setAttribute(((ObjectName)relObj),
new Attribute("Role", role));
} catch (InstanceNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc3) {
throw new RuntimeException(exc3.getMessage());
} catch (MBeanException exc2) {
Exception wrappedExc = exc2.getTargetException();
if (wrappedExc instanceof RoleNotFoundException) {
throw ((RoleNotFoundException)wrappedExc);
} else if (wrappedExc instanceof InvalidRoleValueException) {
throw ((InvalidRoleValueException)wrappedExc);
} else {
throw new RuntimeException(wrappedExc.getMessage());
}
} catch (AttributeNotFoundException exc4) {
throw new RuntimeException(exc4.getMessage());
} catch (InvalidAttributeValueException exc5) {
throw new RuntimeException(exc5.getMessage());
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(), "setRole");
return;
}
Sets the given role in given relation.
Will check the role according to its corresponding role definition
provided in relation's relation type
The Relation Service will keep track of the change to keep the
consistency of relations by handling referenced MBean unregistrations. |
public RoleResult setRoles(String relationId,
RoleList roleList) throws RelationServiceNotRegisteredException, IllegalArgumentException, RelationNotFoundException {
if (relationId == null || roleList == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"setRoles", new Object[] {relationId, roleList});
// Can throw RelationServiceNotRegisteredException
isActive();
// Can throw a RelationNotFoundException
Object relObj = getRelation(relationId);
RoleResult result;
if (relObj instanceof RelationSupport) {
// Internal relation
// Can throw RelationServiceNotRegisteredException
//
// Shall not throw RelationTypeNotFoundException (as relation is
// known, its relation type exists)
try {
result = ((RelationSupport)relObj).setRolesInt(roleList,
true,
this);
} catch (RelationTypeNotFoundException exc) {
throw new RuntimeException(exc.getMessage());
}
} else {
// Relation MBean
Object[] params = new Object[1];
params[0] = roleList;
String[] signature = new String[1];
signature[0] = "javax.management.relation.RoleList";
// Shall not throw InstanceNotFoundException or an MBeanException
// or ReflectionException
try {
result = (RoleResult)
(myMBeanServer.invoke(((ObjectName)relObj),
"setRoles",
params,
signature));
} catch (InstanceNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc3) {
throw new RuntimeException(exc3.getMessage());
} catch (MBeanException exc2) {
throw new
RuntimeException((exc2.getTargetException()).getMessage());
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(), "setRoles");
return result;
}
Sets the given roles in given relation.
Will check the role according to its corresponding role definition
provided in relation's relation type
The Relation Service keeps track of the changes to keep the
consistency of relations by handling referenced MBean unregistrations. |
static void throwRoleProblemException(int pbType,
String roleName) throws IllegalArgumentException, RoleNotFoundException, InvalidRoleValueException {
if (roleName == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
// Exception type: 1 = RoleNotFoundException
// 2 = InvalidRoleValueException
int excType = 0;
String excMsgPart = null;
switch (pbType) {
case RoleStatus.NO_ROLE_WITH_NAME:
excMsgPart = " does not exist in relation.";
excType = 1;
break;
case RoleStatus.ROLE_NOT_READABLE:
excMsgPart = " is not readable.";
excType = 1;
break;
case RoleStatus.ROLE_NOT_WRITABLE:
excMsgPart = " is not writable.";
excType = 1;
break;
case RoleStatus.LESS_THAN_MIN_ROLE_DEGREE:
excMsgPart = " has a number of MBean references less than the expected minimum degree.";
excType = 2;
break;
case RoleStatus.MORE_THAN_MAX_ROLE_DEGREE:
excMsgPart = " has a number of MBean references greater than the expected maximum degree.";
excType = 2;
break;
case RoleStatus.REF_MBEAN_OF_INCORRECT_CLASS:
excMsgPart = " has an MBean reference to an MBean not of the expected class of references for that role.";
excType = 2;
break;
case RoleStatus.REF_MBEAN_NOT_REGISTERED:
excMsgPart = " has a reference to null or to an MBean not registered.";
excType = 2;
break;
}
// No default as we must have been in one of those cases
StringBuilder excMsgStrB = new StringBuilder(roleName);
excMsgStrB.append(excMsgPart);
String excMsg = excMsgStrB.toString();
if (excType == 1) {
throw new RoleNotFoundException(excMsg);
} else if (excType == 2) {
throw new InvalidRoleValueException(excMsg);
}
}
|
public void updateRoleMap(String relationId,
Role newRole,
List<ObjectName> oldValue) throws IllegalArgumentException, RelationServiceNotRegisteredException, RelationNotFoundException {
if (relationId == null ||
newRole == null ||
oldValue == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(),
"updateRoleMap", new Object[] {relationId, newRole, oldValue});
// Can throw RelationServiceNotRegisteredException
isActive();
// Verifies the relation has been added in the Relation Service
// Can throw a RelationNotFoundException
Object result = getRelation(relationId);
String roleName = newRole.getRoleName();
List< ObjectName > newRoleValue = newRole.getRoleValue();
// Note: no need to test if oldValue not null before cloning,
// tested above.
List< ObjectName > oldRoleValue =
new ArrayList< ObjectName >(oldValue);
// List of ObjectNames of new referenced MBeans
List< ObjectName > newRefList = new ArrayList< ObjectName >();
for (ObjectName currObjName : newRoleValue) {
// Checks if this ObjectName was already present in old value
// Note: use copy (oldRoleValue) instead of original
// oldValue to speed up, as oldRoleValue is decreased
// by removing unchanged references :)
int currObjNamePos = oldRoleValue.indexOf(currObjName);
if (currObjNamePos == -1) {
// New reference to an ObjectName
// Stores this reference into map
// Returns true if new reference, false if MBean already
// referenced
boolean isNewFlag = addNewMBeanReference(currObjName,
relationId,
roleName);
if (isNewFlag) {
// Adds it into list of new reference
newRefList.add(currObjName);
}
} else {
// MBean was already referenced in old value
// Removes it from old value (local list) to ignore it when
// looking for remove MBean references
oldRoleValue.remove(currObjNamePos);
}
}
// List of ObjectNames of MBeans no longer referenced
List< ObjectName > obsRefList = new ArrayList< ObjectName >();
// Each ObjectName remaining in oldRoleValue is an ObjectName no longer
// referenced in new value
for (ObjectName currObjName : oldRoleValue) {
// Removes MBean reference from map
// Returns true if the MBean is no longer referenced in any
// relation
boolean noLongerRefFlag = removeMBeanReference(currObjName,
relationId,
roleName,
false);
if (noLongerRefFlag) {
// Adds it into list of references to be removed
obsRefList.add(currObjName);
}
}
// To avoid having one listener per ObjectName of referenced MBean,
// and to increase performances, there is only one listener recording
// all ObjectNames of interest
updateUnregistrationListener(newRefList, obsRefList);
RELATION_LOGGER.exiting(RelationService.class.getName(),
"updateRoleMap");
return;
}
Handles update of the Relation Service role map for the update of given
role in given relation.
It is called in relation MBean setRole() (for given role) and
setRoles() (for each role) methods (implementation provided in
RelationSupport class).
It is also called in Relation Service setRole() (for given role) and
setRoles() (for each role) methods.
To allow the Relation Service to maintain the consistency (in case
of MBean unregistration) and to be able to perform queries, this method
must be called when a role is updated. |