Posted by: smallonely | December 3, 2003

[CORBA] POA 介面 – (3) More POA architecture

POAManagers

必須有一種處理the load on POAs and servants 的方法,
原因是在同一個時間上可能有大量的物件向一個物件發出請求。

POAManager 接收請求並依賴於它的運行狀態把請求發送到它們的 POA。
一個 POAManager 可以有 4 個運行狀態:
活躍(active)、終止(inactive)、保持(holding)、丟棄(discarding)。

in the active state, requests are send to POAs
in the holding state, requests are queued till the POAManager gets back to
the active state
in the discarding state, request are simply thrown out

一般時候,你不需要自己寫 POAManager 的實現 :你可以用下面的介面來使用
RootPOA 的 POAManager :

module PortableServer {
interface POA {

POA create_POA (in string adapter_name,
in POAManager a_POAManager,
in CORBA::PolicyList policies)
raises (AdapterAllreadyExists,
InvalidPolicy);
void destroy (in boolean etherealize_objects,
in boolean wait_for_completion);
POA find_poa (in string adapter_name,
in POAManager a_POAManager
in CORBA::PolicyList ListPolicies);

readonly attribute POA the_parent;
readonly attribute string the_name;
readonly attribute POAManager the_POAManager;
};
};

with :

PortableServer_POA root_poa;
PortableServer_POAManager root_poa_manager;
root_poa = CORBA_ORB_resolve_initial_references (orb,
“RootPOA”,
&ev);
root_poa_manager = PortableServer_POA_get_the_POAManager (root_poa,
&ev);

PortableServer_POA_create_poa (root_poa, “my_own_poa”,
root_poa_manager,
NULL,
&ev);

一個 POA 總是作為另一個 POA 的子 POA 創建的,RootPOA 是 POA 樹的根。
假設你知道的 POA 的名字,通過在 find_poa 方法可以找到特定的一個子 POA。

The the_parent attribute holds the parent POA,
and the the_name attribute holds the POA name assigned with the create_poa
method.
destroy_poa will destroy the POA passed as parameter but also all of its children.

(有點廢話 :p)

To hold your servants, it is thus a good idea to create a child POA of the
RootPOA and use it as the default_poa member of the _base_epv of your
servants.

POA Policies

對於每個 POA 還關聯著一系列Policies, 策略允許你非常精確的控制你的 POA 的生存
,死亡,重生…
每個 POA 由 PortableServer_POA_createPOA 的參數 CORBA::PolicyList policies
給予他的 policies

Each POA is given its policies upon creation through the in CORBA::PolicyList
policies parameter of the PortableServer_POA_createPOA function.

如果傳遞的是一個 NULL 參數,使用default 的策略。

Policy type Possible values(default)
————————————————————
ThreadPolicy ORB_CTRL_MODEL, SINGLE_THREAD_MODEL
In SINGLE_THREAD, only one POA thread may exist.

LifespanPolicy TRANSIENT, PERSISTENT
In TRANSIENT mode, object implementations will disappear with
their POA. Otherwise, a new POA is created when necessary.

ObjectIdUniqueness
UNIQUE_ID, MULTIPLE_ID
在給定的一個 POA 中每個物件都有一個唯一的 ObjectId。

IdAssignmentPolicy
USER_ID, SYSTEM_ID
由用戶或由系統給出 ObjectId。
例如: 對於一個給定的 POA,你可以使用下面的兩個函數之一:
activate_object 或 activate_object_with_id 。

ServantRetentionPolicy
RETAIN, NON_RETAIN
In NON RETAIN mode, a request to a servant already processing
another request will throw an ObjectNotExist exception.

RequestProcessingPolicy
USE_ACTIVE_OBJECT_MAP_ONLY,
USE_DEFAULT_SERVANT, USE_SERVANT_MANAGER
Any request to a servant not found in the POA map will result
in either a call to a default servant, an ObjectNotExist
exception or a request to the Servant Manager to create the
requested servant.

ImplicitActivationPolicy
IMPLICIT_ACTIVATION, NO_IMPLICIT_ACTIVATION
如果使用 NO_IMPLICIT_ACTIVATION ,編程者將需要啟動所有的建立的
servant。

These policy objects should be created with the following calls which are
part of the POA interface.

module PortableServer {
interface POA {

ThreadPolicy create_thread_policy (in ThreadPolicyValue value);
LifespanPolicy create_lifespan_policy (in LifespanPolicyValue value);
IdUniquenessPolicy create_id_uniqueness_policy
(in IdUniquenessPolicyValue value);
IdAssignementPolicy create_id_assignment_policy
(in IdAssignmentPolicyValue value);
ImplicitActivationPolicy create_implicit_activation_policy
(in ImplicitActivationPolicyValue value);
ServantRetentionPolicy create_servant_retention_policy
(in ServantRetentionPolicyValue value);
ProcessingPolicy create_processing_policy
(in ProcessingPolicyValue value);
};
};

這些policies都應該被放在 CORBA::PolicyList 中並傳遞給 create_poa 函數,用來以
正確的policies建立 POA。這一系列policies給與programmer強大的server programming
,這是因programmer可以精確的描述伺服器的行為,並可以控制伺服器的load。下面是
建立一個使用這些策略的 POA 的樣例代碼。注意當在一個 PolicyList 中的某個policy
不存在的時候,為在在前面表格中陳述的default 值。

// idl Policy Object
module CORBA {
typedef unsigned long PolicyType;
interface Policy
{
readonly attribute PolicyType policy_type;
Policy copy();
void destroy();
};

typedef sequence <Policy> PolicyList;
};

舉例而言:

/* C code building a PolicyList object */

CORBA_Policy policies[2];
CORBA_PolicyList list = {2, 2, policies};

policies[1] = PortableServer_POA_create_Id_Uniqueness_Policy (MULTIPLE_ID,
&ev);
policies[2] = PortableServer_POA_create_Id_Assignment_Policy (USER_ID,
&ev);
PortableServer_POA_create_poa (poa,
“my_poa”,
poa_manager,
list,
&ev);

CORBA_Policy_destroy (policies[1]);
CORBA_Policy_destroy (policies[2]);


我願陪你流浪 陪你飛翔 陪你尋找你的方向
有你的地方 就是我的家鄉

夫兵者不祥之器物或惡之故有道者不處君子居則貴左用兵則貴右兵者不祥之器非君子
之器不得已BBS telnet://wretch.twbbs.org 開個人板 超快 不用連署得志於天下
矣吉事尚左凶事尚右偏將軍居左上將軍居右言以喪禮處之殺人之眾以哀悲泣之戰勝以
喪禮處之道常無名樸雖小天下莫能臣侯王若能守之萬物將自賓天地相合以降甘露民莫
之令而自均始制有名名亦既有夫亦將知止知止可以不殆譬道pcs.csie.nctu.edu.tw海






—–


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: