1. /*
  2. * @(#)Relation.java 1.21 04/02/10
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.management.relation;
  8. import java.util.List;
  9. import java.util.Map;
  10. import javax.management.ObjectName;
  11. import javax.management.InstanceNotFoundException;
  12. import javax.management.ReflectionException;
  13. /**
  14. * This interface has to be implemented by any MBean class expected to
  15. * represent a relation managed using the Relation Service.
  16. * <P>Simple relations, i.e. having only roles, no properties or methods, can
  17. * be created directly by the Relation Service (represented as RelationSupport
  18. * objects, internally handled by the Relation Service).
  19. * <P>If the user wants to represent more complex relations, involving
  20. * properties and/or methods, he has to provide his own class implementing the
  21. * Relation interface. This can be achieved either by inheriting from
  22. * RelationSupport class, or by implementing the interface (fully or delegation to
  23. * a RelationSupport object member).
  24. * <P>Specifying such user relation class is to introduce properties and/or
  25. * methods. Those have to be exposed for remote management. So this means that
  26. * any user relation class must be a MBean class.
  27. *
  28. * @since 1.5
  29. */
  30. public interface Relation {
  31. /**
  32. * Retrieves role value for given role name.
  33. * <P>Checks if the role exists and is readable according to the relation
  34. * type.
  35. *
  36. * @param theRoleName name of role
  37. *
  38. * @return the ArrayList of ObjectName objects being the role value
  39. *
  40. * @exception IllegalArgumentException if null role name
  41. * @exception RoleNotFoundException if:
  42. * <P>- there is no role with given name
  43. * <P>- the role is not readable.
  44. * @exception RelationServiceNotRegisteredException if the Relation
  45. * Service is not registered in the MBean Server
  46. *
  47. * @see #setRole
  48. */
  49. public List getRole(String theRoleName)
  50. throws IllegalArgumentException,
  51. RoleNotFoundException,
  52. RelationServiceNotRegisteredException;
  53. /**
  54. * Retrieves values of roles with given names.
  55. * <P>Checks for each role if it exists and is readable according to the
  56. * relation type.
  57. *
  58. * @param theRoleNameArray array of names of roles to be retrieved
  59. *
  60. * @return a RoleResult object, including a RoleList (for roles
  61. * successfully retrieved) and a RoleUnresolvedList (for roles not
  62. * retrieved).
  63. *
  64. * @exception IllegalArgumentException if null role name
  65. * @exception RelationServiceNotRegisteredException if the Relation
  66. * Service is not registered in the MBean Server
  67. *
  68. * @see #setRoles
  69. */
  70. public RoleResult getRoles(String[] theRoleNameArray)
  71. throws IllegalArgumentException,
  72. RelationServiceNotRegisteredException;
  73. /**
  74. * Returns the number of MBeans currently referenced in the given role.
  75. *
  76. * @param theRoleName name of role
  77. *
  78. * @return the number of currently referenced MBeans in that role
  79. *
  80. * @exception IllegalArgumentException if null role name
  81. * @exception RoleNotFoundException if there is no role with given name
  82. */
  83. public Integer getRoleCardinality(String theRoleName)
  84. throws IllegalArgumentException,
  85. RoleNotFoundException;
  86. /**
  87. * Returns all roles present in the relation.
  88. *
  89. * @return a RoleResult object, including a RoleList (for roles
  90. * successfully retrieved) and a RoleUnresolvedList (for roles not
  91. * readable).
  92. *
  93. * @exception RelationServiceNotRegisteredException if the Relation
  94. * Service is not registered in the MBean Server
  95. */
  96. public RoleResult getAllRoles()
  97. throws RelationServiceNotRegisteredException;
  98. /**
  99. * Returns all roles in the relation without checking read mode.
  100. *
  101. * @return a RoleList.
  102. */
  103. public RoleList retrieveAllRoles();
  104. /**
  105. * Sets the given role.
  106. * <P>Will check the role according to its corresponding role definition
  107. * provided in relation's relation type
  108. * <P>Will send a notification (RelationNotification with type
  109. * RELATION_BASIC_UPDATE or RELATION_MBEAN_UPDATE, depending if the
  110. * relation is a MBean or not).
  111. *
  112. * @param theRole role to be set (name and new value)
  113. *
  114. * @exception IllegalArgumentException if null role
  115. * @exception RoleNotFoundException if the role is not writable (no
  116. * test on the write access mode performed when initialising the role)
  117. * @exception InvalidRoleValueException if value provided for
  118. * role is not valid, i.e.:
  119. * <P>- the number of referenced MBeans in given value is less than
  120. * expected minimum degree
  121. * <P>- the number of referenced MBeans in provided value exceeds expected
  122. * maximum degree
  123. * <P>- one referenced MBean in the value is not an Object of the MBean
  124. * class expected for that role
  125. * <P>- a MBean provided for that role does not exist.
  126. * @exception RelationServiceNotRegisteredException if the Relation
  127. * Service is not registered in the MBean Server
  128. * @exception RelationTypeNotFoundException if the relation type has not
  129. * been declared in the Relation Service.
  130. * @exception RelationNotFoundException if the relation has not been
  131. * added in the Relation Service.
  132. *
  133. * @see #getRole
  134. */
  135. public void setRole(Role theRole)
  136. throws IllegalArgumentException,
  137. RoleNotFoundException,
  138. RelationTypeNotFoundException,
  139. InvalidRoleValueException,
  140. RelationServiceNotRegisteredException,
  141. RelationNotFoundException;
  142. /**
  143. * Sets the given roles.
  144. * <P>Will check the role according to its corresponding role definition
  145. * provided in relation's relation type
  146. * <P>Will send one notification (RelationNotification with type
  147. * RELATION_BASIC_UPDATE or RELATION_MBEAN_UPDATE, depending if the
  148. * relation is a MBean or not) per updated role.
  149. *
  150. * @param theRoleList list of roles to be set
  151. *
  152. * @return a RoleResult object, including a RoleList (for roles
  153. * successfully set) and a RoleUnresolvedList (for roles not
  154. * set).
  155. *
  156. * @exception IllegalArgumentException if null role name
  157. * @exception RelationServiceNotRegisteredException if the Relation
  158. * Service is not registered in the MBean Server
  159. * @exception RelationTypeNotFoundException if the relation type has not
  160. * been declared in the Relation Service.
  161. * @exception RelationNotFoundException if the relation MBean has not been
  162. * added in the Relation Service.
  163. *
  164. * @see #getRoles
  165. */
  166. public RoleResult setRoles(RoleList theRoleList)
  167. throws IllegalArgumentException,
  168. RelationServiceNotRegisteredException,
  169. RelationTypeNotFoundException,
  170. RelationNotFoundException;
  171. /**
  172. * Callback used by the Relation Service when a MBean referenced in a role
  173. * is unregistered.
  174. * <P>The Relation Service will call this method to let the relation
  175. * take action to reflect the impact of such unregistration.
  176. * <P>BEWARE. the user is not expected to call this method.
  177. * <P>Current implementation is to set the role with its current value
  178. * (list of ObjectNames of referenced MBeans) without the unregistered
  179. * one.
  180. *
  181. * @param theObjName ObjectName of unregistered MBean
  182. * @param theRoleName name of role where the MBean is referenced
  183. *
  184. * @exception IllegalArgumentException if null parameter
  185. * @exception RoleNotFoundException if role does not exist in the
  186. * relation or is not writable
  187. * @exception InvalidRoleValueException if role value does not conform to
  188. * the associated role info (this will never happen when called from the
  189. * Relation Service)
  190. * @exception RelationServiceNotRegisteredException if the Relation
  191. * Service is not registered in the MBean Server
  192. * @exception RelationTypeNotFoundException if the relation type has not
  193. * been declared in the Relation Service.
  194. * @exception RelationNotFoundException if this method is called for a
  195. * relation MBean not added in the Relation Service.
  196. */
  197. public void handleMBeanUnregistration(ObjectName theObjName,
  198. String theRoleName)
  199. throws IllegalArgumentException,
  200. RoleNotFoundException,
  201. InvalidRoleValueException,
  202. RelationServiceNotRegisteredException,
  203. RelationTypeNotFoundException,
  204. RelationNotFoundException;
  205. /**
  206. * Retrieves MBeans referenced in the various roles of the relation.
  207. *
  208. * @return a HashMap mapping:
  209. * <P> ObjectName -> ArrayList of String (role names)
  210. */
  211. public Map getReferencedMBeans();
  212. /**
  213. * Returns name of associated relation type.
  214. *
  215. * @return the name of the relation type.
  216. */
  217. public String getRelationTypeName();
  218. /**
  219. * Returns ObjectName of the Relation Service handling the relation.
  220. *
  221. * @return the ObjectName of the Relation Service.
  222. */
  223. public ObjectName getRelationServiceName();
  224. /**
  225. * Returns relation identifier (used to uniquely identify the relation
  226. * inside the Relation Service).
  227. *
  228. * @return the relation id.
  229. */
  230. public String getRelationId();
  231. }