| 接口 | 描述 | 
|---|---|
| Relation | 
           这个接口必须由任何MBean类来实现,该类可以表示使用关系服务管理的关系。 
          | 
| RelationServiceMBean | 
           关系服务负责创建和删除关系类型和关系,处理一致性和提供查询机制。 
          | 
| RelationSupportMBean | 
           RelationSupport对象由Relation Service内部使用,用于表示任意关系类型的简单关系(只有角色,无属性或方法)以及无限数量的角色。 
          | 
| RelationType | 
           RelationType接口必须由预期表示关系类型的任何类来实现。 
          | 
| 类 | 描述 | 
|---|---|
| MBeanServerNotificationFilter | |
| RelationNotification | 
           关系服务变更通知。 
          | 
| RelationService | 
           关系服务负责创建和删除关系类型和关系,处理一致性和提供查询机制。 
          | 
| RelationSupport | 
           RelationSupport对象由Relation Service内部使用,用于表示任意关系类型的简单关系(只有角色,无属性或方法)以及无限数量的角色。 
          | 
| RelationTypeSupport | 
           RelationTypeSupport对象实现RelationType接口。 
          | 
| Role | 
           表示角色:包括角色名称和引用的MBean(通过其ObjectNames)。 
          | 
| RoleInfo | 
           RoleInfo对象总结了关系类型中的角色。 
          | 
| RoleList | 
           RoleList表示角色列表(Role对象)。 
          | 
| RoleResult | 
           表示多次访问关系的几个角色(用于阅读或写入)的结果。 
          | 
| RoleStatus | 
           此类描述访问角色时可能遇到的各种问题。 
          | 
| RoleUnresolved | 
           代表一个未解决的角色:由于问题而无法从关系中检索到的角色。 
          | 
| RoleUnresolvedList | 
           RoleUnresolvedList表示RoleUnresolved对象的列表,表示由于在尝试访问(读取或写入)角色时遇到问题,不会从关系中检索到角色。 
          | 
| 异常 | 描述 | 
|---|---|
| InvalidRelationIdException | 
           当已经使用关系id提供给关系时,引发异常。 
          | 
| InvalidRelationServiceException | 
           当提供无效的关系服务时,引发异常。 
          | 
| InvalidRelationTypeException | 
           关系类型无效 
          | 
| InvalidRoleInfoException | 
           当在角色信息中,其最小度大于其最大度时,会引发此异常。 
          | 
| InvalidRoleValueException | 
           角色值无效。 
          | 
| RelationException | 
           这个类是在关系管理期间可以提出的任何异常的超类。 
          | 
| RelationNotFoundException | 
           当关系服务中的给定关系ID没有关系时,会引发此异常。 
          | 
| RelationServiceNotRegisteredException | 
           当对关系服务进行访问并且没有注册时,会引发此异常。 
          | 
| RelationTypeNotFoundException | 
           当在关系服务中没有给定名称的关系类型时,引发异常。 
          | 
| RoleInfoNotFoundException | 
           当给定的关系类型中没有给定名称的角色信息时,会引发此异常。 
          | 
| RoleNotFoundException | 
           当关系中的角色不存在或不可读或不可设置时,引发此异常。 
          | 
 提供关系服务的定义。 关系服务用于记录MBean服务器中的MBean之间的关系。 关系服务本身就是一个MBean。 可以在MBean服务器中注册一个RelationService MBean的多个实例。 
关系类型定义了MBean之间的关系。 它包含了MBeans在关系中扮演的角色 。 通常在关系类型中至少有两个角色。
 关系是一个关系类型的命名实例,其中特定的MBean出现在角色中,由他们的ObjectName代表 。 
 例如,假设有Module MBean,表示应用程序中的模块。 DependsOn关系类型可以表示某些模块依赖于其他模块的关系,可以用于确定模块启动或停止的顺序。 DependsOn关系类型将有两个角色: dependent和dependedOn 。 
 每个角色都是键入的 ,这意味着该角色中出现的MBean必须是角色类型的一个实例。 在DependsOn示例中,这两个角色将是Module类型。 
 每个角色都有一个基数 ,它为给定的关系实例中可以出现在该角色中的MBean的数量提供下限和上限。 通常,下限和上限都是1,正好有一个MBean出现在角色中。 基数只限制每个关系实例的角色中的MBean的数量。 相同的MBean可以在任何数量的关系类型的实例中以相同的角色出现。 在DependsOn示例中,给定的模块可以依赖于许多其他模块,并且取决于许多其他模块,但任何给定的关系实例都将链接一个dependent一个dependent模块的一个dependedOn模块。 
 可以明确地创建关系类型,作为实现RelationType接口的对象,通常为RelationTypeSupport 。 或者,可以使用Relation Service的createRelationType方法隐式创建它。 
 可以明确地创建关系实例,作为实现Relation接口的对象,通常为RelationSupport 。 (A RelationSupport本身是一个有效的MBean,所以它可以在MBean服务器中进行注册,尽管这不是必需的)。或者,可以使用Relation Service的createRelation方法隐式创建关系实例。 
 DependsOn示例可能编码如下。 
  import java.util.*;
import javax.management.*;
import javax.management.relation.*;
// ...
MBeanServer mbs = ...;
// Create the Relation Service MBean
ObjectName relSvcName = new ObjectName(":type=RelationService");
RelationService relSvcObject = new RelationService(true);
mbs.registerMBean(relSvcObject, relSvcName);
// Create an MBean proxy for easier access to the Relation Service
RelationServiceMBean relSvc =
    MBeanServerInvocationHandler.newProxyInstance(mbs, relSvcName,
                                                  RelationServiceMBean.class,
                                                  false);
// Define the DependsOn relation type
RoleInfo[] dependsOnRoles = {
    new RoleInfo("dependent", Module.class.getName()),
    new RoleInfo("dependedOn", Module.class.getName())
};
relSvc.createRelationType("DependsOn", dependsOnRoles);
// Now define a relation instance "moduleA DependsOn moduleB"
ObjectName moduleA = new ObjectName(":type=Module,name=A");
ObjectName moduleB = new ObjectName(":type=Module,name=B");
Role dependent = new Role("dependent", Collections.singletonList(moduleA));
Role dependedOn = new Role("dependedOn", Collections.singletonList(moduleB));
Role[] roleArray = {dependent, dependedOn};
RoleList roles = new RoleList(Arrays.asList(roleArray));
relSvc.createRelation("A-DependsOn-B", "DependsOn", roles);
// Query the Relation Service to find what modules moduleA depends on
Map<ObjectName,List<String>> dependentAMap =
    relSvc.findAssociatedMBeans(moduleA, "DependsOn", "dependent");
Set<ObjectName> dependentASet = dependentAMap.keySet();
// Set of ObjectName containing moduleB  
    Submit a bug or feature 
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
 Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.