【java】Naming.bindとRegistry.bindの違い

1130 ワード

  • NamingクラスとRegistryクラスはjavaにあります.rmiパッケージ
  • NamingクラスはURIを解析してリモートオブジェクトをバインドし、URIをホスト、ポート、およびリモートオブジェクト名に分割します.Registryクラスは使用されます.
  •  public static Remote lookup(String name)
            throws NotBoundException,
                java.net.MalformedURLException,
                RemoteException
        {
            ParsedNamingURL parsed = parseURL(name);
            Registry registry = getRegistry(parsed);
    
            if (parsed.name == null)
                return registry;
            return registry.lookup(parsed.name);
        }
    
     public static void bind(String name, Remote obj)
            throws AlreadyBoundException,
                java.net.MalformedURLException,
                RemoteException
        {
            ParsedNamingURL parsed = parseURL(name);
            Registry registry = getRegistry(parsed);
    
            if (obj == null)
                throw new NullPointerException("cannot bind to null");
    
            registry.bind(parsed.name, obj);
        }
    
        private static Registry getRegistry(ParsedNamingURL parsed)
            throws RemoteException
        {
            return LocateRegistry.getRegistry(parsed.host, parsed.port);
        }