Using the Relation Service Support Classes

In the previous section, we worked through a complete example of how to create an internal relation using an internal relation type. In this section, we will look at the same example, only we will see how to create the relation as an external relation using an external relation type. As we mentioned, the relation service provides a number of support classes that can be used for this purpose. At the risk of being a bit redundant, we will repeat the flow of the previous section as closely as possible so you can compare the internal and external relations and relation types.

Before we can create a relation, we have to create the MBean server and an instance of the relation service MBean, and then register the relation MBean with the MBean server:

try {
  MBeanServer server = MBeanServerFactory.createMBeanServer(  );
  boolean purgeImmediate = true;
  RelationService rs = new RelationService(purgeImmediate);
  ObjectName rsObjName = new ObjectName("AgentServices:name=Relation");
  server.registerMBean(rs, rsObjName);
  // . . .
} catch (Exception e) {
  // . . .
}

As we saw with an internal relation type, we next describe the roles in the relation using one or more RoleInfo objects. However, to create an external relation type, we subclass the RelationTypeSupport class and add code to the subclass constructor to create the RoleInfo objects:

            public class ConsumerSupplierRelationType extends RelationTypeSupport { public ConsumerSupplierRelationType ( ...

Get Java Management Extensions now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.