This section provides
an overview of the Relation Service functions and use.
What is the Relation Service?
It’s a service that allows
the representation of associations between registered Mbeans, grouped in
so-called roles.
A consistency check occurs
when setRole or setRoles method are invoked or when an MBean, referenced
in the Relation Service, is deregistered.
The Relation Service
is a listener of the MBeanServer. In case an MBean is deregistered,
all the relations referencing that MBean are updated.
The constructor of the Relation Service allows to
specify whether an immediate "purge" of the owned relations has to be performed
or not when a notification is received for the unregistration of an MBean
belonging to one of these relations. In case a purge is not performed by
default, it can be executed with the purgeRelations method.
The Relation Service
must be registered with the MBeanServer before being used.
relServiceObjName
= new ObjectName("MyDomain:description=RelationService");
mBeanServer.registerMBean(new
RelationService(true), relServiceObjName);
A simple usage scenario of
the Relation Service consists of the association of a monitor with its observed
MBean as shown in this code example.
How to create a Relation
Each Relation has to be referred
to a relation type. A relation type includes a relation type name and a list
of RoleInfo objects, which represent role information for the relation
type. Role infos include the name of the role, the name of the class of MBean(s)
expected to be referenced in a corresponding role and can also include a flag
to specify if the corresponding role can be read, a flag to specify if the corresponding
role can be set, the minimum degree for this role, i.e. the minimum number of
MBeans that must be provided, the maximum degree for the role, i.e. the maximum
number of MBeans that must be provided and, finally, the description of the
role. Here is an
example of relation type
definition.
Now it is possible to define
two kinds of relation in the Relation Service, an
internal
one using the
createRelation method, or an
external
one using the
addRelation method. Note that an external relation consists
of a registered MBean.