public class RelationService extends NotificationBroadcasterSupport implements RelationServiceMBean, MBeanRegistration, NotificationListener
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.
public RelationService(boolean immediatePurgeFlag)
Constructor.
immediatePurgeFlag
- flag to indicate 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 isActive() throws RelationServiceNotRegisteredException
Checks if the Relation Service is active. Current condition is that the Relation Service must be registered in the MBean Server
isActive
in interface RelationServiceMBean
RelationServiceNotRegisteredException
- if it is not registeredpublic ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception
Description copied from interface: MBeanRegistration
Allows the MBean to perform any operations it needs before being registered in the MBean Server. If the name of the MBean is not specified, the MBean can provide a name for its registration. If any exception is raised, the MBean will not be registered in the MBean Server.
preRegister
in interface MBeanRegistration
server
- The MBean Server in which the MBean will be registered.name
- The object name of the MBean. This name is null if the name parameter to one of the createMBean
or registerMBean
methods in the MBeanServer
interface is null. In that case, this method must return a non-null ObjectName for the new MBean.name
parameter is not null, it will usually but not necessarily be the returned value.Exception
- This exception will be caught by the MBean Server and re-thrown as an MBeanRegistrationException
.public void postRegister(Boolean registrationDone)
Description copied from interface: MBeanRegistration
Allows the MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed.
If the implementation of this method throws a RuntimeException
or an Error
, the MBean Server will rethrow those inside a RuntimeMBeanException
or RuntimeErrorException
, respectively. However, throwing an exception in postRegister
will not change the state of the MBean: if the MBean was already registered (registrationDone
is true
), the MBean will remain registered.
This might be confusing for the code calling createMBean()
or registerMBean()
, as such code might assume that MBean registration has failed when such an exception is raised. Therefore it is recommended that implementations of postRegister
do not throw Runtime Exceptions or Errors if it can be avoided.
postRegister
in interface MBeanRegistration
registrationDone
- Indicates whether or not the MBean has been successfully registered in the MBean server. The value false means that the registration phase has failed.public void preDeregister() throws Exception
Description copied from interface: MBeanRegistration
Allows the MBean to perform any operations it needs before being unregistered by the MBean server.
preDeregister
in interface MBeanRegistration
Exception
- This exception will be caught by the MBean server and re-thrown as an MBeanRegistrationException
.public void postDeregister()
Description copied from interface: MBeanRegistration
Allows the MBean to perform any operations needed after having been unregistered in the MBean server.
If the implementation of this method throws a RuntimeException
or an Error
, the MBean Server will rethrow those inside a RuntimeMBeanException
or RuntimeErrorException
, respectively. However, throwing an exception in postDeregister
will not change the state of the MBean: the MBean was already successfully deregistered and will remain so.
This might be confusing for the code calling unregisterMBean()
, as it might assume that MBean deregistration has failed. Therefore it is recommended that implementations of postDeregister
do not throw Runtime Exceptions or Errors if it can be avoided.
postDeregister
in interface MBeanRegistration
public boolean getPurgeFlag()
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.
getPurgeFlag
in interface RelationServiceMBean
setPurgeFlag(boolean)
public void setPurgeFlag(boolean purgeFlag)
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.
setPurgeFlag
in interface RelationServiceMBean
purgeFlag
- flaggetPurgeFlag()
public void createRelationType(String relationTypeName, RoleInfo[] roleInfoArray) throws IllegalArgumentException, InvalidRelationTypeException
Creates a relation type (a RelationTypeSupport object) with given role infos (provided by the RoleInfo objects), and adds it in the Relation Service.
createRelationType
in interface RelationServiceMBean
relationTypeName
- name of the relation typeroleInfoArray
- array of role infosIllegalArgumentException
- if null parameterInvalidRelationTypeException
- If: - there is already a relation type with that name
- the same name has been used for two different role infos
- no role info provided
- one null role info provided
public void addRelationType(RelationType relationTypeObj) throws IllegalArgumentException, InvalidRelationTypeException
Adds given object as a relation type. The object is expected to implement the RelationType interface.
addRelationType
in interface RelationServiceMBean
relationTypeObj
- relation type object (implementing the RelationType interface)IllegalArgumentException
- if null parameter or if relationTypeObj.getRelationTypeName()
returns null.InvalidRelationTypeException
- if: - the same name has been used for two different roles
- no role info provided
- one null role info provided
- there is already a relation type with that name
public List<String> getAllRelationTypeNames()
Retrieves names of all known relation types.
getAllRelationTypeNames
in interface RelationServiceMBean
public List<RoleInfo> getRoleInfos(String relationTypeName) throws IllegalArgumentException, RelationTypeNotFoundException
Retrieves list of role infos (RoleInfo objects) of a given relation type.
getRoleInfos
in interface RelationServiceMBean
relationTypeName
- name of relation typeIllegalArgumentException
- if null parameterRelationTypeNotFoundException
- if there is no relation type with that name.public RoleInfo getRoleInfo(String relationTypeName, String roleInfoName) throws IllegalArgumentException, RelationTypeNotFoundException, RoleInfoNotFoundException
Retrieves role info for given role name of a given relation type.
getRoleInfo
in interface RelationServiceMBean
relationTypeName
- name of relation typeroleInfoName
- name of roleIllegalArgumentException
- if null parameterRelationTypeNotFoundException
- if the relation type is not known in the Relation ServiceRoleInfoNotFoundException
- if the role is not part of the relation type.public void removeRelationType(String relationTypeName) throws RelationServiceNotRegisteredException, IllegalArgumentException, RelationTypeNotFoundException
Removes given relation type from Relation Service.
The relation objects of that type will be removed from the Relation Service.
removeRelationType
in interface RelationServiceMBean
relationTypeName
- name of the relation type to be removedRelationServiceNotRegisteredException
- if the Relation Service is not registered in the MBean ServerIllegalArgumentException
- if null parameterRelationTypeNotFoundException
- If there is no relation type with that namepublic void createRelation(String relationId, String relationTypeName, RoleList roleList) throws RelationServiceNotRegisteredException, IllegalArgumentException, RoleNotFoundException, InvalidRelationIdException, RelationTypeNotFoundException, InvalidRoleValueException
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.
createRelation
in interface RelationServiceMBean
relationId
- relation identifier, to identify uniquely the relation inside the Relation ServicerelationTypeName
- name of the relation type (has to be created in the Relation Service)roleList
- role list to initialize roles of the relation (can be null).RelationServiceNotRegisteredException
- if the Relation Service is not registered in the MBean ServerIllegalArgumentException
- if null parameter, except the role list which can be null if no role initializationRoleNotFoundException
- if a value is provided for a role that does not exist in the relation typeInvalidRelationIdException
- if relation id already usedRelationTypeNotFoundException
- if relation type not known in Relation ServiceInvalidRoleValueException
- if: - the same role name is used for two different roles
- the number of referenced MBeans in given value is less than expected minimum degree
- the number of referenced MBeans in provided value exceeds expected maximum degree
- one referenced MBean in the value is not an Object of the MBean class expected for that role
- an MBean provided for that role does not exist
public void addRelation(ObjectName relationObjectName) throws IllegalArgumentException, RelationServiceNotRegisteredException, NoSuchMethodException, InvalidRelationIdException, InstanceNotFoundException, InvalidRelationServiceException, RelationTypeNotFoundException, RoleNotFoundException, InvalidRoleValueException
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.
addRelation
in interface RelationServiceMBean
relationObjectName
- ObjectName of the relation MBean to be added.IllegalArgumentException
- if null parameterRelationServiceNotRegisteredException
- if the Relation Service is not registered in the MBean ServerNoSuchMethodException
- If the MBean does not implement the Relation interfaceInvalidRelationIdException
- if: - no relation identifier in MBean
- the relation identifier is already used in the Relation Service
InstanceNotFoundException
- if the MBean for given ObjectName has not been registeredInvalidRelationServiceException
- if: - no Relation Service name in MBean
- the Relation Service name in the MBean is not the one of the current Relation Service
RelationTypeNotFoundException
- if: - no relation type name in MBean
- the relation type name in MBean does not correspond to a relation type created in the Relation Service
InvalidRoleValueException
- if: - the number of referenced MBeans in a role is less than expected minimum degree
- the number of referenced MBeans in a role exceeds expected maximum degree
- one referenced MBean in the value is not an Object of the MBean class expected for that role
- an MBean provided for a role does not exist
RoleNotFoundException
- if a value is provided for a role that does not exist in the relation typepublic ObjectName isRelationMBean(String relationId) throws IllegalArgumentException, RelationNotFoundException
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.
isRelationMBean
in interface RelationServiceMBean
relationId
- relation id identifying the relationIllegalArgumentException
- if null parameterRelationNotFoundException
- there is no relation associated to that idpublic String isRelation(ObjectName objectName) throws IllegalArgumentException
Returns the relation id associated to the given ObjectName if the MBean has been added as a relation in the Relation Service.
isRelation
in interface RelationServiceMBean
objectName
- ObjectName of supposed relationIllegalArgumentException
- if null parameterpublic Boolean hasRelation(String relationId) throws IllegalArgumentException
Checks if there is a relation identified in Relation Service with given relation id.
hasRelation
in interface RelationServiceMBean
relationId
- relation id identifying the relationIllegalArgumentException
- if null parameterpublic List<String> getAllRelationIds()
Returns all the relation ids for all the relations handled by the Relation Service.
getAllRelationIds
in interface RelationServiceMBean
public Integer checkRoleReading(String roleName, String relationTypeName) throws IllegalArgumentException, RelationTypeNotFoundException
Checks if given Role can be read in a relation of the given type.
checkRoleReading
in interface RelationServiceMBean
roleName
- name of role to be checkedrelationTypeName
- name of the relation type- 0 if role can be read
- integer corresponding to RoleStatus.NO_ROLE_WITH_NAME
- integer corresponding to RoleStatus.ROLE_NOT_READABLE
IllegalArgumentException
- if null parameterRelationTypeNotFoundException
- if the relation type is not known in the Relation Servicepublic Integer checkRoleWriting(Role role, String relationTypeName, Boolean initFlag) throws IllegalArgumentException, RelationTypeNotFoundException
Checks if given Role can be set in a relation of given type.
checkRoleWriting
in interface RelationServiceMBean
role
- role to be checkedrelationTypeName
- name of relation typeinitFlag
- flag to specify that the checking is done for the initialization of a role, write access shall not be verified.- 0 if role can be set
- integer corresponding to RoleStatus.NO_ROLE_WITH_NAME
- integer for RoleStatus.ROLE_NOT_WRITABLE
- integer for RoleStatus.LESS_THAN_MIN_ROLE_DEGREE
- integer for RoleStatus.MORE_THAN_MAX_ROLE_DEGREE
- integer for RoleStatus.REF_MBEAN_OF_INCORRECT_CLASS
- integer for RoleStatus.REF_MBEAN_NOT_REGISTERED
IllegalArgumentException
- if null parameterRelationTypeNotFoundException
- if unknown relation typepublic void sendRelationCreationNotification(String relationId) throws IllegalArgumentException, RelationNotFoundException
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.
sendRelationCreationNotification
in interface RelationServiceMBean
relationId
- relation identifier of the updated relationIllegalArgumentException
- if null parameterRelationNotFoundException
- if there is no relation for given relation idpublic void sendRoleUpdateNotification(String relationId, Role newRole, List<ObjectName> oldValue) throws IllegalArgumentException, RelationNotFoundException
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.
sendRoleUpdateNotification
in interface RelationServiceMBean
relationId
- relation identifier of the updated relationnewRole
- new role (name and new value)oldValue
- old role value (List of ObjectName objects)IllegalArgumentException
- if null parameterRelationNotFoundException
- if there is no relation for given relation idpublic void sendRelationRemovalNotification(String relationId, List<ObjectName> unregMBeanList) throws IllegalArgumentException, RelationNotFoundException
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.
sendRelationRemovalNotification
in interface RelationServiceMBean
relationId
- relation identifier of the updated relationunregMBeanList
- List of ObjectNames of MBeans expected to be unregistered due to relation removal (can be null)IllegalArgumentException
- if null parameterRelationNotFoundException
- if there is no relation for given relation idpublic void updateRoleMap(String relationId, Role newRole, List<ObjectName> oldValue) throws IllegalArgumentException, RelationServiceNotRegisteredException, RelationNotFoundException
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.
updateRoleMap
in interface RelationServiceMBean
relationId
- relation identifier of the updated relationnewRole
- new role (name and new value)oldValue
- old role value (List of ObjectName objects)IllegalArgumentException
- if null parameterRelationServiceNotRegisteredException
- if the Relation Service is not registered in the MBean ServerRelationNotFoundException
- if no relation for given id.public void removeRelation(String relationId) throws RelationServiceNotRegisteredException, IllegalArgumentException, RelationNotFoundException
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,
removeRelation
in interface RelationServiceMBean
relationId
- relation id of the relation to be removedRelationServiceNotRegisteredException
- if the Relation Service is not registered in the MBean ServerIllegalArgumentException
- if null parameterRelationNotFoundException
- if no relation corresponding to given relation idpublic void purgeRelations() throws RelationServiceNotRegisteredException
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.
purgeRelations
in interface RelationServiceMBean
RelationServiceNotRegisteredException
- if the Relation Service is not registered in the MBean Server.public Map<String,List<String>> findReferencingRelations(ObjectName mbeanName, String relationTypeName, String roleName) throws IllegalArgumentException
Retrieves the relations where a given MBean is referenced.
This corresponds to the CIM "References" and "ReferenceNames" operations.
findReferencingRelations
in interface RelationServiceMBean
mbeanName
- ObjectName of MBeanrelationTypeName
- can be null; if specified, only the relations of that type will be considered in the search. Else all relation types are considered.roleName
- can be null; if specified, only the relations where the MBean is referenced in that role will be returned. Else all roles are considered.IllegalArgumentException
- if null parameterpublic Map<ObjectName,List<String>> findAssociatedMBeans(ObjectName mbeanName, String relationTypeName, String roleName) throws IllegalArgumentException
Retrieves the MBeans associated to given one in a relation.
This corresponds to CIM Associators and AssociatorNames operations.
findAssociatedMBeans
in interface RelationServiceMBean
mbeanName
- ObjectName of MBeanrelationTypeName
- can be null; if specified, only the relations of that type will be considered in the search. Else all relation types are considered.roleName
- can be null; if specified, only the relations where the MBean is referenced in that role will be considered. Else all roles are considered.IllegalArgumentException
- if null parameterpublic List<String> findRelationsOfType(String relationTypeName) throws IllegalArgumentException, RelationTypeNotFoundException
Returns the relation ids for relations of the given type.
findRelationsOfType
in interface RelationServiceMBean
relationTypeName
- relation type nameIllegalArgumentException
- if null parameterRelationTypeNotFoundException
- if there is no relation type with that name.public List<ObjectName> getRole(String relationId, String roleName) throws RelationServiceNotRegisteredException, IllegalArgumentException, RelationNotFoundException, RoleNotFoundException
Retrieves role value for given role name in given relation.
getRole
in interface RelationServiceMBean
relationId
- relation idroleName
- name of roleRelationServiceNotRegisteredException
- if the Relation Service is not registeredIllegalArgumentException
- if null parameterRelationNotFoundException
- if no relation with given idRoleNotFoundException
- if: - there is no role with given name
or
- the role is not readable.
setRole(java.lang.String, javax.management.relation.Role)
public RoleResult getRoles(String relationId, String[] roleNameArray) throws RelationServiceNotRegisteredException, IllegalArgumentException, RelationNotFoundException
Retrieves values of roles with given names in given relation.
getRoles
in interface RelationServiceMBean
relationId
- relation idroleNameArray
- array of names of roles to be retrievedRelationServiceNotRegisteredException
- if the Relation Service is not registered in the MBean ServerIllegalArgumentException
- if null parameterRelationNotFoundException
- if no relation with given idsetRoles(java.lang.String, javax.management.relation.RoleList)
public RoleResult getAllRoles(String relationId) throws IllegalArgumentException, RelationNotFoundException, RelationServiceNotRegisteredException
Returns all roles present in the relation.
getAllRoles
in interface RelationServiceMBean
relationId
- relation idIllegalArgumentException
- if null parameterRelationNotFoundException
- if no relation for given idRelationServiceNotRegisteredException
- if the Relation Service is not registered in the MBean Serverpublic Integer getRoleCardinality(String relationId, String roleName) throws IllegalArgumentException, RelationNotFoundException, RoleNotFoundException
Retrieves the number of MBeans currently referenced in the given role.
getRoleCardinality
in interface RelationServiceMBean
relationId
- relation idroleName
- name of roleIllegalArgumentException
- if null parameterRelationNotFoundException
- if no relation with given idRoleNotFoundException
- if there is no role with given namepublic void setRole(String relationId, Role role) throws RelationServiceNotRegisteredException, IllegalArgumentException, RelationNotFoundException, RoleNotFoundException, InvalidRoleValueException
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 deregistrations.
setRole
in interface RelationServiceMBean
relationId
- relation idrole
- role to be set (name and new value)RelationServiceNotRegisteredException
- if the Relation Service is not registered in the MBean ServerIllegalArgumentException
- if null parameterRelationNotFoundException
- if no relation with given idRoleNotFoundException
- if the role does not exist or is not writableInvalidRoleValueException
- if value provided for role is not valid: - the number of referenced MBeans in given value is less than expected minimum degree
or
- the number of referenced MBeans in provided value exceeds expected maximum degree
or
- one referenced MBean in the value is not an Object of the MBean class expected for that role
or
- an MBean provided for that role does not exist
getRole(java.lang.String, java.lang.String)
public RoleResult setRoles(String relationId, RoleList roleList) throws RelationServiceNotRegisteredException, IllegalArgumentException, RelationNotFoundException
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 deregistrations.
setRoles
in interface RelationServiceMBean
relationId
- relation idroleList
- list of roles to be setRelationServiceNotRegisteredException
- if the Relation Service is not registered in the MBean ServerIllegalArgumentException
- if null parameterRelationNotFoundException
- if no relation with given idgetRoles(java.lang.String, java.lang.String[])
public Map<ObjectName,List<String>> getReferencedMBeans(String relationId) throws IllegalArgumentException, RelationNotFoundException
Retrieves MBeans referenced in the various roles of the relation.
getReferencedMBeans
in interface RelationServiceMBean
relationId
- relation idObjectName -> ArrayList of String (role names)
IllegalArgumentException
- if null parameterRelationNotFoundException
- if no relation for given relation idpublic String getRelationTypeName(String relationId) throws IllegalArgumentException, RelationNotFoundException
Returns name of associated relation type for given relation.
getRelationTypeName
in interface RelationServiceMBean
relationId
- relation idIllegalArgumentException
- if null parameterRelationNotFoundException
- if no relation for given relation idpublic void handleNotification(Notification notif, Object handback)
Invoked when a JMX notification occurs. Currently handles notifications for unregistration of MBeans, either referenced in a relation role or being a relation itself.
handleNotification
in interface NotificationListener
notif
- The notification.handback
- An opaque object which helps the listener to associate information regarding the MBean emitter (can be null).public MBeanNotificationInfo[] getNotificationInfo()
Returns a NotificationInfo object containing the name of the Java class of the notification and the notification types sent.
getNotificationInfo
in interface NotificationBroadcaster
getNotificationInfo
in class NotificationBroadcasterSupport
© 1993–2017, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.