JavaTM Platform
Standard Ed. 6

javax.management.relation
类 RelationService

java.lang.Object
  继承者 javax.management.NotificationBroadcasterSupport
      继承者 javax.management.relation.RelationService
所有已实现的接口:
EventListener, MBeanRegistration, NotificationBroadcaster, NotificationEmitter, NotificationListener, RelationServiceMBean

public class RelationService
extends NotificationBroadcasterSupport
implements RelationServiceMBean, MBeanRegistration, NotificationListener

Relation Service 负责创建和删除关系类型和关系,负责处理一致性并负责提供查询机制。

它通过扩展 NotificationBroadcasterSupport 实现 NotificationBroadcaster,以便在从中移除关系时发送通知。

它实现 NotificationListener 接口,以便能够接收有关注销关系角色中引用的 MBean 的通知以及注销关系 MBean 的通知。

它实现 MBeanRegistration 接口,以便能够检索其 ObjectName 和 MBean Server。

从以下版本开始:
1.5

构造方法摘要
RelationService(boolean immediatePurgeFlag)
          构造方法。
 
方法摘要
 void addRelation(ObjectName relationObjectName)
          作为 Relation Service 中的关系添加由用户创建(且由其在 MBean Server 中注册)的 MBean。
 void addRelationType(RelationType relationTypeObj)
          作为关系类型添加给定的对象。
 Integer checkRoleReading(String roleName, String relationTypeName)
          检查给定 Role 能否以给定类型的关系进行读取。
 Integer checkRoleWriting(Role role, String relationTypeName, Boolean initFlag)
          检查给定 Role 能否以给定类型的关系进行设置。
 void createRelation(String relationId, String relationTypeName, RoleList roleList)
          创建给定关系类型的简单关系(由 RelationSupport 对象表示),并将其添加到 Relation Service 中。
 void createRelationType(String relationTypeName, RoleInfo[] roleInfoArray)
          用给定的角色信息(由 RoleInfo 对象提供)创建一个关系类型(RelationTypeSupport 对象),并将其添加到 Relation Service 中。
 Map<ObjectName,List<String>> findAssociatedMBeans(ObjectName mbeanName, String relationTypeName, String roleName)
          检索与关系中给定关系相关的 MBean。
 Map<String,List<String>> findReferencingRelations(ObjectName mbeanName, String relationTypeName, String roleName)
          检索在引用给定 MBean 的引用关系。
 List<String> findRelationsOfType(String relationTypeName)
          返回给定类型的关系的关系 id。
 List<String> getAllRelationIds()
          返回由 Relation Service 处理的所有关系的所有关系 id。
 List<String> getAllRelationTypeNames()
          检索所有已知关系类型的名称。
 RoleResult getAllRoles(String relationId)
          返回关系中存在的所有角色。
 MBeanNotificationInfo[] getNotificationInfo()
          返回一个 NotificationInfo 对象,它包含通知的 Java 类的名称和发送的通知类型。
 boolean getPurgeFlag()
          返回一个标志,以指示何时接收注销关系中引用的 MBean 的通知,指示是否必须执行关系的直接“肃清”(查找不再有效的关系),或者是否只在将显式调用 purgeRelations 方法时执行该操作。
 Map<ObjectName,List<String>> getReferencedMBeans(String relationId)
          检索关系的各种角色中引用的 MBean。
 String getRelationTypeName(String relationId)
          返回给定关系的相关关系类型的名称。
 List<ObjectName> getRole(String relationId, String roleName)
          检索给定关系中给定角色名称的角色值。
 Integer getRoleCardinality(String relationId, String roleName)
          检索给定角色中当前引用的 MBean 数。
 RoleInfo getRoleInfo(String relationTypeName, String roleInfoName)
          检索给定关系类型的给定角色名称的角色信息。
 List<RoleInfo> getRoleInfos(String relationTypeName)
          检索给定关系类型的角色信息(RoleInfo 对象)的列表。
 RoleResult getRoles(String relationId, String[] roleNameArray)
          检索给定关系中具有给定名称的角色值。
 void handleNotification(Notification notif, Object handback)
          出现 JMX 通知时调用。
 Boolean hasRelation(String relationId)
          用给定的关系 id 检查是否存在 Relation Service 中标识的关系。
 void isActive()
          检查该 Relation Service 是否处于活动状态。
 String isRelation(ObjectName objectName)
          如果已经将 MBean 作为关系添加在 Relation Service 中,则返回与给定 ObjectName 相关的关系 id。
 ObjectName isRelationMBean(String relationId)
          如果用 MBean 表示关系(由用户创建且作为 Relation Service 中的关系添加),则返回该 MBean 的 ObjectName。
 void postDeregister()
          允许 MBean 在已从 MBean 服务器注销之后执行所需要的任何操作。
 void postRegister(Boolean registrationDone)
          允许 MBean 在被注册到 MBean 服务器或注销失败后执行任何所需要的操作。
 void preDeregister()
          允许该 MBean 在从 MBean 服务器注销之前执行它所需要的任何操作。
 ObjectName preRegister(MBeanServer server, ObjectName name)
          允许 MBean 在被注册到 MBean 服务器之前执行它所需要的任何操作。
 void purgeRelations()
          肃清关系。
 void removeRelation(String relationId)
          从 Relation Service 移除给定的关系。
 void removeRelationType(String relationTypeName)
          从 Relation Service 中移除给定的关系类型。
 void sendRelationCreationNotification(String relationId)
          发送关系创建通知 (RelationNotification)。
 void sendRelationRemovalNotification(String relationId, List<ObjectName> unregMBeanList)
          发送关系移除通知 (RelationNotification)。
 void sendRoleUpdateNotification(String relationId, Role newRole, List<ObjectName> oldValue)
          发送给定关系中的角色更新通知 (RelationNotification)。
 void setPurgeFlag(boolean purgeFlag)
          设置一个标志,以指示注销关系中引用的 MBean 时是否接收通知,是否必须执行关系的直接“肃清”(查找不再有效的关系),或者是否只在显式调用 purgeRelations 方法时执行该操作。
 void setRole(String relationId, Role role)
          设置给定关系中的给定角色。
 RoleResult setRoles(String relationId, RoleList roleList)
          设置给定关系中的给定角色。
 void updateRoleMap(String relationId, Role newRole, List<ObjectName> oldValue)
          针对给定关系中给定角色的更新来处理 Relation Service 角色映射的更新。
 
从类 javax.management.NotificationBroadcasterSupport 继承的方法
addNotificationListener, handleNotification, removeNotificationListener, removeNotificationListener, sendNotification
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

RelationService

public RelationService(boolean immediatePurgeFlag)
构造方法。

参数:
immediatePurgeFlag - 指示何时接收注销关系中引用的 MBean 的通知,指示是否必须执行关系的直接“肃清”(查找不再有效的关系),或者是否只在显式调用 purgeRelations 方法时执行该操作。

true 表示立即肃清。

方法详细信息

isActive

public void isActive()
              throws RelationServiceNotRegisteredException
检查该 Relation Service 是否处于活动状态。当前的条件是,Relation Service 必须在 MBean Server 中注册。

指定者:
接口 RelationServiceMBean 中的 isActive
抛出:
RelationServiceNotRegisteredException - 如果未注册 Relation Service

preRegister

public ObjectName preRegister(MBeanServer server,
                              ObjectName name)
                       throws Exception
从接口 MBeanRegistration 复制的描述
允许 MBean 在被注册到 MBean 服务器之前执行它所需要的任何操作。如果未指定 MBean 的名称,则该 MBean 可以提供一个注册名称。如果引发任何异常,则该 MBean 不会被注册到 MBean 服务器中。

指定者:
接口 MBeanRegistration 中的 preRegister
参数:
server - 将要在其中注册该 MBean 的 MBean 服务器。
name - 该 MBean 的对象名。如果 MBeanServer 接口中的某个 createMBean 方法或 registerMBean 方法的 name 参数为 null,则此 name 也为 null。在这种情况下,此方法必须为新 MBean 返回非 null 的 ObjectName。
返回:
MBean 要被注册的名称。此值必须不为 null。如果 name 参数不为 null,则它通常但并非一定为返回值。
抛出:
Exception - MBean 服务器会捕捉此异常并以 MBeanRegistrationException 的形式重新抛出。

postRegister

public void postRegister(Boolean registrationDone)
从接口 MBeanRegistration 复制的描述
允许 MBean 在被注册到 MBean 服务器或注销失败后执行任何所需要的操作。

指定者:
接口 MBeanRegistration 中的 postRegister
参数:
registrationDone - 指示该 MBean 是否已在 MBean 服务器中成功注册。false 值意味着注册阶段已失败。

preDeregister

public void preDeregister()
                   throws Exception
从接口 MBeanRegistration 复制的描述
允许该 MBean 在从 MBean 服务器注销之前执行它所需要的任何操作。

指定者:
接口 MBeanRegistration 中的 preDeregister
抛出:
Exception - MBean 服务器会捕捉此异常并以 MBeanRegistrationException 的形式重新抛出。

postDeregister

public void postDeregister()
从接口 MBeanRegistration 复制的描述
允许 MBean 在已从 MBean 服务器注销之后执行所需要的任何操作。

指定者:
接口 MBeanRegistration 中的 postDeregister

getPurgeFlag

public boolean getPurgeFlag()
返回一个标志,以指示何时接收注销关系中引用的 MBean 的通知,指示是否必须执行关系的直接“肃清”(查找不再有效的关系),或者是否只在将显式调用 purgeRelations 方法时执行该操作。

true 表示立即肃清。

指定者:
接口 RelationServiceMBean 中的 getPurgeFlag
返回:
如果肃清是自动进行的,则返回 true。
另请参见:
setPurgeFlag(boolean)

setPurgeFlag

public void setPurgeFlag(boolean purgeFlag)
设置一个标志,以指示注销关系中引用的 MBean 时是否接收通知,是否必须执行关系的直接“肃清”(查找不再有效的关系),或者是否只在显式调用 purgeRelations 方法时执行该操作。

true 表示立即肃清。

指定者:
接口 RelationServiceMBean 中的 setPurgeFlag
参数:
purgeFlag - 标志
另请参见:
getPurgeFlag()

createRelationType

public void createRelationType(String relationTypeName,
                               RoleInfo[] roleInfoArray)
                        throws IllegalArgumentException,
                               InvalidRelationTypeException
用给定的角色信息(由 RoleInfo 对象提供)创建一个关系类型(RelationTypeSupport 对象),并将其添加到 Relation Service 中。

指定者:
接口 RelationServiceMBean 中的 createRelationType
参数:
relationTypeName - 关系类型的名称
roleInfoArray - 角色信息的数组
抛出:
IllegalArgumentException - 如果参数为 null
InvalidRelationTypeException - 如果:

- 具有该名称的关系类型已经存在

- 两个不同的角色信息使用了同一个名称

- 未提供角色信息

- 提供了一个 null 角色信息


addRelationType

public void addRelationType(RelationType relationTypeObj)
                     throws IllegalArgumentException,
                            InvalidRelationTypeException
作为关系类型添加给定的对象。该对象期望实现 RelationType 接口。

指定者:
接口 RelationServiceMBean 中的 addRelationType
参数:
relationTypeObj - 关系类型对象(实现该 RelationType 接口)
抛出:
IllegalArgumentException - 如果参数为 null或者 relationTypeObj.getRelationTypeName() 返回 null。
InvalidRelationTypeException - 如果:

- 两个不同的角色用了同一个名称

- 未提供角色信息

- 提供了一个 null 角色信息

- 具有该名称的关系类型已经存在


getAllRelationTypeNames

public List<String> getAllRelationTypeNames()
检索所有已知关系类型的名称。

指定者:
接口 RelationServiceMBean 中的 getAllRelationTypeNames
返回:
关系类型名称的 ArrayList(字符串)

getRoleInfos

public List<RoleInfo> getRoleInfos(String relationTypeName)
                            throws IllegalArgumentException,
                                   RelationTypeNotFoundException
检索给定关系类型的角色信息(RoleInfo 对象)的列表。

指定者:
接口 RelationServiceMBean 中的 getRoleInfos
参数:
relationTypeName - 关系类型的名称
返回:
RoleInfo 的 ArrayList。
抛出:
IllegalArgumentException - 如果参数为 null
RelationTypeNotFoundException - 如果不存在具有该名称的关系类型。

getRoleInfo

public RoleInfo getRoleInfo(String relationTypeName,
                            String roleInfoName)
                     throws IllegalArgumentException,
                            RelationTypeNotFoundException,
                            RoleInfoNotFoundException
检索给定关系类型的给定角色名称的角色信息。

指定者:
接口 RelationServiceMBean 中的 getRoleInfo
参数:
relationTypeName - 关系类型的名称
roleInfoName - 角色的名称
返回:
RoleInfo 对象。
抛出:
IllegalArgumentException - 如果参数为 null
RelationTypeNotFoundException - 如果在 Relation Service 中的关系类型未知
RoleInfoNotFoundException - 如果该角色不是该关系类型的一部分。

removeRelationType

public void removeRelationType(String relationTypeName)
                        throws RelationServiceNotRegisteredException,
                               IllegalArgumentException,
                               RelationTypeNotFoundException
从 Relation Service 中移除给定的关系类型。

此类型的关系对象将要从 Relation Service 中移除。

指定者:
接口 RelationServiceMBean 中的 removeRelationType
参数:
relationTypeName - 要移除的关系类型名称
抛出:
RelationServiceNotRegisteredException - 如果该 Relation Service 未在 MBean Server 中注册
IllegalArgumentException - 如果参数为 null
RelationTypeNotFoundException - 如果不存在具有该名称的关系类型

createRelation

public void createRelation(String relationId,
                           String relationTypeName,
                           RoleList roleList)
                    throws RelationServiceNotRegisteredException,
                           IllegalArgumentException,
                           RoleNotFoundException,
                           InvalidRelationIdException,
                           RelationTypeNotFoundException,
                           InvalidRoleValueException
创建给定关系类型的简单关系(由 RelationSupport 对象表示),并将其添加到 Relation Service 中。

按照在参数中提供的角色列表初始化角色。将未按此方法初始化的角色设置为 ObjectName 的空 ArrayList。

发送类型为 RELATION_BASIC_CREATION 的 RelationNotification。

指定者:
接口 RelationServiceMBean 中的 createRelation
参数:
relationId - 关系标识符,用来唯一地标识 Relation Service 中的关系
relationTypeName - 关系类型的名称(必须在 Relation Service 中创建)
roleList - 要初始化该关系的角色的角色列表(可以为 null)。
抛出:
RelationServiceNotRegisteredException - 如果 Relation Service 未在 MBean Server 中注册
IllegalArgumentException - 如果参数为 null(角色列表除外,它在未进行角色初始化时可以为 null)
RoleNotFoundException - 如果为关系类型中不存在的角色提供值
InvalidRelationIdException - 如果关系 id 已经使用
RelationTypeNotFoundException - 如果在 Relation Service 中关系类型未知
InvalidRoleValueException - 如果:

- 两个不同的角色使用了同一个角色名称

- 给定值中引用的 MBean 数小于期望的最小程度

- 提供的值中引用的 MBean 数超过期望的最大程度

- 该值中引用的 MBean 的一个对象不是该角色期望的 MBean 类的对象

- 如果不存在为该角色提供的 MBean


addRelation

public void addRelation(ObjectName relationObjectName)
                 throws IllegalArgumentException,
                        RelationServiceNotRegisteredException,
                        NoSuchMethodException,
                        InvalidRelationIdException,
                        InstanceNotFoundException,
                        InvalidRelationServiceException,
                        RelationTypeNotFoundException,
                        RoleNotFoundException,
                        InvalidRoleValueException
作为 Relation Service 中的关系添加由用户创建(且由其在 MBean Server 中注册)的 MBean。

将作为关系添加 MBean,它必须遵循以下做法:

- 实现该 Relation 接口

- 具有 RelationService ObjectName,即当前 Relation Service 的 ObjectName

- 具有在当前 Relation Service 中唯一且未使用的关系 id

- 具有关系类型,即在 Relation Service 中创建的关系类型

- 具有遵循在关系类型中提供的角色信息的角色。

指定者:
接口 RelationServiceMBean 中的 addRelation
参数:
relationObjectName - 要添加的关系 MBean 的 ObjectName。
抛出:
IllegalArgumentException - 如果参数为 null
RelationServiceNotRegisteredException - 如果 Relation Service 未在 MBean Server 中注册
NoSuchMethodException - 如果 MBean 没有实现 Relation 接口
InvalidRelationIdException - 如果:

- MBean 中没有关系标识符

- 在 Relation Service 中已经使用关系标识符

InstanceNotFoundException - 如果尚未注册给定 ObjectName 的 MBean
InvalidRelationServiceException - 如果:

- MBean 中没有 Relation Service 名称

- MBean 中的 Relation Service 名称不是当前 Relation Service 的名称

RelationTypeNotFoundException - 如果:

- MBean 中没有关系类型名称

- MBean 中的关系类型名称与 Relation Service 中创建的关系类型不对应

InvalidRoleValueException - 如果:

- 角色中引用的 MBean 数小于期望的最小程度

- 角色中引用的 MBean 数超过期望的最大程度

- 该值中引用的 MBean 的一个对象不是该角色期望的 MBean 类的对象

- 为角色提供的 MBean 不存在

RoleNotFoundException - 如果为关系类型中不存在的角色提供了值

isRelationMBean

public ObjectName isRelationMBean(String relationId)
                           throws IllegalArgumentException,
                                  RelationNotFoundException
如果用 MBean 表示关系(由用户创建且作为 Relation Service 中的关系添加),则返回该 MBean 的 ObjectName。

指定者:
接口 RelationServiceMBean 中的 isRelationMBean
参数:
relationId - 标识关系的关系 id
返回:
相应关系 MBean 的 ObjectName;如果该关系不是 MBean,则返回 null。
抛出:
IllegalArgumentException - 如果参数为 null
RelationNotFoundException - 如果不存在与该 id 相关的关系

isRelation

public String isRelation(ObjectName objectName)
                  throws IllegalArgumentException
如果已经将 MBean 作为关系添加在 Relation Service 中,则返回与给定 ObjectName 相关的关系 id。

指定者:
接口 RelationServiceMBean 中的 isRelation
参数:
objectName - 假定关系的 ObjectName
返回:
关系 id(字符串);或返回 null(如果 ObjectName 不是由 Relation Service 处理的关系)
抛出:
IllegalArgumentException - 如果参数为 null

hasRelation

public Boolean hasRelation(String relationId)
                    throws IllegalArgumentException
用给定的关系 id 检查是否存在 Relation Service 中标识的关系。

指定者:
接口 RelationServiceMBean 中的 hasRelation
参数:
relationId - 标识关系的关系 id
返回:
boolean: 如果存在关系,则返回 true;否则返回 false
抛出:
IllegalArgumentException - 如果参数为 null

getAllRelationIds

public List<String> getAllRelationIds()
返回由 Relation Service 处理的所有关系的所有关系 id。

指定者:
接口 RelationServiceMBean 中的 getAllRelationIds
返回:
String 的 ArrayList

checkRoleReading

public Integer checkRoleReading(String roleName,
                                String relationTypeName)
                         throws IllegalArgumentException,
                                RelationTypeNotFoundException
检查给定 Role 能否以给定类型的关系进行读取。

指定者:
接口 RelationServiceMBean 中的 checkRoleReading
参数:
roleName - 要检查的角色名称
relationTypeName - 关系类型的名称
返回:
包装整数的 Integer,该整数对应于 RoleUnresolved 中用常量表示的可能问题:

- 如果角色可读,则用 0 表示

- 对应于 RoleStatus.NO_ROLE_WITH_NAME 的整数

- 对应于 RoleStatus.ROLE_NOT_READABLE 的整数

抛出:
IllegalArgumentException - 如果参数为 null
RelationTypeNotFoundException - 如果 Relation Service 中的关系类型未知

checkRoleWriting

public Integer checkRoleWriting(Role role,
                                String relationTypeName,
                                Boolean initFlag)
                         throws IllegalArgumentException,
                                RelationTypeNotFoundException
检查给定 Role 能否以给定类型的关系进行设置。

指定者:
接口 RelationServiceMBean 中的 checkRoleWriting
参数:
role - 要检查的角色
relationTypeName - 关系类型的名称
initFlag - 指定已完成角色的初始化检查,并且不验证写入访问的标志。
返回:
包装整数的 Integer,该整数对应于 RoleUnresolved 中用常量表示的可能问题:

- 如果角色可以设置,则用 0 表示

- 对应于 RoleStatus.NO_ROLE_WITH_NAME 的整数

- 对应于 RoleStatus.ROLE_NOT_WRITABLE 的整数

- 对应于 RoleStatus.LESS_THAN_MIN_ROLE_DEGREE 的整数

- 对应于 RoleStatus.MORE_THAN_MAX_ROLE_DEGREE 的整数

- 对应于 RoleStatus.REF_MBEAN_OF_INCORRECT_CLASS 的整数

- 对应于 RoleStatus.REF_MBEAN_NOT_REGISTERED 的整数

抛出:
IllegalArgumentException - 如果参数为 null
RelationTypeNotFoundException - 如果是未知关系类型

sendRelationCreationNotification

public void sendRelationCreationNotification(String relationId)
                                      throws IllegalArgumentException,
                                             RelationNotFoundException
发送关系创建通知 (RelationNotification)。通知类型是:

- RelationNotification.RELATION_BASIC_CREATION,如果该关系是 Relation Service 内部的一个对象

- RelationNotification.RELATION_MBEAN_CREATION,如果该关系是作为关系添加的 MBean。

源对象是 Relation Service 本身。

它在 Relation Service createRelation() 和 addRelation() 方法中调用。

指定者:
接口 RelationServiceMBean 中的 sendRelationCreationNotification
参数:
relationId - 更新的关系的关系标识符
抛出:
IllegalArgumentException - 如果参数为 null
RelationNotFoundException - 如果不存在给定关系 id 的关系

sendRoleUpdateNotification

public void sendRoleUpdateNotification(String relationId,
                                       Role newRole,
                                       List<ObjectName> oldValue)
                                throws IllegalArgumentException,
                                       RelationNotFoundException
发送给定关系中的角色更新通知 (RelationNotification)。通知类型是:

- RelationNotification.RELATION_BASIC_UPDATE,如果该关系是 Relation Service 内部的一个对象

- RelationNotification.RELATION_MBEAN_UPDATE,如果该关系是作为关系添加的 MBean。

源对象是 Relation Service 本身。

它在关系 MBean setRole()(针对给定角色)和 setRoles()(针对每个角色)方法(RelationSupport 类中提供的实现)中调用。

它还在 Relation Service setRole()(针对给定角色)和 setRoles()(针对每个角色)方法中调用。

指定者:
接口 RelationServiceMBean 中的 sendRoleUpdateNotification
参数:
relationId - 已更新关系的关系标识符
newRole - 新的角色(名称和新值)
oldValue - 旧角色值(ObjectName 对象的列表)
抛出:
IllegalArgumentException - 如果参数为 null
RelationNotFoundException - 如果不存在给定关系 id 的关系

sendRelationRemovalNotification

public void sendRelationRemovalNotification(String relationId,
                                            List<ObjectName> unregMBeanList)
                                     throws IllegalArgumentException,
                                            RelationNotFoundException
发送关系移除通知 (RelationNotification)。通知类型是:

- RelationNotification.RELATION_BASIC_REMOVAL,如果该关系是 Relation Service 内部的一个对象

- RelationNotification.RELATION_MBEAN_REMOVAL,如果该关系是作为关系添加的 MBean。

源对象是 Relation Service 本身。

它在 Relation Service removeRelation() 方法中调用。

指定者:
接口 RelationServiceMBean 中的 sendRelationRemovalNotification
参数:
relationId - 已更新关系的关系标识符
unregMBeanList - 期望因为关系移除而注销的 MBean 的 ObjectName 列表(可以为 null)
抛出:
IllegalArgumentException - 如果参数为 null
RelationNotFoundException - 如果不存在给定关系 id 的关系

updateRoleMap

public void updateRoleMap(String relationId,
                          Role newRole,
                          List<ObjectName> oldValue)
                   throws IllegalArgumentException,
                          RelationServiceNotRegisteredException,
                          RelationNotFoundException
针对给定关系中给定角色的更新来处理 Relation Service 角色映射的更新。

它在关系 MBean setRole()(针对给定角色)和 setRoles()(针对每个角色)方法(RelationSupport 类中提供的实现)中调用。

它还在 Relation Service setRole()(针对给定角色)和 setRoles()(针对每个角色)方法中调用。

为了允许 Relation Service 维护一致性(MBean 注销时)以及能够执行查询,更新角色时必须调用此方法。

指定者:
接口 RelationServiceMBean 中的 updateRoleMap
参数:
relationId - 已更新关系的关系标识符
newRole - 新的角色(名称和新的值)
oldValue - 旧角色值(ObjectName 对象的列表)
抛出:
IllegalArgumentException - 如果参数为 null
RelationServiceNotRegisteredException - 如果 Relation Service 未在 MBean Server 中注册
RelationNotFoundException - 如果没有给定 id 的关系。

removeRelation

public void removeRelation(String relationId)
                    throws RelationServiceNotRegisteredException,
                           IllegalArgumentException,
                           RelationNotFoundException
从 Relation Service 移除给定的关系。

发送 RelationNotification 通知,其类型是:

- RelationNotification.RELATION_BASIC_REMOVAL,如果该关系只在 Relation Service 内部

- RelationNotification.RELATION_MBEAN_REMOVAL,如果该关系作为 MBean 注册。

对于在这样的关系中引用的 MBean,将不执行任何操作。

指定者:
接口 RelationServiceMBean 中的 removeRelation
参数:
relationId - 要移除的关系的关系 id
抛出:
RelationServiceNotRegisteredException - 如果 Relation Service 未在 MBean Server 中注册
IllegalArgumentException - 如果参数为 null
RelationNotFoundException - 如果没有对应于给定关系 id 的关系

purgeRelations

public void purgeRelations()
                    throws RelationServiceNotRegisteredException
肃清关系。

根据 purgeFlag 值,此方法即可以在接收到关系中引用的 MBean 的注销通知时自动调用(如果将该标志设置为 true),也可以不调用(如果将该标志设置为 false)。

在此情况下,用户负责调用它来维护关系的一致性。一定要记住:如果注销 MBean 但没立即执行肃清,这时如果重新使用 ObjectName 并将其指派给关系中另一个引用的 MBean,那么手动调用此 purgeRelations() 就会出现问题,因为这样会认为此 ObjectName 就是已注销的 MBean,不把它看作新的 MBean。

该行为取决于在其中引用注销的 MBean 的角色数量:

- 如果移除角色中的一个 MBean 引用使其引用数少于最小程度,则必须移除该关系。

- 如果移除 MBean 引用后剩余的引用数仍然在该容量范围内,则保持该关系并在调用其 handleMBeanUnregistration() 回调时更新。

指定者:
接口 RelationServiceMBean 中的 purgeRelations
抛出:
RelationServiceNotRegisteredException - 如果该 Relation Service 未在 MBean Server 中注册。

findReferencingRelations

public Map<String,List<String>> findReferencingRelations(ObjectName mbeanName,
                                                         String relationTypeName,
                                                         String roleName)
                                                  throws IllegalArgumentException
检索在引用给定 MBean 的引用关系。

这对应于 CIM "Reference" 和 "ReferenceName" 操作。

指定者:
接口 RelationServiceMBean 中的 findReferencingRelations
参数:
mbeanName - MBean 的 ObjectName
relationTypeName - 可以为 null;如果已指定,则将只在搜索时考虑该类型的关系。其他情况下将考虑所有关系类型。
roleName - 可以为 null;如果已指定,则只返回将在该角色中引用的 MBean 关系。其他情况要考虑所有角色。
返回:
HashMap,密钥为在其中引用 MBean 的关系的关系 id,并且每个密钥的值是角色名称的 ArrayList(因为 MBean 可以在同一关系中的几个角色中引用)。
抛出:
IllegalArgumentException - 如果参数为 null

findAssociatedMBeans

public Map<ObjectName,List<String>> findAssociatedMBeans(ObjectName mbeanName,
                                                         String relationTypeName,
                                                         String roleName)
                                                  throws IllegalArgumentException
检索与关系中给定关系相关的 MBean。

这对应于 CIM Associator 和 AssociatorName 操作。

指定者:
接口 RelationServiceMBean 中的 findAssociatedMBeans
参数:
mbeanName - MBean 的 ObjectName
relationTypeName - 可以为 null;如果已指定,则将只在搜索时考虑该类型的关系。其他情况下将考虑所有关系类型。
roleName - 可以为 null;如果已指定,则只返回将在该角色中引用的 MBean 关系。其他情况要考虑所有角色。
返回:
HashMap,密钥是与给定 MBean 相关的 MBean 的 ObjectName,而对于每个密钥而言,该值是这种关系的关系 id 的 ArrayList:密钥 MBean 与给定的 MBean 相关(因为它们可以与几个不同的关系相关)。
抛出:
IllegalArgumentException - 如果参数为 null

findRelationsOfType

public List<String> findRelationsOfType(String relationTypeName)
                                 throws IllegalArgumentException,
                                        RelationTypeNotFoundException
返回给定类型的关系的关系 id。

指定者:
接口 RelationServiceMBean 中的 findRelationsOfType
参数:
relationTypeName - 关系类型名称
返回:
关系 id 的 ArrayList。
抛出:
IllegalArgumentException - 如果参数为 null
RelationTypeNotFoundException - 如果不存在具有该名称的关系类型。

getRole

public List<ObjectName> getRole(String relationId,
                                String roleName)
                         throws RelationServiceNotRegisteredException,
                                IllegalArgumentException,
                                RelationNotFoundException,
                                RoleNotFoundException
检索给定关系中给定角色名称的角色值。

指定者:
接口 RelationServiceMBean 中的 getRole
参数:
relationId - 关系 id
roleName - 角色名称
返回:
作为角色值的 ObjectName 对象的 ArrayList
抛出:
RelationServiceNotRegisteredException - 如果 Relation Service 未注册
IllegalArgumentException - 如果参数为 null
RelationNotFoundException - 如果没有带给定 id 的关系
RoleNotFoundException - 如果:

- 不存在具有给定名称的角色

或者

- 角色不可读。

另请参见:
setRole(java.lang.String, javax.management.relation.Role)

getRoles

public RoleResult getRoles(String relationId,
                           String[] roleNameArray)
                    throws RelationServiceNotRegisteredException,
                           IllegalArgumentException,
                           RelationNotFoundException
检索给定关系中具有给定名称的角色值。

指定者:
接口 RelationServiceMBean 中的 getRoles
参数:
relationId - 关系 id
roleNameArray - 要检索的角色名称的数组
返回:
RoleResult 对象,包括一个 RoleList(针对成功检索到的角色)和一个 RoleUnresolvedList(针对未检索到的角色)。
抛出:
RelationServiceNotRegisteredException - 如果 Relation Service 未在 MBean Server 中注册
IllegalArgumentException - 如果参数为 null
RelationNotFoundException - 如果没有带给定 id 的关系
另请参见:
setRoles(java.lang.String, javax.management.relation.RoleList)

getAllRoles

public RoleResult getAllRoles(String relationId)
                       throws IllegalArgumentException,
                              RelationNotFoundException,
                              RelationServiceNotRegisteredException
返回关系中存在的所有角色。

指定者:
接口 RelationServiceMBean 中的 getAllRoles
参数:
relationId - 关系 id
返回:
RoleResult 对象,该对象包括一个 RoleList(针对成功检索到的角色)和一个 RoleUnresolvedList(针对不可读的角色)。
抛出:
IllegalArgumentException - 如果参数为 null
RelationNotFoundException - 如果没有指定 id 的关系
RelationServiceNotRegisteredException - 如果 Relation Service 未在 MBean Server 中注册

getRoleCardinality

public Integer getRoleCardinality(String relationId,
                                  String roleName)
                           throws IllegalArgumentException,
                                  RelationNotFoundException,
                                  RoleNotFoundException
检索给定角色中当前引用的 MBean 数。

指定者:
接口 RelationServiceMBean 中的 getRoleCardinality
参数:
relationId - 关系 id
roleName - 角色名称
返回:
当前在此角色中引用的 MBean 数
抛出:
IllegalArgumentException - 如果参数为 null
RelationNotFoundException - 如果没有带指定 id 的关系
RoleNotFoundException - 如果不存在具有指定名称的角色

setRole

public void setRole(String relationId,
                    Role role)
             throws RelationServiceNotRegisteredException,
                    IllegalArgumentException,
                    RelationNotFoundException,
                    RoleNotFoundException,
                    InvalidRoleValueException
设置给定关系中的给定角色。

将按照其在关系的关系类型中提供的相应角色定义检查角色

通过处理引用的 MBean 注销,Relation Service 将跟踪更改来保持关系的一致性。

指定者:
接口 RelationServiceMBean 中的 setRole
参数:
relationId - 关系 id
role - 要设置的角色(名称和新值)
抛出:
RelationServiceNotRegisteredException - 如果 Relation Service 未在 MBean Server 中注册
IllegalArgumentException - 如果参数为 null
RelationNotFoundException - 如果不存在具有给定 id 的关系
RoleNotFoundException - 如果角色不存在或不可写
InvalidRoleValueException - 如果为角色提供的值无效:

- 给定值中引用的 MBean 数小于期望的最小程度

或者

- 提供的值中引用的 MBean 数超过期望的最大程度

或者

- 该值中引用的 MBean 的一个对象不是该角色期望的 MBean 类的对象

或者

- 如果不存在为该角色提供的 MBean

另请参见:
getRole(java.lang.String, java.lang.String)

setRoles

public RoleResult setRoles(String relationId,
                           RoleList roleList)
                    throws RelationServiceNotRegisteredException,
                           IllegalArgumentException,
                           RelationNotFoundException
设置给定关系中的给定角色。

将按照其在关系的关系类型中提供的相应角色定义来检查角色

通过处理引用的 MBean 注销,Relation Service 跟踪更改来保持关系的一致性。

指定者:
接口 RelationServiceMBean 中的 setRoles
参数:
relationId - 关系 id
roleList - 要设置的角色列表
返回:
RoleResult 对象,该对象包括一个 RoleList(针对成功设置的角色)和一个 RoleUnresolvedList(针对未成功设置的角色)。
抛出:
RelationServiceNotRegisteredException - 如果 Relation Service 未在 MBean Server 中注册
IllegalArgumentException - 如果参数为 null
RelationNotFoundException - 如果没有带给定 id 的关系
另请参见:
getRoles(java.lang.String, java.lang.String[])

getReferencedMBeans

public Map<ObjectName,List<String>> getReferencedMBeans(String relationId)
                                                 throws IllegalArgumentException,
                                                        RelationNotFoundException
检索关系的各种角色中引用的 MBean。

指定者:
接口 RelationServiceMBean 中的 getReferencedMBeans
参数:
relationId - 关系 id
返回:
一个 HashMap 映射:

ObjectName -> ArrayList of String(角色名)

抛出:
IllegalArgumentException - 如果参数为 null
RelationNotFoundException - 如果不存在给定关系 id 的关系

getRelationTypeName

public String getRelationTypeName(String relationId)
                           throws IllegalArgumentException,
                                  RelationNotFoundException
返回给定关系的相关关系类型的名称。

指定者:
接口 RelationServiceMBean 中的 getRelationTypeName
参数:
relationId - 关系 id
返回:
相关关系类型的名称。
抛出:
IllegalArgumentException - 如果参数为 null
RelationNotFoundException - 如果不存在给定关系 id 的关系

handleNotification

public void handleNotification(Notification notif,
                               Object handback)
出现 JMX 通知时调用。当前处理 MBean 的注销通知,该 MBean 可以是关系类型中引用,也可以是关系本身。

指定者:
接口 NotificationListener 中的 handleNotification
参数:
notif - 通知。
handback - 一个不透明的对象,可帮助侦听器将有关 MBean 发出者的信息(可以为 null)联系在一起。

getNotificationInfo

public MBeanNotificationInfo[] getNotificationInfo()
返回一个 NotificationInfo 对象,它包含通知的 Java 类的名称和发送的通知类型。

指定者:
接口 NotificationBroadcaster 中的 getNotificationInfo
覆盖:
NotificationBroadcasterSupport 中的 getNotificationInfo
返回:
可能的通知数组。

JavaTM Platform
Standard Ed. 6

提交错误或意见
有关更多的 API 参考资料和开发人员文档,请参阅 Java SE 开发人员文档。该文档包含更详细的、面向开发人员的描述,以及总体概述、术语定义、使用技巧和工作代码示例。

版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策