【java】Naming.bind和Registry.bind区别

  1. Naming类和Registry类均在java.rmi包
  2. Naming类通过解析URI绑定远程对象,将URI拆分成主机、端口和远程对象名称,使用的仍是Registry类。

java
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);
}
posted @ 2017-01-07 09:33  每日懂一点  阅读(1244)  评论(0编辑  收藏  举报