Java Reference
In-Depth Information
server.createMBean( "javax.management.relation."
+"RelationService",
relationServiceName,
params,
signature);
}
catch(Exception e)
{
System.out.println("Error Creating the Relation"
+ " Service MBean");
e.printStackTrace();
}
}
You create the relation service by registering the
RelationService
MBean (
javax.
management.relation.RelationService
) with the
JMXBookAgent
. The MBean con-
structor takes a single argument, a
boolean
, which indicates whether the service
should immediately purge a relation that has become invalid due to an invalid
Role
. Remember, a relation is invalid when a participating MBean of the relation
is removed from the agent. If you set this value to
true
, whenever the relation
service notices that an MBean associated with a relation has been unregistered, it
will also remove the MBean reference from the role values. If the role is no
longer valid according to the cardinality of the
RoleInfo
, the relation will also be
removed. If you set this
boolean
value to
false
, the relation will be purged only if
the
purgeRelations()
method is called on the
RelationService
MBean.
11.3.6
Adding a new relation to the relation service
You have created all the necessary MBeans and set up the services to start a rela-
tion. The final step is to instantiate an instance of the
CtlRelation
MBean and
add it to the relation service (as well as register it in the agent). Listing 11.10 cre-
ates the relation by using the
addRelation()
method of the
RelationService
MBean. Again, the listing is from the
RelationMain
class that will execute the
entire example.
Listing 11.10
createRelation() method from RelationMain
public void createRelation()
{
System.out.println("\n>>> CREATE EXTERNAL RELATION of "
+ " type myRelationType");
try
{
//register the relation MBean