12.07.2015 Views

VisiBroker Edition

VisiBroker Edition

VisiBroker Edition

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

实 例Java:C++:Java:C++ :Java :C++ :代 码 解 释导 入 需 要 的 程 序 包为 使 用 可 移 植 接 收 器 接 口 , 其 中 必 须 包 括 相 关 的 程 序 包 或 头 文 件 。 请 注 意 : 如 果 您正 使 用 任 何 可 移 植 接 收 器 的 违 例 , 例 如 , DuplicateName 和 InvalidName, 则 您 可 以选 用 ORBInitInfoPackage。import org.omg.PortableInterceptor.*;import org.omg.PortableInterceptor.ORBInitInfoPackage.*;在 C++ 下 使 用 可 移 植 拦 截 时 所 需 要 的 头 文 件 :#include "PortableInterceptor_c.hh"#include "IOP_c.hh"现 在 , 我 们 要 从 客 户 端 开 始 , 详 细 解 释 请 求 接 收 器 各 个 部 分 是 如 何 编 写 的 。 要 载 入一 个 客 户 端 请 求 接 收 器 , 必 须 实 现 一 个 实 现 ORBInitilializer 接 口 的 类 。 就 初 始 化而 言 , 这 也 适 用 于 服 务 器 端 的 请 求 接 收 器 。 以 下 是 实 现 该 接 口 的 代 码 。public class SampleClientLoader extends org.omg.CORBA.LocalObjectimplements ORBInitializerclass SampleClientLoader : public PortableInterceptor::ORBInitializer装 载 服 务 器 请 求 接 收 器 时 所 需 要 的 对 ORBInitializer 的 适 当 的 继 承public class SampleServerLoader extends org.omg.CORBA.LocalObjectimplements ORBInitializerclass SampleServerLoader : public PortableInterceptor::ORBInitializer注 意 每 个 实 现 ORBInitializer 接 口 的 对 象 也 要 从 LocalObject 对 象 继 承 而 来 。 这 是必 需 的 , 因 为 ORBInitializer 的 IDL 定 义 使 用 local 关 键 字 。 关 于 IDL 关 键 字local 的 详 情 , 请 参 阅 第 26-1 页 " 使 用 valuetypes" 一 节 。在 ORB 的 初 始 化 过 程 中 , 每 个 请 求 接 收 器 都 是 通 过 实 现 pre_init() 接 口 而 加 入的 。 在 该 接 口 内 部 , 客 户 请 求 接 收 器 是 通 过 add_client_request_interceptor() 方法 加 入 的 。 有 关 的 客 户 请 求 接 收 器 在 加 入 ORB 前 , 必 须 实 例 化 。Java: public void pre_init(ORBInitInfo info) {try {info.add_client_request_interceptor(new SampleClientInterceptor());...C++ : public:void pre_init(PortableInterceptor::ORBInitInfo_ptr _info) {SampleClientInterceptor *interceptor = new SampleClientInterceptor;try {_info->add_client_request_interceptor(interceptor);...根 据 OMG 规 范 , 必 需 的 应 用 将 通 过 register_orb_initializer 方 法 来 注 册 各 自的 接 收 器 。 请 参 阅 第 20-33 页 " 开 发 客 户 和 服 务 器 应 用 " 一 小 节 , 以 取 得 更 详 细 的信 息 。 <strong>VisiBroker</strong> 提 供 了 一 个 可 选 的 注 册 这 些 接 收 器 的 方 法 , 即 通 过 动 态 链 接 库(DLL) 来 注 册 。 使 用 这 一 注 册 方 法 的 优 点 是 , 应 用 不 需 要 改 变 任 何 代 码 , 只 需 要改 变 它 们 的 执 行 方 法 。 在 执 行 过 程 中 , 通 过 选 择 额 外 的 选 项 , 就 可 以 注 册 和 执 行 接使 用 可 移 植 接 收 器 20-15

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!