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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.