コードサンプル15-2とコードサンプル15-3に,CreationImplDefクラスとOAD.reg_implementation()メソッドを使用してサーバをOADに登録する方法を示します。この機能は独立した管理プロセスで使用されますが,オブジェクトインプリメンテーションそのもので使用する必要はありません。オブジェクトインプリメンテーションで使用する場合,これらのタスクをオブジェクトインプリメンテーションの活性化より前に実行しなければなりません。
#include "oad_c.hh"
// USE_STD_NS is a define setup by VisiBroker to use the std namespace
USE_STD_NS
int main(int argc, char* const* argv)
{
try {
// Initialize the ORB.
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
Activation::OAD_var anOAD = Activation::OAD::bind();
// Create an ImplDef
extension::CreationImplDef_var _implDef =
anOAD->create_CreationImplDef();
_implDef->repository_id = "IDL:Bank/AccountManager:1.0";
_implDef->object_name = "BankManager";
_implDef->path_name = "/user/TPBrokerV5/Server";
_implDef->activation_policy = extension::SHARED_SERVER;
try {
anOAD->reg_implementation(
*((extension::CreationImplDef*)_implDef));
} catch(const CORBA::Exception& e) {
cerr << "reg_implementation Failed:" <<endl;
cerr << e << endl;
return 1;
}
}
catch(const CORBA::Exception& e) {
cerr << e << endl;
return 1;
}
return 0;
}
// Register.java
import com.inprise.vbroker.Activation.*;
import com.inprise.vbroker.extension.*;
public class Register{
public static void main(String[ ] args) {
// Initialize the ORB.
org.omg.CORBA.ORB orb =
org.omg.CORBA.ORB.init(args,null);
// Locate an OAD
try {
OAD anOAD =
OADHelper.bind(orb);
// Create an ImplDef
CreationImplDef _implDef = new com.inprise.vbroker.
extension.CreationImplDef();
_implDef.repository_id =
"IDL:Bank/AccountManager:1.0";
_implDef.object_name = "BankManager";
_implDef.path_name = "vbj";
_implDef.id = new byte[0];
_implDef.activation_policy = com.inprise.vbroker.
extension.Policy.SHARED_SERVER;
_implDef.env = new String[0];
String[ ] str = new String[1];
str[0] = "Server";
_implDef.args = str;
try {
anOAD.reg_implementation(_implDef);
} catch (Exception e) {
System.out.println("Caught " + e);
}
}
catch (org.omg.CORBA.NO_IMPLEMENT e) {
}
}
}