JavaTM 2 Platform
Standard Ed. 6

org.omg.PortableInterceptor
接口 ORBInitializer

所有超级接口:
IDLEntity, Object, ORBInitializerOperations, Serializable

public interface ORBInitializer
extends ORBInitializerOperations, Object, IDLEntity

便于注册 interceptor 和初始化 ORB。

ORB 服务凭借 Interceptor 这一方法获得进行 ORB 处理的权力,Interceptor 实际上已成为 ORB 的一部分。因为 Interceptor 是 ORB 的一部分,所以当 ORB.init 返回 ORB 时,应该已经注册了 Interceptor。在已经调用 ORB.init 返回 Interceptor 后,不能在 ORB 上注册 Interceptor。

通过注册实现 ORBInitializer 接口的关联的 ORBInitializer 对象才能注册 Interceptor。ORB 在初始化时,应该调用每个已注册 ORBInitializer,并将用来注册其 Interceptor 的 ORBInitInfo 对象传递给该 ORB。

用 Java 注册 ORB Initializer

ORBInitializer 通过 Java ORB 属性注册。

属性名称的形式如下:

org.omg.PortableInterceptor.ORBInitializerClass.<Service>
其中 <Service> 是实现以下类的字符串名称:
org.omg.PortableInterceptor.ORBInitializer
要避免名称冲突,应使用与 DNS 名称约定相反的约定。例如,如果 X 公司有三个 initializer,则它能够定义以下属性: 在 ORB.init 期间,应该收集那些以 org.omg.PortableInterceptor.ORBInitializerClass 开头的属性,提取每个属性的 <Service> 部分,然后将该 <Service> 字符串作为类名来实例化某个对象,并对该对象调用 pre_initpost_init 方法。如果存在异常,ORB 应忽略这些异常并继续进行。

示例

例如,X 公司编写的客户端登陆可能具有以下 ORBInitializer 实现:

 package com.x.logging;
 
 import org.omg.PortableInterceptor.Interceptor; 
 import org.omg.PortableInterceptor.ORBInitializer; 
 import org.omg.PortableInterceptor.ORBInitInfo; 
 
 public class LoggingService implements ORBInitializer { 
     void pre_init( ORBInitInfo info ) { 
         // Instantiate the Logging Service s Interceptor. 
         Interceptor interceptor = new LoggingInterceptor(); 

         // Register the Logging Service s Interceptor. 
         info.add_client_request_interceptor( interceptor ); 
     } 
 
     void post_init( ORBInitInfo info ) { 
         // This service does not need two init points. 
     } 
 } 
要运行使用此日志记录服务的名为 MyApp 的程序,用户可以键入:
java -Dorg.omg.PortableInterceptor.ORBInitializerClass.com.x.Logging.LoggingService MyApp

注册 Interceptor 的有关注意事项:

每个 ORB 都要注册请求 Interceptor。

要获得虚拟的针对对象的 Interceptor,应在截取点内的目标上查询策略以确定它们是否应该执行某些操作。

要获得虚拟的针对 POA 的 Interceptor,应使用不同的 ORB 实例化每个 POA。虽然在管理上 Interceptor 是有序的,但注册 Interceptor 时并不需要按顺序进行。请求 Interceptor 参与服务上下文。服务上下文没有顺序,因此请求 Interceptor 也没有必要有顺序。IOR Interceptor 参与带标记的组件。带标记的组件没有顺序,因此 IOR Interceptor 也没有必要有顺序。

注册代码应该避免使用 ORB(即使用提供的 orb_id 调用 ORB.init)。因为注册发生在初始化 ORB 期间,对出于此状态的 ORB 进行调用的结果是不确定的。

另请参见:
ORBInitInfo

方法摘要
 
从接口 org.omg.PortableInterceptor.ORBInitializerOperations 继承的方法
post_init, pre_init
 
从接口 org.omg.CORBA.Object 继承的方法
_create_request, _create_request, _duplicate, _get_domain_managers, _get_interface_def, _get_policy, _hash, _is_a, _is_equivalent, _non_existent, _release, _request, _set_policy_override
 


JavaTM 2 Platform
Standard Ed. 6

提交错误或意见

版权所有 2008 Sun Microsystems, Inc. 保留所有权利。请遵守GNU General Public License, version 2 only