21.0 Using the Relation Service

 


21.1 Relation Service : An Overview

21.2 Terms used in Relation Service

21.3 Defining Relations

21.4 Defining Role Information

21.5 Defining Relation Types

21.6 Creating Relations

21.7 Relation Service Notifications

21.8 Operations of the Relation Service


 

21.1 Relation Service : An Overview

 

Relation Service allows to define a model for relations between MBeans. A Relation is an user defined association between MBeans in specified roles. The javax.management.relation package contains classes  used for constructing an object  that represents a relation. It also contains the Relation Service,  which centralizes all operations on relations in an agent.

With the help of Relation Service, users can create, update, and remove relations. The Relation Service can also perform queries on all the relations to find related MBeans.

 

The Relation Service itself is registered as a StandardMBean with the MBeanServer, therefore enabling the Relation Service remotely Manageable. The relation service exposes an attribute called Active that is false until its MBean is registered with the MBean server. All  the operations that handle relation or role MBeans, either directly or indirectly, will throw an exception when the service is not active.

 

21.2 Terms used in Relation Service

 

Role : A named category of functionality that is performed by an MBean. A role describes the MBean objects that perform that role and is implemented by the Role class.

Role Information: Information about the role such as the name of the role, minimum and maximum number of MBeans that are allowed to perform that role. Role information is implemented by the RoleInfo class.

Relation type
: Metadata that describes the relationships between RoleInfo objects. The Relation Type interface provides information about the relation type, such as the name of the relation type and the various roles that make up that type.

Relation
: An instance of a relation type. Metadata describing the relationship between MBeans (i.e., the relation type) provides the constraints on the relation that allow the relation service to be used to ensure that the relation remains consistent at all times. Once a relation has been instantiated, it must remain consistent, or the relation service will throw an exception.

 

21.3 Defining Relations

 

A Relation is defined by a Relation Type that provides information about the roles it contains, such as their multiplicity and the class name of the MBeans satisfying the role.  A set of one or more roles defines a relation type. The relation type is a template for all relation instances that wish to associate MBeans representing its roles. The term "relation" means a specific instance of a relation that associates existing MBeans according to the roles in its defining relation type.

Defining relations involves the following steps :

Example, we can say that Students and Class are roles. Students represent the students of a class. This belongs to an MBean class. Class represents the class to which a student belongs, which is of another MBean class. We might define a relation type containing these two roles and call it Student Management:

 

Simple use-case for the example:

  1. The Management registers a student in a Class. The class already has 24 students. A check is done and it is determined that this class is allowed accommodate minimum 10 students and maximum 25 students. So, the student is registered.

  2. The Management decides to registers one more student to this class. As they have defined the number of students to be minimum 10 and maximum 25, and they are trying to add a twenty sixth, they are not allowed to add the extra student.

21.4 Defining Role Information

 

The first step involved in defining relations is to represent information about the roles.  The role information is represented by the RoleInfo class. In our example, students and class are roles.  You have to provide the following information about the roles:

To build an array of RoleInfo objects that are intended to define a relation type, you need to define a valid set of roles. All role names must be unique within the array, and none of the array’s elements should be null. Also, the minimum and maximum cardinalities must define a range of at least one integer.

 

21.5 Defining Relation Types

 

After defining the role information, the next step in defining Relations is to define a Relation Type.  This can be done by associating a name for the relation type with a non-empty array of RoleInfo objects.

 

The method createRelationType() in the Relation Service class is used to create a relation type (RelationTypeSupport object) with given role information (provided by the RoleInfo objects), and adds it in the Relation Service.

 

public void createRelationType(java.lang.String theRelTypeName, RoleInfo[] theRoleInfoArray) throws java.lang.IllegalArgumentException, InvalidRelationTypeException

 

The relation type name given by the caller must be unique among all relation type names already created in the relation service. Relations refer to this name to define their type, and the service verifies that the roles of the relation match the role information in this type.

 

The Relation Service class provides methods for managing the list of relation types it stores. The removeRelationType removes the type’s definition from the relation service and also removes all relation instances of this type.

 

21.6 Creating Relations

 

After defining role information and relation types, the next step is to create a relation. A relation is a set of roles, which fulfills all the role information of the relation type. The Role object contains a role name and value, which is the list of MBeans that fulfills the role. The RoleList object contains the set of roles used when setting a relation or getting its role values.

 

In order to create a relation, you must provide a set of roles whose values will initialize the relation correctly. The createRelation method 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. A RelationNotification, with type RELATION_BASIC_CREATION, is sent.

 

The createRelation method raises an exception, if the provided roles do not fulfill the specified relation type.

 

public void createRelation(java.lang.String theRelId,
java.lang.String theRelTypeName,
RoleList theRoleList)
throws RelationServiceNotRegisteredException,
java.lang.IllegalArgumentException,
RoleNotFoundException,
InvalidRelationIdException,
RelationTypeNotFoundException,
InvalidRoleValueException

 

The corresponding removeRelation method is also exposed for management operations. Removing a relation means that you can no longer access it through the relation service, and the isRelation operation returns false when given its relation identifier.

 

21.7 Relation Service Notifications

 

The Relation Service class 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 relation MBeans.

The Relation Service sends a Notification to all the listeners, in the following cases :

21.8 Operations of the Relation Service

 

The relation service supports to provide the following operations, in addition to creating and removing relation types and instances. The methods for the same are available in the Relation Service class.



Copyright © 1996-2004, AdventNet Inc. All Rights Reserved.