オブジェクトサーバは,まずResolverにバインドし,次にregister_urlメソッドまたはforce_register_urlメソッドを使用してURLをオブジェクトのIORに対応させることによってオブジェクトを登録します。まだURLがオブジェクトのIORに対応づけがされていなければ対応させるためにregister_urlを使用します。force_register_urlメソッドを使用すると,URLがオブジェクトにバインドされていてもいなくても,URLをそのオブジェクトのIORに対応させます。これに対して同じ状況でregister_urlメソッドを使用すると,AlreadyExists例外が発生します。利用できるすべてのメソッドについては,マニュアル「Borland Enterprise Server VisiBroker プログラマーズリファレンス」の「URLネーミングインタフェースとクラス(Java)」の記述を参照してください。
サーバ側でのこの機能の使用例については,コードサンプル26-1を参照してください。ここに示すサンプルでは,force_register_urlを使用しています。force_register_urlが成功するには,WebサーバによってHTTP PUTコマンドの発行が許可されている必要があります。この章で示すサンプルのコードは,Borland Enterprise Server VisiBrokerをインストールしたディレクトリのexamples/vbe/basic下のbank_URLに入っています。
. . .
public class Server {
public static void main(String[ ] args) {
if (args.length == 0) {
System.out.println("Usage: vbj Server <URL string>");
return;
}
String url = args[0];
try {
// Initialize the ORB.
org.omg.CORBA.ORB orb =
org.omg.CORBA.ORB.init(args,null);
// get a reference to the rootPOA
POA rootPOA = POAHelper.narrow(
orb.resolve_initial_references("RootPOA"));
// Create the servant
AccountManagerImpl managerServant =
new AccountManagerImpl();
// Decide on the ID for the servant
byte[ ] managerId = "BankManager".getBytes();
// Activate the servant with the ID on myPOA
rootPOA.activate_object_with_id(managerId,
managerServant);
// Activate the POA manager
rootPOA.the_POAManager().activate();
// Create the object reference
org.omg.CORBA.Object manager =
rootPOA.servant_to_reference(managerServant);
// Obtain the URLNaming Resolver
Resolver resolver = ResolverHelper.narrow(
orb.resolve_initial_references(
"URLNamingResolver"));
// Register the object reference (overwrite
// if exists)
resolver.force_register_url(url, manager);
System.out.println(manager + " is ready.");
// Wait for incoming requests
orb.run();
} catch (Exception e) {
e.printStackTrace();
}
}
}
このコードサンプルでは,args[0]は次の形式になっています。
http://<host_name>:<http_server_port>/
<ior_file_path>/<ior_file_name>
ior_file_nameは,文字列化されたオブジェクトリファレンスが格納されているユーザ指定のファイル名です。ior_file_nameの接尾語は,ゲートキーパーがHTTPサーバの代わりに使用される場合は.iorである必要があります。ゲートキーパーとそのデフォルトのポート番号を使用した例は次のとおりです。
http://mars:15000/URLNaming/Bank_Manager.ior