- java.lang.Object
-
- javax.management.relation.RelationSupport
-
- All Implemented Interfaces:
- MBeanRegistration, Relation, RelationSupportMBean
public class RelationSupport extends Object implements RelationSupportMBean, MBeanRegistration
A RelationSupport object is used internally by the Relation Service to represent simple relations (only roles, no properties or methods), with an unlimited number of roles, of any relation type. As internal representation, it is not exposed to the user.RelationSupport class conforms to the design patterns of standard MBean. So the user can decide to instantiate a RelationSupport object himself as a MBean (as it follows the MBean design patterns), to register it in the MBean Server, and then to add it in the Relation Service.
The user can also, when creating his own MBean relation class, have it extending RelationSupport, to retrieve the implementations of required interfaces (see below).
It is also possible to have in a user relation MBean class a member being a RelationSupport object, and to implement the required interfaces by delegating all to this member.
RelationSupport implements the Relation interface (to be handled by the Relation Service).
It implements also the MBeanRegistration interface to be able to retrieve the MBean Server where it is registered (if registered as a MBean) to access to its Relation Service.
- Since:
- 1.5
-
-
Constructor Summary
Constructors Constructor and Description RelationSupport(String relationId, ObjectName relationServiceName, MBeanServer relationServiceMBeanServer, String relationTypeName, RoleList list)
Creates aRelationSupport
object.RelationSupport(String relationId, ObjectName relationServiceName, String relationTypeName, RoleList list)
Creates aRelationSupport
object.
-
Method Summary
Methods Modifier and Type Method and Description RoleResult
getAllRoles()
Returns all roles present in the relation.Map<ObjectName,List<String>>
getReferencedMBeans()
Retrieves MBeans referenced in the various roles of the relation.String
getRelationId()
Returns relation identifier (used to uniquely identify the relation inside the Relation Service).ObjectName
getRelationServiceName()
Returns ObjectName of the Relation Service handling the relation.String
getRelationTypeName()
Returns name of associated relation type.List<ObjectName>
getRole(String roleName)
Retrieves role value for given role name.Integer
getRoleCardinality(String roleName)
Returns the number of MBeans currently referenced in the given role.RoleResult
getRoles(String[] roleNameArray)
Retrieves values of roles with given names.void
handleMBeanUnregistration(ObjectName objectName, String roleName)
Callback used by the Relation Service when a MBean referenced in a role is unregistered.Boolean
isInRelationService()
Returns an internal flag specifying if the object is still handled by the Relation Service.void
postDeregister()
Allows the MBean to perform any operations needed after having been unregistered in the MBean server.void
postRegister(Boolean registrationDone)
Allows the MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed.void
preDeregister()
Allows the MBean to perform any operations it needs before being unregistered by the MBean server.ObjectName
preRegister(MBeanServer server, ObjectName name)
Allows the MBean to perform any operations it needs before being registered in the MBean Server.RoleList
retrieveAllRoles()
Returns all roles in the relation without checking read mode.void
setRelationServiceManagementFlag(Boolean flag)
Specifies whether this relation is handled by the Relation Service.void
setRole(Role role)
Sets the given role.RoleResult
setRoles(RoleList list)
Sets the given roles.
-
-
-
Constructor Detail
-
RelationSupport
public RelationSupport(String relationId, ObjectName relationServiceName, String relationTypeName, RoleList list) throws InvalidRoleValueException, IllegalArgumentException
Creates aRelationSupport
object.This constructor has to be used when the RelationSupport object will be registered as a MBean by the user, or when creating a user relation MBean whose class extends RelationSupport.
Nothing is done at the Relation Service level, i.e. the
RelationSupport
object is not added to theRelationService
and no checks are performed to see if the provided values are correct. The object is always created, EXCEPT if:- any of the required parameters is
null
.- the same name is used for two roles.
To be handled as a relation, the
RelationSupport
object has to be added to the Relation Service using the Relation Service method addRelation().- Parameters:
relationId
- relation identifier, to identify the relation in the Relation Service.Expected to be unique in the given Relation Service.
relationServiceName
- ObjectName of the Relation Service where the relation will be registered.This parameter is required as it is the Relation Service that is aware of the definition of the relation type of the given relation, so that will be able to check update operations (set).
relationTypeName
- Name of relation type.Expected to have been created in the given Relation Service.
list
- list of roles (Role objects) to initialize the relation. Can benull
.Expected to conform to relation info in associated relation type.
- Throws:
InvalidRoleValueException
- if the same name is used for two roles.IllegalArgumentException
- if any of the required parameters (relation id, relation service ObjectName, or relation type name) isnull
.
-
RelationSupport
public RelationSupport(String relationId, ObjectName relationServiceName, MBeanServer relationServiceMBeanServer, String relationTypeName, RoleList list) throws InvalidRoleValueException, IllegalArgumentException
Creates aRelationSupport
object.This constructor has to be used when the user relation MBean implements the interfaces expected to be supported by a relation by delegating to a RelationSupport object.
This object needs to know the Relation Service expected to handle the relation. So it has to know the MBean Server where the Relation Service is registered.
According to a limitation, a relation MBean must be registered in the same MBean Server as the Relation Service expected to handle it. So the user relation MBean has to be created and registered, and then the wrapped RelationSupport object can be created within the identified MBean Server.
Nothing is done at the Relation Service level, i.e. the
RelationSupport
object is not added to theRelationService
and no checks are performed to see if the provided values are correct. The object is always created, EXCEPT if:- any of the required parameters is
null
.- the same name is used for two roles.
To be handled as a relation, the
RelationSupport
object has to be added to the Relation Service using the Relation Service method addRelation().- Parameters:
relationId
- relation identifier, to identify the relation in the Relation Service.Expected to be unique in the given Relation Service.
relationServiceName
- ObjectName of the Relation Service where the relation will be registered.This parameter is required as it is the Relation Service that is aware of the definition of the relation type of the given relation, so that will be able to check update operations (set).
relationServiceMBeanServer
- MBean Server where the wrapping MBean is or will be registered.Expected to be the MBean Server where the Relation Service is or will be registered.
relationTypeName
- Name of relation type.Expected to have been created in the given Relation Service.
list
- list of roles (Role objects) to initialize the relation. Can benull
.Expected to conform to relation info in associated relation type.
- Throws:
InvalidRoleValueException
- if the same name is used for two roles.IllegalArgumentException
- if any of the required parameters (relation id, relation service ObjectName, relation service MBeanServer, or relation type name) isnull
.
-
-
Method Detail
-
getRole
public List<ObjectName> getRole(String roleName) throws IllegalArgumentException, RoleNotFoundException, RelationServiceNotRegisteredException
Retrieves role value for given role name.Checks if the role exists and is readable according to the relation type.
- Specified by:
getRole
in interfaceRelation
- Parameters:
roleName
- name of role- Returns:
- the ArrayList of ObjectName objects being the role value
- Throws:
IllegalArgumentException
- if null role nameRoleNotFoundException
- if:- there is no role with given name
- the role is not readable.
RelationServiceNotRegisteredException
- if the Relation Service is not registered in the MBean Server- See Also:
setRole(javax.management.relation.Role)
-
getRoles
public RoleResult getRoles(String[] roleNameArray) throws IllegalArgumentException, RelationServiceNotRegisteredException
Retrieves values of roles with given names.Checks for each role if it exists and is readable according to the relation type.
- Specified by:
getRoles
in interfaceRelation
- Parameters:
roleNameArray
- array of names of roles to be retrieved- Returns:
- a RoleResult object, including a RoleList (for roles successfully retrieved) and a RoleUnresolvedList (for roles not retrieved).
- Throws:
IllegalArgumentException
- if null role nameRelationServiceNotRegisteredException
- if the Relation Service is not registered in the MBean Server- See Also:
setRoles(javax.management.relation.RoleList)
-
getAllRoles
public RoleResult getAllRoles() throws RelationServiceNotRegisteredException
Returns all roles present in the relation.- Specified by:
getAllRoles
in interfaceRelation
- Returns:
- a RoleResult object, including a RoleList (for roles successfully retrieved) and a RoleUnresolvedList (for roles not readable).
- Throws:
RelationServiceNotRegisteredException
- if the Relation Service is not registered in the MBean Server
-
retrieveAllRoles
public RoleList retrieveAllRoles()
Returns all roles in the relation without checking read mode.- Specified by:
retrieveAllRoles
in interfaceRelation
- Returns:
- a RoleList
-
getRoleCardinality
public Integer getRoleCardinality(String roleName) throws IllegalArgumentException, RoleNotFoundException
Returns the number of MBeans currently referenced in the given role.- Specified by:
getRoleCardinality
in interfaceRelation
- Parameters:
roleName
- name of role- Returns:
- the number of currently referenced MBeans in that role
- Throws:
IllegalArgumentException
- if null role nameRoleNotFoundException
- if there is no role with given name
-
setRole
public void setRole(Role role) throws IllegalArgumentException, RoleNotFoundException, RelationTypeNotFoundException, InvalidRoleValueException, RelationServiceNotRegisteredException, RelationNotFoundException
Sets the given role.Will check the role according to its corresponding role definition provided in relation's relation type
Will send a notification (RelationNotification with type RELATION_BASIC_UPDATE or RELATION_MBEAN_UPDATE, depending if the relation is a MBean or not).
- Specified by:
setRole
in interfaceRelation
- Parameters:
role
- role to be set (name and new value)- Throws:
IllegalArgumentException
- if null roleRoleNotFoundException
- if there is no role with the supplied role's name or if the role is not writable (no test on the write access mode performed when initializing the role)InvalidRoleValueException
- if value provided for role is not valid, i.e.:- 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
- a MBean provided for that role does not exist
RelationServiceNotRegisteredException
- if the Relation Service is not registered in the MBean ServerRelationTypeNotFoundException
- if the relation type has not been declared in the Relation ServiceRelationNotFoundException
- if the relation has not been added in the Relation Service.- See Also:
getRole(java.lang.String)
-
setRoles
public RoleResult setRoles(RoleList list) throws IllegalArgumentException, RelationServiceNotRegisteredException, RelationTypeNotFoundException, RelationNotFoundException
Sets the given roles.Will check the role according to its corresponding role definition provided in relation's relation type
Will send one notification (RelationNotification with type RELATION_BASIC_UPDATE or RELATION_MBEAN_UPDATE, depending if the relation is a MBean or not) per updated role.
- Specified by:
setRoles
in interfaceRelation
- Parameters:
list
- list of roles to be set- Returns:
- a RoleResult object, including a RoleList (for roles successfully set) and a RoleUnresolvedList (for roles not set).
- Throws:
IllegalArgumentException
- if null role listRelationServiceNotRegisteredException
- if the Relation Service is not registered in the MBean ServerRelationTypeNotFoundException
- if the relation type has not been declared in the Relation Service.RelationNotFoundException
- if the relation MBean has not been added in the Relation Service.- See Also:
getRoles(java.lang.String[])
-
handleMBeanUnregistration
public void handleMBeanUnregistration(ObjectName objectName, String roleName) throws IllegalArgumentException, RoleNotFoundException, InvalidRoleValueException, RelationServiceNotRegisteredException, RelationTypeNotFoundException, RelationNotFoundException
Callback used by the Relation Service when a MBean referenced in a role is unregistered.The Relation Service will call this method to let the relation take action to reflect the impact of such unregistration.
BEWARE. the user is not expected to call this method.
Current implementation is to set the role with its current value (list of ObjectNames of referenced MBeans) without the unregistered one.
- Specified by:
handleMBeanUnregistration
in interfaceRelation
- Parameters:
objectName
- ObjectName of unregistered MBeanroleName
- name of role where the MBean is referenced- Throws:
IllegalArgumentException
- if null parameterRoleNotFoundException
- if role does not exist in the relation or is not writableInvalidRoleValueException
- if role value does not conform to the associated role info (this will never happen when called from the Relation Service)RelationServiceNotRegisteredException
- if the Relation Service is not registered in the MBean ServerRelationTypeNotFoundException
- if the relation type has not been declared in the Relation Service.RelationNotFoundException
- if this method is called for a relation MBean not added in the Relation Service.
-
getReferencedMBeans
public Map<ObjectName,List<String>> getReferencedMBeans()
Retrieves MBeans referenced in the various roles of the relation.- Specified by:
getReferencedMBeans
in interfaceRelation
- Returns:
- a HashMap mapping:
ObjectName -> ArrayList of String (role names)
-
getRelationTypeName
public String getRelationTypeName()
Returns name of associated relation type.- Specified by:
getRelationTypeName
in interfaceRelation
- Returns:
- the name of the relation type.
-
getRelationServiceName
public ObjectName getRelationServiceName()
Returns ObjectName of the Relation Service handling the relation.- Specified by:
getRelationServiceName
in interfaceRelation
- Returns:
- the ObjectName of the Relation Service.
-
getRelationId
public String getRelationId()
Returns relation identifier (used to uniquely identify the relation inside the Relation Service).- Specified by:
getRelationId
in interfaceRelation
- Returns:
- the relation id.
-
preRegister
public 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.- Specified by:
preRegister
in interfaceMBeanRegistration
- Parameters:
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 thecreateMBean
orregisterMBean
methods in theMBeanServer
interface is null. In that case, this method must return a non-null ObjectName for the new MBean.- Returns:
- The name under which the MBean is to be registered.
This value must not be null. If the
name
parameter is not null, it will usually but not necessarily be the returned value. - Throws:
Exception
- This exception will be caught by the MBean Server and re-thrown as anMBeanRegistrationException
.
-
postRegister
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 anError
, the MBean Server will rethrow those inside aRuntimeMBeanException
orRuntimeErrorException
, respectively. However, throwing an exception inpostRegister
will not change the state of the MBean: if the MBean was already registered (registrationDone
istrue
), the MBean will remain registered.This might be confusing for the code calling
createMBean()
orregisterMBean()
, as such code might assume that MBean registration has failed when such an exception is raised. Therefore it is recommended that implementations ofpostRegister
do not throw Runtime Exceptions or Errors if it can be avoided.- Specified by:
postRegister
in interfaceMBeanRegistration
- Parameters:
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.
-
preDeregister
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.- Specified by:
preDeregister
in interfaceMBeanRegistration
- Throws:
Exception
- This exception will be caught by the MBean server and re-thrown as anMBeanRegistrationException
.
-
postDeregister
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 anError
, the MBean Server will rethrow those inside aRuntimeMBeanException
orRuntimeErrorException
, respectively. However, throwing an exception inpostDeregister
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 ofpostDeregister
do not throw Runtime Exceptions or Errors if it can be avoided.- Specified by:
postDeregister
in interfaceMBeanRegistration
-
isInRelationService
public Boolean isInRelationService()
Returns an internal flag specifying if the object is still handled by the Relation Service.- Specified by:
isInRelationService
in interfaceRelationSupportMBean
- Returns:
- a Boolean equal to
Boolean.TRUE
if the object is still handled by the Relation Service andBoolean.FALSE
otherwise.
-
setRelationServiceManagementFlag
public void setRelationServiceManagementFlag(Boolean flag) throws IllegalArgumentException
Description copied from interface:RelationSupportMBean
Specifies whether this relation is handled by the Relation Service.
BEWARE, this method has to be exposed as the Relation Service will access the relation through its management interface. It is RECOMMENDED NOT to use this method. Using it does not affect the registration of the relation object in the Relation Service, but will provide wrong information about it!
- Specified by:
setRelationServiceManagementFlag
in interfaceRelationSupportMBean
- Parameters:
flag
- whether the relation is handled by the Relation Service.- Throws:
IllegalArgumentException
- if null parameter
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
18/12/2024 17:14:30 Cette version de la page est en cache (à la date du 18/12/2024 17:14:30) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 31/08/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-javax/management/relation/relationsupport.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.