Discoveryプロトコルを使用したブートストラップ

この例では、クライアントプログラムがORBのオブジェクトマルチキャスト機能を使用して、ネットワーク上でサービスを検索することにより、プログラム自体をブートストラップします。

1 クライアント

COSネーミングを使用する代わりに、クライアントは、Group.getObjref APIを使用して「out of thin air」でマルチキャストオブジェクト参照を呼び出します。オブジェクト参照を使用して、ネットの"hello"サービスを検索します。

package discovery2;
                                                                           
import util.Util;
                                                                           
import java.util.Hashtable;
import java.net.InetAddress;
                                                                           
import javax.naming.Context;
import javax.naming.InitialContext;
                                                                           
import org.omg.CORBA.ORB;
                                                                           
import com.sssw.jbroker.api.multicast.Group;
                                                                           
import discovery.Discoverable;
import discovery.DiscovererImpl;
                                                                           
public class Client
{
    public static void main(String[] args)
    {
    |   try {
    |   |   // create the jBroker ORB
    |   |   ORB orb = ORB.init(args, null);
    |   |                                                                  
    |   |   // create the Group
    |   |   Group group = Group.createGroup(orb, InetAddress.
    |   |       getByName("230.0.0.1"), "discover");
    |   |                                                                  
    |   |   // get object reference of type Discoverable
    |   |   Discoverable discoverable = (Discoverable) group.createObjref(
    |   |       Discoverable.class);
    |   |                                                                  
    |   |   // discover hello object(s)
    |   |   discoverable.discover("hello", new DiscovererImpl());
    |   |                                                                  
    |   } catch (Exception ex) {
    |   |   ex.printStackTrace();
    |   }
    }
}
Copyright © 2000-2003, Novell, Inc.All rights reserved.