CORBA原理简介与实例

发布时间 : 星期一 文章CORBA原理简介与实例更新完毕开始阅读

void postinvoke(

in ObjectId oid, in POA adapter,

in CORBA::Identifier operation, in Cookie the_cookie, in Servant the_servant );

};

// POA interface interface POA {

# pragma version POA 2.3

exception AdapterAlreadyExists {};

exception AdapterNonExistent {};

exception InvalidPolicy {unsigned short index;}; exception NoServant {};

exception ObjectAlreadyActive {}; exception ObjectNotActive {};

exception ServantAlreadyActive {}; exception ServantNotActive {}; exception WrongAdapter {}; exception WrongPolicy {}; // POA creation and destruction POA create_POA( in string adapter_name,

in POAManager a_POAManager,

in CORBA::PolicyList policies)

raises (AdapterAlreadyExists, InvalidPolicy); POA find_POA(

in string adapter_name, in boolean activate_it) raises (AdapterNonExistent); void destroy(

in boolean etherealize_objects, in boolean wait_for_completion); // Factories for Policy objects

ThreadPolicy create_thread_policy( in ThreadPolicyValue value); LifespanPolicy create_lifespan_policy( in LifespanPolicyValue value);

IdUniquenessPolicy create_id_uniqueness_policy( in IdUniquenessPolicyValue value);

IdAssignmentPolicy create_id_assignment_policy( in IdAssignmentPolicyValue value);

ImplicitActivationPolicy create_implicit_activation_policy(

in ImplicitActivationPolicyValue value);

ServantRetentionPolicy create_servant_retention_policy( in ServantRetentionPolicyValue value);

RequestProcessingPolicy create_request_processing_policy( in RequestProcessingPolicyValue value); // POA attributes

readonly attribute string the_name; readonly attribute POA the_parent;

readonly attribute POAList the_children;

readonly attribute POAManager the_POAManager; attribute AdapterActivator the_activator; // Servant Manager registration: ServantManager get_servant_manager() raises (WrongPolicy); void set_servant_manager( in ServantManager imgr)

raises (WrongPolicy);

// operations for the USE_DEFAULT_SERVANT policy Servant get_servant()

raises (NoServant, WrongPolicy); void set_servant(in Servant p_servant) raises (WrongPolicy);

// object activation and deactivation ObjectId activate_object( in Servant p_servant)

raises (ServantAlreadyActive, WrongPolicy); void activate_object_with_id(

in ObjectId id,

in Servant p_servant)

raises ( ServantAlreadyActive, ObjectAlreadyActive, WrongPolicy); void deactivate_object( in ObjectId oid)

raises (ObjectNotActive, WrongPolicy); // reference creation operations Object create_reference (

in CORBA::RepositoryId intf) raises (WrongPolicy);

Object create_reference_with_id ( in ObjectId oid,

in CORBA::RepositoryId intf) raises (WrongPolicy); // Identity mapping operations: ObjectId servant_to_id( in Servant p_servant)

raises (ServantNotActive, WrongPolicy); Object servant_to_reference( in Servant p_servant)

raises (ServantNotActive, WrongPolicy); Servant reference_to_servant( in Object reference)

raises(ObjectNotActive, Wrongpolicy); ObjectId reference_to_id( in Object reference)

raises (WrongAdapter, WrongPolicy); Servant id_to_servant( in ObjectId oid)

raises (ObjectNotActive, WrongPolicy); Object id_to_reference(in ObjectId oid) raises (ObjectNotActive, WrongPolicy); };

// Current interface

interface Current : CORBA::Current { # pragma version Current 2.3 exception NoContext { }; POA get_POA() raises (NoContext);

ObjectId get_object_id() raises (NoContext); }; };

ORB核心实现数据流程

一、

1.

公共结构:

对象实现注册文件

包括“服务标识”、“IP地址”、“端口号”、POA标识符(POA接口中的the_name属性) 2.

服务标识_POA映射表 struct service_poa { string identifier; POA poa_name; string Object_Id;

}

3. POA内部活跃对象映射表

Struct active_oid {

string Object_Id;

Servant servant_name;

}

typedef sequence active_oid_table 4. Object_Id

string Object_Id; 它的内部格式为:“IP : port : identifier(服务标识)”

5. Object类型(对象引用)中应该增加

Poa poa_name;

Servant servant_name 两个属性项

6. Request类型中也应该增加

Poa poa_name; Servant servant_name 两个属性项

二、 服务方提供某服务(对象实现)后注册过程:

1.服务方根据orb核心所在机器的IP和注册文件的名字查找该文件中对应的是否有这么一项记录:服务标识 该服务方机器的IP和提供该项服务的端口 对应的POA名 2.如果没有,则要写入该记录,然后转3; 如果有,直接进入3

3.根据2中记录中的POA名,由rootpoa.thechildren得到POA对象的句柄,然后调用该POA的方法创建OID和Servant,并将该OID和Servant写入活跃对象映射表; 4.根据2中记录中的POA名和服务标识名,在服务标识_POA映射表中写入相应的记录。 三、 ORB核心初始化后的相关操作流程:

1. ORB初始化

2. 创建根POA(rootpoa)

3. 由根POA创建所有要使用到的POA(在本项目中只有一个POA),并创建相应的POAManager(一一对应关系),将其由保持状态转换为活跃状态 4. POA查找注册文件中与之相关的记录中对象实现是否处于活跃状态

如果处于活跃状态,则根据该记录的信息调用该POA的方法创建OID和Servant,并将该OID和Servant写入活跃对象映射表,然后转5; 如果处于失活状态,则直接转6;

5. 在服务标识_POA映射表中写入相应的记录:标识该POA、OID和服务标识。

四、

6. 如果不止一个POA转4接着做;如果只有一个POA结束。 客户端对象引用的获得过程:(resolve_initial_references( ) ) 1. 客户端程序向ORB核心提交一个请求服务的服务标识identifier 2. ORB核心在服务标识_POA映射表中查找对应该服务标识的POA, 如果找到POA,则转3;

如果未找到POA,则转4;

3. 由POA和OID找到活跃对象映射表中的对应仆从,并生成一个对象引用实例,返回给客户端,转5;

4.说明没有请求所要求的服务处于活跃状态,返回异常,说明该服务目前不可获得,转5;

联系合同范文客服:xxxxx#qq.com(#替换为@)